Engineering for Locality
We know cross-AZ traffic costs $0.01/GB. The problem is that most distributed systems are designed for availability first, which means spreading load across zones — and this directly conflicts with cost optimization.
Consider a typical three-tier application with a load balancer, application servers, and a database, all spread across two Availability Zones:
Without zone affinity:
1. A user request arrives at the load balancer in Zone A.
2. The load balancer (doing round-robin) sends it to an app server in Zone B. (Cross-AZ charge triggered)
3. The app server in Zone B queries the primary database in Zone A. (Cross-AZ charge triggered)
4. The response travels back through the same path. (Two more cross-AZ charges)
A single request can trigger four cross-AZ hops. At scale, this adds up fast.
Zone Affinity (also called Topology-Aware Routing) is the configuration that tells load balancers and service meshes to prefer sending traffic to endpoints in the same zone as the caller.
In Kubernetes, this is enabled with a single topology-mode annotation on a Service, set to automatic. With that annotation set, the Kubernetes EndpointSlice controller adds hints to each endpoint indicating which zone it serves. The kube-proxy on each node uses these hints to prefer local endpoints. A pod in Zone A will preferentially call the Zone A replica of a service rather than the Zone B replica.
AWS Application Load Balancers support a similar feature called Availability Zone Affinity (or "zonal shift"), and AWS NLBs support cross-zone load balancing being disabled to achieve the same effect.
The Trade-off: Zone affinity reduces cost but can create uneven load distribution if zone populations are imbalanced. If Zone A has 10 pods and Zone B has 2 pods, Zone A traffic will be handled locally (good) but Zone B traffic will also try to stay local and overload its 2 pods. Most implementations include a fallback: if local endpoints are overloaded or unavailable, traffic spills over to other zones. This is the right default — optimize for locality, fall back to availability.