Chapter Eight · Problem Two
Real-Time Leaderboard
A top ten that costs next to nothing, a rank that costs 2 seconds, and the 45 minutes it takes to close the gap between them.
"Design the leaderboard for a mobile game: players see the top ten and their own rank, updated as each match ends."
The question names two things on one screen, and they are nowhere near the same size. The top ten is one answer for everyone, and an index on the score hands it over in ten entries. That is the easy half. A player's own rank is a different answer for every player, and the obvious way to get it is to count everybody above them. Most of this round is about that count.
So the problem tests whether you price a read before you choose a store. The structure that replaces the count lives in memory, and Chapter 2's Caching at Scale says how to treat that: as something you can rebuild. Its copy is asynchronous, which brings in what Chapter 4's Leaders, Followers and Everyone says such a copy loses. When one node runs out, the split comes from Chapter 3's Range, Hash and Directory, the live move from Hot Partitions, and the copy of the top ten from the local tier in Chapter 2's When the Cache Hurts.
A mid-level round is its natural home: a working design, a sorted structure once the count is pushed on, a rebuild once the restart is. The sharded global rank is the senior part. Three things are hard here: answering a rank in logarithmic time instead of counting, keeping a global rank once one node can no longer serve it, and an in-memory structure that has to survive a restart.
Put 45 minutes on a clock and sketch your version before the first lesson, down to what you think one rank costs. Scope takes the first ten minutes, First Design the next ten, Scaling It the ten after that, and Deep Dives and Curveballs the last fifteen. Whatever you drew becomes something to argue with as you read.