Our label API runs on EC2 instances in an auto scaling group spread over two availability zones, eu-west-2a and eu-west-2b, behind a Network Load Balancer. We chose a Network Load Balancer years ago because the depot scanners keep long lived TCP connections and two partners allow list fixed addresses.

On a Monday in September an instance in eu-west-2a failed its health check overnight and was replaced. The replacement could not launch in 2a, because AWS had no capacity for our instance type in that zone, so the group put it in 2b. At the morning peak the group scaled from six instances to ten, and every new one went to 2b as well. By nine we had two instances in 2a and eight in 2b. The two in 2a were at a hundred percent CPU, and about half of all label requests were taking more than five seconds or timing out.

A Network Load Balancer has one node in each zone it is enabled in, and its DNS name returns one address per node. Clients spread across those addresses roughly evenly, so each zone's node receives about half the connections. With cross-zone load balancing off, each node sends traffic only to targets in its own zone, and for a Network Load Balancer it is off by default. Application Load Balancers have it on, which is why none of us had ever thought about it. Each instance in 2a was carrying a quarter of our traffic, and each in 2b about six percent.

The scaling policy tracked average CPU across the group. Two instances at a hundred and eight at forty average fifty two, below our target of sixty, so it saw no reason to add anything.

We turned cross-zone load balancing on for the target group and the load evened out within a minute. It adds inter zone data transfer charges, which are small next to an hour of failed labels. The group now uses a mixed instances policy with three instance types, so a shortage of one type no longer pushes the group into one zone. An alarm compares the load balancer's HealthyHostCount per zone and fires when one zone has less than half the hosts of the other, and our CPU panel shows the busiest instance next to the average.

A load balancer balances inside the boundaries it is given. Ours stopped at the edge of each zone, and our autoscaler counted the instances on both sides as if the line were not there.

– Sergey Shinder