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

Variations to practise

3 min read+10 XP

Chapters used

Approach (1), Estimation (2), Caching (12, 13), Sharding (15), Probabilistic data structures and top-K (20), Message queues (22), Real-time updates (21), Failures (29).

Try these variations

Each is a common follow-up. Answer in two minutes, then check the sketch.

  1. "Show a friends' leaderboard." → Look up each friend's score (one ZSCORE each, or a small cached set per user) and sort the few hundred locally.
  2. "A global all-time leaderboard for a game." → Updates are per user action (not fan-out), so update immediately; shard by user, cache the top, use percentiles for most users.
  3. "Weekly leaderboard that resets." → One sorted set per week (lb:2026-w41), with a TTL after the week ends; archive the final top results.
  4. "Prevent cheating." → Scores come only from server-side events, never from the client; anomaly detection on impossible scores; the final job is the source of truth.