Aerospike Read records from a particular node using secondary index
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Aerospike is a popular NoSQL database known for its scalability and performance, especially in situations requiring high throughput and low latency. Among its many features, the ability to read records based on a secondary index is particularly powerful for efficiently querying data. However, reading records from a specific node using a secondary index can be a bit tricky and requires understanding Aerospike’s architecture and query mechanisms.
Understanding Aerospike Architecture and Secondary Index
Aerospike’s architecture is distributed, consisting of several nodes that form a cluster. Data in Aerospike is partitioned across all nodes in the cluster based on a partition key derived from the primary key of each record. However, secondary indexes in Aerospike are global and not partition-specific. That is, a secondary index spans all nodes and all records, allowing queries on attributes other than the primary key.
Secondary indexes in Aerospike are typically used for queries involving non-primary key conditions. They improve the speed of searches across multiple nodes. Once a secondary index is created, it allows clients to efficiently query records based on attributes other than the primary key.
Use Case: Reading Records from a Specific Node
One of the scenarios where it might be necessary to read records from a specific node is for performance tuning or in cases of node-specific data analysis or maintenance. Here are detailed steps and considerations on how it can be accomplished:
- Identify Node ID: First, identify the node from which you wish to read data. Each node in an Aerospike cluster can be uniquely identified using a node ID.
- Record Distribution: Understand that, normally, data is evenly distributed across all nodes based on partitioning. Reading from a specific node ideally involves identifying the partitions hosted on that node and then querying records accordingly.
- Querying with Preferences: In Aerospike, the
preferread policy can be used in client APIs to direct the read to go specifically to one node. Use thesetSendKeymethod to send the user key with the record so that it is available on the server side during the query execution. - Secondary Index Query: When creating a secondary index query, normally, one would not specify a node; the query would run across all nodes. To limit this to a specific node, combine the secondary index search with the node preference configuration in the client API, ensuring that the query is directed to your target node.
Practical Example
Suppose you have a customer database where each record has attributes like CustomerID (Primary Key), Lastname, Age, and so on. You’ve created a secondary index on Age.
When you want to retrieve all records of customers aged 25 from a specific node, configure the client application like this:
Summary Table
| Feature | Detail |
| Secondary Index | Global index for non-primary key querying |
| Node-specific Querying | Achieved through prefer read policy and node identification |
| Use Cases | Performance tuning, node-specific data handling |
| Client API Requirements | Setting node preference in read/query policies |
Conclusion
Querying records from a specific node using a secondary index in Aerospike involves understanding both the database's distribution architecture and client API capabilities. While not typical, there are practical scenarios where such precise control over data querying can be beneficial.
Related reading
- After Spring Boot 2.0 migration jdbcUrl is required with driverClassName
- Algorithm for finding similar images using an index
- Algorithm identify pairwise conflicts in a set of objects, given only there is a conflict in this list oracle
- Algorithm or SQL to find where conditions for a set of columns which ensures result set has value in a particular column always 0
- Algorithm Printing the correct index for the character sequence
- Algorithm Question on File Search Indexing
- Algorithm to efficiently determine the nn element in a matrix
- Algorithm to find if there is any i so that arrayi equals i

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.