System Design · 02. Scaling · 8 min · Beginner
Vertical vs Horizontal
Make one machine bigger, or run many machines side by side.
In short
Scale up (vertical): a bigger machine. Simple, no code change, but it has a ceiling (32,000 users here), costs more per core at the top, and is one thing to lose.
Scale out (horizontal): more machines. It needs a load balancer, shared state and redundancy for the parts that exist once, but it has no ceiling. Here 20 small servers carry 30,000 users at 75% CPU.
Key ideas
- Vertical scaling is fast and simple, but it has a hard upper limit, a rising price and one big machine to lose. (step 4)
- Scaling out adds a new part to the system: the thing that spreads the work. (step 6)
- Count the parts that exist only once. Each one is a risk, and each one needs a spare. (step 8)
Good to know
- For a small app, a bigger machine is often the best first step. Keep it simple while you can. (step 3)
- Large web systems scale out: cheap standard machines, added as needed. (step 5)
Watch out
- Do not wait for 100%. Plan to add capacity when you pass about 70% at the peak. (step 2)
- Anything an app server remembers in its own memory or disk is lost to the other servers. (step 7)
Key numbers
- CPU load
- 75%
- Max users
- 40,000
- Cost a month
- $3,000
Terms
- Vertical scaling (scale up)
- Adding capacity by moving to a bigger machine with more CPU, memory or disk.
- Horizontal scaling (scale out)
- Adding capacity by running more machines side by side.
- Scaling ceiling
- The largest machine you can get; vertical scaling cannot go past it.
- Load balancer
- A server that receives requests and spreads them across many app servers.
- Shared state
- Data such as sessions that every server must be able to reach, so it cannot live in one server's memory.
- Single point of failure (SPOF)
- A part that exists only once, so its failure stops the whole system.
- Redundancy
- Keeping a spare copy of a part so the system survives its failure.
- Capacity headroom
- Unused capacity kept in reserve, because queues grow fast near full load.