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#

AlgorithmHow it routes
Round robinCycles through servers in fixed order, regardless of current load
Weighted round robinSame as round robin, but higher-capacity servers receive a proportionally larger share
Least connectionsSends each new request to whichever server currently has the fewest active connections
IP hashRoutes based on a hash of the client IP, so the same client consistently reaches the same server
Least response timeCombines active connection count with recent response latency to pick the fastest available server

Design patterns#

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.