State Sync & Snapshots
Lockstep and rollback share inputs and require a deterministic simulation. The other big family, state synchronization, shares results: the authority sends the state of the world (or the parts that changed), and the other machines display it. It tolerates non-deterministic physics, different hardware, late joiners and packet loss, at the price of more bandwidth. Most shooters, action games and MMOs use it, usually with an authoritative server.
Lockstep vs state sync
| Deterministic lockstep / rollback | State synchronization | |
|---|---|---|
| What travels | inputs only | state (positions, health, ...) |
| Bandwidth grows with | number of players | number of relevant entities |
| Needs determinism | yes, bit-exact | no |
| Late join / reconnect | hard (needs full state or replay) | easy (send a full snapshot) |
| Packet loss | must wait or roll back | next snapshot repairs it |
| Hidden information | every peer has the whole state (maphacks!) | server can send only what you may see |
| Typical genres | RTS, fighting, sports | shooters, action, MMO, survival |
Three flavours of state sync
- Snapshots: every N ticks the server sends the client a description of the relevant world at that tick, delta-compressed against an acked baseline (Quantization & Delta Compression). Lost snapshots don't matter; the next one carries everything.
- Property replication: each networked object has replicated variables; the engine notices which ones changed (dirty flags) and sends those. This is what Unreal's replicated properties, Unity NGO's
NetworkVariableand Godot'sMultiplayerSynchronizerdo (Engines & Frameworks). - Events/RPCs for one-off happenings: "play explosion at X", "player 3 joined". They complement state, but anything that matters later must also be in the state, because a player joining a minute later never saw the event. A door that was opened by an RPC but has no replicated
isOpenis closed for late joiners.
Newest wins
Snapshots travel unreliably, so they arrive out of order, duplicated or not at all. The receiver keeps only the newest by tick number and throws away anything older. It also keeps a few recent ones in a buffer, because interpolation needs two (Snapshot Interpolation):
type Snapshot = { tick: number; x: number };
class SnapshotBuffer {
private items: Snapshot[] = [];
newestTick = -1;
constructor(private capacity: number) {}
receive(s: Snapshot): string {
if (this.items.some((i) => i.tick === s.tick)) return 'duplicate, ignored';
if (s.tick < this.newestTick - this.capacity) return 'too old, ignored';
this.items.push(s);
this.items.sort((a, b) => a.tick - b.tick); // keep in tick order even if arrival order differs
if (this.items.length > this.capacity) this.items.shift();
const wasNewest = s.tick > this.newestTick;
this.newestTick = Math.max(this.newestTick, s.tick);
return wasNewest ? 'newest' : 'late, stored for interpolation';
}
ticks() { return this.items.map((i) => i.tick).join(','); }
}
const buf = new SnapshotBuffer(4);
// Sent every 2 ticks; arrival order: 6 and 10 are late, 10 comes twice, 12 is lost, the last 2 is ancient.
for (const tick of [2, 4, 8, 6, 14, 10, 10, 16, 2]) {
const result = buf.receive({ tick, x: tick * 3 });
console.log(`got tick ${String(tick).padStart(2)}: ${result.padEnd(32)} buffer [${buf.ticks()}]`);
}got tick 2: newest buffer [2]
got tick 4: newest buffer [2,4]
got tick 8: newest buffer [2,4,8]
got tick 6: late, stored for interpolation buffer [2,4,6,8]
got tick 14: newest buffer [4,6,8,14]
got tick 10: late, stored for interpolation buffer [6,8,10,14]
got tick 10: duplicate, ignored buffer [6,8,10,14]
got tick 16: newest buffer [8,10,14,16]
got tick 2: too old, ignored buffer [8,10,14,16]
Snapshots carry acks the other way too
Every client packet acknowledges the snapshots it received (with the ack bitfield from Reliability over UDP). The server uses that to pick delta baselines, and to know which events each client hasn't confirmed yet, so they can be repeated in the next snapshot until acked. That turns the unreliable snapshot stream into a carrier for reliable events without a separate channel.
Partial state: what each client gets
The server doesn't have to send each client the same snapshot, and usually shouldn't:
- Relevancy: only entities near the player, or in a room they can see (Interest Management).
- Ownership: the player's own entity includes private fields (ammo, cooldowns, inventory) and the last processed input tick for reconciliation.
- Priority: far or unimportant entities update less often (Bandwidth Budgets).
When to choose which model
- Choose state sync with an authoritative server when the game has many players, hidden information, physics, late joining, or anything worth cheating for.
- Choose lockstep when there are many units and few players, and you can make the simulation deterministic.
- Choose rollback when two to four players need instant, frame-precise response and the state is small.
- Hybrids are common: an RTS may lockstep the units and state-sync the chat and lobby; a shooter state-syncs the world but runs its own player with prediction and rollback-style reconciliation, which is the next section.
Test yourself
A door is opened with a one-off RPC and has no replicated state. What does a player who joins later see?
- An open door
- A closed door, because they never received the event
- The RPC is replayed automatically
- An error
A snapshot for tick 10 arrives after the snapshot for tick 14. What should the client do?
- Replace the current state with tick 10
- Never treat it as the newest; at most keep it in the buffer for interpolation
- Request a resend of tick 12
- Disconnect
Which model makes wallhacks easiest to build?
- Authoritative state sync with interest management
- Deterministic lockstep, where every peer has the whole game state
- Snapshots with delta compression
- Server reconciliation