6. Vertical vs Horizontal Scaling
The picture to keep in your head
Every question below is answered twice: first in the kitchen, so you can picture it, then in the system, so you know exactly how it works. Each answer ends with a memory code to lock it in.
The picture to keep in your head
A restaurant gets famous and the orders double. The owner has two choices. Hire one superstar chef with four hands and a giant stove, or hire more ordinary chefs who work side by side. The superstar is simple: nothing about the kitchen changes. But there's only so big one chef can get, and if they fall sick, nobody cooks. More chefs can grow almost without limit, but only if the orders and recipes aren't stuck in one chef's head. And all of them still share one pantry.
That's vertical scaling (a bigger machine) and horizontal scaling (more machines).
Our running example: the bookstore from the last three chapters is planning its yearly Book Fest sale. Normal evening traffic is about 2,000 requests a second. During the sale it's expected to hit 20,000, ten times more, for a few hours. (These are assumptions for the example.)
| In the kitchen | In the system |
|---|---|
| A chef | A server |
| A bigger, faster chef with a bigger stove | Vertical scaling (scale up): more CPU, RAM, disk |
| More chefs working side by side | Horizontal scaling (scale out): more servers |
| The head waiter handing out orders | Load balancer (Chapter 7) |
| Orders on a shared board, not in a chef's head | State in a shared store, not on the server |
| Extra chefs hired for the dinner rush | Autoscaling |
| The one pantry everyone shares | The database |
Figure: the kitchen, mapped to the system. More chefs only help if the orders and recipes aren't stuck in one chef's head.