Day 9 10 min
A game leaderboard
1 / 6 · ≈ 14 min left
The problem
Lina finishes a round of a puzzle game on her phone. The end screen shows the top 100 players of the season, and under it: "You are #1 204 387". She plays again to climb.
The first version ran SELECT count(*) FROM scores WHERE best > $1 for that line. With 5 million rows, each end screen counted up to 5 million rows, and the screen took 4 seconds at peak.
You design the leaderboard so both answers come back in under 100 ms.