Spring Boot Aerospike

Published: 2017-11-23 • Updated: 2019-09-08

What is Aerospike

Aerospike is a key value datastore Or Distributed Hashtable Or NoSQL Database written in C language. It also provides features of in-memory database so its also called in-memory NoSQL database. It basically merges the concept of in memory and No SQL database.

Support for Hybrid Architecture.

Aerospikes' hybrid architecture helps us harness the power of,

  • Flash Memory
  • Hard drives


Aerospike consists of 3 layers

  • Data/Client layer
    • Exposes API for storing and retrieving data.
    • Manages which node to be redirected to based on request coming from users.
  • Cluster layer
    • Nodes are managed at this layer.
    • Maintains the consistency of data.
  • Storage Layer
    • Flash drives and D RAMS are handled in efficient way.
    • Basically Hybrid stuff lies here.

Aerospike Installation

MAC Installation

For vagrant installation follow this URL

Docker Installation

I've used docker to install Aerospike on my machine


docker run -d --name aerospike -p 3000:3000 aerospike/aerospike-server

To bring up Management Console, run

docker run -d -p 8081:8081 mrbar42/aerospike-amc

URL: http://localhost:8081/
Then enter the IP of Aerospike container. To get IP use following command

docker inspect -f "{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" container_id

Aerospike Spring Integration


@EnableAerospikeRepositories(basePackages = "in.kamranali.aerospike.aerospike.repositories")
public class AerospikeConfig {

    AerospikeTemplate aerospikeTemplate(){
        return new AerospikeTemplate(aerospikeClient(), "test"); // test is namespace

    AerospikeClient aerospikeClient() {

        ClientPolicy clientPolicy = new ClientPolicy();
        clientPolicy.failIfNotConnected = true;
        return new AerospikeClient(clientPolicy, "localhost", 3000);


public class UserResource {

    private UserService userService;

    public List<User> getAllUsers(){

        return userService.getAllUsers();

    public List<User> create(@RequestBody final User user){

        return userService.getAllUsers();


public class UserService {

    private UserRepository userRepository;

    public List<User> getAllUsers(){

        List<User> users = new ArrayList<>();
        return users;

    public void create(User user) {



public interface UserRepository extends AerospikeRepository<User, Integer> {

User Model

public class User {

    private Integer id;
    private String name;
    private Long salary;

    public Integer getId() {
        return id;

    public void setId(Integer id) {
        this.id = id;

    public String getName() {
        return name;

    public void setName(String name) {
        this.name = name;

    public Long getSalary() {
        return salary;

    public void setSalary(Long salary) {
        this.salary = salary;


GET http://localhost:8080/rest/users

POST http://localhost:8080/rest/users { "id": 1, "name": "Kamran", "salary": 1234 }

To access the full working code sample, click here


Share this Post