TechnologyNetworking

How load balancers spread requests across servers without dropping any

How load balancers work at the network and application layers: distribution algorithms, health checks, session persistence and the trade-offs between Layer 4 and Layer 7 balancing in real production systems.

MAMichael Adeyemi — Senior Technology Writer, MSc, Distributed SystemsPublished 1 December 2025Last reviewed 20 May 20269 min readIntermediate1,760 words

Fact-checked by Dr. Rina Halvorsen, Editor-in-Chief (PhD, Cognitive Science) · 4 primary sources cited · how we review

Illustration of a single incoming arrow splitting evenly across several server racks

In short

A load balancer sits between clients and a pool of servers, deciding which server handles each connection or request so that no single machine is overwhelmed while others sit idle. The decision looks simple from the outside, but it involves choosing an algorithm, tracking server health continuously, and deciding what layer of the network stack to operate at — choices that shape how a system scales and fails.

Any service popular enough to outgrow a single server needs a way to spread work across many machines while still presenting clients with one address to connect to. That is the job of a load balancer: it receives traffic on behalf of a pool of backend servers, decides which one should handle each unit of work, and forwards it accordingly, ideally without the client ever noticing that more than one server exists.

The word 'balance' suggests an even split, but even distribution is only one goal among several. A good load balancer also needs to avoid sending traffic to a server that is unhealthy, keep related requests going to the same backend when that matters for correctness, and add negligible latency of its own — all while being reliable enough that it does not become the single point of failure it was meant to eliminate.

Layer 4 versus Layer 7 balancing

The most consequential design decision is which layer of the network stack the balancer operates at. A Layer 4 load balancer works at the transport layer, making its routing decision from IP addresses and TCP or UDP port numbers alone, without inspecting the contents of the connection. It is fast and protocol-agnostic, but it cannot make decisions based on anything inside an HTTP request.

A Layer 7 load balancer terminates the connection and reads the actual application-layer request — an HTTP method, path, header or cookie — before deciding where to send it. This allows far more precise routing, such as sending API traffic to one pool and image requests to another from the same public entry point, at the cost of more processing per request and the need to fully understand the protocol being balanced.

Layer 4 versus Layer 7 load balancing
PropertyLayer 4Layer 7
Decision based onIP address, port, TCP/UDP stateHTTP method, path, headers, cookies
Throughput overheadVery lowHigher — must parse and often terminate TLS
Routing precisionCoarse: whole connections to a serverFine: per-request routing by content
Protocol awareness neededNoYes, per protocol supported
Typical useRaw TCP/UDP services, extreme scale, DDoS-facing edgesWeb APIs, microservices, content-based routing

Distribution algorithms

Once the balancer knows it must pick a server from the healthy pool, it needs a rule for which one. Round robin cycles through servers in order, which is simple and works well when servers are identical and requests are roughly uniform in cost. Weighted round robin extends this by sending a proportionally larger share to more capable servers, useful in a pool with mixed hardware.

Least connections routes each new request to whichever server currently has the fewest active connections, which adapts naturally to servers that are slow for reasons the balancer cannot otherwise see, such as a long-running query. IP hash computes a hash of the client's address to consistently map that client to the same server, giving a crude but dependency-free form of session persistence. More recent systems, including those described in the 'power of two choices' line of research, sample a small number of servers at random and pick the less loaded of the two, achieving much of the benefit of full least-connections tracking with far less coordination overhead.

Relative request distribution under different algorithms (illustrative)

Percentage of requests routed to a deliberately slower backend

Simplified illustration of how a pool with one under-provisioned server fares under naive round robin versus load-aware algorithms; actual figures depend heavily on real request cost variance.

Health checks: routing only to servers that can actually respond

An algorithm is only as good as the pool it distributes across, so load balancers continuously probe each backend with health checks — periodic TCP connection attempts, or application-layer requests to a dedicated endpoint that reports the server's own view of its readiness. A server that fails enough consecutive checks is marked unhealthy and removed from rotation until it recovers, without needing any manual intervention.

  • Passive health checks infer server health from real traffic outcomes, such as a rising error rate or timeout count, avoiding extra synthetic load.
  • Active health checks send dedicated probes on a fixed interval regardless of real traffic, giving faster and more predictable detection.
  • A well-designed health endpoint should verify the dependencies that actually matter — such as database connectivity — rather than simply confirming the process is running, otherwise a server can pass checks while unable to serve real requests correctly.

Session persistence: when the same server has to answer twice

