Asked at
URL Shortener (TinyURL)
Asked from Junior level upFoundations & Storage
Distributed Rate Limiter
Asked from Mid level upAPI Gateway & Security
Distributed Key-Value Store
Asked from Senior level upFoundations & Storage
Distributed Notification Service
Asked from Mid level upMessaging & Queues
Distributed Web Crawler
Asked from Mid level upDistributed Systems
Metrics & Monitoring Platform
Asked from Senior level upObservability & Time-Series
Real-Time Chat App (like WhatsApp or Slack)
Asked from Mid level upReal-Time & WebSockets
Social News Feed (like X/Twitter)
Asked from Mid level upSocial & Feed Systems
Ride-Hailing App (like Uber)
Asked from Senior level upGeospatial & Real-Time
Low-Latency Stock Exchange Matching Engine
Asked from Staff level upFintech & Low Latency
Global Video Streaming Platform (like YouTube or Netflix)
Asked from Senior level upMedia & Streaming
Distributed Hotel & Ticket Reservation System
Asked from Mid level upE-Commerce & Transactions
Shared Document Editor (like Google Docs)
Asked from Staff level upReal-Time & Distributed State
Game Leaderboard
Asked from Junior level upCaching & Data Structures
File Sync Service (Dropbox / Google Drive)
Asked from Mid level upStorage
Payment System
Asked from Senior level upPayments & Transactions
Ad Click Aggregation
Asked from Senior level upStream Processing
AI Support Assistant (RAG)
Asked from Senior level upAI Systems
LLM Inference Platform
Asked from Senior level upAI Systems
Enterprise Semantic Search
Asked from Mid level upAI Systems
AI Code Completion
Asked from Senior level upAI Systems
LLM Gateway
Asked from Senior level upAI Systems
AI Agent That Takes Actions
Asked from Senior level upAI Systems
LLM Evaluation Platform
Asked from Senior level upAI Systems
AI Document Processing Pipeline
Asked from Mid level upAI Systems

Design a Game Leaderboard

Asked from Junior level upDomain: Caching & Data Structures
Concepts to know first:

Show the top 100 players and any player's own rank in real time, for a game with millions of players.

An analogy

Like a scoreboard that is always sorted: when one score changes, only that name moves up or down, instead of re-sorting the whole list.

Where this design ends up. This is version 3 of 3. Part 5 builds it up from version 1 and says why each part was added.
  1. Clients
    • Game
    • Player
  2. Services
    • Leaderboard service
    • Rank updater
  3. Queues, caches
    • Sorted set
    • Read replicas
  4. Data, outside
    • Scores database

1. Requirements and scope

Functional Requirements
  • Submit a score after each match.
  • Show the top 100 players.
  • Show a player's rank and the players immediately above and below them.
  • Daily and all-time leaderboards.
Non-Functional Requirements & SLAs
  • Rank changes visible within a second or two.
  • Reads far outnumber writes.
  • Scores are never lost: the database is the source of truth.
Key Traffic Assumptions: 5 million daily active players, each playing about 10 matches a day.

2. Back-of-the-envelope numbers

Writes and reads each second
  • Writes: 3,000 score updates a second, at peak (23%)
  • Reads: 10,000 board views a second, at peak (77%)

Balanced: reads and writes are close. Both paths need care, so neither can be slow.

Write Throughput
5M × 10 / 86,400 ≈ 600 score updates/s; ~3,000/s at peak
Read Throughput
~10,000 leaderboard views/s at peak
Storage Growth
Totals: 50M players × ~50 B ≈ 2.5 GB; match history is larger and lives in the database
RAM Cache Footprint
One Redis sorted set with 50M members ≈ 5 GB of memory

3. API

POST/v1/scoresRecord a match result: { playerId, matchId, score }
GET/v1/leaderboards/{id}/top?limit=100Top N players
GET/v1/leaderboards/{id}/players/{playerId}A player's rank and neighbours

4. Data model and storage

Storage Strategy: A relational database holds players and match results as the source of truth. Redis sorted sets handle rankings: adding a score, reading the top N, and finding one player's rank are all O(log n).
MATCH_RESULT(match_id, player_id, score, played_at) · Redis ZSET leaderboard:alltime { member: player_id, score: total }

5. The design, in three versions

Version 1: SQL ORDER BY

Store totals in a table and sort on read.

Game Leaderboard: Version 1: SQL ORDER BY Version 1 of 3

The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.

One request, step by step

Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.

