Skip to main content
networking

Load Balancer

A load balancer distributes incoming traffic across multiple backend servers to prevent any single server from becoming overwhelmed. Layer 4 (TCP) load balancers route by IP/port. Layer 7 (HTTP) load balancers can route by URL path, headers, or cookies. Health checks remove failed backends automatically.

Definition

Load balancers sit between clients and a pool of backend servers, distributing requests to maintain availability and performance. Layer 4 load balancers (AWS NLB, HAProxy TCP mode) operate on TCP connections – fast, transparent, but cannot inspect application content. Layer 7 load balancers (AWS ALB, Nginx, HAProxy HTTP mode, Envoy) understand HTTP and can route based on URL paths, headers, cookies, and request content. Algorithms include: round-robin (equal distribution), least-connections (send to the least busy), weighted (manual capacity ratios), and consistent hashing (session affinity by key). Health checks probe backends periodically (HTTP GET /health, TCP connect, or custom script) and remove unresponsive servers from the pool within seconds. Without load balancers, a single server failure causes complete outage. With load balancers, failed servers are automatically drained and traffic reroutes to healthy instances.

Examples

  • AWS ALB: routes /api/* to API target group, /* to web target group
  • HAProxy: server web1 10.0.0.1:8080 check inter 5s fall 3 rise 2
  • Nginx: upstream backend { least_conn; server 10.0.0.1:8080; server 10.0.0.2:8080; }

Related Protocols

Related Terms