AlgoViz

Design a Matchmaking System

medium 45 min

Put ten people who are waiting into one fair game, near enough to a server, before they give up.

Video lesson · Chapter 1 of 5

Press Play twice without joining two games

0:00 / 4:36

Theory

Read or listen first. About 1 min.

What it is

A matchmaking system takes players who want to play and groups them into games. It looks at how strong they are, how far they are from each server, who they came with and how long they have waited.

Three wishes pull against each other: a fair game, a short wait and a low delay to the server. Every matchmaker is a way to give up a little of each, and to give up more as time passes.

Why it exists

An unfair game is not fun for either side, and an empty waiting screen makes people leave. Both look to the player like a broken game.

The same problem appears when drivers meet riders, people meet tutors or kidneys meet patients: a pool of waiting people, rules about who fits, and a price for waiting.

A short history

  1. 1960

    The United States Chess Federation adopts Arpad Elo's rating system.

  2. 1970

    The world chess federation FIDE adopts Elo ratings.

  3. 2006

    Herbrich, Minka and Graepel present TrueSkill at NIPS: a rating with a mean and an uncertainty, for teams and many players.

Words to know

Ticket
A request to play: one player or a whole party, with attributes.
Pool
The waiting tickets for one mode in one region.
Rating (MMR)
A number that estimates strength, for choosing opponents.
Uncertainty
How sure we are of a rating. High for new players.
Widening
Accepting a larger difference as the wait grows.
Ready check
Everybody in a proposed game must press Accept.
Backfill
Filling an empty place in a game that is already running.

Solve it like an interview

New to it? Start with Approach. Revising? Go straight to the mock.

  1. 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
  2. 2ScopeAsk what changes the design, then commit to a short list.
  3. 3NumbersWork out a number when the answer changes what you build.
  4. 4API and dataThe contract first, then the data that serves it.
  5. 5DesignStart with the smallest system that works. Change it only when something breaks.
  6. 6Deep divesCompare the options before you open them, then say which you would pick.
  7. 7Explain your choicesAnswer first. Then compare your reasoning.
  8. 8By levelThe same question is judged differently for mid, senior and staff.
  9. 9MockAnswer against the clock, then score yourself.

How it works

Step through the idea, or press Play.

Step 1 of 3

Ask. A player or party opens a ticket with a rating and delays to each region

Understand it

Start here

Fair tug-of-war teams

Tug-of-war at the school fair
88723223 against 7

What we build

Games of five against five

A service for a game with 50 million players a day. It takes tickets from players and parties, forms balanced games, checks that everybody is ready, takes a server close to them, and fills places when somebody leaves. It does not run the game itself: see game state sync.

  • Skill

    Both teams have about the same chance.

  • Wait

    Usually under a minute, never endless.

  • Delay

    A server that all ten can reach quickly.

  • Company

    Friends stay together, and parties meet parties.

The hard part

Choosing, not storing

At peak about 312,000 players are waiting. At 1 KB each that is 312 MB, which fits in the memory of one small machine. What is hard is the choice: 100 candidates can make 17 trillion different groups of ten. And two matchers must never take the same player.

Three wishes

The finished system

Where the design ends up

This is the last version. The Design tab starts with one service and one database.

The whole system

Players send tickets to the ticket API, which reads ratings from PostgreSQL and stores tickets in Redis. Pool matchers read the tickets, keep them in memory and hold a lease for each pool. They pass a proposal to the match service, which runs the ready check through the push gateways and asks the fleet manager for a game server. Results of finished games go to a result log.
Pink opens tickets, blue makes a game, orange updates ratings later.

Similar systems

SystemWhat differs
Chess siteTwo players, one rating, seconds of wait
Battle royale100 players, loose skill, bots may fill places
Team shooterRoles, parties and ranks
Car football gameA rating for each playlist
Ride hailingDistance instead of skill: uber and lyft

Where to read more

The ideas behind it

Each idea has its own page.

For the interview: Approach, Scope, Numbers, API and data, Deep dives and Mock.

Summary

The whole topic in one minute.

A matchmaker keeps a pool of tickets for each mode and region and lets one process own each pool. The owner sorts the pool by rating, forms groups around the longest waiting tickets, and accepts a wider range as they wait.

A proposed game is a promise that can fail. Tickets are reserved, players confirm, a warm server is taken, and whoever accepted returns with the waiting time they had. Game servers cost far more than matchmaking does.

  • The pool is small enough for memory. The choice is the work.
  • One owner for each pool removes double booking.
  • Start strict and widen with the wait, around the longest waiting ticket.
  • A proposal can fail. Give back the waiting time of those who accepted.
  • Servers are the bill: keep warm ones where the next games will be.

Sources