- Newest
- Most votes
- Most comments
Yes, your understanding is correct. if an EC2 instance in AZ1 resolves the internal ALB DNS name and gets back the AZ2 IP first, the traffic will cross AZs and you will incur cross-AZ data transfer charges ($0.01/GB in each direction).
In order to minimize this you can configure Client-side DNS caching. Since, the ALB DNS name returns IPs for all enabled AZs. Many DNS resolvers and HTTP clients will round-robin or return them in arbitrary order. If your client respects DNS TTLs and caches the resolved IP, it may continue sending to an AZ2 IP even after TTL expiry.
Also, AWS supports zonal DNS names for ALBs (e.g., <az>.elb.amazonaws.com). Using the zonal DNS name ensures your client always gets the IP in the specific AZ. This is another recommended approach for AZ-affinity and cross-AZ cost optimization for ALB.
When an EC2 instance in one Availability Zone connects to an Application Load Balancer (ALB) node in a different Availability Zone, cross-AZ data transfer charges do apply. Specifically, a charge of $0.01 per GB applies for both incoming and outgoing traffic between the client and the load balancer when they are in different AZs.
To minimize cross-AZ traffic and associated charges, you can disable cross-zone load balancing on your ALB. When cross-zone load balancing is disabled, the ALB will send traffic to an ALB Elastic Network Interface (ENI) in the same AZ as the target endpoint. This helps keep traffic within the same Availability Zone and reduces the frequency of cross-AZ data transfers.
However, it's important to note that DNS resolution itself may still return IP addresses from different AZs. To further optimize for AZ affinity, you could implement application-level logic where your applications decide which server or resource to connect to within the same AZ, helping to keep traffic local and minimize cross-AZ charges.
Additionally, regularly reviewing your network traffic patterns and monitoring data transfer charges can help you identify opportunities to adjust resource placement and routing strategies to optimize both performance and costs in your multi-AZ architecture.
Sources
Exploring Data Transfer Costs for AWS Network Load Balancers | Networking & Content Delivery
Community | Optimizing Performance and Cost with Multi-AZ Architecture: Guidelines for Multi-Account Environments
Relevant content
- asked 2 years ago
- asked 6 months ago
