Design a Game Leaderboard
Show the top 100 players and any player's own rank in real time, for a game with millions of players.
Like a scoreboard that is always sorted: when one score changes, only that name moves up or down, instead of re-sorting the whole list.
- Clients
- Game
- Player
- Services
- Leaderboard service
- Rank updater
- Queues, caches
- Sorted set
- Read replicas
- Data, outside
- Scores database
1. Requirements and scope
- Submit a score after each match.
- Show the top 100 players.
- Show a player's rank and the players immediately above and below them.
- Daily and all-time leaderboards.
- Rank changes visible within a second or two.
- Reads far outnumber writes.
- Scores are never lost: the database is the source of truth.
2. Back-of-the-envelope numbers
- Writes: 3,000 score updates a second, at peak (23%)
- Reads: 10,000 board views a second, at peak (77%)
Balanced: reads and writes are close. Both paths need care, so neither can be slow.
3. API
4. Data model and storage
MATCH_RESULT(match_id, player_id, score, played_at) · Redis ZSET leaderboard:alltime { member: player_id, score: total }5. The design, in three versions
Version 1: SQL ORDER BY
Store totals in a table and sort on read.
Game Leaderboard: Version 1: SQL ORDER BY Version 1 of 3
The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.
One request, step by step
Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.
- The order of the steps
- A request or its reply
The parts: switch one off
1. Clients
2. Services
3. Data, outside
The steps in words0 of 5 steps shown
Game to Leaderboard service
A game sends a score of 900 for player 42.
Leaderboard service to Scores database
It saves the score.
Player to Leaderboard service
A player asks for the top 100.
Leaderboard service to Scores database
It sorts all scores to find the top 100. This gets slow.
Leaderboard service to Player
The top 100 goes back to the player.
Write path, read path and failures
Each path follows one request through the final design (version 3), one hop at a time.
Write pathSubmit a score
- Game server
- Score API
- Database
- Rank updater
- Redis primary
- Redis replicas
Game server to Score API
After a match, the game server sends the player id and the score. Only game servers may call this API, not the player's app.
Score API to Database
The API saves the score in the database first. The database is the source of truth.
Database to Rank updater
A change event tells the rank updater that a new score is in.
Rank updater to Redis primary
It updates the player's score in the all-time and daily sorted sets (ZADD). Redis keeps each set in score order.
Redis primary to Redis replicas
The primary copies the change to its replicas, usually within a few milliseconds.
Read pathShow the top 100 and my rank
- Player app
- Leaderboard API
- Redis replicas
Player app to Leaderboard API
The app asks for the top 100 and for the player's own place.
Leaderboard API to Redis replicas
ZREVRANGE 0 99 returns the top 100, and ZREVRANK returns the player's place. Both stay fast with millions of players.
Redis replicas to Leaderboard API
A second ZREVRANGE around that place returns the players next to them, above and below.
Leaderboard API to Player app
The app shows the list and the player's rank.
What breaks, and what happens then
The Redis primary fails
- What users see
- New scores stop reaching the board for a short time. Reads keep working from the replicas.
- What the design does
- A replica is promoted. If it missed some changes, the rank updater rebuilds the sorted sets from the database.
A tournament ends and scores arrive in a burst
- What users see
- The rank updater falls behind, so ranks lag behind real scores.
- What the design does
- Watch the event backlog and add updater workers. The requirement allows a second or two of delay.
Someone sends fake scores
- What users see
- Fake names reach the top 100.
- What the design does
- Accept scores only from game servers, and check each one against the match record. Keep a way to remove a score from the database and the set.
6. Deep dives
7. Follow-up questions
- What happens if Redis loses its data? (Rebuild the sorted set from match results in the database; show ranks as temporarily unavailable meanwhile.)
- How do you break ties? (Fold the time into the score — e.g. score × 10^10 − timestamp — so whoever reached it first ranks higher.)
What it costs
The whole board fits in memory: 50 million players need a few gigabytes. Redis replicas for reads are the main cost. An exact rank for every player is the expensive promise, so consider showing exact ranks only near the top.
Another way to design it
For a board of a few thousand players, one SQL query with an index on the score is enough. There is no second system to keep in step. It slows down when millions of rows must be ranked on every view.
8. How answers are judged
A passing answer at Mid level. A complete design with numbers: about 600 score updates a second on average, and about 10,000 leaderboard views a second at peak. It stores scores in a sorted structure for fast ranks and goes deep on one part.
| What is judged | Junior | Mid | Senior | Staff |
|---|---|---|---|---|
| BreadthHow much of the system does the answer cover? | Names the core parts: clients, servers, a database and a cache. | Covers the whole main flow, from the request to the stored data and back. | Builds a complete design without being led through it. | Covers the system, the systems around it and who owns each part. |
| DepthHow far does it go into the hard parts? | Explains what each part does and why it is there. | Goes deep on one part, such as the database or the cache. | Goes deep on the two or three riskiest parts. | Goes deepest where the risk is largest, and explains why the risk is there. |
| DrivingWho leads the conversation? | Follows the interviewer, step by step. | Moves forward alone, with an occasional nudge. | Leads the conversation from start to finish. | Changes the problem when the question asked is not the right one. |
| Trade-offsAre choices compared and justified? | Names more than one option. | Says why one option was picked over another. | Compares options in detail, with what each one costs. | Ties each choice to cost, speed and risk for the business. |
| Unclear questionsWhat happens when the question is vague? | Answers the questions that are asked. | Asks questions to make the problem clear. | Sets the scope and says what is left out. | Questions the assumptions behind the problem itself. |
| ScopeWhat does it consider beyond the normal path? | Covers the normal path, when everything works. | Adds what happens when a part fails. | Adds growth: what breaks at ten times the load, and the fix. | Adds abuse, cost and the daily work of running the system. |
Requirements and scope
Before I design, I want to check the scope. Players submit a score, and we show a top 100 list plus each player's rank and neighbours. Rank changes only need to be visible within a second or two, so clients can pull fresh data instead of getting instant push updates.
Players submit scores after a match. Every viewer's leaderboard must update the instant a new score comes in, so I will push live updates to every connected client over a socket.
Shows: Unclear questionsThe difference: The problem only asks for rank changes to be visible within a second or two, not instantly. Assuming instant push adds a real-time system nobody asked for.
Estimates
5 million players making about 10 matches a day is about 600 score updates a second on average, with a stated peak of 3,000. Reads are larger: about 10,000 leaderboard views a second at peak, over three times peak writes. So the design should be built around fast reads, not fast writes.
About 3,000 score updates a second at peak is the main load to design for, since that is how often the leaderboard changes.
Shows: ScopeThe difference: At peak, reads reach about 10,000 a second, over three times the 3,000 peak writes. The weak answer designs for the smaller side.
Core design
Every match result is written to a database table, which is the source of truth. A player's total score also updates a Redis sorted set. That makes the top 100 and any player's rank both fast lookups, without scanning every score.
I would keep every player's total score in a table. I would run a query sorted by score, with a count of higher scores, to find the top 100 and any rank.
Shows: DepthThe difference: Sorting a table and counting higher scores on every request gets slow at millions of players and thousands of reads a second. A sorted set avoids scanning.
Deep dive
The hard part is finding one player's rank fast among 50 million. A sorted set keeps scores ordered using a skip list next to a hash map. Adding a score, reading the top 100, and finding one rank are all fast, without ever re-sorting everything.
I would keep every score in a Redis hash, one field per player. I would sort all of them in the app whenever someone asks for the top 100 or their rank.
Shows: DepthThe difference: Sorting 50 million scores from a hash on every request is slow. A sorted set keeps them ordered already, so it never needs a full re-sort.
Failures and trade-offs
If Redis loses the sorted set, I would rebuild it from the match results in the database, since that is the source of truth. Ranks show as temporarily unavailable while it rebuilds, rather than showing wrong numbers from a half-built set.
If Redis loses its data, new scores coming in will fill the sorted set back up on their own, so the leaderboard recovers by itself.
Shows: ScopeThe difference: New scores alone never restore players who have not scored again, so most ranks stay missing. Rebuilding from the database recovers everyone at once.
We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.
10. Check your design with your own AI
Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.
The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.
See the prompt
You are a system design interviewer. Review my design for the interview problem below. Problem: Design a Game Leaderboard Show the top 100 players and any player's own rank in real time, for a game with millions of players. What users must be able to do: - Submit a score after each match. - Show the top 100 players. - Show a player's rank and the players immediately above and below them. - Daily and all-time leaderboards. How well it must work: - Rank changes visible within a second or two. - Reads far outnumber writes. - Scores are never lost: the database is the source of truth. Numbers to assume: - 5 million daily active players, each playing about 10 matches a day. Judge my design at the Mid level. A passing answer at this level: A complete design with numbers: about 600 score updates a second on average, and about 10,000 leaderboard views a second at peak. It stores scores in a sorted structure for fast ranks and goes deep on one part. For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each: 1. Requirements and scope 2. Estimates 3. Core design 4. Deep dive 5. Failures and trade-offs Then ask me the two follow-up questions an interviewer would ask next. Do not write a full model answer for me. My design: [Describe your parts, how one request moves through them, and why you chose each one.]