Scale up vs scale out
Traffic keeps doubling. Buy a bigger machine until there's no bigger one, or add machines behind a load balancer, or let an autoscaler do it. Then a machine dies, and it goes viral.
What you'll take away
- Tell scaling up from scaling out, and why a bigger machine has a ceiling
- Know why one machine means downtime: restarts to resize, and a dead site when it dies
- Get an app ready to scale out: stateless, with sessions and uploads off the machines
- Explain why autoscaling still drops a sudden spike, and how a spare machine helps
The 1-minute version
Tap a point and the picture below plays that step.
Step through to 3 a.m., then switch and compare the numbers below. They're the model's (a small machine takes 250 req/s, the biggest 2,000, prices in made-up units)
The site runs on one machine, already the cloud's biggest size, and traffic doubles again. What next?
The picture: each building is a machine, and its lit windows show how busy it is. Lights on the streets are requests; red ones are dropped. A dashed gold outline is a machine restarting at a new size, a faint dashed blue one is still booting, a dark one has died. Every number comes from a model (a small machine 250 req/s, the biggest 2,000, prices in made-up units), not from a real cloud.
Compare them all: Scale up vs scale out
The same day in every tile: 200 → 400 → 800 → 1,600 req/s, a machine dies, it goes viral at 3,200, then 300 at 3 a.m. See which drops requests, how many minutes the site is down, and what the machines cost.
Use it when Early on, a small system, or things hard to split, like one main database: the simplest, no code changes
Skip it when Traffic that keeps growing, or a site that can't go down: sizes have a ceiling, every resize restarts, and one machine dying is everything dying
A model: a small machine takes 250 req/s, the biggest size 2,000, a resize restarts for 2 minutes, a new machine boots in about 3. Prices in made-up units. Press any tile to see it large above, with when it fits.
Up or out?
| Scale up | Scale out | |
|---|---|---|
| How | A bigger machine | More machines + a load balancer |
| Ceiling | The biggest size on sale | Far away (then the database) |
| Growing | Usually a restart | Add one, nothing stops |
| One machine dies | The site is down | A share of the capacity is gone |
| The app | Unchanged | Must be stateless |
Most systems do both
App servers scale out, because they're stateless and cheap to copy. The main database usually scales up first, because it's hard to split, and then gets read replicas and caching in front. Scaling up is a fine first move; just know where its ceiling is.
Out needs a few things first
Sessions and uploads off the machines (into Redis, the database, object storage), a load balancer with health checks, deploys that go one machine at a time, and logs gathered in one place. Then adding the fourteenth machine is as boring as adding the second.
In real code
# Scale out: the same app on four machines behind nginx. Add a line to add a machine; nothing restarts but nginx's
# reload. A machine that fails 3 times is skipped for 10 s, so one dying costs a share of the capacity, not the site.
upstream app {
least_conn;
server 10.0.0.11:3000 max_fails=3 fail_timeout=10s;
server 10.0.0.12:3000 max_fails=3 fail_timeout=10s;
server 10.0.0.13:3000 max_fails=3 fail_timeout=10s;
server 10.0.0.14:3000 max_fails=3 fail_timeout=10s;
}
server {
listen 80;
location / {
proxy_pass http://app;
proxy_next_upstream error timeout http_502 http_503;
}
}
nginx -t (this file goes in /etc/nginx/conf.d/nginx.conf)It printed: nginx: configuration file test is successfulFour copies of the app behind nginx. Adding a machine is one more server line and a reload; a machine that fails 3 times is skipped for 10 s. Checked with nginx -t in Docker.
Common questions
What's the difference between scaling up and scaling out?
Scaling up gives the same machine more CPU, memory and disk. Scaling out adds machines and lets a load balancer share the work. The first is simple but has a ceiling; the second grows much further, and the system gets more complex.
Why does an app have to be stateless before it can scale out?
Each request may land on a different machine. If one machine remembers a session or keeps uploaded files, the others know nothing about them. Move that state somewhere shared (Redis, the database, object storage) and every machine is the same.
What happens when a machine dies?
Scaled up, there's one machine, so the whole site goes down. Scaled out, you lose a share of the capacity: 1 of 7 dies in the picture and a little is dropped. Keep one machine more than you need (N+1) and nothing is.
Autoscaling is on. Why are requests still dropped?
The autoscaler has to see the load before it starts machines, and new ones need minutes to boot and pass health checks. Until then there isn't enough capacity. Keep a spare, make it react sooner, or add machines ahead of an event you know is coming.
What does an autoscaler decide by?
Numbers you set, like average CPU above 70% or the length of a queue. It adds or removes machines between a minimum and a maximum you choose, and a cooldown stops it swinging up and down too often.
So is scaling up a bad idea?
No, it's a fine first move: no code changes, and it suits things that are hard to split, like the main database. Most systems do both: app servers scale out, the database scales up first. Just know where the ceiling is.
You keep adding app servers. What becomes the bottleneck next?
Usually the database. App servers are easy to add because they're stateless, but they all hit the same database. From there it's caching, read replicas, better indexes and, later, sharding.
Next lesson
Load balancingLevel: Basic
Scaling out puts servers behind a load balancer; next, how it picks one for each request and steers around a dead one.