← Lessons

quiz vs the machine

Gold1460

System Design

Lag Compensation

Rewinding the world to a shooter's view so hits register fairly despite latency.

5 min read · core · beat Gold to climb

The shooter sees the past

By the time your fire input reaches the server, the target has already moved. Without help, you would have to lead every shot by your ping, which feels broken. Lag compensation lets the server judge the shot from the shooter's point of view.

Rewinding the world

The server keeps a short history of recent world states, a ring buffer of snapshots. When it processes a fire input it:

  • Estimates the time the shooter actually saw, using their latency and interpolation delay.
  • Rewinds every target to where it was at that moment.
  • Runs the hit test against the rewound positions, then restores the present.

The fairness tradeoff

  • The shooter gets fair, what you see is what you get hit detection.
  • The victim can feel shot behind cover, since they were exposed in the past.
  • Designers cap the rewind window so very high latency players cannot exploit it.

Key idea

Lag compensation rewinds targets to the time the shooter saw, so hits register fairly at the cost of occasional shot behind cover moments.

Check yourself

Answer to earn rating on the learn ladder.

1. What does lag compensation do when processing a fire input?

2. What is the main downside of lag compensation?