Skip to content
MetaStack
All cards
Fundamentalsconceptdifficulty 1/3#load-balancing-algorithms

Name the common load-balancing algorithms and explain when you would pick each one.

Key points

  1. Round robin and weighted round robin for homogeneous, stateless serversIn plain words: Take turns, giving stronger servers extra turns, when servers are alike and remember nothing between requests
  2. Least connections (or least outstanding requests) when request cost variesIn plain words: Send the next request to whichever server is least busy when some requests take much longer than others
  3. Consistent hashing or IP hash when you need the same client to hit the same serverIn plain words: Use a rule based on the caller when the same caller should keep landing on the same server
  4. Health checks remove unhealthy backends from rotation regardless of algorithmIn plain words: Whatever the rule, keep checking each server and stop sending to any that fail the check
  5. Mentions that the balancer itself must be redundant to avoid a single point of failureIn plain words: The thing sharing out the traffic needs a backup too, or it becomes the one part that takes everything down

Model answer

A load balancer spreads incoming requests across a pool of servers so that no single server becomes a bottleneck and the pool can grow or shrink without clients noticing.

Static algorithms decide without looking at live server state:

  • Round robin hands each request to the next server in the list. Simple and fair when every request costs about the same.
  • Weighted round robin sends proportionally more traffic to bigger servers.
  • Hash-based (IP hash, URL hash, consistent hashing) maps a key to a server so the same key keeps landing in the same place, which helps local caches and sticky sessions.

Dynamic algorithms use feedback:

  • Least connections picks the server with the fewest open connections. Good for long-lived or uneven requests.
  • Least response time adds latency into the choice.
  • Power of two choices picks two servers at random and uses the less loaded one; it gets most of the benefit of least connections without global knowledge, which matters for distributed balancers.

Whatever the algorithm, pair it with health checks so failing servers are removed quickly, and run the balancer itself as an HA pair or behind DNS/anycast so it is not the single point of failure you just moved.

Likely follow-ups

  • How would you handle one server that is twice as powerful as the others?
  • What breaks if you use IP hash behind a corporate NAT?

References