GamePlayerLeaderboard serviceScores database12345
  • The order of the steps
  • A request or its reply

The parts: switch one off

1. Clients

Gamesends a score
Playeropens the top 100

2. Services

Leaderboard serviceupdates and reads ranks

3. Data, outside

Scores databaseevery match result

The steps in words0 of 5 steps shown

  1. Game to Leaderboard serviceHTTPS · 3 ms

    A game sends a score of 900 for player 42.

  2. Leaderboard service to Scores databasequery · 8 ms

    It saves the score.

  3. Player to Leaderboard serviceHTTPS · 3 ms

    A player asks for the top 100.

  4. Leaderboard service to Scores databasequery · 8 ms

    It sorts all scores to find the top 100. This gets slow.

  5. Leaderboard service to Playerreply · 20 ms

    The top 100 goes back to the player.

Why this version
Simplest thing that works for a small game.
Next bottleneck
A player's rank needs a COUNT of everyone above them — slow at millions of rows and thousands of reads a second.

Write path, read path and failures

Each path follows one request through the final design (version 3), one hop at a time.

Write pathSubmit a score

  1. Game server
  2. Score API
  3. Database
  4. Rank updater
  5. Redis primary
  6. Redis replicas
  1. Game server to Score API

    After a match, the game server sends the player id and the score. Only game servers may call this API, not the player's app.

  2. Score API to Database

    The API saves the score in the database first. The database is the source of truth.

  3. Database to Rank updater

    A change event tells the rank updater that a new score is in.

  4. Rank updater to Redis primary

    It updates the player's score in the all-time and daily sorted sets (ZADD). Redis keeps each set in score order.

  5. Redis primary to Redis replicas

    The primary copies the change to its replicas, usually within a few milliseconds.

Read pathShow the top 100 and my rank

  1. Player app
  2. Leaderboard API
  3. Redis replicas
  1. Player app to Leaderboard API

    The app asks for the top 100 and for the player's own place.

  2. Leaderboard API to Redis replicas

    ZREVRANGE 0 99 returns the top 100, and ZREVRANK returns the player's place. Both stay fast with millions of players.

  3. Redis replicas to Leaderboard API

    A second ZREVRANGE around that place returns the players next to them, above and below.

  4. Leaderboard API to Player app

    The app shows the list and the player's rank.

What breaks, and what happens then

  • The Redis primary fails

    What users see
    New scores stop reaching the board for a short time. Reads keep working from the replicas.
    What the design does
    A replica is promoted. If it missed some changes, the rank updater rebuilds the sorted sets from the database.
  • A tournament ends and scores arrive in a burst

    What users see
    The rank updater falls behind, so ranks lag behind real scores.
    What the design does
    Watch the event backlog and add updater workers. The requirement allows a second or two of delay.
  • Someone sends fake scores

    What users see
    Fake names reach the top 100.
    What the design does
    Accept scores only from game servers, and check each one against the match record. Keep a way to remove a score from the database and the set.

6. Deep dives

Why a sorted set
A Redis sorted set combines a skip list and a hash map. Adding a score, reading the top N and finding one member's rank are all O(log n). A SQL index can return the top N quickly, but answering "what is my rank?" means counting every higher score.

7. Follow-up questions

  • What happens if Redis loses its data? (Rebuild the sorted set from match results in the database; show ranks as temporarily unavailable meanwhile.)
  • How do you break ties? (Fold the time into the score — e.g. score × 10^10 − timestamp — so whoever reached it first ranks higher.)

What it costs

The whole board fits in memory: 50 million players need a few gigabytes. Redis replicas for reads are the main cost. An exact rank for every player is the expensive promise, so consider showing exact ranks only near the top.

Another way to design it

For a board of a few thousand players, one SQL query with an index on the score is enough. There is no second system to keep in step. It slows down when millions of rows must be ranked on every view.

8. How answers are judged

A passing answer at Mid level. A complete design with numbers: about 600 score updates a second on average, and about 10,000 leaderboard views a second at peak. It stores scores in a sorted structure for fast ranks and goes deep on one part.

