What Is a Load Balancer - and When You Actually Don't Need One

A load balancer sits in front of a group of servers, takes every incoming request, and decides which server handles it. That is the whole job: one address on the outside, many machines on the inside.

It exists because a single server has a ceiling and a single point of failure. Once you run two copies of your application, something has to answer the question "which copy?" on every request — and that something also has to notice when one of the copies stops answering and quietly stop sending traffic there.

The second half is usually the reason people adopt one. Spreading load is the advertised feature; removing a dead server from rotation without a human waking up is the part you actually buy.

What follows is the mechanism, the operational costs it adds, and the scale below which running one is just extra moving parts. Steel framework cabinets housing servers networking devices and cables in contemporary equipped data center

ConceptLoad Balancer (LB)
Where it sitsInfrastructure — sits at the network edge, between clients and your application instances
In one sentenceA single entry point that distributes requests across multiple backend servers and stops routing to ones that fail health checks.

The 60-Second Answer

A load balancer accepts client connections on one address and forwards each request to one of several backend instances.

The one problem it solves: your application can now survive losing an instance, and you can add capacity by adding instances rather than buying a bigger machine.

The one cost it adds: it is a new component on the critical path with its own configuration, its own failure modes, and its own opinions about timeouts and connection reuse. Every request now traverses an extra hop you have to operate and reason about.

If you run one instance and a restart means a short outage you can live with, you do not need one yet.

How It Actually Works

1. It terminates the client connection, then opens its own to a backend

Two connections, not one pipe

The client's TCP connection (and usually its TLS session) ends at the load balancer. The load balancer then uses a separate connection — typically from a pool it keeps warm — to talk to a chosen backend.

This split is what makes everything else possible. Because the load balancer holds both ends, it can read the request, choose a backend per request rather than per connection, retry elsewhere, and swap the backend set underneath without the client noticing.

It also means the backend no longer sees the client's IP as the connection source — it sees the load balancer's. That information has to be carried forward in a header, or it is simply gone.

⚠️ In production — Your application logs will show the load balancer's address as the client for every request until you plumb the forwarded-client-IP header through and tell your framework to trust it. Trust it only from the load balancer's own address range — otherwise any client can claim any IP by setting the header themselves, and your rate limiting and geo rules become decorative.


2. It picks a backend using a selection algorithm

Round robin, least connections, hashing

The selection rule is the part people mean when they say "balancing". Round robin walks the list in order. Least connections (or least outstanding requests) sends the next request to whichever backend is currently handling the fewest. Hashing derives the backend from something stable in the request — a client IP, a header, a URL path — so the same input lands on the same backend.

Round robin assumes requests cost roughly the same. When they do not — one endpoint does a 2ms cache read, another does a 400ms report build — round robin will cheerfully stack slow requests on a backend that is already struggling, because it is not looking.

Least-outstanding-requests is the better default for mixed workloads precisely because it reacts to what is happening rather than to a counter.

⚠️ In production — A backend that has become slow but not dead is the worst case for naive round robin: it keeps receiving its full share while its queue grows, and you see latency spread across the whole fleet instead of isolated to one machine. Load-aware selection turns that into a localised problem, which is far easier to diagnose.


3. It health checks backends and removes failing ones from rotation

The part you actually buy

The load balancer periodically probes each backend — a TCP connect, or an HTTP request to a dedicated endpoint — and tracks consecutive passes and failures. After enough failures it marks the backend unhealthy and stops sending it traffic. After enough passes it brings it back.

The endpoint you expose matters more than the probe interval. A check that returns 200 whenever the process is alive will keep a backend in rotation while its database connection pool is exhausted. A check that queries every dependency will mark the entire fleet unhealthy the moment one shared dependency has a bad second.

# shallow: is this process able to serve?
GET /healthz   -> 200 if the server loop is running

# deep: should this process be in rotation?
GET /readyz    -> 200 only if deps this instance needs are usable

The useful split is liveness (is the process alive) versus readiness (should it receive traffic). Point the load balancer at readiness.

⚠️ In production — Deep health checks that fan out to shared dependencies are how a single degraded database takes down a fleet that was otherwise serving cached traffic fine. Every backend fails the check simultaneously, every backend leaves rotation, and the load balancer has nowhere left to send anything. Check only what this instance needs to serve, and consider what you want to happen when all backends are unhealthy — some load balancers will fail open and route anyway, which is usually what you want.


4. It drains connections instead of cutting them during deploys

Graceful removal, not a yank

When you take a backend out — for a deploy, a scale-down, or a failed health check — in-flight requests on it are still running. Connection draining means the load balancer stops sending new requests to that backend but lets existing ones finish, up to a timeout.

This is what makes zero-downtime deploys possible. The deploy sequence becomes: mark the instance not-ready, wait for the load balancer to notice and drain, then stop the process.

The ordering is the whole trick. If your process exits as soon as it gets the shutdown signal, draining never happens and you serve errors for the length of one health check interval on every single deploy.

