KatInterview

Design the Backend for a Real-Time Multiplayer Board Game

System DesignModel answer
MediumModel answerSystem Designwebsocketsconcurrencyreal-time

Last updated

Design a backend that manages live game state, enforces turn-based rules, and delivers move updates in real time across thousands of concurrent sessions.

Context

A startup is building an online platform for a classic two-player turn-based board game (think 8×8 grid, two opposing piece sets, strict movement rules, and mandatory capture sequences). You have been asked to design the backend that powers live gameplay.

The board state is small, but correctness under concurrent writes and low-latency delivery to both players are non-negotiable.

What you need to design

Functional scope

  • Lobby and pairing: players enter a queue and get matched with an opponent of similar skill.
  • Move handling: the server receives a player's intended move, validates it against the current board and the full ruleset (turn order, legal paths, forced captures, multi-step sequences), and applies it if valid.
  • Live delivery: both players see the updated board within a fraction of a second.
  • Session replay: players can step through every move of a completed game.

Non-functional targets

  • Tens of thousands of simultaneous games.
  • End-to-end move latency under ~150 ms within a region.
  • Zero tolerance for illegal state: two moves sent in the same instant must not both succeed.

What to cover in your answer

  1. API surface — the endpoints or WebSocket events players use to make moves, receive updates, and reconnect after a drop.
  2. Data model — schema for players, active game state, and the move log.
  3. Concurrency control — the exact mechanism that guarantees only one valid move commits per turn.
  4. High-level architecture — the major components (gateways, game service, cache, pub/sub, persistent store) and how a move flows through them end to end.
  5. Trade-offs — at least two meaningful design choices with reasoning.

You are not expected to implement a rules engine. Focus on infrastructure and correctness.

Hints

Hint 1

Start by separating hot state from durable state: the board the server checks every move doesn't need to live in Postgres on the critical path.

Hint 2

Think about what 'one move per turn' really means technically: it's a check-and-set operation. Which primitive gives you an atomic compare-and-swap, and where does it live?

Hint 3

The two players might connect to different gateway nodes. How does a move applied by one gateway reach the other player's socket? Sketch the pub/sub path explicitly.