Design the leaderboard for an online game. Players finish matches and their score updates. Anyone can see the global top 100, and each player can see their own rank and the players just above and below them. Rankings should feel live.
Functional requirements
Submit a score after a match
Show the global top 100
Show a player's rank and neighbours
Reset the board each season
Non-functional requirements
Top 100 loads in under 50 ms
A new score is reflected within 2 seconds
Scores are not lost if a cache node restarts
Constraints and scale
20 million players
5 000 score updates per second at peak
40 000 leaderboard reads per second at peak
You will practise
Use an in-memory sorted structure for ranking
Keep a durable source of truth behind a cache
Handle read-heavy hot keys
Show 2 hints
Which data structure returns rank in O(log n)?
If the cache is wiped, how do you rebuild the board?