System DesignBeginner 11 min Lesson 26 of 42

Vertical Scaling

Adding CPU, memory or faster disks to one machine is often the cheapest fix. Learn when it wins and where it stops.

System Design · Lesson 26 of 42
0/42 done(0%)

What is it? #

Vertical scaling means giving one machine more resources: more CPU cores, more memory, faster storage, more network bandwidth.

It is underrated. Engineers often reach for distributed architectures when doubling the instance size would have solved the problem for a fraction of the effort and cost.

Modern hardware is large. A single server with 64 cores and 256 GB of memory handles workloads that people assume require a cluster.

The limits are real though: there is a maximum size, cost rises steeply at the top end, and one machine is one point of failure.

Think of it like this #

Upgrading from a small van to a lorry, rather than buying five vans and hiring five drivers.

One vehicle is simpler to manage and often cheaper. But there is a largest lorry available, and if it breaks down, nothing moves.

Simple example #

A database is slow under load. Before sharding it across four machines, check whether the working set fits in memory. Doubling memory often eliminates the disk reads that were the actual problem.

Code #

TEXT
Vertical                            Horizontal

no code changes needed              application must be stateless
simple to reason about              more moving parts
has a hard ceiling                  effectively unlimited
single point of failure             redundancy included
cost rises steeply at the top       roughly linear
restart required to resize          add instances with no downtime
BASH
# Find out what is actually constrained before buying anything
top                     # CPU and memory at a glance
vmstat 1 5              # is the CPU waiting on I/O? look at the wa column
free -h                 # memory, and how much the cache is using
iostat -x 1 5           # disk utilisation and await times
df -h                   # is the disk simply full?

# Is the database reading from disk instead of memory?
# PostgreSQL: a high ratio of heap_blks_read to heap_blks_hit means
# the working set does not fit in the cache.
SELECT sum(heap_blks_read) AS from_disk, sum(heap_blks_hit) AS from_cache
FROM pg_statio_user_tables;
TEXT
The sensible ladder, in order of effort

1. fix the slow query, add the missing index        often 100x, costs nothing
2. add caching                                       large win, moderate effort
3. scale vertically                                  minutes of work, no code change
4. add read replicas                                 helps reads only
5. scale horizontally                                needs a stateless application
6. shard                                             last resort, hard to undo

How it works #

The first step is always measurement. Adding CPU to a machine that is waiting on disk changes nothing, and adding memory to a CPU-bound service is wasted money.

vmstat shows the wa column: time the CPU spent waiting for input and output. A high value means storage is the constraint, not processing.

The PostgreSQL query compares blocks read from disk with blocks served from cache. When the ratio is poor, the working set does not fit in memory, and more memory turns disk reads into cache hits — often the single largest improvement available.

Databases are the clearest case for vertical scaling because they hold state, which is exactly what makes horizontal scaling hard. Giving the database a bigger machine requires no architectural change at all.

Cloud instances make this a configuration change plus a restart. On a managed database it can be a few minutes of downtime, or none with a replica failover.

The ladder at the end is the practical order. Query and index fixes routinely beat every infrastructure change combined, and they are free. Vertical scaling is the cheapest infrastructure step. Sharding is last because it is the hardest to reverse.

Real-world use #

Many successful products run on surprisingly modest infrastructure. A single well-tuned database server handles tens of thousands of queries per second, which is far beyond what most applications need.

The common mistake goes the other way: adopting microservices and clusters at a scale where one server would be simpler, cheaper and faster.

Vertical scaling also buys time. When traffic grows unexpectedly, resizing an instance in ten minutes is a far better immediate response than an architectural change under pressure.

The reason it cannot be the only answer is availability. One machine means maintenance windows, restart downtime and no redundancy. In practice most systems end up with both: vertically sized machines, horizontally duplicated for safety.

There is a cost cliff at the top of the range. The largest instances are disproportionately expensive, and that is usually the point where horizontal scaling becomes the better economic choice.

Common mistakes #

  • Adding resources without measuring which one is constrained.
  • Scaling up before fixing an obvious missing index or slow query.
  • Relying on one large machine with no redundancy for a critical service.
  • Forgetting that resizing usually requires a restart and a maintenance window.
  • Paying for the largest instance when two mid-sized ones would cost less and be safer.

Practice #

On any machine under load, use top, vmstat and iostat to determine whether it is CPU-bound, memory-bound or I/O-bound. Write down which resource you would increase and why, then identify one query or code path you would fix first instead.

Quick quiz

  1. 1. What is vertical scaling?

  2. 2. What is its main advantage?

  3. 3. Which column in vmstat indicates an I/O bottleneck?

  4. 4. Why is vertical scaling often right for databases?

  5. 5. What should you try before any scaling at all?

Summary

  • Vertical scaling adds resources to one machine and needs no code changes.
  • Measure first: CPU, memory and I/O constraints need different fixes.
  • Modern single machines handle far more than most applications require.
  • The limits are a hard ceiling, steep cost at the top, and no redundancy.
  • Fix queries and indexes before buying anything.