Real-Time Leaderboard HLD: Your Rank Among 50 Million, Instantly
A real-time leaderboard system design (HLD): why top-N is easy but a single player's rank is hard, the sorted set and order-statistics that make rank O(log n), time windows, and the hot-key at scale.
"Design a real-time leaderboard." The match ends and your screen flashes: "Ranked #2,184,402 — up 9,517 spots." Among fifty million players, the server knew your exact position the instant your score landed — and it does this for every player, thousands of times a second. Stop and ask how, because the obvious answer is a disaster: to know your rank, count everyone with a higher score. That's a scan of fifty million rows, per query, on the hot path. It would melt. Showing the top 10 is trivial — any sorted index hands you the highest few. But a specific player's rank deep in the pack is the que…
What’s inside
Read this one free
Sign in and your first premium article is on us — read Real-Time Leaderboard HLD: Your Rank Among 50 Million, Instantly free.