Multi-AZ Patterns for Stateful Services
Apply Multi-AZ to RDS, ElastiCache, EFS, and ELB to eliminate single points of failure within a Region.
Multi-AZ Patterns for Stateful Services is a free AWS Solutions Architect lesson on CoddyKit — lesson 2 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Why Stateful Services Need Multi-AZ
Stateful services — databases, caches, file systems — are the hardest components to make highly available because they hold data that must survive failures. If a single-AZ database fails, your entire application loses its data store. AWS's answer is Multi-AZ deployments, where the service maintains a synchronous or near-synchronous replica in a second Availability Zone that can take over rapidly when the primary fails.
RDS Multi-AZ: Synchronous Standby
RDS Multi-AZ maintains a synchronous standby replica in a different AZ. Every write to the primary is synchronously replicated before acknowledging success — this means zero data loss (RPO=0) but a slight write latency increase. When the primary fails, RDS automatically updates the DNS endpoint to point to the standby in 60-120 seconds. Your application only needs to reconnect to the same endpoint — no code changes required.
# Enable Multi-AZ on existing RDS instance
aws rds modify-db-instance \
--db-instance-identifier mydb \
--multi-az \
--apply-immediately
# RDS endpoint stays the same after failover
# Application reconnects to same DNS nameAurora Multi-AZ Architecture
Amazon Aurora takes Multi-AZ further with a shared distributed storage layer that automatically replicates data across three AZs in six copies. Aurora instances are stateless — they read and write to this shared storage. When the primary Aurora writer fails, a read replica in another AZ is promoted to writer in under 30 seconds. This is faster than RDS Multi-AZ failover and the data is always consistent across AZs without explicit standby replication.
# Aurora cluster endpoint automatically handles failover
# Writer endpoint: mydb.cluster-xxx.us-east-1.rds.amazonaws.com
# Reader endpoint: mydb.cluster-ro-xxx.us-east-1.rds.amazonaws.com
# Failover time: typically under 30 secondsElastiCache Multi-AZ Replication
ElastiCache for Redis supports Multi-AZ through replication groups. A primary node accepts writes and asynchronously replicates to read replicas in other AZs. When the primary fails, ElastiCache automatically promotes a replica to primary. For Redis cluster mode enabled, data is sharded across multiple node groups each with their own primary and replicas across AZs — this provides both HA and horizontal scaling.
# Create Redis replication group with Multi-AZ
aws elasticache create-replication-group \
--replication-group-id my-redis \
--replication-group-description 'Multi-AZ Redis' \
--num-cache-clusters 3 \
--cache-node-type cache.r6g.large \
--multi-az-enabled \
--automatic-failover-enabledEFS: Inherently Multi-AZ
Amazon Elastic File System (EFS) is inherently Multi-AZ — it is a regional service that stores data redundantly across multiple AZs within a region. You create mount targets in each AZ's subnet, and EC2 instances in any AZ can mount the file system through their local mount target. There is no manual Multi-AZ configuration required. EFS provides shared POSIX file storage that multiple instances across AZs access simultaneously.
# Mount EFS from EC2 in any AZ
# Mount target is created per AZ automatically
sudo mount -t efs -o tls fs-12345678:/ /mnt/efs
# Or use EFS mount helper
sudo mount -t efs fs-12345678 /mnt/efsElastic Load Balancer Cross-Zone
Elastic Load Balancers are themselves Multi-AZ — ALB and NLB deploy load balancer nodes in each AZ you specify. With cross-zone load balancing enabled (the default for ALB), each load balancer node distributes traffic evenly across all registered targets in all AZs, not just its own AZ. This ensures that even if all instances in one AZ fail, the load balancer continues serving traffic through instances in the remaining AZs.
# ALB automatically created in multiple AZs
aws elbv2 create-load-balancer \
--name my-alb \
--subnets subnet-AZ1 subnet-AZ2 subnet-AZ3 \
--security-groups sg-12345
# Cross-zone load balancing is ON by default for ALBNAT Gateway Multi-AZ Pattern
A common mistake is deploying a single NAT Gateway in one AZ while private subnets in other AZs route through it. If that AZ fails, all private instances lose internet access. The correct Multi-AZ pattern is to deploy one NAT Gateway per AZ and configure each AZ's private route table to route 0.0.0.0/0 through its own NAT Gateway. This eliminates the NAT Gateway as a cross-AZ SPOF and reduces cross-AZ data transfer costs.
# Create NAT Gateway in each AZ
aws ec2 create-nat-gateway \
--subnet-id subnet-public-AZ1 \
--allocation-id eipalloc-AZ1
aws ec2 create-nat-gateway \
--subnet-id subnet-public-AZ2 \
--allocation-id eipalloc-AZ2
# Each AZ's private route table points to its own NAT GWDynamoDB Multi-AZ by Default
DynamoDB is a fully managed service that automatically replicates data across three AZs within a region — you do not configure Multi-AZ manually. Every write is durably stored across all three AZs before success is returned. DynamoDB is effectively fault-tolerant at the AZ level out of the box. This is why DynamoDB is often the recommended database choice when the exam question emphasises high availability with minimal operational overhead.
RDS Proxy for Faster Connection Handling
During an RDS Multi-AZ failover, applications that maintain persistent database connections may experience failures as the endpoint changes. RDS Proxy sits between your application and RDS, maintaining a pool of connections to the database. During failover, RDS Proxy automatically reroutes to the new primary — reducing failover impact from 60-120 seconds to under 30 seconds for applications using the proxy endpoint. RDS Proxy also helps with Lambda functions that create many short-lived connections.
# Application connects to RDS Proxy endpoint
# Proxy endpoint: myproxy.proxy-xxx.us-east-1.rds.amazonaws.com
# RDS Proxy handles:
# - Connection pooling
# - Failover routing
# - IAM authentication
# - Secrets Manager integrationData Replication Modes: Sync vs Async
Understanding replication modes is critical for choosing Multi-AZ patterns. Synchronous replication (RDS Multi-AZ, EFS) ensures RPO=0 because every write is confirmed in both AZs before success. The trade-off is slightly higher write latency. Asynchronous replication (ElastiCache Redis replicas, RDS Read Replicas) offers lower write latency but accepts a small replication lag — meaning some data could be lost if the primary fails before replication completes.
# Synchronous replication: RPO = 0, higher write latency
# Used by: RDS Multi-AZ, Aurora storage layer
# Asynchronous replication: RPO > 0 (replication lag)
# Used by: RDS Read Replicas, ElastiCache Redis replicas
# Replication lag can be monitored:
# aws cloudwatch get-metric-statistics \
# --namespace AWS/RDS --metric-name ReplicaLagTesting Multi-AZ Failover
You should regularly test Multi-AZ failover to validate your RTO assumptions. For RDS, you can trigger a failover using the console's Reboot with failover option or the CLI. Monitor CloudWatch for the FailedSQLServerAgentJobsCount metric and watch your application logs to verify it reconnects successfully. Document the actual failover duration — it may differ from AWS documentation depending on your instance class and workload.
# Trigger RDS Multi-AZ failover test
aws rds reboot-db-instance \
--db-instance-identifier mydb \
--force-failover
# Monitor failover in CloudWatch
aws cloudwatch get-metric-statistics \
--namespace AWS/RDS \
--metric-name DatabaseConnections \
--dimensions Name=DBInstanceIdentifier,Value=mydbQuick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you learned: RDS Multi-AZ uses synchronous replication with automatic DNS failover, Aurora uses a shared storage layer across three AZs for faster failover, and EFS and DynamoDB are inherently Multi-AZ without manual configuration. Deploy one NAT Gateway per AZ to avoid cross-AZ SPOFs. Next up we explore multi-region active-active and active-passive patterns.
Frequently asked questions
Is the “Multi-AZ Patterns for Stateful Services” lesson free?
Yes — the full text of “Multi-AZ Patterns for Stateful Services” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “Multi-AZ Patterns for Stateful Services”?
Apply Multi-AZ to RDS, ElastiCache, EFS, and ELB to eliminate single points of failure within a Region. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 2 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Multi-AZ Patterns for Stateful Services” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- HA vs Fault Tolerance: Definitions and Trade-offs
- Multi-AZ Patterns for Stateful Services
- Multi-Region Active-Active and Active-Passive
- Health Checks, Circuit Breakers, and Retry Logic