← Lessons

quiz vs the machine

Silver1080

Networking

Load Balancing Algorithms

How a balancer chooses which backend serves the next request.

4 min read · intro · beat Silver to climb

What a load balancer decides

A load balancer spreads incoming requests across a pool of backend servers. The interesting part is the algorithm that picks which server handles each request, because a bad choice creates hot spots while others sit idle.

Common algorithms

  • Round robin sends each new request to the next server in a fixed rotation. It is simple and fair when servers and requests are uniform.
  • Weighted round robin gives stronger machines a larger share by repeating them more often in the rotation.
  • Least connections routes to the server with the fewest open connections right now, which adapts when some requests run long.
  • Least response time combines active connections with measured latency to favor the snappiest backend.
  • IP hash maps a client address to a server so the same client tends to land on the same backend, useful for sticky sessions.

Round robin assumes requests cost about the same. When they do not, least connections usually balances better because it reacts to real load instead of just counting turns. Sticky strategies trade even distribution for session affinity.

Key idea

Round robin is fair when work is uniform, but least connections adapts to uneven request costs.

Check yourself

Answer to earn rating on the learn ladder.

1. When does least connections outperform round robin?

2. What does IP hash primarily provide?