All articles
Gamedev

How online games work: server logic, synchronization, and cheat prevention

Who determines a match outcome, how to hide network latency, and how to preserve progress after a failure. We explore authoritative servers, synchronization, reconnection, and scaling online games.

In a single-player game, the player's device can calculate movement, hits, and rewards on its own. In a networked game, that is not enough: multiple participants need to see a consistent world, and the system must keep working despite latency, disconnections, and attempts to tamper with data.

That is why developing an online game does not start with choosing WebSocket or a game engine. First, determine who makes decisions, what state the server stores, and how clients learn about changes.

Not every online game needs the same server

A turn-based strategy game, a card game, and a competitive shooter place different demands on infrastructure.

In a turn-based game, the server can process individual actions: accept a move, check the rules, save the result, and notify participants. A continuous simulation loop is often unnecessary.

In a fast-paced game, the server updates the world regularly, calculating movement, collisions, abilities, and round completion. Update frequency and predictable processing times matter here.

In an asynchronous game, participants may never be present at the same time. For example, one player leaves a defensive lineup and another attacks it later. This scenario is closer to processing individual jobs than running a continuous match.

Trying to build all three on a single architecture usually leads either to unnecessary costs or to gameplay limitations.

The server should make decisions that affect the outcome

An authoritative server model suits most competitive games. The client reports the player's intent, while the server validates the action and calculates the result.

For example, the client sends not “I dealt 100 damage,” but “I used an ability on this target.” The server checks:

  • whether the target exists and can be attacked;
  • whether enough resources are available;
  • whether the ability's cooldown has ended;
  • whether the distance and direction are valid;
  • what state the participants were in when the action occurred.

The server then applies the result and reports it to the clients.

The same principle applies to items, currency, and rewards. The client should not independently decide how much money to award for a match or which item appeared in the inventory.

An authoritative server does not eliminate every kind of cheating. But it reduces the situations in which tampering with client data directly changes the game's outcome.

Why you cannot simply keep sending the entire world

The most obvious synchronization method is for the server to send the full game state after every change. That may be enough for a small prototype. As the number of players and objects grows, this approach becomes expensive.

Beyond network traffic, there are costs for serialization, message processing, and updating the client scene.

Several mechanisms are commonly used.

State snapshots. The server periodically sends the current state of the objects a particular player needs.

Delta updates. Only changed data is sent instead of the full state. This requires knowing which acknowledged state the update was calculated against.

Interest management. A player receives information only about relevant objects: those nearby, participating in the match, or visible under the game's rules.

The last mechanism matters for security too. If an opponent is hidden by fog of war, sending their exact coordinates to the client and merely not drawing them on screen is risky. A modified client can read the received data.

Filtering must still account for game mechanics: sometimes a client needs advance information about objects that will soon enter its field of view.

How to hide latency without giving the client control

If a character starts moving only after the server responds, the controls feel sluggish. Even correct server logic cannot save a game in which every button press produces a noticeable delay.

The client therefore often starts displaying the result of its own action immediately. This approach is called client-side prediction.

In simplified form, the process works like this:

  • The player presses a movement button.
  • The client applies the input locally and sends it to the server.
  • The server calculates the authoritative state.
  • The client receives the response and compares it with its prediction.
  • If they differ, it corrects the state and reapplies input that has not yet been acknowledged.

This is called server reconciliation.

Other players are usually displayed differently: the client interpolates their movement between received states. This adds a small display delay but helps smooth out uneven data delivery.

When no new data arrives, movement can be extrapolated briefly. Prolonged extrapolation, however, causes visible errors: the character keeps running on screen even though it has already stopped on the server.

The specific approach depends on the genre. A mechanism that works for a racing game will not necessarily suit a fighting game.

Simulation frequency is not the same as update frequency

The server can update the game simulation at one frequency and send snapshots to clients at another.

For example, the simulation might run 30 times per second, while network updates are sent 10 or 15 times per second. This is just an example, not a universal recommendation.

The choice depends on the game's pace, collision accuracy, acceptable latency, and infrastructure budget.

Increasing the frequency does not automatically improve the game. If the server cannot finish a calculation before the next tick, delays and instability follow. Predictable processing times under real load matter more.

Measure not only average tick time but also infrequent long delays. These are often what cause noticeable stutters during a match.

Lag compensation: a trade-off, not absolute fairness

Two players almost never see the world at exactly the same moment.

