Vertical and Horizontal Scaling
Vertical scaling strengthens one server, and horizontal scaling adds more servers. Both raise capacity, but they fail in different ways.
A stronger single server
The upgrade raises the capacity of the one machine. The limit rises, but the system still rests on a single server.
small = 40
big = 100
print("one server before the upgrade:", small, "requests per second")
print("one server after the upgrade:", big, "requests per second")More servers share the load
Four small servers pool their capacity. Their total is higher than the one big server in this example.
servers = [40, 40, 40, 40]
print("number of servers:", len(servers))
print("capacity of each:", servers[0], "requests per second")
print("total capacity:", sum(servers), "requests per second")When one machine stops
The failure case shows the real difference between the two shapes. One shape loses everything, and the other keeps most of its capacity.
big_total = 100
small_total = 4 * 40
print("the big server stops, capacity left:", big_total - 100)
print("one small server stops, capacity left:", small_total - 40)Example
big = 100
group = 4 * 40
for demand in [90, 120, 170]:
print("demand:", demand, "requests per second")
print(" one big server:", "fits" if demand <= big else "does not fit")
print(" four small servers:", "fits" if demand <= group else "does not fit")Key points
- Vertical scaling: making one server stronger so it handles more requests.
- Horizontal scaling: adding more servers so they share the requests.
- Capacity: the most requests per second a server or group can handle.
- One big server: the worked example gives it a capacity of 100 requests per second.
- Four small servers: each one holds 40 requests per second, and together they hold 160 requests per second.
- Single failure, vertical: the only server stops and capacity falls to 0.
- Single failure, horizontal: one small server stops and 120 requests per second remain.
In this example, rising demand is tested against both shapes in turn. The group of small servers still fits a demand that the one big server cannot hold.
Try it Yourself
Edit the code, then press Run.
Running is simulated
Exercise
Traffic keeps growing past what any one affordable server can hold. Which scaling adds more servers?