AlgoViz

Design a Multiplayer Game Leaderboard

easy 45 min

Keep 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

100M×586,400≈5,800/s100M×5086,400≈57,900/s\frac{100\text{M}\times 5}{86{,}400}\approx 5{,}800/\text{s} \qquad \frac{100\text{M}\times 50}{86{,}400}\approx 57{,}900/\text{s}
At a 3x peak: 17,400 results and 174,000 looks a second. Reads are 10 times writes.

Memory of one board

250M×100 B=25 GB500M×100 B=50 GB250\text{M}\times 100\,\text{B} = 25\,\text{GB} \qquad 500\text{M}\times 100\,\text{B} = 50\,\text{GB}
Assumed: 250M players in a week, 500M registered, 100 bytes a member. Measure it with MEMORY USAGE.

All the numbers

QuantityWorkingDecides
Top-list looks40 of 50 (assumed): 46,300/s, peak 139,000Use a CDN
Personal looks10 of 50: 11,600/s, peak 34,700Sorted sets and replicas
Fills from the edge100 boards x 200 places / 10 s = 2,000/s98.6% of peak top looks never reach us
Board updates3 boards a result: 52,200/s at peakBoards spread over primaries
Personal commands3 each: 104,000/s at peakRead from replicas
Steps for a ranklog2 of 250M, about 28Order structure, not a count
Result history500M x 200 B = 100 GB a day, 36.5 TB a year90 days in the database (9 TB), then object storage

What if

ChangeNew numberThen
1 million players a day58 results a secondPostgreSQL and one Redis
A final with 10 times the top looks1.39M/sThe edge takes it. Fills stay 2,000/s
1 billion players on one board100 GBSplit that board by score