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.
| Property | Layer 4 | Layer 7 |
|---|---|---|
| Decision based on | IP address, port, TCP/UDP state | HTTP method, path, headers, cookies |
| Throughput overhead | Very low | Higher — must parse and often terminate TLS |
| Routing precision | Coarse: whole connections to a server | Fine: per-request routing by content |
| Protocol awareness needed | No | Yes, per protocol supported |
| Typical use | Raw TCP/UDP services, extreme scale, DDoS-facing edges | Web 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.
- DNS or anycast-based routing sends the client to the nearest healthy region.
- An edge Layer 4 or Layer 7 balancer accepts the connection and terminates TLS if applicable.
- Requests are distributed to an application server pool using a load-aware algorithm.
- Health checks continuously remove and restore backends from rotation as their status changes.
- 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
AdvertisementChecking for a video ad…
Frequently asked questions
Sources
- The Power of Two Choices in Randomized Load Balancing — Michael Mitzenmacher, IEEE Transactions on Parallel and Distributed Systems
- Envoy Proxy: Load Balancing — Envoy Proxy Documentation
- NGINX HTTP Load Balancing — NGINX Documentation
- Elastic Load Balancing Concepts — Amazon Web Services Documentation
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
- Contact:
- michael@inquro.example
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.






