When traffic grows, a server runs out of CPU, memory or disk. You can buy a bigger machine (vertical scaling, "scale up") or add more machines (horizontal scaling, "scale out"). The scaling lesson introduced both. Here we make the decision concrete with capacity math, failure behaviour and cost, and show why the right answer is usually "scale up first, design to scale out".
Detailed Notes
What Problem Are We Solving?
A service has a capacity: the requests per second (RPS) it can handle before latency rises sharply. When demand approaches capacity, you need more. Two moves exist.
Vertical scaling (scale up): replace the machine with a larger one, with more CPU cores, RAM, faster disk or network.
Horizontal scaling (scale out): keep the machine size and add more of them behind a load balancer, which spreads requests across the machines.
Capacity math makes the gap visible.
text
Peak traffic = 30,000 requests per second
One app server handles = 3,000 requests per second at 60% CPU
Servers needed = 30,000 / 3,000 = 10
One spare for a failed server (N+1) = 11
Survive losing 1 of 3 zones: the 2 left must carry 30,000
-> 10 servers in 2 zones = 5 per zone -> 15 servers in total
With a vertical approach you would need one machine 10 times larger, and none exists at a sensible price. For a stateless web tier the answer is clear. For a relational database, it is not: a database holds state, so adding machines means splitting or copying that state.
Scale Up vs Scale OutComparison
Vertical
one bigger machine
1
Measure the bottleneck
CPU, RAM, disk, or network
2
Move to a larger instance
16 to 64 cores
3
Restart or fail over
short interruption
4
Keep one machine
no coordination needed
No code change
No distributed bugs
Quick win
Hard ceiling, steep price at top
Single point of failure
Resize may need downtime
Best for stateful parts, early on
Horizontal
many identical machines
1
Make servers stateless
state moves to shared stores
2
Put a load balancer in front
health checks, spreading
3
Add machines as load grows
auto scaling by CPU
4
Lose one, lose a fraction
10 servers = 10% each
Near-unlimited headroom
Fault tolerant
Rolling deploys, pay as you go
Needs stateless design
More components to run
Data tier is hard to split
Best for stateless tiers and large scale
Key point. Scale up buys simplicity until the ceiling. Scale out buys resilience and headroom at the price of complexity.
The same 30,000 RPS peak handled two ways.
Option 1: Vertical scaling (scale up)
How it works
You stop the service, move to a larger instance type (for example 8 to 32 cores, 32 to 256 GB RAM), and start again. The code does not change. The application still talks to one machine, so there is no distributed coordination.
Pros
Simplest possible change. No new components, no data splitting, no network between parts.
No distributed-systems bugs. Transactions, joins and in-memory caches all work as before.
Fast to do. Often a configuration change and a restart.
Cheap at small scale. Cost grows roughly linearly with size for common machine sizes.
Cons
A hard ceiling. The largest machine is finite, and prices climb steeply near the top. Doubling the biggest instance may cost more than double.
Single point of failure. One machine means one crash takes everything down, and the blast radius (the share of users affected by a failure) is 100%.
Downtime to resize. Many resizes need a restart, so you need a failover plan or a maintenance window.
Diminishing returns. Software may not use 64 cores well because of locks and memory bandwidth.
When to use it
Choose vertical scaling when the component holds state that is hard to split (a relational primary), the load fits one large machine with years of headroom, or the team and traffic are small.
Realistic scenario. A SaaS invoicing product has a PostgreSQL primary at 1,500 writes per second and 800 GB of data. CPU is at 70%. Upgrading from 16 to 48 cores and 128 to 384 GB RAM costs perhaps double, takes an hour with a replica promoted during the switch, and buys two years. Sharding the database would take six engineer-months, so scaling up is the right call.
Option 2: Horizontal scaling (scale out)
How it works
You run many identical machines and put a load balancer in front. To add machines without the clients noticing, the servers must be stateless: they keep no per-user data in memory between requests. Session data, uploads and caches live in shared stores (a cache cluster, a database, object storage), so any server can handle any request. For stateful components such as a database, scaling out means replication (copies for reads) and partitioning (splitting data by key), both covered in chapter 2.
An auto scaling group can add servers when CPU passes 60% and remove them at night.
Pros
Almost no ceiling. Add the 11th, 100th, 1,000th machine.
Fault tolerance. If one of 10 servers dies, you lose 10% of capacity, not 100%. The load balancer's health checks stop sending it traffic.
Zero-downtime changes. Roll out new versions one machine at a time.
Pay for what you use. Scale down at off-peak times.
Flexible shape. Use many small commodity machines, spread across zones.
Cons
Needs a stateless design (or partitioning for data). Retrofitting statelessness into an app that keeps sessions in memory takes work.
More moving parts. Load balancer, service discovery, deployment automation, monitoring across many hosts.
Data is hard. Cross-shard joins and transactions are expensive, as the partitioning lesson showed.
When to use it
Choose horizontal scaling when the load exceeds the largest sensible machine, you need fault tolerance, or the component is naturally stateless (web servers, API servers, workers).
Realistic scenario. A ticket-sales site has an everyday load of 2,000 RPS and a 40,000 RPS spike when a concert goes on sale. Running 14 servers all year to cover the spike wastes money. With an auto scaling group of stateless servers behind a load balancer, it runs 2 servers normally and grows to 14 within a few minutes, then shrinks again.
The hybrid: scale up first, scale out where it is easy
Most teams combine both, tier by tier.
Web and API tier: stateless, scale out from day one with an auto scaling group.
Database: scale up the primary as far as sensible, add read replicas (scale out reads), then shard only when writes outgrow one machine.
Cache: a cluster partitioned with consistent hashing, which is horizontal by design.
A useful rule from interviews: scale up is a first step, scale out is the design. Build so you can scale out (stateless services, a shardable key chosen early), and use vertical scaling to buy time cheaply.
Scaling Each Tier the Right WayArchitecture
Key point. Move state out of the app servers, and scaling out the web tier becomes routine.
The stateless tier scales out, the database primary scales up and fans out reads with replicas.
Interview Discussion
Walk tier by tier instead of choosing one style for the whole system.
Estimate the peak load and divide by per-server capacity, as in the example above.
Ask which tiers hold state. Stateless tiers: scale out. Stateful tiers: scale up first, then replicate, then partition.
Count the failure domain. "If one machine fails, how much traffic do we lose?" One machine: 100%. Ten machines: 10%.
Name the trigger for moving on: "I'd shard when the primary passes about 60% write CPU, or storage passes what we can back up and restore in our recovery window."
Interview tip. Do not jump to sharding at 100 GB. Interviewers often probe whether you scale before you must. Equally, do not run a single server with no failover and call it a plan.
Interview discussion. "At 30,000 peak RPS and about 3,000 per server, I need ten app servers plus headroom across three zones, so I'd scale out the stateless tier. The database is 800 GB at 1,500 writes per second, which one large primary with two replicas handles, so I'd scale that vertically and revisit if writes pass about five thousand per second."
Trade-off thinking. Vertical scaling trades a ceiling and a single point of failure for simplicity. Horizontal scaling trades complexity for headroom and resilience. Spend complexity only when the numbers require it.
Final Takeaway
Choose vertical scaling when the component is stateful and hard to split, one machine has years of headroom, or you need a quick, simple win. Choose horizontal scaling when load exceeds one machine, you need fault tolerance, or the tier is stateless. In practice, scale out the stateless tiers from the start, scale up the database first, and add replicas and shards when the numbers show you must. Always show the arithmetic.