Why connection count, not request count, decides the design

connections = rate x hold time

Balance sockets, not requests: concurrency is arrival rate times hold time, so every routing policy bets on which backend can afford that state.

The thing a balancer spreads is server-side state per open connection, and that count grows with clients times backends, not with traffic. A load balancer terminates client connections and reuses upstream ones, so the backend's connection count stops tracking the client count. Adding backends does not shrink the front-side socket table, which is usually what saturates first.

Each open connection costs memory on the machine holding it: a file descriptor, buffers, and a slot in the kernel's table, at both ends of the link. A layer four balancer needs almost none of the request. It reads addresses and protocol, forwards packets, and keeps only a mapping from each connection to a backend. A layer seven balancer parses the message, so it can route by path or header, but it must buffer enough of each request to find that field, for every request in flight. Memory per request rises, and an extra hop adds latency. Round robin assumes every request costs the same and keeps no state. Least connections, by contrast, must count in-flight requests on the balancer itself, updating the count on every open and close.

The abstraction hides a failure in the reconnects. Take a fleet of server-sent event clients. Automatic reconnect is the feature that makes SSE attractive, and it is also the trap. When a backend restarts, every client attached to it reconnects in the same instant. That thundering herd can knock the backend over again, and the retries sustain the collapse. Consistent hashing limits the damage to one slice of the ring, but that slice moves as a block, so its clients land together on the neighbouring server and make it a hot spot. Two balancers running active-active sound like redundancy, yet each keeps its own response-time averages, so a stateful policy decides on half the evidence.

Start by computing concurrent connections as arrival rate times hold time, because that number sizes memory and file descriptors before any other choice. Keep a connection open only when events arrive often enough that re-establishing costs more than idling; for rare events, use long polling and accept the handshake. Route at layer four unless the decision needs the payload, and buffer for layer seven only where the routing field justifies it. Hash when backends cache per-client state, and choose consistent hashing so a resize moves one slice instead of everything. Jitter every reconnect delay across a randomised window. Run two balancers in active-passive, with heartbeats through a coordination service, so the state is held once rather than split.

orders of magnitude
Direct links
N x M

Every client wired to every backend. Each new client adds one socket per backend.

Brokered links
N + M

Each side holds one link to the middle, so growth is linear.

Connections per node
10,000

The rough ceiling where the connection table starts limiting a single machine.

Hold time
minutes

Long-lived sessions multiply arrival rate into open sockets, so concurrency tracks connected users.

field note

The naive design scaled by adding application nodes and letting every client connect to them directly. More clients meant more servers, and that looked like the whole problem. Each node took requests, and the cost of a request seemed to be CPU and bandwidth.

The wall was connection state. Each open connection costs memory and a file descriptor on the server, and long-lived streams turn ten thousand users into ten thousand open sockets on one node. The limit arrived long before the CPU was busy, which is why the naive count of requests misled everyone.

Load balancers, connection multiplexing and event-driven servers all attacked that same number. The balancer terminated client sockets at the edge, multiplexing reused upstream links, and event-driven servers handled many open sockets in one process instead of one thread each. The C10K document collects these practical problems of serving ten thousand concurrent connections from one machine.

The lesson is that the scarce resource was per-connection state, not bandwidth. That is why the design changed the moment connections became long-lived: a short request could be served and forgotten, while a held stream kept its state for the whole session.