advanced
Load balancing
Distribute traffic by health, locality, load, sticky needs, retries, and failure behavior at each layer.
Load balancers distribute requests across healthy backends using round-robin, least connections, weighted routing, or consistent hashing. Layer-4 balancers route TCP; layer-7 balancers understand HTTP paths, headers, and TLS. Sticky sessions pin users to one instance when local state exists — prefer external session stores instead.
Place load balancers at the edge, between services, and in front of databases via connection poolers. Configure health checks, graceful drain on deploy, and retry policies that avoid amplifying failures.
On interviews: compare L4 versus L7, explain when sticky sessions are needed, and describe health check failure behavior.
Common pitfalls: retry storms through the LB; unequal load when connections are long-lived; no zone-aware routing in multi-AZ setups.
The trade-off is flexibility versus complexity—know when the simpler path is enough.
Checklist:
- Choose LB layer and algorithm for workload.
- Configure health checks and drain periods.
- Avoid unnecessary session stickiness.
- Plan cross-AZ and failover behavior.