Sub topic 4
Vertical scaling: a bigger machine
Vertical scaling (also called scaling up) means adding capacity to a system by giving a single machine more resources. You move the same workload to a server with faster CPUs, more memory, faster disks, or a faster network link. The software architecture stays the same. Only the size of the box changes.
This chapter assumes you know what CPU, memory, disk, and network mean as server resources. It also assumes you have read the earlier chapters on capacity and load, on latency, throughput, and utilization, and on finding the bottleneck. Scaling up helps only when the resource you add is the one that is limiting you.
What vertical scaling changes
Vertical scaling changes the capacity of one node. It does not change how many nodes there are. Each resource can be scaled on its own:
| Resource | What you add | What it typically helps |
|---|---|---|
| CPU | More cores or higher clock speed | CPU-bound work such as encoding, parsing, and computation |
| Memory | More RAM | Caches, in-memory datasets, and database working sets |
| Disk | Faster storage (SSD or NVMe) or more IOPS | Database reads and writes, logging, and file-heavy work |
| Network | Higher bandwidth or more network interfaces | Large transfers, streaming, and chatty services |
More cores and a higher clock speed do different things. A higher clock speed makes a single thread finish sooner, which lowers latency for one request. More cores let more requests run at the same time, which raises throughput. If your code runs on a single thread, extra cores sit idle.
When vertical scaling fits
Scaling up is often the first move, and for good reasons.
- No application changes. The same code, configuration, and deployment run on the larger machine. This matters most for software that was not designed to run on several nodes.
- No distributed-system problems. One machine has no network partitions between its parts, no data replication lag, and no need to keep several copies of state in agreement.
- Simple operations. There is one server to patch, monitor, and back up.
- Fast results. On a cloud provider, resizing an instance can take minutes.
Relational databases are the classic example. A single-node database is often easier to scale up than to split across nodes, because transactions and joins across one machine are cheap. Many teams scale a database vertically for a long time before they add replicas or shards.
A worked example
Suppose a service runs on a 4-core machine. Monitoring shows the following during peak traffic:
- CPU utilization is 95% on all four cores.
- Memory use is 40%.
- Disk and network utilization are low.
- Median latency is 80 ms, and p99 latency has climbed to 1.2 s as requests queue for CPU.
The bottleneck is CPU. Moving to an 8-core instance with the same memory is a reasonable first step. If the work parallelizes across requests, as most web request handling does, CPU utilization should fall to roughly 48% at the same traffic, and queueing delay should drop.
Check the change with a measurement instead of assuming it worked. The following script estimates the expected utilization after a resize, assuming the load stays the same and spreads evenly across cores.
def expected_utilization(current_util, current_cores, new_cores):
"""Estimate CPU utilization after resizing, assuming the same load
and perfect spreading of work across cores."""
busy_cores = current_util * current_cores
return busy_cores / new_cores
before = 0.95
print(f"4 -> 8 cores: {expected_utilization(before, 4, 8):.0%}")
print(f"4 -> 16 cores: {expected_utilization(before, 4, 16):.0%}")This prints 48% and 24%. The estimate is optimistic. Real systems do not spread work perfectly, and the next sections explain why.
Why a bigger machine does not give proportional gains
Doubling the cores rarely doubles throughput. Several effects get in the way.
Serial portions of the work
Any part of a request that cannot run in parallel limits the speedup. Amdahl's law, covered in a later chapter, puts a number on this. With 5% serial work, even 1000 cores give less than a 20x speedup.
Contention
Threads that share data must coordinate. Locks, shared queues, and a single database connection pool become points where threads wait for each other. Adding cores adds more threads competing for the same lock, so throughput can flatten or even drop.
Memory architecture
Large servers often have several CPU sockets. Each socket has memory attached to it, which makes the machine a NUMA system (non-uniform memory access). A thread reading memory attached to another socket is slower than one reading its own. Software that is not NUMA-aware can lose much of the benefit of a large machine.
Garbage collection and runtimes
Runtimes with garbage collection, such as the JVM, can behave differently with very large heaps. A pause that took milliseconds with a 4 GB heap can take much longer with a 512 GB heap unless you pick and tune a collector designed for large heaps.
A different bottleneck appears
Removing one bottleneck exposes the next. After you fix CPU, the disk or the network may become the limit. This is normal, and it is why you re-measure after every change.
Downtime and how resizing works
Resizing is not always free of interruption. How disruptive it is depends on the platform.
- Physical servers. You may need to power down, install parts, and boot again. This can take hours and needs a maintenance window.
- Virtual machines in the cloud. Changing the instance type usually means stopping the instance, changing its type, and starting it again. Expect a few minutes of downtime for that node.
- Hot-add features. Some hypervisors can add CPU or memory to a running VM, but the operating system and the application must support it.
- Managed databases. Many managed services resize by failing over to a standby that has already been upgraded. The interruption is then short, often under a minute, but connections still drop and clients must reconnect.
Plan for the interruption. Use a maintenance window, drain traffic if you can, and make sure clients retry on connection errors.
Limits of scaling up
Vertical scaling has three kinds of limit.
- A hardware ceiling. The largest machine available has a fixed number of cores, a fixed amount of RAM, and a fixed network speed. When you reach it, you cannot scale up further.
- Rising cost per unit. Prices rarely grow in a straight line. The largest machines often cost much more per core or per gigabyte than mid-sized ones, because few are made and they use specialized parts.
- A single point of failure. One machine is one failure domain. If it crashes, loses power, or needs a reboot, everything on it is unavailable. A bigger machine concentrates more work, and so more risk, in one place.
The following diagram shows how the gains typically flatten as machine size grows, while the cost keeps rising.
The two lines are illustrative, not measured. The shape is what matters. The first line, throughput, bends over because of serial work and contention. The second line, cost, climbs faster than linearly at the high end.
Effect on availability
Vertical scaling does not improve availability on its own. A single larger server fails just as completely as a single smaller one. In some cases it is worse, because the failure affects more users and more data, and because recovery takes longer. Restoring a 2 TB in-memory dataset after a crash takes more time than restoring a 20 GB one.
You can combine scaling up with redundancy. A common pattern is a primary and a standby of the same large size, with automatic failover. This protects against a node failure, but you pay for two large machines and only one does the work, unless the standby also serves reads.
Cost considerations
Cost depends on how you buy capacity.
- Cloud, on demand. You pay by the hour or second for the instance size you choose. Resizing up and down is easy, which lets you match size to demand.
- Cloud, reserved or committed. Discounts apply when you commit to a size or family for a term. Committing to a large size reduces your freedom to change it.
- Owned hardware. You pay up front, and the machine is a fixed asset. Scaling up means buying a new machine and migrating to it, which is slow and costly.
Compare options by cost per unit of useful work, such as cost per thousand requests, not by price per machine. A machine twice the size that costs three times as much is a worse deal if you only needed 1.5 times the capacity.
Also account for software licensing. Some commercial databases and middleware charge per core. Doubling the cores can double the license bill, which can outweigh the hardware cost.
Common mistakes
- Scaling before measuring. Resizing on a hunch often targets the wrong resource.
- Ignoring single-threaded code. A process that uses one thread gains nothing from more cores. It only benefits from a faster clock.
- Forgetting limits in software. Connection pools, thread pool sizes, and database settings such as maximum connections or buffer sizes often stay at their old values after a resize. The new memory then goes unused. Update the configuration to match the new hardware.
- Skipping the load test. Test the new size under realistic load before you rely on it.
- Treating the ceiling as far away. Growth is often exponential. A machine that has headroom for six months at current growth may have little left after a year. Track the trend so you start planning the next step early.
Checking that a resize helped
After the change, compare the same metrics you used to justify it:
- Utilization of the resource you added. It should have dropped at the same load.
- Latency, especially tail latency (p95 and p99). It should have dropped if queueing was the cause.
- Throughput at saturation. Run a load test and find the request rate at which latency starts to climb sharply.
- Utilization of other resources. If another resource is now near its limit, you have found the next bottleneck.
If utilization fell but latency did not, the latency was not caused by waiting for that resource. Go back to the measurements.
Where vertical scaling sits in the larger picture
Scaling up is a good fit when the workload is hard to split, when the application keeps state in memory, when operational simplicity matters more than the last bit of capacity, or when the load is modest and well within the largest available machine. It is a weaker fit when you need to survive the loss of a machine, when load varies a lot, or when you expect to outgrow the biggest instance. The next chapters cover horizontal scaling, which addresses those cases and brings its own requirements, such as load balancing and stateless design.
Exercise
A service runs on one 8-core server. At peak, CPU is at 90% and memory is at 35%. Latency is high and requests are queueing. The team proposes moving to a server with 4 times the memory and the same 8 cores. Will this likely help? What would you propose instead, and what would you check afterward?
Show answer
It will likely not help. Memory is at 35% and is not the limiting resource, while CPU at 90% is the bottleneck. Quadrupling memory adds cost without relieving the queueing. A better step is to move to a machine with more cores, for example 16, which at the same load should bring utilization to about 45%. Before resizing, check that the application is multi-threaded or runs several worker processes, because single-threaded code gains nothing from extra cores. Also update thread pool and worker settings so the new cores get used. Afterward, compare CPU utilization, p95 and p99 latency, and throughput at saturation under a load test, and check whether disk or network is now the next bottleneck.
Exercise
Name three reasons that doubling the cores on a server usually gives less than double the throughput.
Show answer
Any three of: serial portions of the work that cannot run in parallel (Amdahl's law); contention for shared locks, queues, or connection pools; NUMA effects, where threads access memory attached to another CPU socket; garbage collection or runtime behavior that degrades with larger heaps; and a different resource, such as disk or network, becoming the new bottleneck.
Exercise
Why does vertical scaling not improve availability by itself, and what is a common way to add availability to a scaled-up system?
Show answer
A single machine is a single failure domain, so if it fails, everything on it is unavailable, and a larger machine concentrates more load and data in that one place. A common remedy is to add redundancy, such as a standby machine of the same size with automatic failover, accepting the extra cost of the second machine.