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)
Sources
3 min read+10 XP
Source notes
- Redis sorted set commands and their time complexities (
ZADDO(log N),ZREVRANKO(log N),ZREVRANGEO(log N + M),ZCOUNTO(log N)): Redis command documentation. - Double-precision floats represent integers exactly up to 2⁵³: IEEE 754.
- Contest sizes, pick rates, shard throughput and refresh rates are interview assumptions agreed in Step 1, not figures for any real app. Arithmetic computed 2026-10-08.
- Sorted-set behaviour, fan-out share, composite tie scores, competition ranking, sharded top-K and rank, and histogram percentiles: tested 2026-10-08 (
code/ch35_leaderboard.py, all checks pass).