Design a Leaderboard
System Design Cases: lesson 18 of 20
Keep it sorted on the way in, and the top hundred is free.
Lesson 18 of 20 · 6 min
Design a Leaderboard
Step 1 of 11
Ten million players, thousands of score changes a second, and a board that must never be sorted at read time.
The Idea
Show the top hundred and a player's own rank while scores keep changing. Assume ten million players and thousands of score updates a second, so nothing may be re-sorted at read time.
Real-World Example
A scoreboard on a wall. Moving one name up is a single slide; what you avoid is recounting everybody's position from the register every time somebody scores.
The Tradeoff
A score-ordered set makes the top hundred a range read and every update a logarithmic move, all in memory, with the durable copy written behind it. Exact rank deep in the list is the part to watch: a set that keeps per-node counts answers it with another logarithmic walk, but a database index without them has to count everyone above, and a board split across shards has to ask every shard. Counting players per score bucket answers it closely enough for a fraction of the work.
Your turn
Put the steps in the right order.
- Serve the top hundred as a range read from the front of the set
- Apply the score change to the in-memory ranked set
- Answer a deep rank from per-bucket counts rather than a full scan
- Persist the new score asynchronously to the durable store
Mini quiz
1 / 3