Sub topic 12
Static stability: pre-provisioned capacity for AZ loss
This chapter assumes you have read the earlier chapters on subnets across Availability Zones (AZs), load balancing, Auto Scaling groups (ASGs), and RDS Multi-AZ. You should know what a health check is and how an ASG uses a launch template.
What static stability means
A system is statically stable if it keeps working during a failure without making changes. It does not need to launch instances, edit DNS records, or attach addresses at the moment something breaks. It already has the capacity and routing it needs.
The idea comes from a split between two kinds of AWS operations:
- The control plane creates, changes, and deletes resources. Examples are
RunInstances,CreateNatGateway, andChangeResourceRecordSets. - The data plane does the work of running resources. Examples are packets flowing through a NAT gateway, an instance serving requests, and a load balancer routing to healthy targets.
Data planes are simpler and are built to be more available than control planes. During an AZ impairment, many customers react at once. They launch replacements, and the control plane and the EC2 capacity pools in the surviving AZs come under heavy load. A design that needs those calls to succeed in order to recover is betting on the part of the system most likely to be strained.
A statically stable design avoids that bet. It runs enough capacity in each AZ ahead of time that losing one AZ only shifts traffic. Recovery is a data-plane event: the load balancer stops sending to failed targets.
Sizing headroom for N zones
Suppose peak load needs P instances and you spread across N AZs. If one AZ is lost, the remaining N-1 AZs must carry P together, so each needs P/(N-1) instances. Total provisioned capacity is N × P/(N-1).
| AZs (N) | Instances per AZ after loss | Total provisioned | Extra capacity over P |
|---|---|---|---|
| 2 | P | 2P | 100% |
| 3 | P/2 | 1.5P | 50% |
| 4 | P/3 | 1.33P | 33% |
More AZs lower the cost of headroom. Three AZs is the usual balance between cost and resilience. This is one place where the cost trade-offs chapter applies directly.
Here is a small helper that computes the numbers, rounding up so you never undersize:
import math
def instances_per_az(peak_instances: int, az_count: int, survive_losses: int = 1) -> int:
"""Instances to run in each AZ so peak load survives losing `survive_losses` AZs."""
if az_count - survive_losses < 1:
raise ValueError("Not enough AZs left to carry the load")
return math.ceil(peak_instances / (az_count - survive_losses))
peak = 12
for n in (2, 3, 4):
per_az = instances_per_az(peak, n)
print(f"{n} AZs: {per_az} per AZ, {per_az * n} total")For a peak of 12 instances this prints 12 per AZ (24 total) for two AZs, 6 per AZ (18 total) for three, and 4 per AZ (16 total) for four.
Putting headroom into the Auto Scaling group
The ASG's MinSize is where static stability lives. If MinSize equals the post-failure requirement, the group holds that capacity at all times, even when traffic is low. Scaling policies then add instances above that floor.
Resources:
WebAsg:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MinSize: "18"
MaxSize: "36"
DesiredCapacity: "18"
VPCZoneIdentifier:
- !Ref PrivateSubnetA
- !Ref PrivateSubnetB
- !Ref PrivateSubnetC
LaunchTemplate:
LaunchTemplateId: !Ref WebLaunchTemplate
Version: !GetAtt WebLaunchTemplate.LatestVersionNumber
TargetGroupARNs:
- !Ref WebTargetGroup
HealthCheckType: ELB
HealthCheckGracePeriod: 120With 18 instances over three AZs, each AZ holds 6. If one AZ goes away, 12 remain, which matches the peak of 12 from the example above.
Be careful about what the floor represents. A group sized only for average load, say MinSize: 6, would depend on scale-out to survive an AZ loss. That scale-out is a series of RunInstances calls made during the event.
Two ASG behaviors matter here:
- When an AZ becomes unhealthy, the ASG launches replacements in the remaining AZs. This is useful, but treat it as a bonus on top of the pre-provisioned floor, not as the plan.
- When the AZ recovers, the ASG rebalances back across zones. This can briefly launch instances before terminating others, so give
MaxSizesome room above your normal peak.
Other things that must be ready in advance
Compute is the obvious case. Several other parts of the stack follow the same rule.
- NAT gateways. Run one per AZ, and route each private subnet to the NAT gateway in its own AZ. If all subnets share a single NAT gateway in one AZ, losing that AZ cuts off egress everywhere. Creating a new gateway and rewriting route tables during the event is a control-plane recovery.
- Load balancer. Enable subnets in every AZ that holds targets. Pre-registered targets and health checks let the load balancer stop using a failed AZ without any API call from you. With NLB, cross-zone load balancing is off by default, so each load balancer node sends only to targets in its own AZ. Decide deliberately whether to enable it.
- Databases. An RDS Multi-AZ standby or an Aurora replica in another AZ already exists and is already replicating. Promotion is automatic, so recovery does not involve creating a new instance. A design that plans to restore from a snapshot in another AZ is not statically stable.
- DNS. Use health-check-driven routing so Route 53 stops returning an unhealthy endpoint on its own. A runbook step that says "edit the record" depends on the control plane.
- Addresses and configuration. Avoid recovery steps such as remapping an Elastic IP to a new instance. Put the instances behind a load balancer instead, so no address needs to move.
- Quotas. Headroom is only real if you can use it. Check that your EC2 instance quotas allow the full
MaxSize, and that subnets have enough free IP addresses for the floor plus a rebalance.
Whether the extra capacity is truly available depends on the instance type. If a type is scarce in a Region, the capacity you already run is worth more than capacity you hope to launch. For critical workloads, On-Demand Capacity Reservations can guarantee that an AZ has room for your instances. Without them, nothing guarantees a later launch will succeed.
Where manual action still fits
Static stability removes the need for a recovery action, but it does not forbid actions. AWS offers zonal shift in Amazon Application Recovery Controller, which moves load balancer traffic away from one AZ. Starting a shift is something you do, so it is a deliberate operator step. It works best on top of a statically stable design. The surviving AZs must already hold the headroom, or the shift only moves the overload somewhere else.
You can also check the current layout of an ASG from the CLI to confirm headroom is spread evenly:
aws autoscaling describe-auto-scaling-groups \
--auto-scaling-group-names web-asg \
--query 'AutoScalingGroups[0].Instances[].[AvailabilityZone,LifecycleState,HealthStatus]' \
--output tableCount the InService instances per AZ. If one AZ holds far more than the others, losing it breaks the plan, even though the total looks correct.
Common errors
- Sizing on totals alone. 18 instances total means nothing if 10 of them sit in one AZ. Check the per-AZ count.
- Forgetting dependencies. The application tier survives, but it calls a single-AZ cache, a single NAT gateway, or a single-instance license server. Look back at the failure-domains chapter and trace every call path.
- Assuming cross-zone hides imbalance. With cross-zone off, an AZ with fewer targets takes the same share of traffic as the others, so its instances run hotter. With it on, the share follows target count.
- Headroom that is not exercised. Capacity you never test may fail for reasons such as a stale launch template, an exhausted quota, or a full subnet. The next chapters cover observing and testing.
- Too-short grace periods. A
HealthCheckGracePeriodshorter than boot time makes the ASG replace instances that are still starting, which compounds the failure.
Exercise
A workload needs 20 instances at peak and runs across three AZs. It must stay within capacity if one AZ is lost, using only the instances already running. How many instances should run in each AZ, what should the ASG MinSize be, and why is a MinSize of 10 insufficient?
Show answer
After losing one AZ, two AZs must carry 20 instances, so each needs 10. Three AZs at 10 each gives a MinSize of 30. A MinSize of 10 is sized for average load and would rely on scale-out to launch replacement capacity during the failure. Those launches are control-plane calls competing with other customers for capacity in the surviving AZs, so recovery would not be guaranteed.
Exercise
Your private subnets in three AZs all route 0.0.0.0/0 to one NAT gateway in AZ A. Is the design statically stable for the loss of AZ A, and what change fixes it?
Show answer
No. When AZ A fails, instances in AZs B and C lose outbound access, and restoring it requires creating a gateway and editing routes during the event. Create one NAT gateway in each AZ and point each AZ's private route table at the gateway in the same AZ.