Clients need one stable entry, not a server inventory#
You add a second application server, then a third. Clients need a way to reach a healthy instance without learning which machines exist. A load balancer accepts traffic and selects a target according to health, routing policy, and available request information.
The workload should influence the algorithm#
| Algorithm | Useful when | Watch for |
|---|---|---|
| Round robin | Targets and requests are broadly similar | Long requests can create uneven in-flight work |
| Weighted round robin | Targets have different capacity or are being introduced gradually | Weights become another control to tune |
| Least connections / outstanding requests | Request duration varies | Connection count may not equal actual cost |
| Hash-based routing | Affinity by client or key matters | Skew and target changes can move load |
Consistent hashing reduces remapping when targets change, but hot keys and uneven work still require explicit handling.
Health checks remove targets; draining protects in-flight work#
Periodic checks mark a backend unhealthy and restore it after recovery criteria are met. A shallow check can pass while a critical dependency is broken; a deep check can remove every backend during a shared dependency failure. Thresholds, timeouts, startup readiness, and connection draining shape the behavior.
Sticky sessions, L4, and L7#
Sticky routing sends a client back to the same target. It can simplify local session state, but backend failure loses affinity and uneven clients produce uneven load. Shared or external session state often makes application replicas easier to scale, though stickiness is not inherently wrong.
An L4 balancer routes from transport information such as IP and port. An L7 balancer understands HTTP information such as hostname, path, or headers, enabling rules like:
/api/payments/* → Payment Service
/api/users/* → User ServiceL7 adds application-aware flexibility and processing; L4 can operate with less application interpretation.
The balancing layer also needs redundancy#
If every request passes through one load-balancer process, it can become a single failure point. Production deployments use redundant instances and health/failover mechanisms, with DNS, virtual addresses, or managed infrastructure supplying the reachable entry point.
Use these prompts to extend the design. The useful answer is a reasoned change, not a memorized sentence.
- What happens when a backend fails?
- How are stateful sessions handled?
- When is L4 preferable to L7?
- How does the balancing layer avoid becoming a single point of failure?
- How would routing change across regions?
Related practice problems
Use the manifest-backed prompts below to apply this lesson in a complete design.
- How Elastic Load Balancing worksAWS Documentation