35. Design a Leaderboard (Top-K)
1
The interview prompt2
35.1 What do you ask first?3
35.2 How big is this, really?4
35.3 What are the doors?5
35.4 What do we store?6
35.5 What does the whole system look like?7
35.6 How do sorted sets work for this?8
35.7 How do you handle real-time updates?9
35.8 How do you handle ties?10
35.9 How do you shard a leaderboard?11
35.10 What would you say in the last five minutes?12
Score yourself13
Variations to practise14
Sources15
Code lab35. Design a Leaderboard (Top-K)
35.10 What would you say in the last five minutes?
3 min read+10 XP
Step 6: Wrap-up (5 minutes)
- Bottlenecks: write bursts from popular players (batching, sharding, pipelining) and refresh traffic (cached top 100, cached per-user rank until the next batch).
- Single points of failure: Redis shards (replicas; rebuildable from teams and player points), the batch scheduler (run two with a lock or leader, Chapter 17).
- Correctness for money: the final job recomputes from the verified event list, applies tie and prize rules, and writes an audited table; live ranks are informational.
- Next with more time: friends' leaderboards (a small sorted set per group, or rank lookups for a list of friends), private leagues with instant updates, and historical leaderboards stored cheaply after the match.
Memory code: "Live is fast and roughly right; final is slow and exactly right."