System Design Academy

Saving…

Lesson 4 of 7 in Module 60 of 54 lessons complete

Multiplayer Matchmaking & Live Leaderboards — Part A

Module 6, lesson 4Case study15 min

Definitions

Matchmaking

In plain English
Matchmaking is grouping waiting players into fair matches based on skill, region and game mode.
Think of it like
It is like a dance teacher pairing students of similar level.

Skill rating

In plain English
A skill rating is a number estimating how good a player is, updated after every match.
Think of it like
Like a chess player's rating.

The brief

An online team game has five million daily players and 500,000 playing at peak. Build fair five-versus-five matches and seasonal leaderboards.

What it must do

  • Queue by region and mode; form ten-player matches with similar skill.
  • Allocate a game server, report results, and update ratings.
  • Show the global top 100, friends rankings, and each player rank.

How well it must do it

  • Match 90% of queued players within 30 seconds.
  • Target gameplay latency below 60 milliseconds within a region.
  • Update leaderboards within five seconds of a match ending.
  • Recover matchmaking queues after a server failure.

Out of scope

  • In-game physics, anti-cheat, payments, and chat.

Design walkthrough

Estimates

Steady peak assumptions; daily users alone do not determine peak match starts.
Text
Assume ten players per match and 20-minute matches.
Running matches: 500,000 ÷ 10 = 50,000
Match duration: 20 × 60 = 1,200 s
New matches: 50,000 ÷ 1,200 ≈ 41.67/s
Players entering matches: 41.67 × 10 ≈ 416.7/s
Average wait assumption: 20 s
Waiting players: 416.7 × 20 ≈ 8,333
Rounded planning values: 420/s × 20 s = 8,400
Results: 41.67 match events/s × 10 ≈ 416.7 player updates/s
Leaderboard read assumption: 5,000 requests/s
  • The queue estimate uses arrivals multiplied by average wait: the relationship called Little's law.
  • Assume queue arrivals equal match departures, with little abandonment and stable traffic.
  • One match result contains ten player outcomes; distinguish event count from player-update count.
  • A 20-second average does not prove the 30-second target for 90% of players. Measure the waiting-time distribution.

API sketch

The WebSocket carries join, cancel, queue-status, and match-found messages.
HTTP
GET /matchmaking/queue
Upgrade: websocket

GET /leaderboards/{season}/top
GET /leaderboards/{season}/me
GET /leaderboards/{season}/friends

Authenticate queue actions and allow only one active entry per player and mode. Game servers report results using authenticated server APIs.

Gameplay uses UDP to a regional game-server address. This reuses transport choices from Module 1; lost gameplay packets need game-specific handling.

Data model

RecordKey and important fields
Playerplayer_id; region and account details
Ratingseason_id plus player_id; rating and version
Matchmatch_id; region, mode, ten assigned players, server, state
Resultmatch_id unique; final outcome and player results
Queue entryplayer_id plus mode; original join time, skill, region
LeaderboardOrdered scores per season globally, plus regional views

Keep authoritative results and ratings in a relational database. A key-value store serves ordered leaderboard views; the next lesson explains its ordering structure.

Use Module 3 keys and transactions to prevent one result from changing ratings twice.

Architecture

Players receive queue messages through gateways and play on game servers; result events reach a rating service and leaderboard store.

Separate gameplay from queue updates and leaderboard reads.

Players receive queue messages through gateways and play on game servers; result events reach a rating service and leaderboard store.

The gateway also serves leaderboard REST requests. Cache the top 100 there for one second using Module 4 caching.

Raw match results feed the rating service first. It publishes committed rating values; leaderboards must not race ahead using uncomputed results.

Core flow

The matchmaker allocates a server, players connect, and a final result passes through rating computation before updated ratings are published.

A match result becomes a committed rating before leaderboard publication.

The matchmaker allocates a server, players connect, and a final result passes through rating computation before updated ratings are published.

Waiting players are claimed together, then either enter a game or return to waiting if allocation fails.

Claim players before allocating a match server.

Waiting players are claimed together, then either enter a game or return to waiting if allocation fails.

Claim all ten players atomically within the region and mode. Repeated allocation requests reuse the match ID rather than creating extra servers.

Design decisions

How is matchmaking split across machines?

Our choice

Split by region and mode. This is sharding from Module 3 and horizontal scaling from Module 2.

Why not the alternatives

  • One global matchmakerOne queue grows large and may pair players far from their game servers.

How do players learn a match is ready?

Our choice

Push queue updates using WebSockets. This uses Module 1 two-way communication.

Why not the alternatives

  • Repeated pollingPolling adds requests and can delay match-found messages.

How does gameplay travel?

Our choice

Use UDP to regional servers with stable match routing. This applies Module 1 packets and Module 2 load balancing.

Why not the alternatives

  • Use HTTP for every gameplay updateRepeated request-response exchanges do not fit rapid gameplay updates.

How do results reach ratings and leaderboards?

Our choice

Use replayable event streams from Module 4. Publish ratings only after the rating transaction commits.

Why not the alternatives

  • Call every consumer directly from the game serverA slow consumer can block result delivery, and each new consumer changes the server.

Trade-offs

Pros

  • Regions scale independently.
  • Players receive immediate queue updates.
  • Results can be replayed to consumers.

Cons

  • More services require coordination.
  • Cross-region groups face latency trade-offs.
  • Gateways maintain many connections.

Use when

  • Real-time multiplayer with regional game servers.

Avoid when

  • Turn-based games where occasional polling meets the latency target.

Quick check

420 players are matched per second and each waits about 20 s. Roughly how many are in queues at once?
Why split matchmakers by region and mode?

Takeaways

  • Split queues by region and mode.
  • Push match events with WebSockets and use UDP for gameplay.
  • Stream durable results into ratings, then leaderboard views.

Try the quick check above whenever you feel ready.

Previous: Concert Ticket Flash Sale — Part B: Deep Dives & Failures