KatInterview

Skill-Based 1v1 Pairing Backend for a Board Game Platform

System DesignModel answer
HardModel answerSystem Designmatchmakingdistributed-systemsredis

Last updated

Design a scalable, fault-tolerant service that pairs two players of similar rating, loosens its criteria as waiting grows, supports cancellation, and discourages opponent dodging.

Build a Pairing Service for a Two-Player Board Game

You are designing the backend that connects two players for a head-to-head chess game. The platform has millions of people online at once. Players should get into a game quickly, and the opponents should be reasonably evenly matched.

What the service must do

  1. A player can enter a waiting pool. Their skill rating (Elo) is associated with the request.
  2. The service tries to find an opponent whose rating is close.
  3. The acceptable rating gap grows the longer a player waits.
  4. A player can withdraw from the pool at any time.

Qualities the system must have

  1. Speed: games should start as soon as a suitable opponent exists.
  2. Availability: if a single pairing node dies, the service keeps working.
  3. Elasticity: it must absorb bursts, for example during large events.
  4. Fairness: players should not be able to repeatedly avoid certain opponents without consequence.

What to deliver in your answer

  1. API: the main endpoints for entering and leaving the pool.
  2. Architecture: the components, how the pool is split across machines, and where state lives.
  3. Pairing logic: how the widening acceptable gap works in practice.
  4. Storage: how you keep player state and active search requests.

Behaviors to cover

  • A player rated 1500 who has waited 10 seconds might only be paired with ratings from 1480 to 1520. After 30 seconds, the range might be 1400 to 1600.
  • If a player's connection drops, their request must be cleaned up from the pool without manual action.

State your assumptions and back them with rough numbers. Discuss trade-offs and failure cases.

Hints

Hint 1

Do a quick capacity estimate with Little's law (arrival rate x average wait). The number of players waiting at any moment is probably small enough to fit comfortably in memory, so the real difficulty is coordination, not storage.

Hint 2

Treat the acceptable rating gap as a pure function of elapsed wait time that is recomputed each pairing cycle, rather than a value you store and update. Think about whether both players must accept each other's gap.

Hint 3

Ask what happens when a cancel request and a pairing decision happen at the same moment, and when a worker dies mid-cycle. Single ownership per partition plus an atomic claim step solves most of it.

Hint 4

For fairness, consider hiding the opponent's identity until the game is committed, escalating cooldowns for aborts right after a match, and avoiding immediate rematches of the same pair.