Sub topic 8
Reducing inter-AZ traffic
This chapter assumes you know what Availability Zones (AZs), VPCs, and subnets are. It also assumes you have read the earlier chapters on traffic paths and finding costs in Cost Explorer. Here you will find where inter-AZ traffic comes from in a typical workload, learn which fixes are safe, and learn which ones trade away resilience.
Why inter-AZ traffic costs money
Traffic between two AZs in the same region is billed per GB. In most regions the rate is about $0.01/GB in each direction, which makes about $0.02/GB for a round trip. Always check the current price for your region. Traffic inside one AZ over private IP addresses is free.
The charge shows up in Cost Explorer under usage types that end in DataTransfer-Regional-Bytes, for example USE1-DataTransfer-Regional-Bytes. Because it is billed per direction, a chatty service pair can cost more than expected. A request of 1 KB with a response of 100 KB crosses the AZ boundary in both directions, and both directions are billed.
Inter-AZ cost is a side effect of a design choice. Spreading workloads across AZs gives you availability. The goal is to keep that availability and remove the unnecessary cross-AZ hops.
The usual sources
Inter-AZ traffic tends to come from a short list of places.
- Load balancer to targets. With cross-zone load balancing, a load balancer node in one AZ can send requests to targets in another AZ.
- Application to database. An app server that reads from a database primary or replica in another AZ pays on every query and result set.
- Database replication. Synchronous or asynchronous replication to a standby in another AZ is billed. RDS Multi-AZ replication traffic is included in the RDS price, but your own self-managed replication on EC2 is billed as regular inter-AZ traffic.
- Distributed data systems. Kafka, Elasticsearch/OpenSearch, Cassandra, and similar systems replicate data between nodes and brokers in different AZs. Consumers that read from a leader in another AZ add more traffic.
- Service-to-service calls. Microservices that call each other through a service name resolve to any healthy instance, in any AZ.
- Kubernetes. Pods that talk to a Service are routed to any matching pod by default, regardless of AZ.
Quantify each one before you change anything. The Flow Logs approach from the earlier chapter works well here, because the default flow log record format includes srcAddr and dstAddr, which you can map to subnets and therefore to AZs.
Confirm that cross-AZ traffic is the problem
Start with the bill. This command lists last month's cost for regional (inter-AZ) data transfer usage types.
aws ce get-cost-and-usage \
--time-period Start=2026-10-01,End=2026-11-01 \
--granularity MONTHLY \
--metrics UnblendedCost UsageQuantity \
--group-by Type=DIMENSION,Key=USAGE_TYPE \
--query "ResultsByTime[].Groups[?contains(Keys[0], 'DataTransfer-Regional-Bytes')].[Keys[0], Metrics.UnblendedCost.Amount, Metrics.UsageQuantity.Amount]" \
--output textIf this number is small relative to your total bill, stop. The engineering time to re-architect may cost more than the savings. If it is a meaningful share, move on to finding which flows produce it.
For attribution, query Flow Logs for the largest address pairs and match them to your subnet CIDR ranges.
stats sum(bytes) as bytesTransferred by srcAddr, dstAddr
| sort bytesTransferred desc
| limit 10For each pair, look up the subnets that contain the two addresses and compare their AZs. Pairs whose two addresses are in different AZs are your inter-AZ flows. Flow Logs also support a az-id field in newer custom formats, which removes the manual lookup. Add it to a custom format if your account supports it.
Fix 1: Keep application-to-database traffic local where you can
For read-heavy workloads, place read replicas in each AZ that runs application servers, and have each server read from the replica in its own AZ. Writes still go to the primary, so the saving applies only to reads.
With Amazon Aurora, the reader endpoint balances across all readers without regard to AZ. To keep reads local, connect to an instance endpoint in the same AZ as the client, or use a driver that supports AZ-aware routing. The AWS Advanced JDBC Wrapper supports this kind of reader selection.
The trade-off is operational. Instance endpoints bypass automatic failover for readers. If the local reader fails, your application must fall back to another endpoint. Build that fallback in, and test it.
Fix 2: Control cross-zone load balancing
Cross-zone load balancing spreads requests evenly across all targets in all enabled AZs. This keeps load even when your targets are unevenly distributed, but it adds inter-AZ traffic. The defaults differ by load balancer type.
| Load balancer | Cross-zone default | Inter-AZ data charge when enabled |
|---|---|---|
| Application Load Balancer | On, cannot be turned off at the load balancer level | Not charged for the ALB's own cross-zone distribution |
| Network Load Balancer | Off | Charged as regular inter-AZ transfer |
| Gateway Load Balancer | Off | Charged as regular inter-AZ transfer |
The ALB row is a trap. The ALB does not bill its own cross-zone distribution, but the application behind it still pays if it then calls other services across AZs. Do not assume that the ALB hop is the only cross-AZ cost on a request path.
For an NLB, leave cross-zone off when your targets are spread evenly across AZs. If one AZ has fewer targets, those targets receive a larger share of traffic and can overload. Keep target counts balanced per AZ before turning cross-zone off.
You can check and set the attribute from the CLI.
aws elbv2 describe-load-balancer-attributes \
--load-balancer-arn "$NLB_ARN" \
--query "Attributes[?Key=='load_balancing.cross_zone.enabled']"
aws elbv2 modify-load-balancer-attributes \
--load-balancer-arn "$NLB_ARN" \
--attributes Key=load_balancing.cross_zone.enabled,Value=falseSet NLB_ARN to your load balancer's ARN before you run these.
Fix 3: Make service calls zone-aware
Service meshes and orchestrators can prefer endpoints in the caller's own AZ.
- Kubernetes (EKS). Topology Aware Routing, enabled with the annotation
service.kubernetes.io/topology-mode: Autoon a Service, asks kube-proxy to prefer endpoints in the same zone. It only applies when endpoints are spread proportionally across zones. If they are not, Kubernetes falls back to cluster-wide routing to avoid overload. - Service meshes. Envoy-based meshes such as Istio and AWS App Mesh support locality-weighted load balancing. They prefer local endpoints and fail over to other zones when local endpoints are unhealthy.
- Kafka. Setting
client.rackon consumers enables fetching from a follower replica in the same AZ (KIP-392). The brokers must also setreplica.selector.classtoorg.apache.kafka.common.replica.RackAwareReplicaSelector, and each broker needsbroker.rackset to its AZ. Amazon MSK supports this.
A Kubernetes example follows.
apiVersion: v1
kind: Service
metadata:
name: orders
annotations:
service.kubernetes.io/topology-mode: Auto
spec:
selector:
app: orders
ports:
- port: 80
targetPort: 8080Fix 4: Stay in one AZ, deliberately
The strongest saving is to run a workload in a single AZ. This removes inter-AZ traffic for that workload entirely. It also removes your protection against an AZ failure, so apply it selectively.
Good candidates are:
- Batch and analytics clusters, such as EMR or Spark, that can be rerun if an AZ is lost.
- Development and test environments.
- Tightly coupled HPC jobs that run in a cluster placement group.
Poor candidates are customer-facing services and anything with a recovery objective you cannot meet with a rerun. For those, keep multi-AZ and use Fixes 1 to 3 to reduce cost without giving up resilience.
Use VPC endpoints and NAT gateways with AZ in mind
A NAT gateway lives in one AZ. If instances in AZ b send their internet traffic to a NAT gateway in AZ a, that traffic pays inter-AZ transfer before it pays NAT processing. Create one NAT gateway per AZ and point each private subnet's route table at the gateway in its own AZ. The hourly cost of extra NAT gateways is usually smaller than the inter-AZ charges they remove, but check this against your traffic volume. Interface endpoints behave similarly: enable them in every AZ you use, so clients resolve to the endpoint network interface in their own AZ.
Check your work
After a change, wait for at least a few days of normal traffic. Compare the DataTransfer-Regional-Bytes usage quantity before and after, and compare it with request volume so that traffic growth does not hide the effect. Also watch latency and error rates. Zone-local routing can shift load unevenly, and a saving is not worth it if it causes throttling.
Exercise
An NLB with cross-zone load balancing disabled has 6 targets in AZ a and 2 targets in AZ b. Clients are spread evenly across both AZs. Why can disabling cross-zone cause a problem here, and what should you do first?
Show answer
With cross-zone off, each load balancer node sends traffic only to targets in its own AZ. Clients are split evenly, so each AZ gets half the traffic. The 2 targets in AZ b then receive the same load that 6 targets in AZ a share, so they are likely to overload. Balance the target counts across AZs first (for example, 4 and 4), and then disable cross-zone to remove the inter-AZ transfer.
Exercise
Your Cost Explorer query shows high USE1-DataTransfer-Regional-Bytes cost. Name two ways to find out which flows cause it, and one reason a fix might not be worth doing.
Show answer
Run a CloudWatch Logs Insights query on VPC Flow Logs to find the top source and destination address pairs and compare the AZs of their subnets. You can also check which services generate the traffic, such as the load balancer, database replication, or Kafka, by reviewing the architecture. A fix may not be worth doing if the regional transfer cost is a small share of the bill, because the engineering effort and the added operational risk can exceed the saving.