topics / traffic-routing
Load Balancer
Round robin, least connections, weighted and IP-hash routing across a pool of backends. Break one on purpose and watch the routing decision change.
What a load balancer actually does
A load balancer sits between clients and a pool of backend servers. Every incoming request has to be assigned to exactly one backend — that assignment rule is the “algorithm”. Switch it in the simulation and watch the same traffic pattern get distributed completely differently.
Routing algorithms
Round robin
Least connections
Weighted round robin
IP hash
URL hash
Random
Failure modes, and what the load balancer should do about each
- Backend goes down— the LB has to detect it (usually via failed health checks) and stop routing to it. In the simulation this happens automatically after 3 consecutive failed requests, mirroring how a real health check takes a few misses before it declares a backend dead. Toggle “Kill” to simulate a hard crash directly.
- Backend is slow— the backend still responds, just later. This doesn't trip health checks on its own, which is exactly why it's dangerous: a slow backend keeps receiving traffic (especially under round robin) and its request queue backs up.
- Backend returns errors— the connection succeeds but the response is a failure (5xx). This counts against the backend's consecutive-failure count the same as a hard failure would.
- Backend is overloaded — it has hit its own connection limit and starts refusing new connections outright, rather than queuing them. Notice this can also happen organically in the simulation if too many concurrent requests land on one backend — try IP hash during a DDoS and watch a handful of unlucky backends drown while others sit idle.
- Timeout— the backend never responds at all. A real LB waits until its timeout budget expires, then gives up and — if it's configured to — retries the request on a different backend. That's what the simulation does: one retry, then a final timeout if the retry also fails.
DDoS traffic
A denial-of-service flood looks different from normal traffic in two ways the simulation models directly: a much higher request rate, and requests coming from many distinct (often spoofed) source addresses rather than a handful of regular clients.
The rate alone is often enough to push backends into organic overload regardless of algorithm. But the algorithm still matters: round robin and least connections spread the flood evenly across every backend, while IP hash — precisely because it's deterministic — can end up concentrating a disproportionate share of the flood onto whichever backends the flood's source hashes land on. A load balancer alone doesn't stop a DDoS; rate limiting and upstream filtering do that. What the LB decides is how gracefully the pool degrades while it's happening.
Layer 4 vs. Layer 7 load balancing
This simulation models Layer 7 behaviour: the load balancer is aware of individual requests, can inspect them, and decides per-request where traffic goes. Real load balancers actually split into two distinct categories based on which layer of the network stack they operate at:
| Layer 4 (transport) | Layer 7 (application) | |
|---|---|---|
| Sees | IP address and port only | Full request: headers, path, cookies, body |
| Routing granularity | Per TCP/UDP connection | Per HTTP request |
| Can route by URL path | No | Yes (e.g. /api → service A, /static → service B) |
| Overhead | Very low — just forwards packets | Higher — has to terminate and parse the request |
| Typical use | Raw throughput, non-HTTP protocols, DDoS-scale traffic | Content-aware routing, A/B testing, sticky sessions |