Load Balancer
A component that sits in front of a pool of servers and distributes incoming traffic across them, so no single instance becomes a bottleneck or a single point of failure.
Definition#
A load balancer is a system component — hardware appliance, software process, or managed cloud service — that sits between clients and a pool of backend servers, and decides which server handles each incoming request. Its job is to spread load evenly enough that no single backend is overwhelmed while others sit idle.
Load balancers operate at different layers of the network stack. A Layer 4 load balancer routes based on IP address and port, without inspecting the request itself — fast, but blind to content. A Layer 7 load balancer reads the actual HTTP request (path, headers, cookies) and can route based on it — for example, sending API traffic to one service and static asset traffic to another.
Why it matters#
Without a load balancer, scaling out means clients need to know about every server individually, and any single server going down takes its share of traffic offline with it. A load balancer turns a pool of individually fragile servers into a single, resilient endpoint: it enables horizontal scaling (add more servers, no client-side changes needed), removes the backend as a single point of failure (unhealthy servers are automatically taken out of rotation), and makes zero-downtime deployments possible — new versions can be rolled in gradually while the balancer keeps routing traffic to whichever instances are healthy.
How it works#
A load balancer continuously runs health checks against each backend — a periodic request to a lightweight health endpoint — and removes any server that fails to respond correctly from the rotation. Traffic is then distributed across the remaining healthy servers according to a routing algorithm.
Common algorithms#
| Algorithm | How it routes |
|---|---|
| Round robin | Cycles through servers in fixed order, regardless of current load |
| Weighted round robin | Same as round robin, but higher-capacity servers receive a proportionally larger share |
| Least connections | Sends each new request to whichever server currently has the fewest active connections |
| IP hash | Routes based on a hash of the client IP, so the same client consistently reaches the same server |
| Least response time | Combines active connection count with recent response latency to pick the fastest available server |
Design patterns#
- Redundant load balancers — run at least two balancers behind a floating IP or DNS record, so the balancer itself isn't a single point of failure.
- Health checks with sane thresholds — require several consecutive failures before removing a server, avoiding flapping on a single slow response.
- SSL/TLS termination — decrypt traffic at the balancer so backend servers handle only plain HTTP, simplifying certificate management.
- Session persistence (sticky sessions) — route a given client to the same backend when server-side session state requires it, used sparingly since it limits even distribution.
- Global and local balancing — a DNS-level global balancer routes to the nearest region, then a local load balancer distributes within that region's server pool.
Common pitfalls#
- Relying on sticky sessions by default, which quietly defeats even load distribution and concentrates load on whichever servers hold active sessions.
- Misconfigured health checks that either flap healthy servers out of rotation or fail to detect a genuinely unhealthy one.
- Treating the load balancer itself as infallible — a single load balancer instance is still a single point of failure for the entire pool behind it.
- Choosing round robin for workloads with highly variable request cost, where a fairer algorithm like least-connections would prevent hot spots.