Lobbies & Matchmaking
Before a match can start, players have to find each other. Games do it in two broad ways:
- Lobbies (also called rooms or custom games): players browse or share a code, join a room, see each other, and the host starts the match. Common in co-op, party games and private matches.
- Matchmaking: players press "Find match" and a service groups them by skill, region and mode. Common in competitive and ranked play.
Most games have both: matchmaking for public queues, lobbies for friends.
The lobby lifecycle
create ─▶ open (joinable, listed or by code) ─▶ full / locked ─▶ ready check ─▶ starting ─▶ in match
▲ │ players join/leave, chat, │ someone not ready
└──────────┘ change team or settings └─▶ back to openThings to get right:
- Lobby state lives on a service, not on the host's machine: a lobby service (Steam lobbies, EOS lobbies, Unity Lobby, Nakama, your own backend) stores members, settings and a small key-value blob. Clients subscribe to changes.
- Ownership: one member is the owner who can change settings and start. When the owner leaves, the service promotes another member (host migration of the lobby). Migrating a running game host is much harder; that is one reason to prefer dedicated servers.
- Ready check: before spending money on a server, every member confirms within a timeout (often 10–20 s). Members who don't answer are removed and the lobby goes back to "open" (or the matchmaker requeues the others first).
- Parties: a group of friends queues as one unit. The matchmaker treats the party as a single ticket with several players, a combined rating and the worst ping of its members.
- Join codes: short, unambiguous (no
O/0,I/1), expiring.
Ratings: Elo, Glicko, TrueSkill
Skill-based matchmaking needs a number per player, often called MMR (matchmaking rating). The classic system is Elo: the expected score of A against B is
E_A = 1 / (1 + 10^((R_B - R_A) / 400))
R_A' = R_A + K × (S_A - E_A) S_A = 1 win, 0.5 draw, 0 lossThe K factor sets how fast ratings move. A surprise result moves ratings a lot; an expected result barely moves them:
using System;
static double Expected(double ra, double rb) => 1.0 / (1.0 + Math.Pow(10, (rb - ra) / 400.0));
static (double, double) Update(double ra, double rb, double scoreA, double k = 32)
{
double ea = Expected(ra, rb);
return (ra + k * (scoreA - ea), rb + k * ((1 - scoreA) - (1 - ea)));
}
void Show(string label, double ra, double rb, double scoreA)
{
var (na, nb) = Update(ra, rb, scoreA);
Console.WriteLine(quot;{label,-28} A {ra,4:F0} -> {na,7:F1} B {rb,4:F0} -> {nb,7:F1} (A expected {Expected(ra, rb):F2})");
}
Show("equal players, A wins", 1500, 1500, 1);
Show("favourite A wins", 1800, 1400, 1);
Show("underdog A wins", 1400, 1800, 1);
Show("draw, A higher", 1700, 1500, 0.5);equal players, A wins A 1500 -> 1516.0 B 1500 -> 1484.0 (A expected 0.50)
favourite A wins A 1800 -> 1802.9 B 1400 -> 1397.1 (A expected 0.91)
underdog A wins A 1400 -> 1429.1 B 1800 -> 1770.9 (A expected 0.09)
draw, A higher A 1700 -> 1691.7 B 1500 -> 1508.3 (A expected 0.76)
Elo has no idea how certain a rating is. Newer systems track that too:
- Glicko / Glicko-2 add a rating deviation (uncertainty). New or returning players have a large deviation, so their rating moves quickly; it shrinks as they play.
- TrueSkill (Microsoft Research, used on Xbox Live) models each player as a mean
μand an uncertaintyσ, supports teams and free-for-all, and is commonly displayed as a conservativeμ − 3σ. TrueSkill is patented and trademarked by Microsoft; check licensing before using it commercially. OpenSkill is an open alternative in the same family.
Many games show players a separate, friendlier rank (tiers, divisions) and keep the real MMR hidden.
Matchmaking with widening buckets
A matchmaker balances two costs: match quality (close skill, low ping) and wait time. The usual compromise: start with a narrow skill window and widen it the longer a ticket waits. A ticket also only matches within its region (or within an acceptable ping to a server region).
This model runs a 1v1 queue on a simulated clock, one evaluation per second. Each ticket's window is 50 + 40 × seconds waited MMR, capped at 400. Two tickets match when they share a region and their MMR gap fits inside both windows, so a newcomer can't drag a long-waiting player into a bad match. Oldest tickets are served first.
using System;
using System.Collections.Generic;
using System.Linq;
record Ticket(string Name, int Mmr, string Region, int EnqueuedAt);
class Program
{
static int Window(Ticket t, int now) => Math.Min(400, 50 + 40 * (now - t.EnqueuedAt));
static void Main()
{
var incoming = new List<Ticket>
{
new("ana", 1510, "eu", 0), new("ben", 1540, "eu", 0),
new("chen", 1900, "eu", 0), new("dara", 1205, "na", 1),
new("eli", 1650, "eu", 2), new("femi", 1360, "na", 3),
new("gus", 2400, "eu", 3), new("hana", 1690, "eu", 6),
};
var queue = new List<Ticket>();
for (int now = 0; now <= 10; now++)
{
queue.AddRange(incoming.Where(t => t.EnqueuedAt == now));
var matched = new HashSet<Ticket>();
foreach (var a in queue.OrderBy(t => t.EnqueuedAt).ThenBy(t => t.Name))
{
if (matched.Contains(a)) continue;
var best = queue
.Where(b => b != a && !matched.Contains(b) && b.Region == a.Region)
.Where(b => Math.Abs(a.Mmr - b.Mmr) <= Math.Min(Window(a, now), Window(b, now)))
.OrderBy(b => Math.Abs(a.Mmr - b.Mmr))
.FirstOrDefault();
if (best == null) continue;
matched.Add(a); matched.Add(best);
Console.WriteLine(quot;t={now,2}s MATCH {a.Name} ({a.Mmr}) vs {best.Name} ({best.Mmr}) gap {Math.Abs(a.Mmr - best.Mmr),3} waited {now - a.EnqueuedAt}s/{now - best.EnqueuedAt}s");
}
queue.RemoveAll(matched.Contains);
if (now % 2 == 0 && queue.Count > 0)
Console.WriteLine(quot;t={now,2}s waiting: " + string.Join(", ", queue.Select(t => quot;{t.Name}[{t.Region} {t.Mmr}±{Window(t, now)}]")));
}
}
}t= 0s MATCH ana (1510) vs ben (1540) gap 30 waited 0s/0s
t= 0s waiting: chen[eu 1900±50]
t= 2s waiting: chen[eu 1900±130], dara[na 1205±90], eli[eu 1650±50]
t= 4s waiting: chen[eu 1900±210], dara[na 1205±170], eli[eu 1650±130], femi[na 1360±90], gus[eu 2400±90]
t= 6s MATCH dara (1205) vs femi (1360) gap 155 waited 5s/3s
t= 6s MATCH eli (1650) vs hana (1690) gap 40 waited 4s/0s
t= 6s waiting: chen[eu 1900±290], gus[eu 2400±170]
t= 8s waiting: chen[eu 1900±370], gus[eu 2400±250]
t=10s waiting: chen[eu 1900±400], gus[eu 2400±330]
Read the output as a story: ana and ben are 30 apart and match instantly. eli waits four seconds until hana, a close opponent, arrives. dara and femi are 155 apart, so they wait until both windows have grown past 155 (at 6 s, femi's window reaches 170). chen and gus are left: their windows keep growing, but they are 500 apart, more than the 400 cap, and nobody else in their region is close. Real matchmakers handle that last case explicitly: after a maximum wait they relax other rules (a neighbouring region, a bot match, or a message such as "few players at your rank right now").
What real matchmakers add
- Team games: fill teams so the sums (or the averages plus spread) of ratings are close, and keep parties together. Teams of five solo players versus a five-person party is a known fairness problem; many games match parties against parties.
- Latency: clients ping each server region (or a set of beacons) and send the results with the ticket; the matchmaker only uses regions under a ping limit such as 80–120 ms.
- Backfill: when a player leaves a running match, ask the matchmaker for a replacement.
- Allocation: once a match is formed, the matchmaker asks the fleet for a server (Dedicated Servers & Hosting) and returns the address plus a connect ticket to every player.
Ready-made matchmakers exist: Open Match (open source, built for Kubernetes), FlexMatch (part of Amazon GameLift Servers), the Unity Matchmaker, the matchmaker in Nakama, and platform services. They implement the same loop: tickets in, rules and widening windows, matches out.
Test yourself
Two players have Elo ratings 1800 and 1400. The 1800 player wins. What happens to the ratings?
- Both change by a lot
- They change only slightly, because the result was expected
- Only the loser's rating changes
- Nothing changes
Why does the model require the MMR gap to fit inside **both** tickets' windows?
- To make the code simpler
- So a long-waiting player's wide window can't pull a fresh player into an unfair match
- Because windows are always equal
- To reduce server cost
What does Glicko add that plain Elo lacks?
- Team support only
- A measure of uncertainty (rating deviation), so new players' ratings move faster
- Ping-based matching
- Anti-cheat