Interview Prep/AWS/EC2, Auto Scaling and Load Balancing

Behind an NLB, one target gets most of the traffic while the others sit idle.

AdvancedTroubleshootingEC2, Auto Scaling and Load Balancing
Answer

Likely causes → An NLB balances per connection (flow hash), not per request. A few long-lived connections, such as gRPC, HTTP/2, WebSockets or pooled DB clients, stick to whichever target they first hit. Cross-zone load balancing is off by default on an NLB, so an AZ with fewer targets gets proportionally more load per target.

Diagnose →

aws elbv2 describe-load-balancer-attributes --load-balancer-arn <nlb-arn> \
  --query "Attributes[?Key=='load_balancing.cross_zone.enabled']"
aws elbv2 describe-target-health --target-group-arn <tg-arn>
# per-target ActiveFlowCount / NewFlowCount in CloudWatch (AWS/NetworkELB)

Fix →

  1. Turn on cross-zone: aws elbv2 modify-load-balancer-attributes --load-balancer-arn <nlb-arn> --attributes Key=load_balancing.cross_zone.enabled,Value=true
  2. For HTTP/2 or gRPC, use an ALB, which balances per request. Or make clients recycle connections regularly (max connection age)
  3. Spread targets evenly across AZs

Prevent → Pick the LB for the protocol: an ALB for request-level balancing, an NLB for raw TCP, static IPs and very high throughput.

aws All AWS questions Roadmap: AWS core services

More on EC2, Auto Scaling and Load Balancing