Sub topic 9
Where scaling stops: hardware ceilings and Amdahl's law
This chapter assumes you know the difference between vertical and horizontal scaling, can read basic latency and throughput numbers, and understand what a load balancer and a stateless application server do. Here you will learn why neither approach grows capacity without end, and how to estimate the limit before you spend money on it.
Two kinds of ceiling
Scaling stops for two different reasons. They call for different responses, so keep them apart.
- Hard ceilings are limits of the hardware or the platform. You cannot buy past them.
- Soft ceilings are limits of the workload. You can add hardware, but the result barely improves.
Vertical scaling mostly runs into hard ceilings. Horizontal scaling mostly runs into soft ones. Both can hit either kind.
Hardware ceilings in vertical scaling
A bigger machine helps only until you reach the largest machine that exists. Several limits show up in practice.
- Largest available instance. Every cloud provider and hardware vendor has a top size, measured in cores, memory, and network bandwidth. Past that size, the only option is more machines.
- Price that grows faster than capacity. The largest sizes are often priced at a premium. Doubling capacity near the top of the range can cost more than double.
- Diminishing returns inside the box. On a machine with many cores, threads compete for locks, memory bandwidth, and cache. Adding cores does not add the same capacity each time.
- A single point of failure. One large machine is still one machine. Scaling it up does not make it more available.
- Downtime to resize. On many platforms, changing the machine size means a restart. That is a cost you pay each time you hit the ceiling.
The following table lists the resources that most often set the ceiling on one machine.
| Resource | Typical way it limits you | What raising it costs |
|---|---|---|
| CPU cores | Lock contention, single-threaded code paths | Larger instance, higher license cost for per-core software |
| Memory | Dataset no longer fits in RAM | Large-memory instances are priced at a premium |
| Disk throughput and IOPS | Database writes queue at the disk | Faster storage tiers, provisioned IOPS |
| Network bandwidth | Link saturates before CPU does | Bigger instance class, since bandwidth is tied to size |
The practical point is that vertical scaling has a known end. You can look up the largest machine and compute how much headroom you have left. That makes it easy to plan for, as long as you actually do the check.
Ceilings in horizontal scaling
Adding machines removes the single-machine limit, but it introduces others.
- Shared components. Every server still talks to the same database, cache, or message broker. If that component cannot grow, adding application servers only moves the queue.
- Coordination cost. Servers that must agree on something (a lock, a leader, a counter) spend time communicating. That time grows with the number of servers.
- The load balancer and network. The balancer itself has a throughput limit, and the network between tiers has finite bandwidth.
- Operational limits. More machines mean more deployments, more failures per day, and more monitoring. These costs grow even when the capacity gain does not.
These ceilings are soft in the sense above. You can keep adding machines, but each one contributes less. Amdahl's law gives a way to put a number on this.
Amdahl's law
Gene Amdahl described the limit on speedup from parallel work in 1967. The idea is simple. Every job has some part that can be split across workers and some part that cannot. Extra workers shorten only the splittable part.
Let p be the fraction of the work that can run in parallel, and n the number of workers. The speedup is:
speedup = 1 / ((1 − p) + p / n)
The term (1 − p) is the serial fraction. It stays the same no matter how many workers you add. As n grows, p / n shrinks toward zero, and the speedup approaches 1 / (1 − p). That value is the ceiling.
The following code computes the speedup for a workload that is 95% parallelizable.
def amdahl_speedup(parallel_fraction, workers):
return 1 / ((1 - parallel_fraction) + parallel_fraction / workers)
print(round(amdahl_speedup(0.95, 16), 2)) # 9.14
print(round(amdahl_speedup(0.95, 1000), 2)) # 19.63With a 5% serial fraction, 16 workers give about a 9.14x speedup. That is only 57% of the ideal 16x. With 1000 workers the speedup is about 19.63x. It can never exceed 1 / 0.05 = 20x, so the last 984 workers buy you about 10 extra units of speedup.
Seeing the curve
It helps to compute the speedup at several worker counts and several serial fractions side by side.
def amdahl_speedup(parallel_fraction, workers):
return 1 / ((1 - parallel_fraction) + parallel_fraction / workers)
worker_counts = [1, 2, 4, 8, 16, 64, 256, 1024]
fractions = [0.50, 0.90, 0.95, 0.99]
print("workers", *[f"p={p:.2f}" for p in fractions], sep="\t")
for n in worker_counts:
row = [f"{amdahl_speedup(p, n):.2f}" for p in fractions]
print(n, *row, sep="\t")
print()
for p in fractions:
print(f"p={p:.2f} ceiling: {1 / (1 - p):.0f}x")Running this shows the pattern. At p = 0.50, the curve flattens near 2x almost immediately. At p = 0.99, 64 workers give roughly 39x, and the ceiling is 100x. The gains from doubling the workers shrink each time you double.
What counts as the serial fraction
Amdahl's law uses a clean split between serial and parallel work. Real systems have many sources of serial work, and spotting them is the useful skill.
- A single primary database. If every write goes to one primary, write throughput does not scale with application servers.
- Global locks and counters. One row that every request updates, such as a global sequence number, serializes those requests.
- Leader election and coordination. Work that only one node may perform, such as running a scheduled job, is serial by design.
- Startup and warm-up. New instances may need time to load caches or connect to dependencies before they help.
- Fan-in steps. A request that gathers results from many servers waits for the slowest one, and then merges the results on one node.
- The load balancer. All traffic passes through it, so its capacity is a shared limit.
In a web system, you rarely compute p exactly. You estimate it. If profiling shows that 20% of request time is spent waiting on a single database primary, then your serial fraction for application-tier scaling is near 0.20, and the ceiling is about 5x.
Amdahl's law has limits too
The law answers a specific question: how much faster can a fixed job run with more workers? Keep its assumptions in mind.
- The job size is fixed. Many web systems instead grow the workload with the workers. Serving ten times as many users on ten times as many servers is a different question. Gustafson's law covers the case where the problem grows with the machine, and it is more optimistic.
- It ignores overhead. The formula has no term for coordination cost. Real speedup can fall below the Amdahl value, and in systems with heavy contention it can even get worse when you add workers.
- It assumes equal workers and even splitting. Uneven load, hot keys, and slow nodes lower the real result.
- The serial fraction is not constant. It can change with the workload, the data size, and the code. Measure it again after each change.
A useful way to hold both laws together is this. Amdahl's law tells you the ceiling for making one fixed workload faster. Gustafson's law reminds you that adding servers also lets you handle more work, as long as the serial part does not grow with it.
Reading the ceiling in practice
You can estimate the ceiling from measurements you already have, using the bottleneck work from earlier chapters.
- Profile a typical request and split its time into parts that scale with more servers and parts that do not.
- Treat the non-scaling time as the serial fraction, 1 − p.
- Compute the ceiling 1 / (1 − p), and the speedup at your planned worker count.
- Compare the planned speedup with the ceiling. If you would reach, say, 80% of the ceiling, more servers are not the best use of money.
- Look for a way to shrink the serial part: caching, read replicas, sharding, batching, or removing a global lock.
- Measure again with a load test, because the model is an estimate.
A short script can do the arithmetic for you and tell you how many workers are worth buying.
def amdahl_speedup(parallel_fraction, workers):
return 1 / ((1 - parallel_fraction) + parallel_fraction / workers)
def workers_for_fraction_of_ceiling(parallel_fraction, target=0.80, limit=100000):
ceiling = 1 / (1 - parallel_fraction)
for n in range(1, limit + 1):
if amdahl_speedup(parallel_fraction, n) >= target * ceiling:
return n
return None
p = 0.95
n = workers_for_fraction_of_ceiling(p, 0.80)
print("ceiling:", round(1 / (1 - p), 2))
print("workers to reach 80% of ceiling:", n)
print("speedup at that count:", round(amdahl_speedup(p, n), 2))For p = 0.95, the script reports that 76 workers reach 80% of the 20x ceiling. Reaching 90% of the ceiling takes 171 workers, more than twice as many for 10 more points. That is the diminishing return in a single number you can bring to a budget discussion.
Common mistakes
- Scaling the tier that is not the bottleneck. Adding application servers when the database is saturated raises cost and leaves latency unchanged.
- Quoting the ideal speedup. Saying "16 servers means 16x" ignores the serial fraction. Use the formula to get a defensible number.
- Treating the ceiling as fixed. The serial fraction is a property of your design. Removing a global lock changes the ceiling.
- Forgetting the hard ceiling. If your plan relies on vertical scaling, check how much room is left on the largest available machine before the next growth step.
- Ignoring overhead. Amdahl's law is optimistic. Leave margin, and confirm with load tests.
Summary
Vertical scaling ends at the largest machine you can buy, and its cost often rises faster than its capacity. Horizontal scaling ends more gradually, because the serial parts of the system (a single primary database, global locks, the load balancer) do not speed up when you add servers. Amdahl's law quantifies that: the speedup can never exceed 1 divided by the serial fraction. Estimate the serial fraction from profiling, compute the ceiling, and decide whether to add capacity or to reduce the serial work first.
Exercise
A service spends 10% of each request's time on work that cannot be parallelized (a lock on a single shared row). The remaining 90% scales across application servers. (a) What is the maximum possible speedup? (b) What is the speedup with 9 servers? (c) The team proposes going from 9 to 90 servers. Is that a good use of money, and what would you try first?
Show answer
(a) The ceiling is 1 / (1 − 0.90) = 10x. (b) The speedup is 1 / (0.10 + 0.90 / 9) = 1 / 0.20 = 5x. (c) With 90 servers the speedup is 1 / (0.10 + 0.90 / 90) = 1 / 0.11, or about 9.09x. Ten times the servers gives only about 1.8 times the speedup (9.09 / 5), so it is a poor use of money. A better first step is to shrink the serial part, for example by removing or sharding the shared-row lock. If the serial fraction fell to 2%, the ceiling would rise from 10x to 50x.
Exercise
Name two reasons Amdahl's law can overestimate the speedup you actually get from adding servers, and one reason it can underestimate the capacity gain.
Show answer
It can overestimate because it ignores coordination overhead (locks, network calls, consensus) and because load is rarely split evenly (hot keys, slow nodes). It can underestimate the capacity gain because it assumes a fixed job size. If adding servers lets you serve proportionally more users or data, as Gustafson's law describes, the system can handle much more total work, provided the serial part does not grow with the workload.