Design the load balancing tier in front of a large service. What layers do you use, and how do you handle failures and scale?
Sketch your own answer first, then compare it with the one below.
A strong answer
A common shape has two layers. A network-level layer (layer 4) spreads connections across a fleet of application-level proxies (layer 7), and those proxies route individual requests to backends.
Points to cover:
- Layer 4 is cheap per packet and can spread flows with consistent hashing, so the same connection keeps landing on the same proxy, and adding a proxy disturbs few flows.
- Layer 7 proxies can inspect requests, terminate TLS, retry, and apply request-level strategies such as power of two choices.
- Health checks, with both active probes and passive observation of errors, to remove sick backends quickly and bring them back gradually.
- Draining for deploys, so in-flight requests finish.
- Overload behaviour: limits, load shedding, and retry budgets so retries do not amplify an outage.
- No single balancer is a single point of failure, so use redundancy and spreading by anycast or equivalent routing.
Before drawing boxes, pin down the traffic shape and the failure domains, and decide what you would measure to know the tier is healthy.
Sources
- Daniel E. Eisenbud, Cheng Yi, Carlo Contavalli, Cody Smith, Roman Kononov, Eric Mann-Hielscher, Ardas Cilingiroglu, Bin Cheyney, Wentao Shang, Jinnah Dylan Hosein (2016). Maglev: A Fast and Reliable Software Network Load Balancer.
- Michael Mitzenmacher (2001). The Power of Two Choices in Randomized Load Balancing.