How would you design a real-time gaming leaderboard?
0 views
96 of 106
1
The problem
Question presented to candidate:
"Our mobile game has 25 million players per season. After every match we want to show the player their global rank, the top 10, and the five players around them, all updated in real time. How would you design the leaderboard?"
What a strong answer should cover:
Why ORDER BY score with OFFSET / COUNT(*) in a relational database gets slow for rank queries at this size, and the sorted set (skip list plus hash) that gives O(log N) update and rank
Redis commands: ZINCRBY, ZRANGE ... REV (top N), ZREVRANK (my rank), a range around my rank; memory per member and whether one node is enough
Tie-breaking: equal scores are ordered by member name in Redis; encode "who got there first" into the score and stay under 2^53
Source of truth: match results in a durable database, the leaderboard as a rebuildable derived index; idempotent score updates keyed by match id
Scale-out: hash sharding with a scatter-gather top-K merge vs score-range sharding, and approximate rank (histogram buckets) for the long tail
Seasons, regional and friend leaderboards
Clarifying questions expected:
How many players, how many score updates per second at peak, and how many rank reads?
Does rank need to be exact for everyone, or only for the top players?
How are ties broken, and when does a season reset?
Code / implementation expected: Optional โ the design with numbers; the example simulates a Redis sorted set with ranks, ties, sharding and approximate rank.
system-design
case-study
2
Try it yourself
Sketch your approach before you read the solution. That is what the interview tests.
Stuck? Get a hint.
A short nudge toward the approach. It will not give the answer away.
3
Solution
Target Audience: Developers preparing for system design interviews. You know what a database index and a cache are; sorted sets are explained from scratch.
Difficulty: Hard
Verified with: Node 22.22, Python 3.12, Go 1.24 and Java 21 (all four print identical output). Redis behaviour and memory were checked on Redis 7.0.15.
How to read this doc: Every idea is explained in plain language first, then tagged with ๐ Interview term: so you also learn the exact words an interviewer expects. All behaviour shown comes from running the example; the Verified section quotes the full output. Capacity numbers are worked from stated assumptions.
1. Why This Even Matters โ A Story First
A marathon has 40,000 runners. Showing the top 10 at the finish line is easy: the organisers watch the first few runners. But every runner also wants to know "what place did I finish?" seco
The solution is hidden so you can try first
15 min read ยท 17 sections
4
Read the code
Leaderboard on a simulated Redis sorted set: rank, around-me, tie-breaking, sharded top-K and approximate rank