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.
Numbers that decide
Work out a number when the answer changes what you build.
Estimates
Only the sums that decide something
Results and looks
Memory of one board
All the numbers
| Quantity | Working | Decides |
|---|---|---|
| Top-list looks | 40 of 50 (assumed): 46,300/s, peak 139,000 | Use a CDN |
| Personal looks | 10 of 50: 11,600/s, peak 34,700 | Sorted sets and replicas |
| Fills from the edge | 100 boards x 200 places / 10 s = 2,000/s | 98.6% of peak top looks never reach us |
| Board updates | 3 boards a result: 52,200/s at peak | Boards spread over primaries |
| Personal commands | 3 each: 104,000/s at peak | Read from replicas |
| Steps for a rank | log2 of 250M, about 28 | Order structure, not a count |
| Result history | 500M x 200 B = 100 GB a day, 36.5 TB a year | 90 days in the database (9 TB), then object storage |
What if
| Change | New number | Then |
|---|---|---|
| 1 million players a day | 58 results a second | PostgreSQL and one Redis |
| A final with 10 times the top looks | 1.39M/s | The edge takes it. Fills stay 2,000/s |
| 1 billion players on one board | 100 GB | Split that board by score |