Lesson 3 of 15
35. Design a Leaderboard (Top-K)

35.2 How big is this, really?

3 min read+10 XP

Step 2: Estimates (5 minutes)

Assume about 100 bytes per member in a sorted set, a popular player picked by ~66% of teams, about 100,000 sorted-set updates a second per shard, and users refreshing every ~10 seconds during peak.

WhatWorkingResult
Membersgiven20 million teams
Memory for one leaderboard20 million × 100 bytes≈ 2 GB: fits one Redis node, but busy
Scores changed by one six from a popular player20 million × 0.66≈ 13 million
Time to apply on one shard13.2 million ÷ 100,000 a second≈ 132 s: longer than the gap between balls
On 20 shards13.2 million ÷ 2 million a second≈ 7 s
Read trafficsay 5 million users watching ÷ 10 s≈ 500,000 reads a second at peak

What the numbers say, out loud:

  • "Memory is fine; write bursts are not. Per-ball updates on one node can't keep up, so we batch and shard."
  • "Reads are huge, but most are the same top 100. Cache that; 'my rank' is the only per-user read."
  • "Exact final ranks are a separate, slower job at the end, not something the live system must guarantee every second."

Interviewer pushback:

  • "Why not recompute every team's score from scratch every few seconds?" → 20 million teams × 11 players is cheap arithmetic in a batch; the expensive part is writing them into the ranked structure. Rescoring only affected teams, once per batch, keeps writes down.

Memory code: "One ball, millions of writes: batch them and spread them."