Dedicated Servers & Hosting
An authoritative server has to run somewhere. There are three common choices, and many games use more than one:
| Model | Who runs the server | Good | Bad |
|---|---|---|---|
| Listen server | one player's game is also the server | free, easy, fine for co-op | host advantage (0 ms ping), host can cheat, the match ends when the host quits, NAT problems |
| Relay | a relay forwards packets between players; one of them is still the host | gets through NAT, hides IP addresses | adds latency; authority is still on a player's machine |
| Dedicated server | you run a headless build in a data centre | fair, cheat-resistant, survives any player leaving | costs money and operations work |
Competitive games, and any game where cheating would ruin it, run dedicated servers. Co-op and small indie games often start with listen servers plus a relay (Steam Datagram Relay, EOS P2P relays, Unity Relay) and move to dedicated servers later. Designing the code as client + server from day one keeps that move possible.
Headless server builds
A dedicated server is the same game without graphics, audio or input. Each engine has a way to build one:
Unity 6 has a Dedicated Server platform, a sub-target of the Windows, macOS and Linux desktop platforms that strips assets and code a server doesn't need. Install the Dedicated Server module in Unity Hub, then add a server build profile (for example Linux Server) in File > Build Profiles. Unity defines the UNITY_SERVER scripting symbol for these builds:
#if UNITY_SERVER
// server-only setup: start listening, skip menus
NetworkManager.Singleton.StartServer();
#endifFrom the command line or CI: -buildTarget Linux64 -standaloneBuildSubtarget Server; from an editor script, set BuildPlayerOptions.subtarget = (int)StandaloneBuildSubtarget.Server.
Unreal Engine 5 needs a source build of the engine for server targets. Add a <ProjectName>Server.Target.cs next to the game target:
using UnrealBuildTool;
public class ArenaServerTarget : TargetRules
{
public ArenaServerTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Server;
DefaultBuildSettings = BuildSettingsVersion.Latest;
ExtraModuleNames.Add("Arena");
}
}Build the Development Server configuration, cook content for the server platform, then run ArenaServer -log (it listens on port 7777 by default; -port=7778 changes it). Server-only C++ code checks IsRunningDedicatedServer() or the actor's net mode.
Godot 4 needs no special binary: run the exported game with --headless. An export preset whose resources mode is Export as dedicated server strips textures and audio and adds the dedicated_server feature tag, which code can test:
func _ready() -> void:
if OS.has_feature("dedicated_server"):
start_server()Whatever the engine, a server build should start without a user, read its port and settings from command-line arguments or environment variables, log to stdout, and exit cleanly when told to.
Where servers run
- Bare metal rented by the month: the cheapest per CPU for steady load, slow to scale.
- Cloud VMs: scale up for launch day and evenings, down at night; outbound bandwidth is often a big part of the bill.
- Containers on Kubernetes with Agones, an open-source project that adds game-server resources to Kubernetes (see the Kubernetes and Docker courses).
- Managed game-server hosting: you upload a build, the service runs fleets in many regions. Examples are Amazon GameLift Servers, Edgegap, Gameye and others. Offerings change: Unity's own Multiplay Game Server Hosting was wound down in 2026 (its Matchmaker, Lobby and Relay services continue), so check the current status and terms of any provider before you depend on it.
- Hybrid: bare metal for the base load, cloud for the peaks.
The lifecycle of a game server
Agones makes the lifecycle explicit, and its states are a good mental model for any hosting:
Scheduled ─▶ (process starts, loads map) ─▶ Ready ─▶ Allocated ─▶ (match ends) ─▶ Shutdown
▲ │ no Health() pings
│ └──────────▶ Unhealthy ─▶ replaced
matchmaker asks for oneThe server process talks to the platform through an SDK: Ready() when it can accept players, Health() pings every few seconds (a missed ping marks it Unhealthy), Allocate()/allocation when players are sent to it, and Shutdown() when the match ends. A Fleet keeps a number of servers running; a GameServerAllocation picks a Ready one and marks it Allocated, so it is never scaled down while players are on it.
apiVersion: "agones.dev/v1"
kind: Fleet
metadata:
name: arena
spec:
replicas: 10
template:
spec:
ports:
- name: default
portPolicy: Dynamic # Agones picks a free host port for each server
containerPort: 7777
health:
periodSeconds: 5 # Health() must be called at least this often
failureThreshold: 3
template:
spec:
containers:
- name: arena
image: registry.example.com/arena-server:1.4.2
---
apiVersion: "autoscaling.agones.dev/v1"
kind: FleetAutoscaler
metadata:
name: arena-autoscaler
spec:
fleetName: arena
policy:
type: Buffer
buffer:
bufferSize: 5 # always keep 5 Ready servers waiting
minReplicas: 10
maxReplicas: 200Ports: many server processes share one machine, so each gets its own port (portPolicy: Dynamic), and the matchmaker returns ip:port to the players.
Why a buffer: a fleet model
Starting a server process (container start, map load) takes time, often tens of seconds to minutes. If the fleet only starts servers when a match needs one, players wait. A buffer of ready servers absorbs bursts. This model runs a fleet minute by minute: servers take 2 minutes to start, a match lasts 3 minutes and then the process exits (a fresh process per match avoids leaked state), and the autoscaler keeps buffer servers Ready or starting.
type Server = { state: 'starting' | 'ready' | 'allocated'; until: number };
const DEMAND = [2, 2, 3, 5, 8, 8, 6, 4, 3, 2, 6, 9, 4, 2, 1]; // matches requested per minute
const START_MIN = 2, MATCH_MIN = 3, MAX_SERVERS = 30;
function simulate(buffer: number, verbose: boolean) {
let servers: Server[] = [];
for (let i = 0; i < buffer; i++) servers.push({ state: 'ready', until: 0 });
let failed = 0, idleServerMinutes = 0;
if (verbose) console.log('min demand allocated ready starting failed');
DEMAND.forEach((demand, minute) => {
servers = servers.filter((s) => !(s.state === 'allocated' && s.until <= minute)); // matches ended
for (const s of servers) if (s.state === 'starting' && s.until <= minute) s.state = 'ready';
let failedNow = 0;
for (let m = 0; m < demand; m++) {
const s = servers.find((x) => x.state === 'ready');
if (s) { s.state = 'allocated'; s.until = minute + MATCH_MIN; } else failedNow++;
}
failed += failedNow;
const count = (st: Server['state']) => servers.filter((s) => s.state === st).length;
// Autoscaler: keep `buffer` servers ready or starting, plus replace what we just lacked.
const want = buffer + failedNow - count('ready') - count('starting');
for (let i = 0; i < want && servers.length < MAX_SERVERS; i++) servers.push({ state: 'starting', until: minute + START_MIN });
idleServerMinutes += count('ready');
if (verbose) {
console.log(`${String(minute).padStart(3)} ${String(demand).padStart(6)} ${String(count('allocated')).padStart(9)} ${String(count('ready')).padStart(5)} ${String(count('starting')).padStart(8)} ${String(failedNow).padStart(6)}`);
}
});
return { failed, idleServerMinutes };
}
simulate(4, true);
console.log('');
for (const b of [0, 2, 4, 8, 12]) {
const r = simulate(b, false);
console.log(`buffer ${String(b).padStart(2)}: ${String(r.failed).padStart(2)} matches had to wait, ${String(r.idleServerMinutes).padStart(3)} idle server-minutes`);
}min demand allocated ready starting failed
0 2 2 2 2 0
1 2 4 0 4 0
2 3 6 0 5 1
3 5 6 0 7 3
4 8 7 0 9 5
5 8 9 0 8 4
6 6 12 0 5 1
7 4 12 0 5 1
8 3 10 0 5 1
9 2 7 1 3 0
10 6 7 0 7 3
11 9 6 0 12 8
12 4 8 2 6 0
13 2 7 6 0 0
14 1 7 5 0 0
buffer 0: 43 matches had to wait, 4 idle server-minutes
buffer 2: 35 matches had to wait, 10 idle server-minutes
buffer 4: 27 matches had to wait, 16 idle server-minutes
buffer 8: 15 matches had to wait, 39 idle server-minutes
buffer 12: 7 matches had to wait, 70 idle server-minutes
A "failed" request is a match that found no Ready server that minute; in a real system those players go back to the queue for another try. With a buffer of 4, the rushes at minutes 3–5 and 10–11 still outruns the 2-minute start time. The trade-off is plain in the summary: a bigger buffer means fewer players waiting and more money spent on idle servers. Real autoscalers also use a schedule (scale up before the evening peak) and history (last week's curve), and a failed allocation sends players back to the queue for a few seconds instead of failing the match.
Operations checklist
- Health: call the health ping from the game loop, not from a separate thread, so a frozen simulation is detected.
- Logs and metrics: tick time (p99), player count, packets in/out, allocation latency, crash count per build version.
- Versioning: clients and servers must speak the same protocol; the matchmaker only allocates servers whose build matches the client's version.
- Draining: for a deploy, stop allocating old servers and let running matches finish.
- Regions: place fleets near players; measure ping from clients to each region (see Lobbies & Matchmaking).
Test yourself
Why does a game-server fleet keep a buffer of Ready servers?
- Kubernetes requires it
- Starting a server takes time, so ready servers absorb bursts of new matches without making players wait
- To run more matches per server
- To reduce bandwidth
In Agones, what protects a server with players on it from being removed when the fleet scales down?
- Its health checks
- It is in the Allocated state
- Its port number
- Its container image
Which statement about Unreal Engine 5 dedicated servers is true?
- Any launcher build can produce one
- You need a source build of the engine and a
<Project>Server.Target.cswithTargetType.Server - They are built with Blueprints only
- They require Unity's Dedicated Server module