Sub topic 2
Spreading Traffic Across Availability Zones
Assume you know AWS Regions, VPC subnets, security groups, and basic AWS CLI usage. This chapter focuses on the web and database tiers of a multi-AZ workload.
Spreading traffic with load balancers
An Application Load Balancer (ALB) uses a node in each enabled Availability Zone (AZ). It sends requests only to healthy targets, such as EC2 instances in private subnets. For ALB, cross-zone load balancing is always enabled. The load balancer can therefore send a request received in one AZ to a healthy target in another AZ.
Network Load Balancers (NLBs) have different defaults. Cross-zone load balancing is disabled by default, so enable it when your target distribution requires it.
aws elbv2 modify-target-group-attributes \
--target-group-arn "$TARGET_GROUP_ARN" \
--attributes Key=load_balancing.cross_zone.enabled,Value=trueKeeping the application tier stateless
A stateless application does not require a particular instance to remember a user's session. Store sessions in a shared service such as ElastiCache or DynamoDB. Store uploaded files in S3 or another shared storage service. Then any healthy instance can handle the next request.
This design lets the load balancer remove failed instances without losing application state.
Auto Scaling groups across AZs
An Auto Scaling group (ASG) should use subnets in at least two AZs. Set its minimum capacity high enough that losing one AZ still leaves useful service capacity. Attach the target group and use load balancer health checks so unhealthy instances are replaced.
A two-AZ group with desired capacity four might place two instances in each AZ. During an AZ failure, the remaining instances must have enough capacity for the required workload.
Highly available databases
RDS Multi-AZ maintains a synchronous standby in another AZ and performs managed failover. The standby is for availability, not read scaling. Aurora uses a distributed storage layer across AZs and can provide faster reader and writer failover for suitable workloads.
Choose RDS Multi-AZ for a familiar engine with managed standby failover. Choose Aurora when its cluster model, scaling options, and cost fit the workload. Test connection recovery because failover changes the database endpoint's active target.
Exercise
Why should an ASG and its load balancer use more than one AZ?
Show answer
Losing one AZ can remove its instances and load balancer capacity. Other AZs can continue serving traffic and replace capacity.