Skip to the guide

Load-balancing algorithms and health checks

IntermediateConcept3 pages

A load balancer makes two decisions all day: which server gets the next request, and which servers are healthy enough to get any. Interviewers usually ask through a story: one slow server, or a health check that took the whole site down.

Handing out exam papers

An exam has finished and a teacher has 500 papers to share among ten markers. She could deal piles in turn, one to each marker, round and round. That's fair until one marker is slow: dealt in turn, he keeps getting piles while his desk overflows. She could look at every desk and give the next pile to whoever has the smallest stack. Or, quicker, glance at two desks at random and give it to the smaller of the two. Every few minutes she also asks each marker "still with us?", and stops giving piles to anyone who doesn't answer, or whose papers keep coming back unmarked.

  • the teacher, the markers and the piles → the load balancer, the servers and the requests
  • dealing in turn → round robin
  • the smallest stack → least outstanding requests (or least connections)
  • two desks at random → power of two choices
  • "still with us?" → an active health check
  • noticing a marker's papers coming back unmarked → a passive health check, judged from real traffic