Scrivio Interview library
DebuggingIntermediate6 min read · updated 13 November 2026

During a live tournament 2 million connected clients poll the top 100 every second. The leaderboard is one sorted set of 30 million members in Redis Cluster, and the node that owns its slot hits 100 percent CPU while other nodes are idle.

Explain the bottleneck and fix it without changing the game client.

All 2 million polls per second run ZRANGE for 100 members on one key, and a key lives on exactly one primary, so its single main thread does all the work however many nodes the cluster has. The fix is to compute once and serve many: a job reads the top 100 once per second and publishes it as one small value or pushes it to the API servers, which answer polls from memory. We add a short local cache for per-player ranks, rate-limit polling per client, let replicas take the remaining slightly stale rank queries, and batch score writes in the game servers if writes are heavy too.

Why this question is asked

Redis Cluster spreads keys across nodes, so it is natural to assume a bigger cluster means more capacity for everything. A single hot key is where that assumption fails, and live events produce hot keys reliably. Interviewers like this question because the fix is architectural, not a Redis setting, and because the constraint, no change to the game client, forces the fix into the server side. In this answer, we will work out why one node is saturated, apply the compute-once pattern, deal with the other queries, and look at the write side.

1Why One Node Is at 100 Percent

Redis Cluster splits the keyspace into 16,384 hash slots and assigns slots to primaries. Every key maps to exactly one slot, so the whole leaderboard sorted set lives on one primary. Adding nodes moves other keys around; it cannot split one key.

Each poll runs ZRANGE lb 0 99 REV WITHSCORES. Finding the start is O(log N) in 30 million members, which is cheap, but each reply then serializes 100 members and scores, a few kilobytes. Two million of those per second means building and sending several gigabytes per second of replies from one main thread. No single Redis process can do that, so the node sits at 100 percent while its neighbours idle, and every other key on that node suffers too.

Step throughBefore: every poll reaches the hot node
2M game clientsAPI serversPrimary owning lb
GET /top100 (every second)
ZRANGE lb 0 99 REV WITHSCORES
100 members, a few KB
top 100
x 2,000,000 per second on one thread

5 messages in order. Play them, or step through them one at a time.

The cluster's other nodes cannot help with a single key.

2Compute Once, Serve Many

Every client asks the same question within the same second and gets the same answer. So we ask Redis once and share the result. A small job, running in one place with leader election or as a scheduled task, reads the top 100 once per second and either stores it as one small precomputed value, such as a JSON string under lb:top100:snapshot, or pushes it to the API servers through pub/sub or a message stream. The API servers keep the current snapshot in memory and answer every poll from it.

Java
@Scheduled(fixedRate = 1000)
void refreshTop100() {
Set<TypedTuple<String>> top = redis.opsForZSet()
.reverseRangeWithScores("lb", 0, 99); // one ZRANGE per second
String json = mapper.writeValueAsString(toEntries(top));
redis.convertAndSend("lb:top100", json); // API servers swap their snapshot
}
// API server
volatile String top100Json = "[]";
@GetMapping("/top100") String top100() { return top100Json; } // memory, no Redis call

Redis now serves one ZRANGE per second for this query instead of two million. The API servers scale horizontally, which they already do, and the clients notice nothing except that the data can be up to one second old, which it effectively was already since they poll every second. Notice that the game client did not change: same endpoint, same response.

3Per-Player Ranks and Polling Limits

Clients probably also ask for their own rank. Those queries differ per player, so they cannot be shared as easily, but most of them come from a small set of active, popular players during an event. A short local cache in the API layer, 500 ms to one second per player id, absorbs repeat polls from the same player and from spectators watching the same player.

We also rate-limit polling per client at the API layer, for example two requests per second per session. A buggy client or a script polling ten times a second gets a 429 response or the cached answer; well-behaved clients do not notice.

4Letting Replicas Share the Rest

The remaining rank queries can go to replicas when slightly stale results are acceptable, which for a leaderboard they usually are. In Lettuce we configure ReadFrom.REPLICA_PREFERRED on the cluster connection, so read commands go to a replica of the slot's primary when one is available. With two replicas per primary, the hot slot now has three threads to share reads. Replication lag is normally milliseconds, invisible on a leaderboard that refreshes every second.

5If Writes Are Heavy Too

Score updates must go to the primary. If a live event also produces a flood of ZADD or ZINCRBY calls, the game servers can aggregate changes per player for about 100 ms and send one update per player per interval, in a pipeline. A player who scores five times in 100 ms then costs one write instead of five, and the leaderboard is still at most a tenth of a second behind.

Step throughAfter the fix
  1. Game clientsUnchanged, poll every second
  2. API serversTop 100 from memory, rank cache 0.5 to 1 s, polling limit
  3. Refresh jobOne ZRANGE per second, pushes the snapshot
  4. Redis replicasStale-tolerant rank queries
  5. Redis primaryBatched score writes, one refresh read

5 layers, from the top down. Step through them one at a time.

6Follow-up questions

What would you change if every player needs an exact personal rank each second?

Two million ZREVRANK calls per second on one key still cannot fit on one primary, even with replicas helping. I would precompute ranks instead of querying them: a job walks the sorted set in chunks every few seconds, for example ZRANGE by index in blocks of 100,000, and writes each player's rank into a sharded store, such as hashes spread across the cluster by player id, which API servers read cheaply. Or we shard the board itself by player and compute rank as a sum of counts across shards. Exact to the second for every player is expensive, so I would also ask whether a rank a few seconds old or a percentile would do.

Why not just add more replicas of the hot node?

Replicas help reads, so they would raise the ceiling by a few times. But 2 million identical reads per second is wasteful whatever serves them; computing once removes the load instead of spreading it, and replicas cost memory for all 30 million members each.

Could client-side caching with tracking solve this?

It would let API servers cache the ZRANGE result and drop it when lb changes, but during a tournament lb changes constantly, so the cache would be invalidated many times a second. A timed snapshot is simpler and more predictable here.

7Conclusion

In this answer, we saw that a single sorted set lives on one primary, so 2 million ZRANGE polls per second saturate one main thread no matter how big the cluster is. The fix is to compute the top 100 once per second and serve it from API memory, with short local caches for player ranks, polling limits per client, replicas for stale-tolerant rank queries, and batched score writes, all without changing the game client.

What to say in the interviewAbout 80 seconds aloud

Open with

The leaderboard is one key, and a key lives in one slot on one primary, so every poll lands on that node's single main thread no matter how many nodes the cluster has.

Then, if they want more

Each poll is a ZRANGE of 100 members with scores, which is cheap to find but produces a reply of a few kilobytes, and 2 million of those per second is far more than one thread can build and send.

Since every client asks the same question in the same second, I would compute once and serve many: a job reads the top 100 once per second and stores it as one small value or pushes it to the API servers, and they answer polls from memory.

Redis goes from 2 million reads to one per second for that query, and the client sees the same endpoint and response. For per-player ranks I would add a short local cache of 500 ms to a second in the API layer and rate-limit polling per client.

Remaining rank queries can go to replicas with a client configured to read from replicas, since a slightly stale rank is fine. And if writes are heavy too, the game servers can aggregate score changes per player for about 100 ms before sending them.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Redis documentation
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Explain the bottleneck and fix it without changing the game client.": https://scrivio-interview-library.netlify.app/databases/redis-patterns/052b000a50/