Sub topic 13
Capacity planning and surviving the loss of a region
This chapter assumes you know how global routing and health-based failover work, and that you understand availability and latency as service goals. Active-active only protects you if the surviving regions can carry the load of a failed one. Capacity planning is how you make sure they can.
Why headroom matters
When a region fails, its traffic moves to the others. If every region runs near full capacity, the failover overloads them and the outage spreads. This is a cascading failure.
Each region needs spare capacity, called headroom. How much depends on the number of regions, N, and how many failures you want to survive.
Sizing for N-1
The usual target is N-1: the system carries full peak traffic with one region lost. Suppose peak traffic is 100 units and load is split evenly. Each region must handle its own share plus its share of the lost region's traffic.
| Regions (N) | Normal load per region | Load after one loss | Max utilization in normal operation |
|---|---|---|---|
| 2 | 50 | 100 | 50% |
| 3 | 33.3 | 50 | 66.7% |
| 4 | 25 | 33.3 | 75% |
| 5 | 20 | 25 | 80% |
The maximum safe utilization is (N-1)/N. More regions lower the overhead, but each added region adds cost and complexity. Two regions mean 100% spare capacity, because each region must be able to carry everything alone.
def required_capacity_per_region(peak_load, regions, failures=1):
"""Capacity each region needs to survive `failures` lost regions."""
survivors = regions - failures
if survivors < 1:
raise ValueError("no regions would survive")
return peak_load / survivors
for n in (2, 3, 4, 5):
cap = required_capacity_per_region(100, n)
print(f"{n} regions: provision {cap:.1f} per region, "
f"normal utilization {100 / n / cap:.0%}")Uneven traffic
Traffic is rarely split evenly. A region near a large user base may carry 50% of the load. Size for the worst case: the loss of your busiest region, with its traffic landing on the remaining ones. Also check the time of day. Regions peak at different hours, and a failure at one region's peak can coincide with another's busy period.
Beyond compute
Compute is the easy part to scale. Check each dependency in the failover path:
- Databases. Surviving regions take more writes and reads. Replication traffic and connection counts also change.
- Quotas and limits. Cloud service quotas are set per region. Request raises ahead of time, because they may not be granted during an incident.
- Autoscaling speed. Scaling out takes minutes. Traffic arrives in seconds. Pre-provisioned headroom covers the gap that autoscaling cannot.
- Caches. Users moving to a new region meet cold caches, which sends extra load to the database.
- Downstream services. Third-party APIs and shared services may have rate limits that your combined traffic now exceeds.
Protecting the survivors
Plan to degrade gracefully if load still exceeds capacity:
- Use load shedding: reject low-priority requests, with a clear error, rather than slowing everything down.
- Turn off non-essential features, such as recommendations or analytics.
- Apply rate limits per client, so one noisy caller cannot consume the headroom.
- Use gradual traffic shifts where your routing allows it, so load rises in steps and not all at once.
Verify with tests
Capacity numbers on paper are estimates. Run a load test with one region removed from routing and confirm latency and error rates stay within your targets. Repeat the test whenever traffic grows or the architecture changes.
Exercise
You run four regions with evenly split traffic and a peak of 200 units. Each region is provisioned for 80 units. Can the system survive the loss of one region? What utilization would each survivor reach?
Show answer
No. After one loss, 200 units are split across 3 regions, about 66.7 units each, which is 83% of the 80-unit capacity. That is under 100%, so the system does survive on paper. It leaves only 17% margin, so you should add headroom for uneven traffic and test it. The N-1 minimum is 66.7 units per region.