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.
Grow the design
Start with the smallest system that works. Change it only when something breaks.
Six versions
Version 1: One service, one database
Forced by: The feature: keep scores and show the top.
- What changes
- A table of best scores with an index on board and score. The top 100 reads 100 index entries. A rank counts the rows ahead.
- What it costs
- One machine to run.
- What breaks next
- A rank in the middle of 250 million counts 125 million entries.
Say: "With ten thousand players I would stop here."
Where am I?
Why each part is there
| Part | Job | Without it |
|---|---|---|
| Result log | Keeps results until applied | A Redis outage loses scores |
| PostgreSQL | Owns scores and history | A lost board cannot be rebuilt |
| Redis shards | Order and place | Ranks count rows |
| CDN | Answers shared lists | 139,000 reads a second |
| Profile cache | Names for IDs | Stale names inside the board |
| Live topic | Own result only | Players poll after a match |