Server authority and lag compensation
The server holds the real game state and clock; clients send inputs and draw what comes back. Lag compensation lets the server judge an input at the moment the player acted, within a bound the server sets.
What it is
An authoritative server runs the game. Clients send inputs (a key press, a chosen answer, a shot), the server applies them to the one copy of the state that counts, and it sends the result back for clients to draw. The stance behind it is simple: assume players will try to cheat, so don't trust what a client reports about itself. A hacked client can show its player 10000% health, but if the server holds the real value the player still dies when attacked. A client allowed to report its own position could walk through walls or outrun everyone, so instead it asks to move and the server replies with where it now stands. In fast shooters this authority over each player's character is treated as a hard requirement, not a preference.
The price is delay. With 50 ms each way, a player presses a key, nothing happens for a tenth of a second, then the character moves; delays of 100, 200 or even 500 ms do occur, and half a second makes a fast game unplayable. The first Quake worked this way, with the client as a dumb terminal, and players felt the round trip on each move and shot.
Three techniques keep the server in charge while hiding the delay. Client-side prediction: the client runs a subset of the game code for its own character and moves at once, keeping a buffer of recent inputs; when a server state arrives that disagrees, the client drops buffered state older than the correction, adopts the server's version and replays its stored inputs forward to the present. A correction describes the past (200 ms ago on a link with 100 ms each way), which is why a replay is needed rather than a plain overwrite. Entity interpolation: other players are drawn slightly in the past, between known positions, so they move smoothly. Lag compensation: for a time-sensitive input, the client sends the event with a timestamp, and the server, which keeps timestamped inputs, reconstructs the world as that client saw it at that instant and judges the action there. The shooter aimed at where the target's head was 100 ms before the trigger; compensation evaluates the shot against that position.
| What | Who is the authority | What the client does |
|---|---|---|
Health, score, lives | The server | Displays the server's value |
A player's own position | The server; the client predicts | Simulates ahead, replays on correction |
Other players' positions | The server | Draws them a little in the past |
The round clock and its deadline | The server's clock, stored when the question opens | Renders a countdown as display |
A shot or an answer | The server, judged at the input's time within a bound | Sends the input with a timestamp |
A timed round is the same idea with a clock in place of a position. In one pub-quiz backend, the long-running WebSocket server owns all the timers while the web app keeps the state machine; each deadline is derived from columns the database already holds (when the question launched, when it closed, the session's advance mode), and a sweep re-derives them on a three-second cycle, so a deploy in the middle of a question re-arms the deadlines in the new process. The answer window closes with one second of grace, because a phone on pub Wi-Fi and the server are not on the same millisecond, and without it a press at 14.9 seconds of a 15-second window would be ruled late. Our reading: the client's countdown is a courtesy rendering, and the decision rests on when the answer reached the server by the server's clock.
When to use it
Use server authority whenever a player's input changes something other players see or compete for: a shared world, a leaderboard, a prize. Cheating in a single-player game harms nobody else, which is why that case tolerates a trusted client; in a competitive game one cheater degrades the experience for the others, and the server is the one machine you control.
Treat any time the client reports as a claim. The device clock is set by its owner and the page is editable, so a countdown that stays above zero, or a timestamp that says the answer was early, proves nothing. A strong design has the server record when it opened the question, record when each answer arrived on its own clock, and compare the two. Use the client's timestamp for display, or for compensation inside a bound the server has measured (the round-trip time it has observed on that connection, for example), and clamp anything outside the bound.
Add prediction when the player's own actions must feel immediate, which is movement in a shooter or a racing game, and reserve the server-side rewind for events where timing and position decide a result: a shot, a tag, a buzzer press. Rewinding is a trade-off accepted on purpose: it keeps attacks fair for the attacker at the cost of making damage feel less immediate for the target, who can be hit a moment after reaching cover.
When not to
Skip prediction and compensation for slow, turn-based games: strategy, poker, a card game. A dumb client that waits a round trip for each move is fine there, and it's the simplest version to build, with no predicted state for the server to correct. The same holds on a LAN, where the round trip is close to instant.
Deterministic lockstep between peers is a different model, not a weaker one: each machine runs the same simulation and exchanges commands each turn, which is how real-time strategy games such as Age of Empires and Starcraft move many thousands of units, a state far too large to send between players. Its costs are that nobody advances until the slowest peer's inputs arrive, that each turn must play out identically on each machine, and that joining mid-game is rare because a deterministic starting point is hard to capture. Pick it for a few players and a huge world; pick a server when players come and go or latency between peers varies widely.
Don't rewind for everything. Compensation favors the acting player: the target can be hit a moment after reaching cover, so a game that rewinds each action spreads that unfairness across the whole match. Our advice: compensate the one event whose fairness matters most to the acting player (the shot, the buzzer press), consider judging slower actions at server time, and cap how far back the server will rewind, which limits what a client can gain by claiming an old timestamp to at most that cap.
Keep the grace window small. It exists to cover the network delay between an honest press and the server's receipt, not to rescue a stalled client or a player who paused the page. A grace sized to the delays you've measured, around a second in the quiz design above, rejects an answer that is five seconds late no matter what the device clock claims.
Compared
| Model | What the client does | What the server does | When it's the right choice |
|---|---|---|---|
Dumb client, authoritative server | Sends inputs, draws the returned state | Runs everything, judges at arrival | Turn-based and quiz games, LAN play, anything where a round trip of delay goes unnoticed |
Prediction with reconciliation | Simulates its own character, buffers inputs, replays after a correction | Stays authoritative, sends corrections | Fast movement where your own input must feel instant; skip it for turn-based play |
Server rewinds to the input's time | Sends the event with a timestamp | Rewinds to that time within a bound and judges there | Hitscan shots and buzzer presses; a design can choose to judge slow projectiles at server time when the target's fairness matters more |
Deterministic lockstep (peer to peer) | Runs the full simulation, exchanges commands | None | Few players and a huge world; accept waiting for the slowest peer, and that joining mid-game is uncommon |
Client authoritative | Reports its own state and time | Trusts the report | Single player and prototypes, where cheating harms nobody else |
In a picture
Step 1 of 3
The server opens the question
The server records the opening time and the deadline in its store, then tells clients the question is open. Each client starts a countdown from the moment the message arrives.
How to say it in an interview
The common mistake
Quiz
Questions that use this
Related
Sources
- Gabriel Gambetta: Fast-Paced Multiplayer (Part I): Client-Server Game Architecture
- Gabriel Gambetta: Fast-Paced Multiplayer (Part IV)
- Gaffer On Games: What Every Programmer Needs To Know About Game Networking
- Official Team Fortress Wiki: Lag compensation
- DEV Community: Our game clock does not live in the app (Daniel Pertu)