You are signed in. Close

You are signed out. Close

Thank you. Your subscription has started. Close

Thank you. You will get an email when a new comic comes out. Close

We could not confirm your payment. If you paid, use the link "Sign in" at the bottom of the page. Close

Something went wrong on our side. Please try again in a moment. Close

Previous episode Load balancers: why many small servers beat one big one

What happens when a website goes viral: how a site keeps up with millions of visitors

Stateless servers: why a growing website can forget who you are

A website runs on many servers. A visitor is halfway through something, and suddenly their work is gone. Nothing crashed, and no error shows on the screen.

  1. 1 Forty copies of your site share the crowd. Halfway through her puzzle, Miva's guesses vanished. Her first three went to server 2, and server 2 wrote them down in its own memory, as your one server always did.load balancerserver 2Miva:3 guesses

    Forty copies of your site share the crowd. Halfway through her puzzle, Miva's guesses vanished. Her first three went to server 2, and server 2 wrote them down in its own memory, as your one server always did.

  2. 2 Her fourth guess went to server 7. The load balancer sends each request to whichever server it picks, and server 7 had never heard of her.load balancerserver 2Miva:3 guessesserver 7Whoare you?

    Her fourth guess went to server 7. The load balancer sends each request to whichever server it picks, and server 7 had never heard of her.

  3. 3 What a website must remember about a visitor from one request to the next is called state: here, Miva's guesses so far. Kept inside one copy, state works only while every request goes back to that copy.Miva:3 guessesstate

    What a website must remember about a visitor from one request to the next is called state: here, Miva's guesses so far. Kept inside one copy, state works only while every request goes back to that copy.

  4. 4 So you take the memory out of the servers. Each one now writes Miva's guesses in one shared place, a database, and reads them back from there, whichever server gets her next request.server 2server 7databaseMiva:3 guesses

    So you take the memory out of the servers. Each one now writes Miva's guesses in one shared place, a database, and reads them back from there, whichever server gets her next request.

  5. 5 Your servers now keep nothing of their own between two requests: they are stateless. Any server can take any request, and a new copy is useful the moment it starts.newstateless

    Your servers now keep nothing of their own between two requests: they are stateless. Any server can take any request, and a new copy is useful the moment it starts.

  6. 6 The next morning at 9:05, all forty servers are ready. Yet the page loads slower than the day before, and none of the forty is busy. What are they all waiting for?9:05?40 servers

    The next morning at 9:05, all forty servers are ready. Yet the page loads slower than the day before, and none of the forty is busy. What are they all waiting for?

  7. Quick check

    A shop website has ten servers behind a load balancer. Each server keeps the cart of a shopper in its own memory.You put a lampin your cart andclick again. Whatcan go wrong?

    A shop website has ten servers behind a load balancer. Each server keeps the cart of a shopper in its own memory.

    Show the answer

    The next click can land on another server, which has no cart for that shopper, so the cart looks empty. The cart is state: it belongs in a shared place, such as the database.

  8. Go further

    Miva's lost guesses, with the names people use.Miva:3 guessessessionone visitor's visit, andthe state a website keepsfor it, like Miva'sguesses todaysticky sessionsa load balancer settingthat sends a visitor backto the same server eachtime: her state is lostwhen that server stops

    Miva's lost guesses, with the names people use.

Next episode Database bottlenecks: why more web servers can make a site slower

Share this comic

More comics