Skip to content
BytePatterns

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.

  1. Serve the top hundred as a range read from the front of the set
  2. Apply the score change to the in-memory ranked set
  3. Answer a deep rank from per-bucket counts rather than a full scan
  4. Persist the new score asynchronously to the durable store

Mini quiz

1 / 3

Reading the top hundred is a range read because:

New lessons land every few weeks

Leave an address and we will tell you when the next one is up. That is the only reason we will use it.

One address, stored so we can email you. Nothing else, ever.