Back to blog

Three servers, one IP: who gets the next request?

Thắng Đoàn
Thắng Đoàn

FotoFlow scaled to three servers, but users only know one DNS address, so every request still lands on Server B while A and C sit idle. The extra hardware bought nothing: adding servers only helps if traffic actually reaches them.

One front door

A load balancer becomes the one public address of the service. Clients connect to it, it forwards each request to one of the servers behind it, and relays the answer back. The servers behind it are called its pool, and they can now come and go without clients ever knowing.

Who gets the next request

The simplest rule is round robin: A, then B, then C, then A again. Cheap and fair, as long as the servers are equally powerful and every request costs the same. Weighted round robin gives bigger servers a bigger share.

But real traffic is lumpy: loading a page takes 5 ms, exporting a year of photos takes 5 seconds. Round robin counts requests, not work, and if the heavy ones land on B by luck of the rotation, B drowns while A and C coast. Round robin has no idea how busy a server actually is.

The fix is least connections: the balancer tracks how many requests each server is busy with and sends the next one to the least busy. A server stuck on slow work holds more open connections, so it automatically receives less new work. Other strategies include least response time, IP hash for same-client-same-server, and power of two choices.

Routing around the dead

Every few seconds the balancer probes each server with a health check such as GET /health. A server that misses several checks in a row is pulled from the pool until it recovers. Server C can crash and no user notices. Health checks plus spare servers mean no single server is a single point of failure any more.

Who balances the balancer?

Removing one single point of failure created another: when the balancer dies, everything behind it is unreachable. Anything that every request depends on must itself be redundant. The standard answer is two load balancers, an active one and a passive standby, sharing a virtual IP and exchanging heartbeats every second. When the active dies, the standby claims the virtual IP within seconds and clients keep using the same address. Cloud balancers do this for you across machines and zones.

Reading the request: layer 4 and layer 7

A layer 4 balancer sees only IP addresses and ports and forwards whole connections. A layer 7 balancer reads the HTTP request itself, so it can route by path: /api/* to the API servers, /images/* to a separate image service, each pool scaled and deployed on its own. Layer 7 also terminates TLS and can add caching or compression.

Layer 7 is what makes zero-downtime deploys possible. In a rolling deploy the balancer drains one server at a time, no new requests but in-flight ones finish, then updates it, waits for the health check, and rejoins it. Blue-green goes further: bring up a full new pool and switch the balancer over at once, and back if anything looks wrong.

What this does not solve

The balancer now spreads requests blindly across servers, which exposes a hidden assumption: that any server can handle any request. The moment Alice's login session lives in one server's memory, round robin itself becomes the bug. That is the next post.

If you removed your load balancer today, how many minutes would users notice, and what would they see?
Does your heaviest endpoint cost roughly the same as your lightest one? If not, which balancing rule are you relying on right now?

One front door, many rooms behind it.

Next in the series: Why does login break the moment you add a second server?

Sources

System Design Primer

MDN Web Docs: HTTP redirections

undefined

Google SRE Books

Share:

Recommended for you

Enjoyed this article?

Subscribe for new articles. No spam. Unsubscribe anytime.

No pasting. This is the challenge.0/200

Typed live, never pasted.