6. Vertical vs Horizontal Scaling
6.5 If servers are stateless, where does the state go?
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.
Figure: each kind of state has a natural home outside the app servers.
| Kind of state | Where it goes | Chapter |
|---|---|---|
| Sessions, carts, counters (small, fast-changing) | A shared cache like Redis | 12, 25 |
| Orders, users, books (the source of truth) | The database | 8 |
| Uploaded files and images | Object storage | 11 |
| Work still to be done (send email, resize image) | A message queue | 22 |
| Who the user is | A signed token the client carries | 3 |
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."