⚠️ In production — The gap between "your orchestrator sent SIGTERM" and "the load balancer stopped routing here" is real and it is at least one health check cycle. Your application should fail readiness immediately on shutdown signal, then keep serving for longer than that gap before exiting. Deploys that produce a small burst of 502s almost always have this ordering wrong rather than a load balancer problem.


5. It can route on request content, or only on connection metadata

Layer 7 vs layer 4

A layer 7 load balancer parses the application protocol. It sees the path, the method, the headers, the host, and can route /api/* to one pool and /static/* to another, rewrite headers, and retry a failed request on a different backend because it knows where the request boundaries are.

A layer 4 load balancer forwards packets based on addresses and ports without reading the payload. It is faster, cheaper, protocol-agnostic, and can carry anything — but it cannot distinguish two requests on one connection, so it balances connections rather than requests.

The practical consequence shows up with multiplexed protocols. A long-lived connection carrying many concurrent streams is a single unit to a layer 4 balancer, so a client that opens one connection and sends a thousand requests pins all thousand to one backend.

⚠️ In production — This is the most common surprise when teams put a layer 4 balancer in front of HTTP/2 or gRPC: traffic looks badly skewed and nothing is wrong with the algorithm, because there are only as many balancing decisions as there are connections. The fixes are a layer 7 balancer that understands streams, or client-side balancing — not a different layer 4 algorithm.


6. It optionally pins a client to one backend with session affinity

Sticky sessions, and why they hurt

Session affinity (sticky sessions) makes the load balancer send the same client back to the same backend, usually via a cookie it sets or a hash of the client address. Teams reach for it when the application keeps per-user state in local process memory.

It works, and it is a trap. Affinity means your balancing is now only as even as your client distribution, a scale-down event logs those users out, and a restart loses their state. You have made the backend stateful at the exact layer you were trying to make replaceable.

The better fix is almost always to move session state out — into a shared cache or a signed token the client carries — so any backend can serve any request.

⚠️ In production — Affinity hides the stateful-backend problem rather than solving it, and it hides it until the day you need to deploy during peak traffic. Treat it as a temporary bridge with an owner and a removal date, not as a configuration setting you turn on and forget.


7. The load balancer itself has to not be a single point of failure

Who balances the balancer

You have just funnelled all traffic through one component. If it dies, every backend is healthy and entirely unreachable.

Managed load balancers solve this out of sight: the thing you configure is a logical endpoint backed by redundant instances across failure domains, fronted by DNS or anycast routing. If you run your own, you own the problem — typically a pair sharing a virtual address with automatic failover, or several advertising the same address.

Above the load balancer, DNS is the usual fallback layer. It is also a slow one: resolvers and clients cache records past their stated TTL, so DNS-based failover is measured in minutes and is not a substitute for health checking.

⚠️ In production — Capacity planning for the load balancer is separate from capacity planning for your backends, and it is easy to forget. TLS handshakes, connection tracking tables, and ephemeral port exhaustion on the backend side are all real ceilings that have nothing to do with how much application work you are doing.

Detailed view of blue ethernet cables connected to a network switch in a data center. ## Where You Meet It
  • A web application running three identical instances behind one hostname. The load balancer spreads requests across them and handles deploys by draining one instance at a time, so a rolling release never takes the site down. This is the baseline case and it is the majority of deployments.
  • An API gateway edge routing by path: /auth/* to the identity service, /search/* to the search cluster, everything else to the monolith. Here the load balancer is doing layer 7 routing as much as balancing — it is the component that lets you carve services out of a monolith without changing a single client.
  • A database read fleet behind a layer 4 balancer on one port. Read queries land on whichever replica is least busy; the primary stays on a separate address because writes cannot be balanced. Health checks here must consider replication lag, not just whether the process accepts connections.
  • An internal service mesh where each pod talks to a local sidecar proxy rather than a central load balancer. The balancing logic is identical — health checks, outlier ejection, least-outstanding-requests — but it has been pushed to the client side, which is the standard answer to the HTTP/2 pinning problem.
  • A blue/green cutover where two complete environments exist and the load balancer's backend pool is the switch. You shift the pool, watch error rates, and shift back if it goes badly. The load balancer is the deployment mechanism, not just a traffic splitter.

When You Actually Need It

  • You run more than one instance of the same application and something has to choose between them on every request.
  • A single instance restarting or crashing currently causes a visible outage, and you want deploys that do not require a maintenance window.
  • Your traffic has outgrown one machine, or you want the option to add capacity by adding instances rather than resizing a server.
  • You need TLS terminated, request logging, or rate limiting in one place rather than reimplemented in each service.
  • You want to route by path or host — splitting a monolith, adding a new service, or serving static assets from a different pool — without changing client configuration.
  • You need to shift traffic deliberately: canary releases, blue/green cutovers, or draining a whole availability zone.

When You Don't

  • You run one instance. A load balancer in front of a single backend adds a hop, a configuration surface, and a component that can fail, in exchange for nothing. If you want HTTPS and sane logs, a reverse proxy on the same host (or your platform's built-in ingress) gives you that without the distributed-systems bill.
  • Your traffic fits comfortably on one machine and a few minutes of downtime per deploy is acceptable. Many internal tools, admin panels, and early products are in this category honestly. Vertical scaling and a restart script is the correct engineering answer; revisit when downtime starts costing something you can name.
  • Your application keeps session state in local memory and you would turn on sticky sessions to cope. You are not ready for multiple instances yet. Externalise session state first — a shared cache or a signed token — then add the load balancer. Doing it in the other order buys you uneven load and users who get logged out by every deploy.
  • You are already on a platform that provides it. Container orchestrators, serverless runtimes, and PaaS products route to healthy replicas as a built-in function. Standing up your own in front of that is usually two balancers in series, each with its own timeouts, which makes every latency investigation twice as hard.
  • You are reaching for one to add failover across regions. A load balancer balances within the set of backends it can health check. Cross-region failover is a DNS, anycast, or global-routing problem with completely different latency and consistency characteristics — solve it at that layer instead.
  • You want to balance writes to a primary database. There is one primary; there is nothing to balance. A load balancer in that path adds a hop and an opportunity to send a write to a replica during failover. Use the driver's or proxy's topology awareness, which understands which node is actually writable. Two architects in hard hats working on a blueprint indoors, highlighting teamwork.

What People Get Wrong

"A load balancer makes my application highly available."

It removes one class of single point of failure — an individual application instance — and only if your instances are genuinely independent. If all of them talk to the same database, cache, or availability zone, that shared dependency is still your availability ceiling, and the load balancer will not notice until it is already failing. Availability is a property of the whole dependency graph, not of one component in it.

"It balances load, so my backends will have roughly even utilisation."

It balances requests or connections, which is only the same thing when requests cost the same. Mixed workloads, long-lived multiplexed connections, and sticky sessions all produce visibly uneven utilisation with a perfectly correct algorithm. Even utilisation requires choosing a selection strategy that matches your traffic shape, and watching per-backend metrics rather than fleet averages.

"Adding a load balancer is transparent to the application."

Client IPs now arrive in a header you have to trust correctly, idle timeouts become a negotiation between three parties, keep-alive behaviour changes, and your shutdown sequence has to cooperate with draining. Most new-load-balancer incidents are timeout and shutdown mismatches, not routing bugs.

"Layer 4 is strictly faster, so use it unless you need layer 7 features."

Layer 4 is cheaper per byte, but it cannot see request boundaries — so it cannot retry a failed request, cannot balance streams inside one connection, and gives you no per-request visibility. With modern multiplexed protocols that is not a minor tradeoff; it determines whether balancing happens at all.

Why It Was Built This Way

The constraint that produced the load balancer is that clients must reach your service through one stable address, while the set of machines behind it changes constantly. Machines fail, get patched, get replaced, get added under load. There is no mechanism in the client's path that can keep up with that — DNS was the obvious candidate and it is cached in places you do not control, by resolvers and application runtimes that treat TTL as advisory. Pushing the backend list to clients was tried and it means every client needs your service topology and your health information, which is a far bigger coupling problem than the one you started with.

So the indirection was placed one hop in front of the backends, where it can see every request and every backend simultaneously. That position is what makes per-request decisions, sub-second health reactions, and draining possible — none of which DNS can do. The price was accepting a stateful intermediary on the critical path: it has to track connections, hold TLS state, maintain health status, and it has to be made redundant itself. The problem was not eliminated, it was moved to a layer where it could be solved once instead of in every client.

The second trade is in the layer 4 / layer 7 split, and it is a direct consequence of the first. To make smart per-request decisions you must parse the protocol, which costs CPU and ties the balancer to that protocol. To stay fast and protocol-agnostic you must stay blind to request boundaries, which means you balance connections instead of requests. Neither is wrong — but the rise of long-lived multiplexed connections quietly shifted the default answer, because balancing connections stopped approximating balancing work. That is also why balancing logic has been migrating back toward the client as sidecars and smart clients: it is the same mechanism, placed where it can see request boundaries without a central chokepoint. Once you see the load balancer as where the indirection lives rather than as a box, the architectural arguments stop being confusing.

Related Briefs

What to Read Next

  • reverse proxy vs load balancer
  • how to design a health check endpoint
  • client side load balancing and service mesh

A load balancer is indirection in front of a replaceable fleet: its real value is noticing failure and routing around it without you, not the arithmetic of spreading requests. Add it when you genuinely have more than one instance and a dead instance would otherwise be an outage. Below that, one server plus a restart is not a compromise — it is the correct design, and the balancer is a component you would be operating for no return.

댓글

이 블로그의 인기 게시물

What Is a Message Queue - and When You Actually Don't Need One

What Is a Bloom Filter - and When You Actually Don't Need One

When to Use GraphQL Over REST API - and When REST Is Still the Right Call