Stateless services can be routed anywhere on every request, but many real applications keep some state — an in-memory shopping cart, an authenticated session, a WebSocket connection — tied to whichever server first handled a client. Session persistence, often called sticky sessions, ensures subsequent requests from the same client keep landing on that server, typically by setting a cookie the balancer reads on each request, or by hashing the client's IP address.

Sticky sessions

Pros

  • Lets applications keep local, in-memory state without a shared session store
  • Simple to enable on most load balancers with no application changes
  • Works well for long-lived connections such as WebSockets that cannot be transparently moved between servers

Cons

  • Undermines even load distribution if some sessions are far more active than others
  • Complicates rolling deployments and scaling down, since removing a server disrupts every session pinned to it
  • Encourages architectures that do not scale horizontally as cleanly as fully stateless designs backed by shared session storage

Where load balancers sit in a real architecture

Production systems commonly layer several load balancers rather than relying on one. A global or DNS-based layer directs users to the nearest healthy data centre or region; within that region, a Layer 4 balancer distributes raw connections across a tier of Layer 7 load balancers or API gateways; and those, in turn, route individual requests to specific application server pools, sometimes with a further layer in front of a database or cache cluster. Each layer solves a different problem at a different scale, and conflating them is a common source of confusing latency and failure behaviour.

  1. DNS or anycast-based routing sends the client to the nearest healthy region.
  2. An edge Layer 4 or Layer 7 balancer accepts the connection and terminates TLS if applicable.
  3. Requests are distributed to an application server pool using a load-aware algorithm.
  4. Health checks continuously remove and restore backends from rotation as their status changes.
  5. Internal services may sit behind their own balancers, invisible to the original client entirely.

Key points

  • Layer 4 balancing is fast and protocol-agnostic; Layer 7 balancing is slower but allows routing decisions based on request content.
  • Round robin and its weighted variant are simple defaults; least connections and power-of-two-choices adapt better to uneven request cost.
  • Health checks — active, passive, or both — keep traffic away from servers that cannot actually serve it, regardless of process status.
  • Sticky sessions solve stateful application needs but reduce distribution evenness and complicate scaling operations.
  • Real systems typically layer several load balancers across DNS, edge and internal tiers rather than relying on a single instance.

Sponsored video

Advertisement

Checking for a video ad…

Frequently asked questions

Sources

About the author

Michael Adeyemi — Senior Technology Writer

Michael writes Inquro's computing and web-infrastructure coverage. He worked for eight years as a platform engineer on high-traffic content systems before moving into full-time technical explanation, and he still prototypes every measurement described in his articles before publishing the numbers.

Qualifications
  • MSc, Distributed Systems — University of Manchester
  • BEng, Computer Engineering — University of Lagos
Experience
  • Eight years as a platform engineer on high-traffic content delivery systems
  • Four years writing standards-based technical documentation
Subject areas:
Web performance, Networking, Systems architecture

Reviewed for factual accuracy by Dr. Rina Halvorsen, Editor-in-Chief (PhD, Cognitive Science), on 20 May 2026.

Structure, claim strength and whether an explanation actually answers the question a reader arrived with.

Inquro articles are commissioned, sourced, reviewed and re-checked under a published editorial policy. Corrections are made in place and dated — write to editorial@inquro.example if you find an error.

Related explainers

More from Technology and connected clusters across the full library.

TechnologyNetworking

How TCP congestion control decides how fast data can safely flow

An explanation of TCP congestion control: slow start, additive-increase multiplicative-decrease, fast retransmit and modern algorithms such as CUBIC and BBR, and why they shape the throughput of every internet connection.

Michael AdeyemiUpdated 18 March 20268 min
TechnologyNetworking

How DNS resolution works, step by step

A complete walkthrough of DNS resolution: the recursive resolver, root, TLD and authoritative servers, caching layers, TTL behaviour, and why DNS is so often the hidden cause of slow first loads.

Michael AdeyemiUpdated 15 July 202611 min
TechnologyNetworking

What actually happens between pressing Enter and seeing a page

A complete walk-through of the pipeline behind a single web request: DNS resolution, TCP and TLS setup, the HTTP exchange, and browser parsing and rendering, with the latency each stage typically adds.

Michael AdeyemiUpdated 14 February 20269 min
TechnologyNetworking

How public key infrastructure turns a key pair into verifiable identity

How public key infrastructure links cryptographic keys to real-world identity through certificates, certificate authorities and trust chains, and how revocation, transparency logs and automation keep the system trustworthy at internet scale.

Michael AdeyemiUpdated 11 April 20269 min

Keep reading

Definitions used here

Go deeper