Animation10 min

Load Balancing

Distributing traffic and surviving server failures.

A load balancer spreads incoming requests across multiple servers so no single one is overwhelmed — and so dead servers stop receiving traffic. It is the first box you draw after the client in nearly every design, which means an interviewer will ask what yours actually does.

In the animation, request dots flow from many clients into the diamond-shaped load balancer, which deals them out round robin — one to each server in turn, the simplest algorithm. Other options exist: least connections sends work to the least busy server, and hashing pins a client to a specific server.

The key moment to watch: one server turns red after failing a health check — a periodic "are you alive?" ping from the load balancer. The stream of dots visibly re-routes around the dead server, and no requests are lost. Health checks are what make horizontal scaling safe: machines can die (or be replaced during a deploy) without users noticing.

One distinction worth remembering: Layer 4 balancers route on network-level info (TCP connections) and are fast — the right choice for long-lived WebSocket connections. Layer 7 balancers read the HTTP request itself and can route by path or header. Know which yours is and why.