← The table of explainers · 4 min read

Explainer · Load Balancing≈ in everyday life

A host seating restaurant guests.

One server can only handle so much before it falls over, so don't send everyone to the same one.

The Docerity teamEngineers who explain for a living
  • Infrastructure
  • Networking

The problem: one server, all the traffic

If every visitor to your app is handled by a single server, that server eventually runs out of room (CPU, memory, open connections) while everything else you've paid for sits idle. Past a certain point, it doesn't get slower gracefully; it stops responding at all.

What a load balancer actually does

A load balancer sits in front of a group of identical servers and decides, for each incoming request, which one should handle it, based on who's least busy, or simply taking turns. The client never talks to a specific server directly; it talks to the load balancer, which routes the request onward.

A few common strategies

Round robin just takes turns, server one, two, three, one again. Least connections sends the next request to whichever server currently has the fewest active requests. Fancier setups factor in server health, response time, or geography.

The catch: state

If a server remembers something about you between requests, like your logged-in session, and the next request lands on a different server that doesn't know you, things break. This is why systems either keep servers stateless (session data lives elsewhere, shared) or use “sticky sessions” to keep a user on the same server.

Written by

The Docerity teamEngineers who explain for a living

One explainer, now and then.

When a new piece goes out, it comes to you. Nothing else, and one click to leave.

Or follow along by RSS.