How would you implement a leaderboard that supports multiple different ranking categories, such as by region or by game mode, efficiently in Redis?
Short answer
You would create a separate sorted set for each distinct combination of category you need to rank by, such as leaderboard:region:us or leaderboard:mode:ranked, updating a player's score in every relevant category specific sorted set whenever they earn points, letting each…
Advertisement
AModel answer
You would create a separate sorted set for each distinct combination of category you need to rank by, such as leaderboard:region:us or leaderboard:mode:ranked, updating a player's score in every relevant category specific sorted set whenever they earn points, letting each category be queried independently and efficiently without any complex filtering logic.
Example
ZADD leaderboard:global 1000 'player1' ZADD leaderboard:region:us 1000 'player1' ZADD leaderboard:mode:ranked 1000 'player1'
Real-world example
A competitive game maintains separate leaderboards for global rankings, regional rankings, and specific game mode rankings, updating a player's score across all the relevant sorted sets simultaneously whenever they complete a match.
Likely follow-ups
- What is the overhead of maintaining several sorted sets simultaneously for the same player?
- How do you keep all these separate leaderboards consistent with each other?
Related topics