6. Vertical vs Horizontal Scaling
6.3 What is horizontal scaling?
In the kitchen: Hire more chefs who cook the same menu side by side. Ten chefs can cook roughly ten times the plates, and if one is sick, the other nine keep going. But it only works if the work can be split: if every plate needs the one chef who makes the secret sauce, the others stand around waiting.
In the system: Horizontal scaling (scaling out) means adding more machines that do the same job, with a load balancer spreading requests across them (Chapter 7).
Figure: scaling up is simple but has a ceiling; scaling out has almost no ceiling but needs stateless servers and a load balancer.
Why it's the default for big systems:
- Almost no ceiling: need more capacity, add more servers.
- Survives failures: one server dies, the others carry on.
- No downtime to grow: add servers while the old ones keep serving.
- Cheap, ordinary machines, and you can remove them when traffic drops (6.6).
The catch: the work must split. The speed-up you get is limited by the part of the work that can't be spread out: a shared lock, a single counter every request updates, one database row everybody writes to. This is Amdahl's law:
best speed-up with n servers = 1 / (serial part + (1 - serial part) / n)
Figure: if 10% of the work can't be split, even 1,000 servers give less than 10 times the speed.
If 10% of each request waits on one shared thing, no number of servers makes it more than 10 times faster. That's why scaling out goes hand in hand with removing shared bottlenecks.
Memory code: "More chefs, but only if the work can be split."