How each level is judged
What is judgedJuniorMidSeniorStaff
BreadthHow much of the system does the answer cover?Names the core parts: clients, servers, a database and a cache.Covers the whole main flow, from the request to the stored data and back.Builds a complete design without being led through it.Covers the system, the systems around it and who owns each part.
DepthHow far does it go into the hard parts?Explains what each part does and why it is there.Goes deep on one part, such as the database or the cache.Goes deep on the two or three riskiest parts.Goes deepest where the risk is largest, and explains why the risk is there.
DrivingWho leads the conversation?Follows the interviewer, step by step.Moves forward alone, with an occasional nudge.Leads the conversation from start to finish.Changes the problem when the question asked is not the right one.
Trade-offsAre choices compared and justified?Names more than one option.Says why one option was picked over another.Compares options in detail, with what each one costs.Ties each choice to cost, speed and risk for the business.
Unclear questionsWhat happens when the question is vague?Answers the questions that are asked.Asks questions to make the problem clear.Sets the scope and says what is left out.Questions the assumptions behind the problem itself.
ScopeWhat does it consider beyond the normal path?Covers the normal path, when everything works.Adds what happens when a part fails.Adds growth: what breaks at ten times the load, and the fix.Adds abuse, cost and the daily work of running the system.

Requirements and scope

Strong answer
Before I design, I want to check the scope. Players submit a score, and we show a top 100 list plus each player's rank and neighbours. Rank changes only need to be visible within a second or two, so clients can pull fresh data instead of getting instant push updates.
Weak answer
Players submit scores after a match. Every viewer's leaderboard must update the instant a new score comes in, so I will push live updates to every connected client over a socket.

Shows: Unclear questionsThe difference: The problem only asks for rank changes to be visible within a second or two, not instantly. Assuming instant push adds a real-time system nobody asked for.

Estimates

Strong answer
5 million players making about 10 matches a day is about 600 score updates a second on average, with a stated peak of 3,000. Reads are larger: about 10,000 leaderboard views a second at peak, over three times peak writes. So the design should be built around fast reads, not fast writes.
Weak answer
About 3,000 score updates a second at peak is the main load to design for, since that is how often the leaderboard changes.

Shows: ScopeThe difference: At peak, reads reach about 10,000 a second, over three times the 3,000 peak writes. The weak answer designs for the smaller side.

Core design

Strong answer
Every match result is written to a database table, which is the source of truth. A player's total score also updates a Redis sorted set. That makes the top 100 and any player's rank both fast lookups, without scanning every score.
Weak answer
I would keep every player's total score in a table. I would run a query sorted by score, with a count of higher scores, to find the top 100 and any rank.

Shows: DepthThe difference: Sorting a table and counting higher scores on every request gets slow at millions of players and thousands of reads a second. A sorted set avoids scanning.

Deep dive

Strong answer
The hard part is finding one player's rank fast among 50 million. A sorted set keeps scores ordered using a skip list next to a hash map. Adding a score, reading the top 100, and finding one rank are all fast, without ever re-sorting everything.
Weak answer
I would keep every score in a Redis hash, one field per player. I would sort all of them in the app whenever someone asks for the top 100 or their rank.

Shows: DepthThe difference: Sorting 50 million scores from a hash on every request is slow. A sorted set keeps them ordered already, so it never needs a full re-sort.

Failures and trade-offs

Strong answer
If Redis loses the sorted set, I would rebuild it from the match results in the database, since that is the source of truth. Ranks show as temporarily unavailable while it rebuilds, rather than showing wrong numbers from a half-built set.
Weak answer
If Redis loses its data, new scores coming in will fill the sorted set back up on their own, so the leaderboard recovers by itself.

Shows: ScopeThe difference: New scores alone never restore players who have not scored again, so most ranks stay missing. Rebuilding from the database recovers everyone at once.

We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.

10. Check your design with your own AI

Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.

The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.

See the prompt
You are a system design interviewer. Review my design for the interview problem below.

Problem: Design a Game Leaderboard
Show the top 100 players and any player's own rank in real time, for a game with millions of players.

What users must be able to do:
- Submit a score after each match.
- Show the top 100 players.
- Show a player's rank and the players immediately above and below them.
- Daily and all-time leaderboards.

How well it must work:
- Rank changes visible within a second or two.
- Reads far outnumber writes.
- Scores are never lost: the database is the source of truth.

Numbers to assume:
- 5 million daily active players, each playing about 10 matches a day.

Judge my design at the Mid level.
A passing answer at this level: A complete design with numbers: about 600 score updates a second on average, and about 10,000 leaderboard views a second at peak. It stores scores in a sorted structure for fast ranks and goes deep on one part.

For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each:
1. Requirements and scope
2. Estimates
3. Core design
4. Deep dive
5. Failures and trade-offs

Then ask me the two follow-up questions an interviewer would ask next.
Do not write a full model answer for me.

My design:
[Describe your parts, how one request moves through them, and why you chose each one.]