Pebble Games asks for a live leaderboard. The fictional scale is 5,000,000 ranked players and 20,000 score updates per second at peak. Deliver the scope, a memory estimate, a rank API, the score and rank paths, a tie rule and a precision trade-off.
How interviewers level this design
- Junior: uses an ordered in-memory structure for ranks and a durable store for scores.
- Mid-level: sizes the structure, makes ties deterministic and explains how to rebuild ranks after a cache loss.
- Senior: trades exactness for scale in the tail, shards by game or tier and handles cheating and score corrections.
Pebble Games wants a live leaderboard: the global top 100 and every player's own rank, updated as scores arrive. A relational query that sorts five million rows on every request will not keep up, so ranking needs a structure that keeps scores in order as they change.
An in-memory sorted set does that: inserting a score and reading a rank both take logarithmic time. The sorted set is fast but not the system of record, so scores also go to durable storage. You will estimate the memory a sorted set needs, define the rank API, draw the update and read paths, break ties fairly and decide how exact the rank must be for players far from the top.
Keep scores ordered in memory, store them durably and choose where exact ranks matter.