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
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
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
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
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
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
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?
-
Quick check
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.
-
Go further
Miva's lost guesses, with the names people use.