I am currently designing a UserProfile system that handles three different types of events:
- UserViewEvent
- UserSearchEvent
- UserOrderEvent
Each event includes a timestamp and either an SKU or a search keyword. I need to maintain a sorted set of these events, ordered by timestamp, with a limit of 15 entries per user.
Currently, I use Redis sorted sets (zset) to store each type of event, sorted by timestamp. While this approach works well, it requires three separate Redis calls to read the data for each event type. I am looking to optimize these Redis calls.
Here are some possible approaches I’ve considered:
-
Using Redis Hashes:
Redis hashes do not support nested sets or lists as values. This means that I would need to serialize the input before saving and perform atomic operations by reading, deserializing, and then updating the data. This can be inefficient due to a read call has to made before each write -
Using Redis Hashes with Lua Scripting:
Although using hashes with Lua scripts could potentially reduce network round-trips, it still requires extra redis calls -
Using Lua Scripts to Read All Related Sorted Sets:
Keeping the current architecture with zset but leveraging Lua scripts to read all related sorted sets in a single call. This approach could minimize the number of network round-trips by retrieving data from multiple sorted sets in one go but still internally i guess there will be multiple redis calls
Do you have any recommendations or additional approaches for optimizing this problem?