Lesson 6 of 9 · 27m
Client Prediction and Reconciliation: Feeling Fast, Staying Honest
Predict local movement immediately, reconcile against authoritative server state, and correct errors without turning every mismatch into a teleport.
Pure server authority without prediction feels awful: press forward, wait a round trip, then move. Players describe it as input lag, ice skating, or "the game being online." Prediction solves the feel problem by letting the local client simulate the likely result immediately. Reconciliation is the price: when the server's answer returns, the client must repair any difference without making the player seasick.
Prediction is not authority
The client predicts only what it can plausibly know: local movement, camera response, perhaps a simple animation or sound. The server still decides collisions, damage, pickups, and interactions. If prediction is wrong, the prediction is discarded. That distinction keeps convenience from becoming trust.
input seq 200 -> predicted locally now
input seq 200 -> sent to server
server ack at tick 912 -> authoritative state after input 200
client re-simulates inputs 201..current on top of server stateThe sequence number is the spine. Without it, the client cannot know which input the server state includes.
A minimal reconciliation loop
pending = []
def on_input(cmd):
state = predict(state, cmd)
pending.append(cmd)
send_to_server(cmd)
def on_snapshot(snapshot):
state = snapshot.player_state
pending[:] = [c for c in pending if c.seq > snapshot.last_input]
for cmd in pending:
state = predict(state, cmd)This is conceptually simple and practically unforgiving. The prediction function must match the server's movement rules closely enough that corrections are rare and small.
Mispredictions are engineering data
Every correction has a cause. Common ones are collision differences, floating-point divergence, variable timestep use, input quantization, different friction constants, unacknowledged impulses, animation-driven movement, and server-side anti-cheat modification. Log correction distance and cause category during development:
correction 2 mm visually irrelevant, normal
correction 20 cm noticeable; investigate movement mismatch
correction 2 m teleport/rubber-band; systemic fault or extreme lossA few millimeters can be smoothed. Large repeated corrections mean prediction is lying too often and players will feel constant rubber-banding.
Correction presentation matters
Snapping instantly to authoritative state is correct but harsh. Blending position over 50-100 ms can hide small errors, yet blending too much makes collisions and interactions feel detached from server truth. Separate gameplay correction from visual smoothing: correct the logical state immediately, then let the rendered representation catch up.
logical player state corrects immediately
camera may smooth small error
cosmetic mesh/animation interpolates aggressively
other players already use interpolation, not predictionDo not smooth the crosshair or aim direction casually; players notice aim manipulation immediately.
Predict events conservatively
Predicting footsteps or weapon view-model animation is usually safe. Predicting damage, kills, pickups, trades, or objective capture is dangerous because reversal feels like theft. For high-consequence events, show pending or ambiguous feedback until the server confirms. A hit marker is a design decision, not a networking obligation.
Prediction under packet loss
When inputs are lost, the server cannot simulate what it never received. Clients often resend recent commands or include redundant input history in each packet. The server deduplicates by sequence. This redundancy is usually cheaper than waiting for reliable retransmission because movement input becomes stale quickly.
Field notes
- Never "reconcile" inventory, health, or currency upward because the client predicted a convenient outcome.
- Deterministic movement code on client and server reduces corrections but does not make client state authoritative.
- Keep a replay or ring buffer of predicted inputs and server acknowledgments; otherwise correction bugs are impossible to reconstruct.
- Rubber-banding is often a symptom of loss, overload, or validation rejection — not proof that reconciliation itself is broken.
Was this lesson helpful?