Lesson 6 of 16
6. Vertical vs Horizontal Scaling

6.5 If servers are stateless, where does the state go?

3 min read+10 XP

In the kitchen: Nothing important lives in a chef's head. Orders go on the board, recipes are on the wall, ingredients are in the pantry, and tomorrow's prep list is on the clipboard. A chef can walk out mid-shift and nothing is lost.

In the system: State doesn't disappear. It moves to shared places every server can reach, each chosen for the kind of state it is.

app servers hold nothing; state lives in Redis, the database, object storage, a queue, or the client.

Figure: each kind of state has a natural home outside the app servers.

Kind of stateWhere it goesChapter
Sessions, carts, counters (small, fast-changing)A shared cache like Redis12, 25
Orders, users, books (the source of truth)The database8
Uploaded files and imagesObject storage11
Work still to be done (send email, resize image)A message queue22
Who the user isA signed token the client carries3

What can stay on a server: things you can lose and rebuild, like a small local cache of hot data (Chapter 12's "pocket"), or a temporary file for one request.

A useful test: "If I kill this server right now, does any user lose anything?" If the answer is no, the server is stateless enough to scale out.

Memory code: "Nothing important lives in a chef's head."