Real-Time Leaderboards Are a Ranking and Throttle Problem
A real-time leaderboard at scale is a ranking plus throttle problem, not a broadcast one. Learn why sorted sets and throttled updates beat pushing every score change.
A leaderboard at scale is two problems wearing one costume: ranking a large set of scores cheaply, and pushing updates to viewers without flooding them. Neither is solved by naively broadcasting every score change. During a busy tournament, scores update thousands of times a second, but the leaderboard a user sees only has room for the top 100 and their own neighbors. Rank with the right data structure, throttle the broadcast to a human cadence, and a leaderboard that looks impossible to keep live becomes cheap.
Ranking: use a sorted set, not a query
The wrong way to build a leaderboard is to sort the whole player table on every read. At scale that query gets slow exactly when traffic peaks. The right primitive is a sorted set, the data structure Redis and similar systems provide natively: insert a score in logarithmic time, read the top N in logarithmic time, and get any player's rank without scanning everyone.
A sorted set gives you the top slice and an individual player's rank as cheap operations, which is all a leaderboard ever displays. You never materialize the full ranking; you ask for the window you show. This is the difference between a leaderboard that holds up under a million players and one that falls over at ten thousand, and it is the same lesson as not confusing a real-time database with a purpose-built backend: pick the structure that answers your actual query cheaply.
Broadcast: throttle to what a human can read
Even with fast ranking, do not push an update every time any score changes. During a live event that is thousands of broadcasts a second to every viewer, and it renders as a blur. A leaderboard changing faster than a person can read is not more useful; it is less.
So throttle. Recompute and broadcast the top slice on a fixed cadence, maybe every one to two seconds, not on every write. Between broadcasts, scores keep updating the sorted set; you just sample it on your cadence. This is a latency budget decision: a leaderboard that is one second stale is indistinguishable from live to a human, and it costs a fraction as much. And when you do broadcast, send the delta, the rows that moved, not the entire board each tick.
Personalize without personalizing the broadcast
The trap in leaderboards is that everyone wants a slightly different view: the global top 100 is shared, but "your rank and your neighbors" is unique per player. If you broadcast a custom payload to every player, your fan-out cost explodes back to the per-connection problem you were avoiding.
Split it. Broadcast the shared top slice to everyone on the throttled cadence, which is one payload fanned out cheaply. Serve the personal "your rank" view on demand or on a slower per-player cadence, because a player's own rank does not need sub-second freshness. That separation keeps the expensive shared broadcast small and the personal query cheap, and it is the leaderboard version of getting pub/sub channel granularity right: a shared channel for the top, a light per-player lookup for the rest.
Scale by tournament, not by player
Leaderboards partition naturally. A global all-time board, a daily board, a per-region board, a per-tournament board: each is its own ranked set with its own viewers. Shard on that. A hot tournament ending in the final minute is where your cost concentrates, and you want that isolated to its own room so it does not drag every other board with it. This is scaling real-time rooms, not connections applied to competition: the board is the room.
Protect the write path too. In a game, players will try to spam score submissions or forge them. Validate every submission server-side and rate-limit the connection so no client can flood your sorted set. A leaderboard is trusted display over an untrusted input stream, so the input stream gets treated as hostile.
What the backend should handle
For leaderboards you want fast ranked storage, throttled room broadcast, delta payloads, and per-tournament sharding, with a separate cheap path for personal rank. A real-time platform like AltoHost gives you the throttled room broadcast and fan-out so you pair it with a sorted set and get a leaderboard that stays live at scale without melting. If you are choosing infrastructure, evaluate the real-time backend on how it handles throttled fan-out to large shared rooms, because that is the exact shape a leaderboard applies.
The whole trick is refusing to treat a leaderboard as a broadcast of every change. Rank cheaply, throttle to human speed, share the top and personalize the rest, and shard by competition. Do that and a million-player board is boring to run, which is what you want. AltoHost handles the throttled fan-out half.