KatInterview

Design a Live Multiplayer Typing Race with Spectator Support

System DesignModel answer
MediumModel answerSystem Designreal-timewebsocketsmatchmaking

Last updated

Design a real-time platform where players matched by language race to type the same passage, see live progress and errors, serve error-freeze penalties, and can be watched by spectators.

Live Multiplayer Typing Race

You are designing a platform where users compete in real-time typing races. A player picks a language, gets matched with others into a race, and everyone types the same passage from start to finish. The race is live: each racer sees every other racer's cursor position and mistakes as they happen. Making a mistake locks that racer's keyboard for one second. Anyone who wants to watch a race in progress can join as a spectator.

What the system must do

  • Match players by chosen language into races of 2 to 8 participants, all typing the identical passage.
  • Validate keystrokes on the server and enforce a 1-second input freeze whenever a racer makes an error.
  • Broadcast each racer's progress and errors to all other racers and to any spectators watching that race, in real time.
  • Allow spectators to watch without affecting the race itself.

What is intentionally left open — state your assumptions or ask first

  • How many concurrent racers and spectators does the system need to handle?
  • What latency is acceptable for the live view — 100 ms? 500 ms?
  • How long can a player wait in the matchmaking queue before a race starts with fewer than 8 players?
  • How does a race end and how is the winner determined — first to finish, time limit, partial-progress ranking?
  • Does "language" mean the natural language of the passage (English, French, …), a programming language for code snippets, or both?
  • Are keypresses that arrive during the freeze period silently dropped or queued?
  • Must the system defend against cheating such as automated input or clipboard paste?
  • Do race results feed a persistent leaderboard or player ranking?

What is expected

Walk through your design end-to-end. Cover matchmaking, the race loop, real-time state distribution to racers and spectators, fairness under network jitter, and failure handling. Include a rough data model, the key APIs or message types, and capacity estimates tied to your stated assumptions.

Hints

Hint 1

Start by pinning down your assumptions on scale and latency — every downstream choice (transport, topology, fan-out strategy) depends on them. A matchmaking queue per language is the natural unit; think about what triggers a race to start early when the queue is short.

Hint 2

The server must be the authority on keystroke validity and freeze timing, not the client. Sketch the per-race state the server maintains (cursor position, freeze-until timestamp, finish time) and the exact message the server emits after each valid keystroke so all viewers stay in sync.

Hint 3

Spectator fan-out is the scalability pressure point. Spectators should receive the same event stream as racers but through a path that cannot block or slow the race loop — think about separating the write path (racer → race server) from the read/broadcast path (race server → everyone watching).