Module 2 · Backend architectureLesson 15 of 886 minBeginner
Scaling up vs scaling out
You can buy a bigger machine or add more machines. Bigger is simpler; more is what lets you grow without limit.
Push traffic up until requests drop. Fix it once with "Server power" (scale up), then reset and fix it by adding servers (scale out). Then crash a server in each setup.
When traffic outgrows your server, you have two choices.
Scale up (vertical)
Move to a bigger machine: more CPU cores, more memory, faster disks.
- Pros: no code changes, nothing new to manage, no network between parts.
- Cons: there's a ceiling, and the biggest machines are very expensive. Upgrading often means downtime. And it's still one machine: when it fails, everything fails.
Scaling up is a great first move, and it's how many databases grow for a long time.
Scale out (horizontal)
Add more machines and put a load balancer in front.
- Pros: almost no ceiling; add capacity in small steps; one machine dying just means slightly less capacity.
- Cons: you need a load balancer, and your app must be stateless.
Stateless servers
A server is stateless when it doesn't keep anything important in its own memory between requests. Sessions, carts and uploads go to a shared place: a database, a cache like Redis, or object storage.
Then any request can go to any server, servers can be added or removed at any time, and a crash loses nothing.
In practice
- App servers: scale out. Cheap, simple, and it's what autoscaling does.
- Databases: usually scale up first, then add read replicas, and only then split data across machines (sharding). You'll see why in the database module.
- Watch the next bottleneck: adding app servers just moves the pressure to the database. Scaling is a chain; it's only as strong as the weakest link.