Design a Multiplayer Game Leaderboard
easy 45 minKeep 250 million players in order while results arrive all the time, and tell any of them their place in milliseconds.
How to approach it
What this question tests, where it gets hard, and how to spend the time.
Read the question
What this problem tests
A structure, not a box
Can you say why counting a rank is expensive, and which structure makes it cheap?
Shared and personal
Do you separate the list everyone sees from the place only one player sees?
Trust
Who is allowed to say what the score is?
Knowing when to stop
250 million players fit on one machine. Do you notice?
| Ask yourself | Here |
|---|---|
| Who does what? | Game servers report results; players read boards |
| What must never go wrong? | An accepted result is never lost, and a fake one is never shown |
| What is the hardest thing? | One player's place among hundreds of millions |
| What breaks first? | Counting rows for a rank, then the number of reads |
| What am I giving up? | A few seconds of freshness |
Five questions in order
Spend the 45 minutes
| Minutes | Do | Skip |
|---|---|---|
| 0 to 5 | Score rule, boards, ties, freshness | Achievements |
| 5 to 10 | Writes, reads split in two, memory | Bandwidth |
| 10 to 15 | Result and rank calls | Profile fields |
| 15 to 25 | Version 1 and then grow | Product names |
| 25 to 40 | Rank at scale, ties, trust | Every edge case |
| 40 to 45 | Failures and recap | New features |
Do
- Say that ranks are counted, not stored
- Split reads into shared and personal
- Name the game server as the source
- Say what the place of player 40 million is worth
Traps
- A row with a rank column
- Pushing all rank changes
- A job that empties the board at midnight
- Sharding by player hash, then asking for a rank