Designing a Live Trivia Elimination Game with Spectator Fan-Out
System DesignModel answerLast updated
Design the backend for a live riddle battle: rooms partitioned by coordinator, server-authoritative timing, crash recovery, and spectator isolation.
You're building the backend for a live multiplayer riddle game ("Riddle Showdown"). Dozens to a few hundred players join a room together. Each round, a riddle is broadcast to the room with a fixed answer window. When the window closes, every player who answered incorrectly is eliminated, plus the slowest fraction of those who answered correctly. Play repeats until one player remains or riddles run out. Anyone — player or not — can open an in-progress room and watch a live leaderboard.
Design a system that supports:
- Matchmaking: grouping waiting players into rooms, roughly balanced by skill, without excessive waiting.
- Live round state: each player's alive/eliminated status and running score propagate to everyone in the room in real time.
- Authoritative settlement: the server — not any client — decides who was correct and in what order, then applies the elimination rule.
- Spectating: a spectator can join any in-progress room at any time and watch a live leaderboard without participating.
Non-functional requirements: round outcomes publish within a second or two of the window closing; scale horizontally to roughly 2,000 concurrent rooms of up to 300 players each; a crash in one room must not affect other rooms; a room that goes viral with tens of thousands of spectators must not slow or destabilize gameplay in that room.
State any additional assumptions you need and justify them. The interviewer cares most about partitioning and failure recovery, not exact API shapes.
Hints
Hint 1
The elimination math for one round only involves players in that one room — let that property drive your sharding key.
Hint 2
Clients lie about timing. Timestamp answers on the server at the moment of receipt, measured from a round-start time the server itself controls.
Hint 3
Write an answer to a durable, room-keyed log and only acknowledge it to the player after the write succeeds; replay the log on takeover.
Hint 4
Never let spectators subscribe to the gameplay process — publish a small leaderboard delta and fan it out through a separate tier.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Partitioning: one room, one owner
Round settlement only needs the answers from players inside a single room, so the room is the natural sharding unit. Each active room is owned by exactly one "room coordinator" process. A room-assignment service hands out leases — e.g., entries in etcd or Redis with TTLs — so a coordinator owns a room only while it keeps its lease fresh. The coordinator keeps the room's live state in memory: roster, scores, alive flags, current round, round-start and deadline timestamps. It is the single source of truth for that room.
Because rooms never talk to each other, capacity grows linearly: more concurrent rooms means more coordinators, and a slow or dead coordinator touches only its own room. At 2,000 rooms × 300 players = 600,000 players max, one coordinator can comfortably own many rooms — the in-memory state per room is tiny (300 players × a few fields plus a round buffer), so a single process can hold dozens or hundreds of rooms. The lease is per-process; on loss, every room that process owned fails over together, which is a trade-off worth stating.
Matchmaking is a separate, roughly stateless service. It buckets waiting players by a skill rating, batches them into target-sized groups, and when a bucket doesn't fill within a timeout either widens the skill band or starts an under-filled room. It then requests a fresh lease and hands the finished roster to a coordinator. This queue never touches in-progress room state, so it scales on its own.
Authoritative, tamper-resistant timing
You cannot trust a client to report how fast it answered — a patched client could always claim to be first. Instead, the coordinator timestamps every answer at the moment it receives it, using its own clock, and computes elapsed time relative to the round-start timestamp it broadcast. Correctness and the speed ranking are both derived only from these server receipts, only after the answer window has closed — never from any timing hint the client supplies.
This doesn't erase network latency differences between players, but it removes the obvious cheat and gives everyone the same auditable rule. A refinement to mention: players with poor connections are at a mild disadvantage, which you can partially mitigate by ranking within a tolerance band or using a server-side submission-order proxy. Keep settlement purely server-driven.
Settlement and durability
The coordinator buffers answers only during the open window and computes eliminations exactly once, when its own clock passes the deadline — a single cutover nobody can race. To survive a crash, it appends every accepted answer and every round-boundary checkpoint (roster, scores, round number, start/deadline) to a durable, room-keyed log: a row per room in a fast KV store, or a per-room append-only stream. An answer is acknowledged to the player only after it is durably written, which is what makes replay sound.
On crash, a per-coordinator heartbeat on the lease lets a watchdog detect death quickly. A standby claims the lease, replays the last checkpoint plus any logged answers for the open round, and then either resumes the same window with its remaining time (if the deadline hasn't passed) or settles immediately from the already-logged answers (if it has). Players see a short "reconnecting" state rather than losing the room. The main dial to discuss is the heartbeat/lease timeout: shorter means a tighter availability gap but more false failovers on transient network blips.
Isolating spectators
Spectators never connect to the coordinator. After each round the coordinator publishes one small leaderboard delta — player id, score, alive flag — to a per-room pub/sub topic. A separate, horizontally scaled fan-out tier (WebSocket gateways or an SSE relay) subscribes to that topic and serves any number of viewers. A room with 50,000 spectators costs the coordinator exactly the same one message per round as a room with zero, so popularity on the viewing side can never degrade gameplay. A spectator joining mid-round first reads the latest persisted checkpoint for a baseline leaderboard, then subscribes for subsequent deltas.
Trade-offs
Pinning a room to one coordinator gives a clean, totally-ordered source of truth, at the cost of a short availability window bounded by the failover timeout. To keep the game responsive, the answer window and settlement kickoff should be driven by server time shared across coordinators (or an external timer service), so a slow coordinator can't stretch a round indefinitely.