Sub topic 5
Reliability: recovering from failure and meeting demand
This chapter assumes you know core AWS services (EC2, S3, VPC, IAM), the idea of a Region and an Availability Zone (AZ), and the shared responsibility model from earlier chapters.
What the pillar asks of you
The Reliability pillar is about a workload doing its intended job correctly and consistently. It covers two things: recovering from failure, and meeting demand as it changes.
Under the shared responsibility model, AWS is responsible for the resilience of the cloud, meaning the data centers, networks and managed service internals. You are responsible for resilience in the cloud. That means how many AZs you use, how you back up data, and how your application behaves when a dependency fails.
Design principles
- Automatically recover from failure. Monitor key indicators and trigger recovery when a threshold is crossed.
- Test recovery procedures. Simulate failures, because an untested runbook often fails when you need it.
- Scale horizontally. Several small resources reduce the impact of losing any one of them.
- Stop guessing capacity. Use automatic scaling instead of a fixed estimate.
- Manage change through automation. Make infrastructure changes with code that can be reviewed and rolled back.
Foundations: quotas and networking
Before designing for failure, check your service quotas. A scaling plan fails if you hit the EC2 instance limit during a spike. Plan IP address space for your VPC and subnets too, since resizing later is painful.
Workload architecture
Three choices shape most of a reliable design.
- Spread across AZs. An AZ is one or more isolated data centers. Running instances in at least two AZs protects you from a single-AZ failure.
- Loosely couple components. Put a queue such as Amazon SQS between a producer and a consumer. A slow or failed consumer then doesn't take the producer down with it.
- Make requests safe to retry. Use idempotent operations, retries with exponential backoff and jitter, and timeouts. Without backoff, retries from many clients can overload a recovering service.
Meeting demand with automatic scaling
An Auto Scaling group replaces unhealthy instances and adds or removes capacity. This example keeps average CPU near 50 percent:
aws autoscaling put-scaling-policy \
--auto-scaling-group-name orders-api-asg \
--policy-name cpu-target-50 \
--policy-type TargetTrackingScaling \
--target-tracking-configuration '{
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ASGAverageCPUUtilization"
},
"TargetValue": 50.0
}'The group needs a minimum of at least two instances across two AZs for this to help with availability as well as load.
Change management and failure management
Monitor with Amazon CloudWatch and alarm on symptoms users feel, such as error rate and latency. Back up data with AWS Backup, and test restores, not just backups.
Define two recovery targets for each workload:
| Term | Meaning | Example |
|---|---|---|
| RTO (recovery time objective) | Longest acceptable time to restore service | 1 hour |
| RPO (recovery point objective) | Longest acceptable window of lost data | 5 minutes |
Disaster recovery strategies trade cost against these targets. From cheapest and slowest to most expensive and fastest: backup and restore, pilot light, warm standby, and multi-site active/active.
Common mistakes
- Running everything in one AZ because it is cheaper.
- Never testing failover or restore.
- Ignoring dependencies. If your app needs a service that is single-AZ, your availability is limited by it.
- Retrying without backoff, which can turn a small outage into a larger one.
Reliability often competes with cost, since extra capacity and standby environments cost money. The trade-offs chapter covers how to balance this.
Exercise
A workload has an RPO of 5 minutes and an RTO of 4 hours. Name the cheapest disaster recovery strategy that could plausibly meet the RTO, and say what you would need to confirm about the RPO.
Show answer
Backup and restore is the cheapest strategy and a 4-hour RTO leaves time to rebuild from backups or infrastructure code. You must confirm that backups or replication run often enough to lose at most 5 minutes of data. Daily backups would not meet that RPO, so you would add continuous replication or point-in-time recovery for the data store.
Exercise
Why does retrying failed requests immediately and without limits make an outage worse?
Show answer
Many clients retry at once, which multiplies the load on a service that is already struggling and stops it recovering. Exponential backoff with jitter spreads the retries out over time and caps the load.