Skip to the page

Networking for operators · mid

Load balancers, 502 errors and CIDR

Layer 4 and layer 7 load balancers fit different needs, 502 errors often come from mismatched idle timeouts, and CIDR sizes decide how far a network can grow.

The notes

What you must know

  • NLB works at layer 4 (TCP, UDP, TLS): very high throughput, a static IP per AZ or your own Elastic IPs, keeps the client IP and has no HTTP awareness.
  • ALB works at layer 7: host and path routing, redirects, header rules, authentication and WAF. ALB IP addresses change as it scales, so never allow-list them.
  • For fixed IPs plus path routing and WAF: an NLB with Elastic IPs in front of the ALB, or a global accelerator with static IPs in front of the ALB. The ALB passes the client IP in X-Forwarded-For.
  • 502 from the load balancer with no target status in the access log means the ALB failed to talk to the target. The app logs show nothing because the app never saw the request.
  • Cause: the ALB reuses idle connections up to its idle timeout (60 seconds by default). If the app closes idle connections sooner, such as Node with a 5 second keep-alive timeout, a request can hit a closing connection. Fix: set the app keep-alive timeout above the load balancer idle timeout.
  • A /16 has 65,536 addresses, a /24 has 256 and a /20 has 4,096. Each bit halves or doubles the size.
  • AWS reserves 5 addresses in each subnet, so a /24 has 251 usable.
  • Plan CIDR from a company-wide address plan. With the EKS VPC CNI every pod takes a VPC IP, so small subnets run out. Fixes are bigger subnets, prefix delegation or a secondary CIDR.

The red pen

Common traps: mistake → fix

  • Mistake: Allow-list the ALB IPs for the partner

    Fix: they change; use an NLB or accelerator with static IPs.

  • Mistake: A 502 means the app crashed

    Fix: check ELB 502 versus target 5xx metrics and the keep-alive timeouts.

  • Mistake: A /24 gives 256 usable addresses in AWS

    Fix:

Easy to hard

Questions interviewers ask, easy to hard

  1. ALB, NLB or both for a partner API with fixed IPs?
  2. What does 10.20.0.0/16 mean? How many usable addresses in a /24 in AWS?
  3. Random 502s from the load balancer. Where do you look?
  4. Why choose the VPC CIDR carefully?

Practise

Practise with these questions

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview