Wirebook

Wirebook › Lesson 14 of 18

How can lots of people play the same game together?

About 7 minutes · hands-on · nothing you type leaves your browser unless a button says so

You and your friends are in different houses, but you're all running around the same park in a game. Who decides where everyone really is? Is there a giant invisible playground somewhere? Sort of: it's a shared world kept on a server, and every move is a short message racing across the internet. Here's a little park so you can see the messages, the lag, and who gets the star when two people grab it at once.

The invisible playground

You are the fox. Three friends (in other houses) are also trying to catch stars. The shared park on the right is what the game's server says is true. Your tablet on the left is what you see. Drag the lag slider, then try waiting for the server versus guessing first. Nothing leaves this page: the "server" is pretend and lives in your browser.

Your tablet

Shared park (the server's truth)

Move with the arrow keys or click a neighbouring square. Catch a star by stepping on it.

Messages on the wire

    Press Start, then move the fox. Watch the shared park catch up when there's lag.

    Is there a giant invisible playground?

    Yes, in a way. When lots of people play the same game from different houses, there has to be one shared world that everyone agrees on: where each player is, who has which star, whose score is what. That shared world lives on the game maker's server, a computer that keeps the park in its memory and answers messages from every tablet. Your tablet doesn't invent the truth on its own; it asks the playground and draws what it's told.

    Every time you press an arrow, your tablet sends a tiny message: "Fox wants to step right." The server checks whether that move is allowed (is the square empty? is the star still there?), updates the shared park, and tells every tablet "Fox is now at square 4,2 and got the star." Friends in other houses see you move because their tablets get the same update.

    So why don't people bump into each other? Because the shared park is the referee. If two of you try to stand on the same square or grab the same star, the server picks one answer and tells everyone. There isn't a separate park in each house that might disagree: there's one park, and every house gets a copy of the latest picture.

    Why does lag make the park feel weird?

    Messages aren't instant. The time a message takes to travel is called latency, or lag. Under the sea and across cities, even at the speed of light, a round trip often takes 30 to 100 milliseconds, and on a busy Wi-Fi it can be much more. In the playground above, the lag slider is how long each message spends "in the post".

    If your tablet waited for every reply before moving the fox on your screen, the game would feel sticky: you'd press right and the fox would freeze for a tenth of a second. So most games guess first. Your tablet moves the fox straight away (that's called prediction), and when the server's reply arrives it checks whether the guess matched. If it did, nothing changes. If it didn't — maybe a friend grabbed the star a moment earlier — the fox snaps back to where the server says it should be. That snap is the rubber-band feeling in online games.

    Try it above with lag turned up and "Guess first" on: your tablet looks ahead, then the shared park catches up. Switch guessing off and every step waits for the post.

    Who got the star?

    When two players step on the same star "at the same time", their messages still arrive one after the other. The server deals with them in order: the first message that reaches it wins the star, and the second finds the square empty. From each player's house it can feel unfair ("I was clearly first!"), because each tablet saw its own move instantly. The shared park settles the argument.

    Real games do this many times a second. The shared world updates on a steady beat, a tick, often 20 or 60 times a second. Between ticks the server queues moves, then applies them in order and broadcasts the new picture. Faster ticks feel snappier but cost more work; slower ticks save power and bandwidth.

    Same idea as high scores. Just as a high-score server shouldn't trust a tablet that claims "I scored a million" (see how a game knows you really won), a multiplayer park shouldn't trust a tablet that claims "I am standing here with every star". Your device only asks to move; the shared playground decides what actually happened.
    Be kind on the real playground. Lag and rubber-banding can feel frustrating, but they're the price of sharing one world across many houses. Cheating (speed hacks, fake positions) spoils that world for everyone else.

    Related lessons: how a game controller talks to the console (the lag before your move even leaves the house) · why the game lags when someone starts a download.

    Words from this lesson

    Earn your stamp

    Get all 3 right to collect the Playing together stamp. Wrong answers are fine: just try again.

    1. Where does the one shared park really live when friends play from different houses?

    2. Your tablet moves the fox before the server replies. What is that called?

    3. Two players step on the same star 'at once'. Who decides the winner?

    Try another lesson

    1. 15How does a website check your password without keeping it?8 min · interactive
    2. 16How can you spot a fake message?7 min · interactive
    3. 17What are bots doing on the web?7 min · interactive