Understanding Cross-Zone Load Balancing in AWS
Cross-Zone Load Balancing is a feature in AWS Elastic Load Balancing (ELB) that ensures even distribution of traffic across EC2 instances, regardless of their Availability Zones (AZs). This article explains how it works, when to enable or disable it, and the cost implications for different load balancer types.
How Cross-Zone Load Balancing Works
Let's consider an example with two Availability Zones (AZs):
- AZ1 has a load balancer (ALB instance) managing two EC2 instances.
- AZ2 has another ALB instance, but it manages eight EC2 instances.
- Both ALB instances are part of the same general load balancer.
With Cross-Zone Load Balancing Enabled
- Traffic is distributed evenly across all EC2 instances, regardless of which AZ they belong to.
- Each ALB instance receives 50% of the traffic from clients.
- Each ALB instance then forwards 10% of its traffic to each of the 10 EC2 instances (since there are 10 instances total).
- This ensures even load distribution, preventing one AZ from being overloaded.
Without Cross-Zone Load Balancing
- Each ALB instance only distributes traffic within its AZ.
- The client sends 50% of the traffic to each ALB instance.
- The ALB in AZ1 distributes traffic only to its 2 EC2 instances, causing them to handle 25% of total traffic each.
- The ALB in AZ2 distributes traffic only to its 8 EC2 instances, each getting 6.25% of total traffic.
- This can result in an uneven distribution if AZs have an imbalanced number of EC2 instances.