Design Online Chess
Understanding the Problem
♟️ What is online chess? Sites like chess.com and lichess let two people anywhere in the world play a game of chess against each other in real time. Each player has a clock that runs only on their turn, and when the game ends both players' ratings move up or down. On top of that sit leaderboards, spectating, and the constant background work of catching people who use engines.
The interesting part isn't the chess. Validating a move is a solved problem and a library call. What makes this a good interview question is that a game is a tiny, strictly ordered state machine shared by two people over unreliable networks, where a hundred milliseconds of lag can lose someone a bullet game, and where there are hundreds of thousands of these games running at once.
Functional Requirements
Start by agreeing with your interviewer on the user-facing features. A chess site has a lot of them (puzzles, lessons, analysis boards, forums), so be explicit about the slice you're designing.
Core Requirements
- Users should be able to find an opponent for a chosen time control (for example 3+2 blitz), matched to someone of similar rating.
- Users should be able to play a game in real time: make moves, see the opponent's moves immediately, and see both clocks tick down accurately.
- Users' ratings should update when a rated game ends.
- Users should be able to view leaderboards of the top players for each time control, and see their own rank.
Below the line (out of scope)
- Puzzles, lessons, analysis boards and chat.
- Tournaments and arenas (they reuse the same game engine with a different pairing loop).
- Correspondence chess, where a move can take days. That's a CRUD app, not a real-time one.
- Building the cheat-detection model itself. We'll design where it plugs in.
Non-Functional Requirements
Ask your interviewer how big the site is and which time controls matter, because bullet chess (one minute per side) is what sets the latency bar. For our design: 10 million daily active users, a peak of 1 million players online at once, and therefore up to 500,000 concurrent games.
Core Requirements
- The system should deliver a move to the opponent in under 100 ms within a region (p99 under ~250 ms), because players feel lag directly in bullet games.
- The system should keep time fairly: the clock is authoritative on the server, and players with slow connections shouldn't be robbed of time by network delay.
- The system should never lose or reorder a move, even if a server crashes mid-game. A game in progress should resume where it left off.
- The system should scale to 500,000 concurrent games and 1M open connections, with famous games watched by 100,000+ spectators.
- Ratings should be updated exactly once per game, and leaderboards can be a few seconds stale.
Below the line (out of scope)
- Cross-region play with sub-50 ms latency between players on different continents. Physics wins; we'll host each game in one region.
- Full anti-abuse and account-security systems.
A quick back-of-the-envelope tells us where the pressure is. A blitz game lasts around 8 minutes and has about 80 plies (moves by either side), so each game produces a move roughly every 6 seconds. With 500,000 games, that's about 83,000 moves per second, call it 100k at peak. Each move is tiny: a move in UCI notation (e2e4) plus two clock values fits in well under 100 bytes. Even with fan-out to both players and a few spectators, that's tens of MB per second of traffic, which is nothing for a fleet.
Storage is small too. If each player plays around five games a day, that's 25 million games a day. Stored compactly (moves, clock times, metadata) a game is around half a kilobyte, so that's roughly 12 GB a day and 4-5 TB a year.
The number to notice is the write rate per game: one move every few seconds, from two writers who strictly take turns. There is no contention problem here. The challenge is latency, fair timekeeping, durability and routing a message to the one place that owns a game. Everything can be sharded by game ID, and no game ever needs to talk to another.