How can i implement one-to-many relationship on Aerospike?

relationship

#1

If I have some data like users and their comments, i can store users in one set and comments in other set. But to get comments of one user, i have to iterate all records and take exactly that user’s comments(by id), and i know that it’s slow. Or just to keep all the comments as array in one bin of user record? is it good option?


#2

Yes and no. It depends on what if you are able to limit or plan how large the number of comments and size of them would be - as well as if you expect any kind of filtering or ordering on these.

It would be simple to have the user id and a map/list of their comments attached to that record - but you then need to worry about reaching the record limit if you are using a persistent storage backed namespace (not in-memory only) FAQ - Write Block Size .

Another alternative would be to write all of the comments into their own set, and have a bin you can create a secondary index on to query against.

So questions:

  • how big is each comment/related data stored with it?
  • how many comments do you expect per user (peak)?
  • how many total users do you expect (peak)?