I don’t know exactly which operations are faster than others, so I’m not sure what’s the way to go here…
Here’s the case: I need to store events to be sent several hours later to a bunch of users. I don’t need to store any data for these events, only a time and a recipient. I also occasionally need to be able to delete these events to prevent them from being sent. I don’t need to store more than 1 event per user. I run a cron scrip every minute that will recover the messages to send for the current time stamp / 60 (only changes every minute) from Aerospike, and send the messages to the received “recipient” values.
Adding and removing messages for users will happen a lot more often than reading the messages for a specific timestamp, but reading will result in bigger activity spikes because they will all be recovered at once.
I have 2 solutions in mind :
1st solution would be to save in memory a record with the “user_id” as PK, a bin named “recipient” containing the same user id, and a bin named “time_to_send” containing the divided timestamp value, and then create a secondary index for that “time_to_send”. In order to add or delete a message, I just need to put a new record or delete the one corresponding to the user_id key. But I’m concerned about the speed of the query on the secondary index when I read the messages…
2nd solution would be to do the opposite: Save in memory a record with the “time_to_send” as PK, and a list of “recipients”. I would use a UDF to append and remove messages from the list. But I’m concerned about the speed of execution of the LUA script.
Thanks in advance.