Skip to the article content

Online gaming: The real-time illusion created by client-side prediction

Certain online games may feel like they’re playing out in real time, but it’s actually a complex mix of real-time illusions and recent-past wizardry.

The ‘First person shooter’ (FPS) genre is one of the most popular types of online video games, the appeal of which comes, in part, from the real-time nature in which matches play out.

Interestingly, online shooters – and other online game genres that rely on fast controller input and precision movement – don’t really operate in true real-time ways.

Game developers use clever smoke and mirrors to give the illusion of real-time play when, in reality, all players in an online game are interacting with the (very) recent past.

Here’s how it works. 

Playing games offline

To understand how online games work, let’s first explore how playing games offline differs to online.

When you play a game offline, either by yourself or in a shared experience on the same screen, all of your controller input is calculated on the same device you’re playing on.

This device is called the ‘client’.

Let’s say you’re playing Call of Duty: Infinite Warfare in local split-screen with a friend on an Xbox One or PlayStation 4.

All of your controller input data – running, jumping, crouching, reloading, firing a weapon, etc. – is processed on that same Xbox or PlayStation console.

This is different to how the same example works online. 

Playing games online

When you play a game online, you and every other player in the same match connects to a single server or host.

This might be a dedicated server – which, as the name implies, is dedicated to the task of running a game server – or a peer-to-peer (P2P) server, which is when a player in a pre-match lobby is designated ‘host’ and their machine acts as the game server.

While an offline game has its input information processed on the very machine you’re playing on, that same machine in an online match has to send and receive updates to and from a server before that input can be accepted as ‘true’.

The only exception to this is if your machine is designated host in an online game that uses P2P networking.

In this case, your machine – the host – is the one receiving input updates from other players, accepting them as true (or rejecting them), then transmitting back to the all connected players accordingly.

The host player in this scenario has an input advantage because there’s effectively no latency; their input is being processed and accepted as true instantaneously on the same machine, just like how it is with an offline game.

The trouble of time

If you’re playing a turn-based or even real-time-strategy game, the impact of the client/server (or host) relationship is easier to hide because it’s not as fast-paced and dependent on real-time input translation as, say, an FPS title.

It takes time for information to be sent from a client machine (the player) to the server, then for that information to be verified by the server as true and, finally, transmitted back to all connected players.

Because the server will update multiple times a second – determined by its tick or simulation rate – this “old” data is only milliseconds in the recent-past.

That said, even milliseconds can matter when it comes to maintaining the illusion of real-time gameplay for all players who are effectively interacting with the very recent past ‘ghosts’ of the other players in an online game.

Temporal smoke and mirrors

This is where the client-side prediction comes in to play in online games.

As a player (client), your gaming platform can make new command inputs and these are assumed to be true on your client machine.

This data is transmitted to the server and is only overturned if it’s at ends with data received by the server from other players.

Most of the time, this assumed client input data relates to movement, which allows an individual player to move smoothly in the game world and also see other players as moving smoothly, too.

This process is called ‘interpolation’, which is effectively an estimation of other players’ movements between the updates (tick rate) sent from the server, where the server updates occur in terms of players’ last confirmed position.

Without interpolation, players would appear to teleport between the (millisecond) tick rate updates from the server, which would damage the real-time illusion of playing online. 

The downside of interpolation

Because interpolation comes into effect from the last confirmed update from the server, and not necessarily the most recent one, it adds an additional layer of latency to the online game world.

If packet loss occurs between server updates, an online game may fall back on a process called ‘extrapolation’.

Where interpolation is reliant on consistency between server updates to be effective, extrapolation estimates what the game will look like in the near future.

For example, if you’re running in a straight line towards a corner, extrapolation will assume you want to keep running past the corner.

That’s a useful piece of software design, but it also demonstrates the trouble with extrapolation.

Player input isn’t always consistent. For instance, you might want to stop before the corner – but extrapolation wouldn’t be able to predict that change in input between running and stopping.

This may lead to your position being given away to an opponent around that corner, even though, according to the server (the true state of an online game), you never rounded it.

The result would likely be that your character warps back around the corner on the enemy player’s screen.

While you never actually rounded the corner from the server’s perspective, or even yours, the other player may have seen you briefly pop out, giving away your position.

While neither system is perfect, interpolation and extrapolation are effective ways of maintaining the illusion of real-time interaction.

Ever wondered how much data gaming uses? We took a look at some popular examples.

You might also like