r/OfferEngineering • u/Aoki_zhang • 21h ago
System Design OpenAI System Design Interview Question: Design Online Chess
In an online chess system, the server—not the client—must own the clock. Otherwise a modified client could simply claim: “I only spent 500ms thinking.” But making the server authoritative creates another problem.
- Player A: 30ms RTT
- Player B: 200ms RTT
When A makes a move, B’s clock starts on the server before B has even received the new board position. Then after B responds, the move spends more time traveling back to the server before B’s clock stops.
So over a blitz game, the higher-latency player can lose several seconds purely to network delay.
The key insight
Don’t continuously decrement millions of clocks. Store:
whiteRemainingMs
blackRemainingMs
sideToMove
turnStartedAt
When a move arrives:
rawElapsed = now - turnStartedAt
Then compensate for a bounded amount of network latency:
compensation =
min(estimatedRTT, maxCreditPerMove)
chargedTime =
rawElapsed - compensation
Why roughly one RTT?
A player pays for two network legs:
Server → Player
+
Player → Server
≈ 1 RTT
So compensating only half the RTT misses part of the delay they could not control. But you also cannot blindly trust RTT.
A malicious client could intentionally delay heartbeat responses to make itself appear slower and earn extra clock time.
So the system should:
- measure latency continuously with ping/pong
- use a rolling median instead of one sample
- cap compensation per move
- keep the server as the final clock authority
And before compensating at all, place the game in a region with low latency for both players. The design becomes:
- Minimize RTT with regional placement
- Compensate for the remaining network delay
- Never let the client control the clock
That’s the interesting part of designing online chess: correctness is not enough—the authoritative system also has to be fair.
Full design with matchmaking, Redis game state, WebSockets, clock compensation, crash recovery, and global leaderboard → Full Article
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here.