Elimination Quiz Arena: Scalable Live Game Backend Design
System DesignModel answerLast updated
Design a backend for elimination-style live quiz games with many players per room, fair timing, crash recovery mid-round, and spectator traffic kept away from gameplay.
You are asked to design the backend for an online quiz game played in elimination format.
How a game works
- Between a few dozen and a hundred or more players are placed together in one room.
- Questions are shown one round at a time. Each round has a fixed answer window.
- When a round closes, anyone who answered incorrectly is removed, and so are the slowest of the players who answered correctly.
- The game continues until one player remains. That player wins.
- Anyone can watch a game in progress and follow its live leaderboard without taking part.
Required capabilities
- Matching: place waiting players into rooms with others of similar skill.
- Live state: each player's status (still in or out, current score) is updated in real time for everyone in the room.
- Round resolution: compute eliminations at the end of every round, then produce the final ranking and winner when the game ends.
- Spectating: let viewers open any running room and follow its leaderboard.
Non-functional goals
- Low-latency updates inside each round.
- Horizontal scaling as the number of rooms grows with the player count.
- Isolation: a fault in one room, or a surge of spectators, must not degrade other rooms or the players in the same room.
What to cover
- Only the room size is specified. State your own assumptions for concurrent rooms, players and spectators, and design for them.
- The discussion will concentrate on how work is divided among servers and how you recover when a server dies mid-game. Detailed API design is less important.
- Make explicit decisions on the open points: how many slow players are removed per round and what happens when everyone is wrong, how answer speed is measured fairly, and whether a disconnected player can rejoin.
Hints
Hint 1
Make the room the unit of everything: one room is owned by exactly one game server at a time, which keeps ordering and settlement simple. Then ask how ownership is assigned, renewed, and taken away.
Hint 2
For fairness and recovery, think about what must be durable before the server acknowledges an answer or closes a round, and how a new owner can rebuild a room from a snapshot plus an append-only log of events.
Hint 3
Treat spectators as a separate read path: publish already-settled state to a pub/sub or cache tier and fan out through edge or gateway servers, so spectator load never touches the game server's hot loop.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Assumptions
- Peak: about 20,000 concurrent players, 200-500 active rooms of up to ~100 players, and about 200,000 spectators (spectators greatly outnumber players).
- Round window of 10-15 s, up to ~15 rounds. Each round's result is pushed to clients within ~200 ms of the round closing.
- Elimination rule (my decision, stated up front): remove everyone who answered wrong or not at all, plus the slowest
ceil(10%)of the correct answerers. If every survivor is wrong, nobody is eliminated that round, or alternatively the fastest wrong answerer is kept; I would pick "no elimination, replay with a new question" to avoid ending the game with zero winners. Ties on time are broken by earlier server receive sequence, then by score.
High-level architecture
- Matchmaking service: players enter a queue keyed by skill bucket (for example by rating band). A matcher fills a room when it reaches the target size or when a wait timeout expires, widening the band as waiting time grows. It creates a room record and asks the placement service for an owner.
- Room placement / coordinator: keeps a map
room_id -> game serverin a strongly consistent store (etcd or ZooKeeper style). - Game servers: each owns a set of rooms and runs the round loop in memory.
- Realtime gateway: WebSocket servers holding client connections. Players' messages are routed to the owner of their room.
- State store: a fast store (Redis or similar) for room snapshots and an append-only event log (Kafka or a durable stream) per room.
- Spectator tier: read-only fan-out, described below.
- Question service: serves question content and correct answers, with answers never sent to clients before a round closes.
Partitioning
Partition by room_id. A room is a small, self-contained state machine of ~100 players, so there is no cross-room coordination and it scales linearly: add game servers and place new rooms on the least loaded. Use consistent hashing or a placement table; a table is better because it permits explicit migration and draining during deploys. A single game server comfortably handles dozens of rooms since each is only a few thousand messages per round.
Authoritative round settlement
- The game server is the only authority. Clients send an answer choice and a client nonce; they never send timing or correctness.
- Fair timing: the server releases the question at time T0 and records T_recv for each answer. Latency differences are unavoidable, so reduce them: use a short fixed answer window, start each player's timer on a server-sent "question shown" acknowledgement if fairness demands, or compensate with measured per-connection RTT (capped, to avoid players faking high RTT). Mention the trade-off: RTT compensation is fairer but is gameable, so cap and audit it.
- Settlement: at window close, the server freezes the answer set, ignores late arrivals, sorts correct answers by (time, receive sequence), computes eliminations and scores, and writes one
RoundSettled(room, round, eliminated[], scores)event. - Exactly once: the settlement event has a deterministic key
(room_id, round). Writes are idempotent (conditional put), so a retry or a second server cannot eliminate someone twice. - Anti-cheat: validate that the player is alive, the round is open, and only the first answer per round counts. Rate limit messages. Keep correct answers server-side. Flag suspiciously constant response times for offline review rather than blocking inline.
Failure recovery mid-round
What is durable: the room snapshot after every settled round (alive set, scores, round number, question id, round deadline) plus the log of accepted answers for the open round, written before the ack goes to the client (or batched within a few ms).
Detection and takeover:
- Each game server holds a lease per room (or per server) in the coordinator, renewed every ~1-2 s with a TTL of ~5 s.
- When the lease expires, the coordinator picks a new owner and increments a fencing token / epoch.
- The new owner loads the last snapshot, replays the answer log for the open round, and continues. If the deadline already passed it settles immediately; otherwise it keeps the original absolute deadline, or extends it by the outage length for fairness (my choice: extend, and announce it to clients).
- All writes carry the epoch. The state store rejects writes from an older epoch, so a paused old owner (GC pause, network partition) cannot corrupt the room. That is the answer to "how do you prevent two servers running the same room".
- Gateways re-resolve the room owner and clients reconnect automatically with exponential backoff and jitter, resuming from the last event sequence number they saw.
Trade-offs: synchronous logging of each answer adds a few ms but removes lost answers; batching is faster but loses up to a batch if the server crashes, so clients should retry unacknowledged answers (idempotent by nonce).
Reconnection
A disconnected player keeps their seat until the round ends. If they reconnect within the window they can still answer; missing a round counts as wrong. After elimination they become spectators automatically.
Spectator isolation
- Spectators never connect to game servers. After each settlement (and at a throttled rate for in-round live counts, for example 2 updates/s), the game server publishes a compact leaderboard event to a pub/sub topic per room.
- A separate spectator gateway tier subscribes to the topics and fans out to viewers. Popular rooms are served by many gateways, each subscribing once, so game-server load is constant regardless of viewer count.
- Late joiners get the latest snapshot from a cache plus a stream of deltas. Spectators may lag players by a second or two, which is acceptable and lets you coalesce updates.
- Back-pressure: drop or coalesce updates for slow spectator connections; never block the publisher.
- Spectating can also be hidden slightly behind the live state to limit information leaking to players via a second screen.
Isolation and operations
- Per-room goroutine or actor with bounded queues, so one room's burst cannot starve others.
- Per-server rooms cap and autoscaling based on rooms and CPU; drain servers by migrating rooms between rounds, when state is smallest.
- Separate resource pools for players and spectators.
- Metrics: round settlement latency, answer-to-ack latency, lease expiries, reconnect rate, spectator lag.
Common mistakes
- Trusting client timestamps for speed.
- Letting the spectator path read from the game server directly.
- Failover without fencing, producing split-brain rooms.
- Not defining behavior when all players are wrong or tie on time.
- Storing only in-memory state, so a crash ends every game on that server.