How do you read and write data from an Aerospike cluster?


Every database has its own mechanism for reading or writing. The exact method will directly impact the performance of these operations. Aerospike has optimized for both operations to occur on the cluster at the same time. Regardless as to whether you are reading or writing to the cluster, your code will not need to worry about the state of the cluster. All the work will be handled by the Aerospike intelligent API. It will keep track of which node to connect to for the operations.

Write When you issue a write command for a key/value pair, the Aerospike API will hash the key and use its value to determine which node is the master (primary) for that key. It will then connect to the node and commit the value to memory. If the replication factor is 2 or greater, the node will then communicate with the other nodes to commit the data in memory.When these have all been committed in memory, the node returns the client as committed. If using SSDs rather than RAM to store the data, the writes will be streamed to disk for persistence.

Read When you issue a read command for a key, the Aerospike API will again hash the key and use the value to determine which node is the master for that key. It will then connect to it to get the value. No other connection is necessary, even if there are replicated copies in the database. If the master is down, the API will automatically reroute the request to a replicated copy. No changes to the client code or configuration are needed.


Shall I configure client with multiple cluster nodes or it’s enough to specify 1 node? My concern is a case when primary node goes down. Does client API gets full cluster information after first connection automatically so it will pick another node if primary one goes down?


Functionality wise, providing one node’s IP from the cluster will be enough. But in order to have failover in case that one node is down during a client restart we recommend adding the IP address for the other nodes of the cluster. Keep in mind that this is only needed at client restart. As you stated, the client will get full cluster info once first connection is made. You just need to ensure that the first connection gets made by providing additional IPs.