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 Availability Zones and Regions, and how a multi-tier application is deployed. It covers the Reliability pillar: what it asks of you, the design principles behind it, and the errors teams most often make.
What the pillar asks for
The Reliability pillar is the ability of a workload to perform its intended function correctly and consistently, and to recover quickly from failure. Two ideas sit in that definition:
- Recovering from failure. Components fail. Disks die, deployments go wrong, a dependency times out. A reliable workload expects this and returns to normal operation without long manual effort.
- Meeting demand. Load changes by hour, by season, and by accident (a viral link, a retry storm). A reliable workload adds and removes capacity to match it.
The framework groups its questions into four areas: foundations, workload architecture, change management, and failure management.
Design principles
| Principle | What it means in practice |
|---|---|
| Automatically recover from failure | Monitor business-level indicators, not only CPU, and trigger automated recovery when they cross a threshold. |
| Test recovery procedures | Rehearse failure on purpose, for example with fault injection, instead of assuming the runbook works. |
| Scale horizontally | Replace one large resource with several small ones so one failure affects a smaller share of requests. |
| Stop guessing capacity | Use Auto Scaling and managed services to follow demand instead of sizing for a forecast. |
| Manage change through automation | Deploy and configure with infrastructure as code so changes are repeatable and reversible. |
Foundations: limits and network
Reliability starts before you write application code.
Service quotas. Every account has quotas, such as vCPUs per Region or API request rates. A scale-out event that hits a quota fails exactly when you need it. Track quotas, request increases before launches, and remember that a failover Region needs headroom too. A common error is raising quotas in the primary Region only, then finding the recovery Region cannot hold the workload.
Network topology. Place workloads across at least two Availability Zones (AZs). An AZ is one or more discrete data centers with independent power and networking inside a Region. Use private subnets for application tiers, and make sure IP ranges do not overlap with networks you will connect later through VPC peering or Transit Gateway. Overlapping CIDR ranges are expensive to fix after the fact.
Workload architecture
Choose a service-oriented design
Break the system into components with clear contracts. Smaller services limit the blast radius, the portion of the workload affected when something breaks. Each service should own its data and expose it through an API, so a failure in one does not corrupt another.
Design interactions to prevent failure
Distributed systems fail in partial ways, so the interactions between components matter as much as the components. Four techniques recur:
- Timeouts. Every remote call needs one. A call with no timeout holds a thread or connection until something else breaks.
- Retries with exponential backoff and jitter. Retrying immediately, in lockstep, multiplies load on a dependency that is already struggling. Backoff spaces retries out, and jitter randomizes them so clients do not synchronize.
- Idempotency. An operation is idempotent if repeating it has the same effect as doing it once. Retries are only safe when the operation is idempotent, or when you attach an idempotency token so the server can discard duplicates.
- Graceful degradation. When a non-critical dependency fails, return reduced functionality (for example, product pages without recommendations) instead of an error.
The following Python function shows a retry loop with capped exponential backoff and full jitter. It treats only the listed exceptions as retryable.
import random
import time
class TransientError(Exception):
"""Raised for failures worth retrying, such as timeouts or throttling."""
def call_with_retries(operation, max_attempts=5, base_delay=0.2, max_delay=5.0):
for attempt in range(1, max_attempts + 1):
try:
return operation()
except TransientError:
if attempt == max_attempts:
raise
# Full jitter: wait a random time up to the capped exponential delay.
ceiling = min(max_delay, base_delay * (2 ** attempt))
time.sleep(random.uniform(0, ceiling))
if __name__ == "__main__":
calls = {"count": 0}
def flaky():
calls["count"] += 1
if calls["count"] < 3:
raise TransientError("temporary failure")
return "ok"
print(call_with_retries(flaky), "after", calls["count"], "calls")Meeting demand
Horizontal scaling needs stateless application servers. Keep session data in a shared store such as ElastiCache or DynamoDB, not on the instance disk, so any instance can serve any request and instances can be replaced freely.
An Application Load Balancer spreads traffic across targets in several AZs and removes targets that fail health checks. An Auto Scaling group adds and removes instances based on a metric or a schedule. Two settings are often wrong:
- Health check depth. A check that only confirms the port is open will keep sending traffic to an instance whose application is broken. A check that tests a database connection can cause the opposite problem: when the database is down, every instance fails its check and the load balancer has nowhere to send traffic. Make health checks verify the instance itself, and handle dependency failures with graceful degradation.
- Scaling lag. New instances take time to boot and warm up. Scale on a metric that moves before users are hurt, and keep a minimum capacity that survives the loss of one AZ.
When a spike arrives faster than scaling can react, put a queue (Amazon SQS) between the caller and the worker. The queue absorbs the burst and workers drain it at their own pace. This also protects the downstream database.
Change management and failure management
Monitor the workload so that you learn about failure from an alarm, not a customer. Amazon CloudWatch alarms can trigger Auto Scaling actions or EC2 recovery. Deploy changes with automation, and use strategies that limit exposure, such as blue/green or canary deployments with an automatic rollback.
For failure management, back up data, and test that you can restore it. A backup that has never been restored is an assumption, not a recovery plan. AWS Backup can manage backup policies across services.
Recovery objectives and disaster recovery
Two numbers define how you plan for disaster:
- Recovery Time Objective (RTO): the longest acceptable time between an outage and restored service.
- Recovery Point Objective (RPO): the longest acceptable span of data loss, measured back from the outage.
The business sets these targets. Engineers then choose a strategy that meets them, accepting more cost for tighter objectives.
| Strategy | Approach | Typical RTO / RPO | Relative cost |
|---|---|---|---|
| Backup and restore | Copy data to another Region, rebuild on demand | Hours | Lowest |
| Pilot light | Replicate data, keep core infrastructure switched off or minimal | Tens of minutes | Low |
| Warm standby | Run a scaled-down full copy | Minutes | Medium |
| Multi-site active/active | Serve traffic from several Regions at once | Near zero | Highest |
Common errors
- Treating Multi-AZ as disaster recovery. Multi-AZ protects against the loss of one AZ. It does not protect against a bad deployment, data corruption, or a Regional event.
- Untested failover. A failover path that is never exercised usually fails because of configuration drift, expired credentials, or exhausted quotas in the target.
- Hidden single points of failure. One NAT gateway, one DNS provider, one shared license server, or one NFS mount can undo an otherwise redundant design.
- Unbounded queues and retries. A queue that grows without limit, or retries without a cap, turns a short outage into a long one.
- Dependencies with weaker availability than the workload. If you promise 99.99% but depend hard on a component rated 99.9%, your promise is unreachable. Make that dependency soft, with a fallback.
Reviewing this pillar
In the Well-Architected Tool, answer the Reliability questions with the best practices your workload follows. Unanswered or unmet practices produce high or medium risk items. You can list those answers from the CLI, using the pillar ID reliability:
aws wellarchitected list-answers \
--workload-id <workload-id> \
--lens-alias wellarchitected \
--pillar-id reliabilityReliability also trades against other pillars. Extra AZs, standby Regions and over-provisioned minimum capacity cost money, which later chapters cover under Cost Optimization and trade-offs.
Exercise
A team runs a web application in one Region across two AZs behind an Application Load Balancer. The business requires an RTO of 15 minutes and an RPO of 5 minutes if the entire Region is lost. The team says Multi-AZ already covers this. Is that correct, and which disaster recovery strategy from this chapter would you start with?
Show answer
It is not correct. Multi-AZ protects against the loss of an AZ, not a whole Region. A Region-level target needs data in a second Region and infrastructure ready to take traffic. Backup and restore usually cannot meet a 15-minute RTO. Start with warm standby, which keeps a scaled-down full copy running with continuously replicated data (so the 5-minute RPO is feasible) and can scale up and take traffic within minutes. Pilot light is a cheaper option only if testing shows it can start and scale within 15 minutes.
Exercise
Your Auto Scaling group's load balancer health check calls an endpoint that queries the database. The database has a short outage. What happens, and how would you change the design?
Show answer
Every instance fails the health check at once, so the load balancer treats all targets as unhealthy and cannot serve even the requests that do not need the database. Change the health check to verify only the instance and application process, and let the application degrade gracefully (for example, serve cached or read-only content) when the database is unreachable. Monitor the database dependency separately with alarms.