Interview Prep/Networking/Load balancers and reverse proxies

An app on an EC2 instance calls its own internal NLB, and connections time out only when the NLB picks that same instance.

AdvancedTroubleshootingLoad balancers and reverse proxies
Answer

Likely causes → Hairpinning with client IP preservation. The packet arrives at the instance with source = its own IP and destination = its own IP; the instance replies locally instead of via the NLB, the client socket sees a reply from an unexpected address, and the connection never completes.

Diagnose →

aws elbv2 describe-target-group-attributes --target-group-arn <tg> \
  --query "Attributes[?Key=='preserve_client_ip.enabled']"
sudo tcpdump -ni any host <instance-ip> and port <port>   # SYN from self, SYN-ACK goes direct

Roughly 1/N of calls fail, where N is the number of targets.

Fix → Disable client IP preservation on that target group (use PROXY protocol v2 if you need the client IP), use IP targets without preservation, or call the local service directly instead of through the NLB.

Prevent → Avoid services calling themselves through their own LB; document this NLB limitation in service templates.

All Networking questions Roadmap: Networking for DevOps

More on Load balancers and reverse proxies