Katkat

Design a Real-Time Online Chess Platform

OpenAISoftware Engineer · Technical Screen

Last updated

This question tests your ability to design a low-latency, stateful distributed system that handles real-time bidirectional communication and ensures strict move consistency.

Problem Statement

Design the backend architecture for a global, real-time chess platform similar to Lichess. The system must support millions of concurrent players and spectators. Key requirements include low-latency move broadcasting, accurate clock synchronization, and high availability in the event of server failure.

Functional Requirements

  • Move Validation: Ensure moves follow chess rules and turn-based logic.
  • Real-Time Updates: Players and spectators must receive move updates with sub-100ms latency.
  • Clocks: Accurate countdown for both players, independent of client-side latency.
  • Resilience: If a user loses connection, they must be able to resume the game in the exact state upon reconnection.

Non-Functional Requirements

  • Concurrency: Support 100k+ concurrent active games.
  • Consistency: Moves must be processed sequentially. No "double moves" or race conditions.
  • Availability: A server crash should not result in a lost game state.

Deliverables

  1. High-level system architecture diagram (describe components).
  2. API/Protocol definition for move submissions and state synchronization.
  3. Strategy for clock management (how to account for network lag).
  4. Data storage strategy for game history and state persistence.

Hints

Hint 1

Consider using WebSockets for bidirectional communication and a message broker for pub/sub game events.

Hint 2

Think about where the 'authoritative' game state resides: is it in a database, a cache, or memory?

Hint 3

Address clock drift by calculating time elapsed on the server rather than trusting client-reported timestamps.

Follow-up questions

  • How would you handle a scenario where a player disconnects and reconnects mid-move to a different server instance?
  • How would you optimize the fan-out for a 'Grandmaster' game with 50,000 active spectators?
  • What specific strategies would you use to ensure move ordering remains consistent under high load?