Best way to get X last messages from the set


What would be the most performant way to get last records in a particular set? Our use case requires us to retrieve the tail of the set, say 100 last records written.


There isn’t any notion of order in an Aerospike set or namespace. That said, if you write to the set with a TTL and that TTL is always the same, you could:

scan the set for meta data only (the meta data is in RAM on Aerospike)
Filter out the N largest TTLs
Do a batch read on these N records

This would return the N most recently updated/written records.