Sub topic 3
Where Scaling Stops: Hardware Ceilings and Amdahl's Law
Assume you understand web servers, databases, CPU, memory, disk, and network resources. This chapter focuses on choosing a scaling strategy after you have measured the system.
Hardware ceilings and Amdahl's law
Vertical scaling adds resources to one machine: more CPU cores, memory, faster storage, or network capacity. Each resource has a physical or provider limit. A larger machine can also become expensive and create a single failure point.
Horizontal scaling adds machines. It can increase capacity beyond one machine's limit, but only when the workload can be divided. Some work remains serial, such as a lock, a database transaction, or a single-threaded step.
Amdahl's law estimates the maximum speedup:
speedup = 1 / ((1 - p) + p / n)
Here, p is the parallel fraction and n is the number of workers.
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 95% parallel work, unlimited workers cannot produce more than a 20x speedup. Improve the serial part before adding more workers.
Availability, cost, and complexity
Vertical scaling is usually simpler. It may require only a machine resize, but resizing can cause downtime and leaves one main failure point.
Horizontal scaling improves availability when machines run across failure zones. It costs more to operate and requires request routing, shared observability, deployment coordination, and often stateless application design.
Autoscaling based on load
Autoscaling changes capacity as demand changes. A policy might keep average CPU near 70%, with between two and ten application replicas. CPU alone may be misleading, so also consider request rate, queue depth, and latency. Use cooldown periods to avoid constant scaling activity.
Choosing a strategy
Choose vertical scaling when the application is difficult to partition, the workload is moderate, or simplicity matters most. Choose horizontal scaling when demand is variable, availability matters, and requests can run independently. Scale the data tier separately with read replicas, partitioning, or sharding when it is the bottleneck.
Exercise
A service has high CPU usage on one server, but requests share no state. Which strategy is a reasonable next step?
Show answer
Add application replicas behind a load balancer, then verify that the database and other dependencies can handle the extra load.