Load balancer strategies
A load balancer doesn’t “split traffic evenly”: it applies a rule, and the right rule depends on how your requests behave.
Notes
- 1.There are two common layers, named after the OSI model. At L4 (transport layer) the decision uses IP, port and protocol (TCP/UDP) without reading the HTTP content: it is faster and serves TCP/UDP in general. At L7 (application layer) the balancer reads method, path, headers and cookies: you can route /api and /static to different targets, terminate TLS and run canaries.
- 2.Round robin sends each new request to the next server in the list. It works when machines and per-request cost are similar; when they aren’t, weighted round robin steps in.
- 3.Least connections sends the next request to whoever has the fewest open connections. It fits long or irregular connections (WebSocket, streams). Few connections doesn’t mean low CPU.
- 4.IP or key hashing tries to send the same client to the same server. Plain modulo (hash % N) remaps almost everything when a server joins or leaves; consistent hashing cuts that to roughly 1/N of the keys.
- 5.Sticky sessions are a patch for state held in server memory: they make deploys, failover and distribution harder. The healthier design is stateless servers with sessions in a shared store.
When to use
Start with L7 and round robin (or least connections, if request duration varies) when traffic is HTTP and backends can be stateless. Move to L4 when the protocol isn’t HTTP, when you need TLS passthrough or when raw throughput is the priority. Use consistent hashing when affinity helps a local cache.
Trade-offs
Sticky sessions as a long-term architecture charge you when scaling, draining a node or surviving a machine failure. And no algorithm replaces health checks and connection draining when taking a server out.
References
Sheet
01 / 03
Type
concept
Category
System design
Level
Intermediate
Tags
infra · traffic · reliability
Published
[DATE]
Address
fabricioereche.dev/en/concepts/load-balancer-strategies/