Opscraft
Networking fundamentals · Lesson 6 of 9 · 4 min read

AWS load balancers in practice

Choosing a load balancer

ALB NLB GWLB
Layer 7 (HTTP/HTTPS, gRPC, WebSockets) 4 (TCP, UDP, TLS) 3 (IP packets, GENEVE)
Routing Host, path, header, query, method, source IP rules; weighted target groups Port-based Transparent insertion of appliances
Targets Instances, IPs, Lambda Instances, IPs, ALB Appliances
Static IP No (DNS name; IPs change) Yes — one per AZ, or your Elastic IPs —
Client IP X-Forwarded-For Preserved (or Proxy Protocol v2) Preserved
Extras WAF, OIDC/Cognito auth, redirects, fixed responses, sticky cookies Very high throughput, ultra-low latency, PrivateLink services Firewalls/IDS fleets

The Classic Load Balancer is legacy. Rules of thumb: HTTP apps → ALB; non-HTTP TCP/UDP, static IPs, extreme performance, or exposing via PrivateLink → NLB.

Enlarge diagramIs the traffic HTTP, HTTPS, gRPC orWebSockets?ALBrouting by host and path, WAF, authNeed static IPs, UDP, TCP passthrough orPrivateLink?NLBlayer 4, extreme throughputInserting firewall or inspectionappliances?GWLBtransparent appliance fleetsyesnoyesnoyes
Figure 1. Choosing an AWS load balancer in three questions.
Swipe sideways to see all of it, or tap to open it full screen.

Settings that cause real incidents

  • Health checks — path, port, protocol, success codes (200 by default; an app that redirects / to /login with 302 will fail), interval, thresholds. The target's security group must allow the LB (reference the LB's SG). "Health checks fail but the app works when I curl it on the instance" → SG, wrong port/path, expected code, or the app binds to 127.0.0.1.
  • Idle timeout — ALB default 60 s. Requests longer than that get 504 unless raised; the backend's keep-alive timeout must be longer than the ALB idle timeout, otherwise the app closes connections the ALB still reuses → intermittent 502.
  • Deregistration delay (connection draining) — default 300 s; tune for rollout speed.
  • Cross-zone load balancing — on by default for ALB, off by default for NLB (inter-AZ data charges apply when enabled on NLB). Uneven targets per AZ + cross-zone off = uneven load.
  • Slow start (ALB) — ramp traffic to new targets gradually.
  • Target type — ip targets (pods directly, with the AWS LB Controller) vs instance (NodePort hop).
  • ELB vs target 5xx metrics — HTTPCode_ELB_5XX_Count (the LB generated it: no healthy targets, timeouts, connection errors) vs HTTPCode_Target_5XX_Count (your app returned it). This tells you instantly who's at fault.
Enlarge diagramclientALByour appHTTPCode_ELB_5XX_Countthe ALB made it: no healthy targets, timeout,connection errorHTTPCode_Target_5XX_Countyour app returned it: check app logs
Figure 2. Who returned the 5xx? The ALB reports its own errors and your targets' errors separately, which tells you where to look first.
Swipe sideways to see all of it, or tap to open it full screen.
Enlarge diagramClientALBidle timeout 60 sAppkeep-alive 5 sconnection idle for 5 s: the app closes it, the ALB has not noticedyetrequest 1request 1200 OK200 OKrequest 2reuses the closed connectionRST502 Bad Gateway
Figure 3. The classic intermittent 502: the app closes an idle connection that the ALB still thinks it can reuse. Keep the app's keep-alive longer than the ALB idle timeout.
Swipe sideways to see all of it, or tap to open it full screen.