Design an Online Multiplayer Chess Service with Real-Time Moves
OpenAISoftware Engineer · OnsiteLast updated
Design an online chess service where two remote players play live games, every move is validated and delivered to the opponent immediately, and results are recorded. It tests authoritative game state, real-time transport, fair clocks, move ordering, recovery of games in progress after failures, and scaling to many concurrent games and spectators.
Design an online chess service: two players on different devices play a game of chess against each other over the internet, each move is checked against the rules of chess and shown to the opponent right away, and the game ends in a win, loss or draw that the service records. This came up as the system design portion of a phone screen for a software engineer role. The prompt was only "chess", so how far the scope extends beyond live two-player games is something to settle with the interviewer.
Go past a component diagram. Be ready to explain in detail how a single move travels from one player to the other, who decides whether it is legal and when it happened, and what happens to a game in progress when a server or a connection fails.
Clarifying Questions
- Is the scope only live two-player games, or also finding an opponent (matchmaking), ratings, game history and replays?
- Are games timed, and if so, which time controls must be supported, from very fast games to games with days per move?
- What scale should the design target: concurrent games, active players, and moves per second at peak?
- Web, mobile, or both? Must a player be able to reconnect mid-game, possibly from another device?
- Are spectators in scope, including a single game watched by a very large audience?
- Is cheat detection in scope, or only worth mentioning?
Hints
Hint 1
Decide who owns the truth of a game: Pick one place that holds the authoritative state of each game and accepts or rejects every move, and work out how both players' connections reach that place.
Hint 2
If games are timed, the clock is game state: Work out which component decides that a player has run out of time, and what should happen when a move is still in flight as the clock reaches zero.
Follow-up questions
- A game server crashes mid-game. How do both players end up back in the same position with correct clocks?
- How would you let a very large number of people watch one top game live without slowing it down for the players?
- How do you stop a player from submitting two moves for the same turn, or a move after the game has ended?
- How would you detect players who use a chess engine during games without adding latency to move delivery?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.