Load Balancing & Algorithms

Distributing traffic at Layer 4 (L4) and Layer 7 (L7) using Round Robin, Least Connections, and health-checked pools

Difficulty: Beginner · Read time: 7 min · Access: Free Interactive Lesson

How It Works

A Load Balancer (LB) sits in front of backend servers, spreading incoming traffic evenly, running active/passive health checks, and terminating Transport Layer Security (TLS). Layer 4 (L4) Transport Load Balancers route packets solely by IP address and TCP/UDP port at ultra-high speed; Layer 7 (L7) Application Load Balancers inspect HTTP paths, headers, and cookies for smart content-based routing.

Why It Matters

Without load balancing, horizontal scaling across multiple servers is impossible. Choosing the wrong routing algorithm (like blind Round Robin for mixed slow/fast queries) allows slow database exports to pile up and starve healthy servers.

Interactive Architecture Scenarios

  • Least Connections Routing
  • Failure Mode: Round Robin & Retry Storm

Key Terms & Short Forms

  • L4 Load Balancer (Layer 4 (Transport Layer) Load Balancer): Forwards raw TCP/UDP packets using only source/destination IP and port without decrypting TLS or reading HTTP URLs.
  • L7 Load Balancer (Layer 7 (Application Layer) Load Balancer): Terminates TLS and parses HTTP headers, URL paths (`/api` vs. `/video`), and cookies to make intelligent routing or auth decisions.
  • Least Connections (Least Active Connections Routing Algorithm): Sends each new request to the healthy backend server currently holding the fewest in-flight open connections.
  • Health Check (Active Probe & Passive Outlier Detection): Active probes poll `/healthz` every few seconds, while passive checks eject a server immediately if it returns consecutive `5xx` errors.
  • VRRP & Anycast (Virtual Router Redundancy Protocol & Anycast IP): Failover techniques ensuring the Load Balancer itself is not a Single Point of Failure (SPOF) via Active-Passive or Active-Active pairs.
  • SPOF (Single Point of Failure): Any single non-redundant component whose crash takes down the entire system.

Related Lessons in Networking & Traffic