Online Chess

Real-Time Chess Platform

Design an online chess site: pair players of similar strength, relay moves in real time, run fair clocks on the server, rate players with Glicko-2, and keep every game safe through disconnects and crashes.

Overview

Two people who have never met play a game of chess over the internet, each with a few minutes on the clock. The site pairs them, sends each move to the other in a fraction of a second, runs both clocks, and ends the game correctly when someone is mated, runs out of time, or the position is drawn.

The hard parts are not the chess rules (a library can check legal moves). They are trust and time. A client cannot be trusted to report its own clock or its own moves, so a server must decide both. Network delay is different for each player, so the clock must be fair without letting anyone claim free time. And a game in progress must survive a player's train going through a tunnel, or a server restarting.

This topic designs a generic online chess site. The numbers are interview assumptions; where Lichess, an open-source chess site, documents its own behavior, that is named and cited.

Questions to ask first

  • How many players and games? — 10 million players a day, 5 games each: 25 million games a day
  • Which time controls? — Bullet, blitz, rapid and classical, with an optional increment per move
  • Rated games? — Yes, with a separate Glicko-2 rating per time control
  • Variants? — Standard chess first; variants are separate pools
  • Spectators? — Yes, anyone can watch a live game
  • What if a player disconnects? — Their clock keeps running; they can reconnect and continue

What you will be able to do

  • Explain why one server must own each game, and route every message for that game to it.
  • Run a fair server-side clock with increment and capped lag compensation.
  • Pair players with a rating window that widens as they wait.
  • Update ratings with Glicko-2, with runnable code checked against Glickman's example.
  • Recover a game after a disconnect or a server crash from its move log.

Key concepts

  • Authoritative game server
  • One owner per game
  • WebSocket
  • Move sequence numbers
  • Fischer increment
  • Lag compensation
  • Flag fall
  • Seek pool
  • Glicko-2
  • Move log

Functional requirements

  • Seek a game by time control and rated or casual; get paired with a similar-rated player
  • Play moves in real time; illegal moves are rejected
  • Run both clocks with an optional increment; end the game on flag fall
  • End games on checkmate, stalemate, resignation, agreed draw and the draw rules
  • Update ratings after rated games
  • Replay past games and let anyone watch live games

Non-functional requirements

  • A move reaches the opponent within 100 ms plus network delay at p99 (a target we chose)
  • The server's clock is the only clock that counts
  • No move is lost once the server has confirmed it, even if a server crashes
  • Pair players within about 10 seconds in popular pools (a target we chose)
  • Spectators never slow down the players

Interview questions

  • Why must the server be authoritative for moves and clocks?
  • How do you route both players to the same game state?
  • How does lag compensation work, and how do you stop abuse?
  • How does matchmaking balance fairness and waiting time?
  • How is Glicko-2 different from Elo?
  • What happens if a game server crashes mid-game?
  • How do you serve thousands of spectators for one game?
  • How do you make sure ratings are applied exactly once?

Sign up free to read the full topic

More System Design topics

Start free on Cariara · Coding problems · System design studio