When a player fires, the server receives the command later. By then, the target may have moved. Checking hits exclusively against the server's current state means a high-latency player will more often miss a target that appeared in their sights.

One approach is to keep a short history of states. The server estimates when the shot occurred and checks the hit against an eligible past state of the world.

But this has a downside: the other player may take damage when, on their screen, they have already moved behind cover.

Lag compensation therefore needs limits:

  • a maximum rewind window;
  • validation of timestamps and command order;
  • protection against artificially inflated latency;
  • clear rules for different types of actions.

Network latency cannot be eliminated entirely. The architectural goal is to choose a manageable trade-off that is acceptable for the particular game.

Keep match state separate from persistent progress

During a match, the server needs fast access to live state: coordinates, health, active effects, and timers.

Persistent progress serves a different purpose. Purchases, inventory, ratings, and rewards must be stored reliably and remain consistent after failures.

There is usually no need to write every character movement to the main database. But keeping the only copy of an awarded reward in process memory is not acceptable either.

It helps to separate:

  • temporary match state;
  • the confirmed match result;
  • operations that change persistent progress.

Reward allocation must tolerate repeated processing. If a service receives the same match result again, the player must not receive the reward twice. Unique operation identifiers, storage constraints, and transactional processing are used for this.

The result delivery mechanism must also account for failures. Duplicate detection alone is not enough if a result can be lost before it is stored.

Design reconnection in advance

A mobile app moves to the background, Wi-Fi switches to a cellular network, a connection drops. These are normal situations for an online game.

Decide in advance:

  • how long the player's place is reserved;
  • whether the character remains in the match;
  • who controls it while the player is absent;
  • how the current state is restored;
  • what happens if the same account connects again.

After reconnecting, the client usually needs a fresh, consistent state snapshot. Continuing to apply an old event queue without validation is dangerous: some events may already have been processed, while others are no longer relevant.

Restoring a connection and recovering a crashed game server are different tasks. Being able to return after a network interruption does not mean a match can survive the loss of its process.

Scaling starts with the unit of distribution

For session-based games, a match or game room is often the natural unit of scaling.

The system matches players, allocates a server with suitable capacity, and routes participants to the right session. New matches can be distributed across processes and machines.

The total user count is not the only thing that matters here. Infrastructure planning requires:

  • the number of concurrent players;
  • the number of participants per match;
  • the computational cost of simulating a match;
  • network traffic;
  • the audience's geographic distribution;
  • session duration.

One hundred thousand registered users and one hundred thousand concurrent players require fundamentally different infrastructure.

A seamless shared world is harder to scale than independent rooms. Dividing the world into zones, transferring players between servers, and handling interactions at boundaries require dedicated architectural solutions. Take on that complexity only when the gameplay genuinely needs it.

Cheat prevention has multiple layers

Server-side action validation is the foundation, but not the only measure.

You also need command rate limits, replay protection, message ordering checks, and access validation for the specific game session.

It is important to distinguish technically impossible actions from suspicious behavior.

If a player tries to spend more currency than they have, the server can reject the operation immediately. If a player aims unusually accurately, that alone is not enough to justify an automatic ban.

Behavior-based systems require statistics, assessment of false positives, and the ability to investigate disputed cases.

Bot prevention is a separate challenge. Even actions that are entirely valid under the protocol can be performed by an automated client. An authoritative server alone does not solve this problem.

What to test before a public launch

A load test should reproduce real gameplay actions, not merely open connections.

Useful scenarios to test include:

  • many players joining simultaneously;
  • creating and completing matches;
  • active movement and ability use;
  • mass reconnections;
  • slow clients and unstable networks;
  • database or reward service unavailability;
  • a game server process crashing.

During tests, monitor simulation tick time, outgoing traffic volume, message queues, memory usage, and error rates.

Match identifiers, server ruleset versions, and a history of significant events help with investigations. However, authentication tokens and other sensitive data must not be carelessly written to logs.

Where to start development

For the first working release, clear boundaries of responsibility usually matter more than complex distributed infrastructure.

The server validates actions and determines outcomes. The client handles input and smooth rendering. Persistent progress is stored separately from the live simulation. Repeats, disconnections, and failures have predefined handling.

With these foundations in place, the game is easier to develop and scale. Without them, audience growth merely exposes existing architectural flaws sooner.

What do you want to do?

Explain the idea in a couple of sentences. We'll come back with an estimate, deadlines and a plan - free of charge and under NDA.