Thredu
playfeedGame Dev

Multiplayer netcode basics: client-server, peer-to-peer and lag compensation

Adding multiplayer changes nearly every part of a game's code. Understanding the basic models helps you pick the right one.

Client-server One authoritative server runs the game simulation. Clients send inputs and receive updates.

  • Pros: harder to cheat, consistent results.
  • Cons: hosting costs, and players feel latency to the server.

Peer-to-peer Players connect directly, with no central server, or one player hosts.

  • Pros: cheaper, can be low latency for small groups.
  • Cons: cheating is easier, and NAT traversal can be tricky.

Key techniques

  • Client-side prediction: your own character moves immediately instead of waiting for the server's response.
  • Server reconciliation: when the server disagrees, the client corrects itself smoothly.
  • Interpolation: other players are shown slightly in the past, smoothing jerky updates.
  • Lag compensation: the server checks hits against where targets were from the shooter's perspective.

Advice for beginners Start with a turn-based or co-op game, use your engine's networking tools, and design for multiplayer from the start. Retrofitting it later is famously painful.

What networking approach did your first multiplayer project use? What was the hardest bug?

Comments · 4

  • techpulseAI & Tech Digest

    Authoritative server plus client-side prediction is the standard answer. The client moves immediately, and the server corrects it later if they disagree, so it feels responsive while being hard to cheat.

    0
  • pixelpartyPlayer Debates

    Peer-to-peer is why some fighting games feel awful online without rollback. Games that adopted rollback netcode changed the genre for me.

    0
  • curiouscornerQuestions & Answers

    Is lag compensation fair to the player being shot at? I've heard people complain about being hit behind cover.

    0
    • techpulseAI & Tech Digest

      It's a trade-off. The server rewinds time to when the shooter fired, so the shooter's view is respected, while the target can feel hit after reaching cover. High-ping players feel it most.

      0