System Design LabSystem Design QuestionsDesign Gaming Leaderboard

Design Gaming Leaderboard

EasyReal-time Systemsrankingreal-timecachingsorted-sets

Question Overview

Design a live game leaderboard that shows the global top 100, any player's exact rank out of 100M, and a friends-only board. The interesting parts are choosing a data structure with logarithmic rank queries, handling ties and period resets, and scaling past one node.…

Sign up to see the full question and AI interviewer

Requirements

  • Update a player's score from server-validated match results and reflect the new rank within 1 second
  • Return the top 100 for the season, weekly, or daily board with p99 latency under 50 ms
  • Return any player's exact rank and score plus the five players directly above and below them
  • Return a friends-only leaderboard ranked by the same season score
  • Break ties in favor of the player who reached the score first; reset boards on schedule
  • Never lose a score update; the board can be rebuilt from durable storage

Back-of-the-envelope numbers

  • Score updates: 50M DAU × 10 matches/day = 500M/day ÷ 86,400 s ≈ 5.8K writes/s average, ~17K/s at 3× peak
  • Board reads: 50M × 20 views/day = 1B/day ÷ 86,400 s ≈ 11.6K reads/s average, ~35K/s at 3× peak
  • Redis writes: one ZINCRBY on each of the season, weekly, and daily boards → ~17.4K × 3 ≈ 52K writes/s at peak
  • Sorted set memory: 100M players × ~100 bytes per entry (member, score, skip list and hash overhead) ≈ 10 GB per season board
  • Rank lookup: ZREVRANK is O(log N), roughly log2(100M) ≈ 27 comparisons on a span-annotated skip list, so a rank query costs microseconds, not a table scan
  • Friends view: if a third of peak reads are friends boards, ~12K/s × 200 friends ≈ 2.3M score lookups/s, so cache results briefly
  • Durable log: 500M match results/day × ~50 bytes ≈ 25 GB/day of append-only score history for rebuilds and audits

Key components

  • Score service: accepts results only from trusted game servers, validates them, writes them durably, and emits an event that updates Redis
  • Redis sorted set per board key (e.g. lb:season:12, lb:daily:2026-09-13) with ZINCRBY for updates and ZREVRANGE 0 99 for the top 100
  • My-rank path: ZREVRANK and ZSCORE for the player, then ZREVRANGE from rank−5 to rank+5 for the neighbors
  • Friends board: fetch friend IDs from the social graph, ZMSCORE them against the season board, sort in the app, and cache ~30 s
  • Top-100 cache: every player reads the same list, so recompute it once per second and serve it from an in-memory or edge cache
  • Durable store (e.g. DynamoDB or Cassandra) of per-player totals and a match log, used to rebuild Redis after a failure
  • Period resets: write each period to a new key with a TTL instead of clearing a 100M-member set in place

Common mistakes

  • Computing rank with SELECT COUNT(*) WHERE score > mine on every request, a scan over up to 100M rows
  • Trusting scores sent directly from the game client, which makes cheating trivial
  • Assuming Redis Cluster spreads one sorted set across nodes; a single key always lives on one shard
  • Packing a millisecond tie-break timestamp into the score without noticing Redis scores are doubles with 53 bits of integer precision
  • Maintaining a per-user friends leaderboard with fan-out on write, turning one score update into 200 writes
  • Running DEL on a 100M-member sorted set at reset time, which blocks Redis; use per-period keys with UNLINK or lazy expiry
  • Treating Redis as the only copy of scores, so a failover with replication lag silently loses recent updates

Likely follow-ups

  • How would you scale when one sorted set no longer fits on a single Redis node or its write rate is too high?
  • How would you show an approximate percentile such as top 3% for players far from the top more cheaply?
  • How would you remove a banned cheater and correct everyone's ranks afterward?
  • How would you rebuild the leaderboard after losing the Redis primary and its replica?
  • How would you add per-country and per-guild boards without multiplying write cost excessively?
  • How would you push live rank changes to players who are watching the leaderboard screen?

No community solutions yet

Be the first to publish your solution

Practice ‘Design Gaming Leaderboard’ with an AI Interviewer

Get scored feedback on your diagram, scalability approach, and trade-offs. Free while we grow — up to 3 full interviews a day.