Why load balancers exist

A load balancer sits in front of multiple servers and distributes incoming requests so no single machine gets overwhelmed.

Common algorithms

Algorithm Best for
Round robin Equal-capacity servers
Least connections Variable request duration
IP hash Session stickiness

Layer 4 vs Layer 7

  • L4 (TCP): fast, routes by IP/port — AWS NLB
  • L7 (HTTP): routes by URL, headers, cookies — AWS ALB

Health checks

Always configure health checks. Unhealthy instances should be removed automatically before users hit errors.

AWS mapping

  • ALB: HTTP/HTTPS apps, path-based routing
  • NLB: ultra-low latency TCP/UDP
  • API Gateway: serverless APIs in front of Lambda/ECS