Sub topic 10
Trade-offs: availability, cost, and complexity
This chapter assumes you know the difference between vertical scaling (a bigger machine) and horizontal scaling (more machines). It also assumes you know what a load balancer does and why application servers should be stateless. The goal here is to compare the two approaches on three dimensions: how likely the system is to stay up, what it costs, and how hard it is to build and run.
Availability
Availability is the fraction of time a system answers requests correctly. The two approaches differ most in what happens when a machine fails.
A vertically scaled system often has a single server. If that server crashes, is rebooted for patching, or is resized, the service is down. Resizing a virtual machine usually requires a restart, so the act of scaling itself can cause an outage.
A horizontally scaled system has several servers behind a load balancer. If one fails, the load balancer's health checks stop sending it traffic and the others absorb its share. You can also replace servers one at a time during a deploy (a rolling update) without downtime.
Redundancy only helps if the remaining servers can carry the load. Three servers running at 80% utilization cannot lose one: the other two would need to run at 120%. Plan for N+1 capacity, meaning enough servers to handle peak load even with one missing.
Cost
Costs behave differently as you grow.
- Vertical scaling has a price curve that bends upward. Doubling a machine's size on a cloud provider often roughly doubles the price at small sizes. At the top of the range, the largest machines carry a premium, and specialized hardware costs more per unit of capacity.
- Horizontal scaling has a roughly linear price for commodity machines. You pay for each added server, plus the load balancer, extra network traffic between machines, and monitoring for a larger fleet.
- Idle capacity matters for both. A big single machine must be sized for peak load and sits underused the rest of the time. A fleet can shrink during quiet hours (see the autoscaling chapter), so you pay closer to actual use.
- People cost often dominates. A distributed system takes more engineering time to build and operate than one large server.
Complexity
Vertical scaling needs almost no changes to the application. You move to a larger instance and the same code runs faster. This is why it is a good first step.
Horizontal scaling moves complexity into the design:
- Sessions and uploaded files cannot live on one server's local disk, so the application must be stateless.
- Deployments must update many servers consistently.
- Logs and metrics come from many machines and must be collected in one place.
- Requests may fail partway, so clients need timeouts and safe retries.
- Data shared across servers needs a plan for consistency, especially once the data tier is replicated or sharded.
The diagram shows how the failure of one server plays out in each design.
Comparing the two
| Dimension | Vertical scaling | Horizontal scaling |
|---|---|---|
| Failure of one machine | Whole service down | Capacity reduced, service continues |
| Scaling event | Often needs a restart | Add servers without stopping others |
| Cost curve | Rises steeply at the high end | Close to linear |
| Application changes | Few or none | Stateless design, shared state stores |
| Operational effort | Low | Higher: fleet, deploys, observability |
| Upper bound | Largest available machine | Limited by the serial parts of the system |
Common errors
- Treating a fleet as automatically highly available. Servers in one rack, zone, or power domain can fail together. Spread them across availability zones.
- Skipping capacity headroom. Running at high utilization leaves no room for a failure or a traffic spike.
- Scaling out before the application is stateless. Users get logged out or lose data when the load balancer sends them to a different server.
- Comparing only instance prices. Include the load balancer, data transfer, tooling, and engineering time.
Exercise
A service runs on 4 identical servers behind a load balancer. Each server can handle 100 requests per second, and peak traffic is 320 requests per second. Does the service survive the loss of one server at peak? What would you change?
Show answer
No. After losing one server, the remaining 3 can handle 300 requests per second, which is less than 320, so they would be overloaded. Add a fifth server (N+1 sizing for this peak: 4 servers needed, 1 spare), or reduce per-server load by other means such as caching.
Exercise
Name two reasons why a single very large server can be less available than a fleet of smaller ones, even if the large server's hardware is more reliable.
Show answer
Any failure or maintenance restart takes the whole service down, since there is no other server to take over. Resizing the machine to scale further also usually requires a restart. A fleet can lose or replace individual servers while the others keep serving traffic.