Voting and how to store

hello,

I need to store the relation “voting” for a topic in aerospike. What is the best approach ? This is what Ive done in redis before:

e.g.

userid=13 topicid=44

to see if user with id=13 has been voted for the topic with the id=44 Ive create following rediskey: “44:13” … and with a dummy value. So this is the fasted thing to see if an user has been voted for a topic. I can do this also for aerospike … this is a normal key/value functionality.

Now the other case. How can I see who has voted for topic id =44. For this I can do a redis.keys(‘44:*’) … a kind of wildcard search. How can I solve this in aerospike, afaik there is no wildcard search … Is it better to store a “json” in the key “44” with all users ? I dont know if areospike is good in large json structures …

Thank you very much, greets

Ledil,

Depending on the use case there are two ways to solve this in Aerospike.

  • If your cardinality of topics is low, i.e when you do query like topics = x you tend to get many rows (>10 and < 100000). The best way to solve it to be to create a record like

    key = userid:topicid bin1 = topidid

    Build secondary index on topicid. Query secondary index when lookup is needed by topic. And normal primary key get when looking up based on userid:topicid

  • If topicid is high cardinality (e.g unique key), along with solution 1 above alternative and possibly higher performance way of doing this would be to have two stores (2 sets in same namespace or 2 namespaces).

    store1

    key = userid bin1 = topidid [list]

    store 2

    key = topicid bin = userid [list]

    When updating, you may need to update both store1 and store2 (remember that the application has to take care of the fact that both the updates have made it atomically. Aerospike does not provide multi-record transactions). Then you query either store1 or store2 using primary key based on the need.

HTH

– Raj