Load Balancing Algorithms
What you'll learn: You'll discover the four most common methods load balancers use to decide which server receives the next incoming request.
The Core Challenge
Once a load balancer receives traffic (Layer 4 or Layer 7), it needs a decision rule for routing each request to one of several healthy backend servers. That rule is called a load balancing algorithm or distribution method.
Four Common Algorithms
Round Robin
Each new request goes to the next server in line, cycling through all targets like dealing cards. Simple and fair when all servers have equal capacity.
Analogy: Like a group taking turns washing dishes—everyone gets their turn in order.
Least Connections
Sends traffic to the server currently handling the fewest active connections. Great when requests vary significantly in processing time.
Analogy: Choosing the shortest checkout line at the grocery store.
Weighted Distribution
Assigns each server a weight (number) based on capacity. Servers with higher weights receive proportionally more traffic.
Example: Two servers—one with weight 3, another with weight 1—would receive traffic in a 3:1 ratio. Useful when you have different-sized instances.
IP Hash
The load balancer hashes the client's IP address and uses that result to consistently route that client to the same server. Creates "sticky sessions" without cookies.
Analogy: Assigning students to classrooms based on their last name—same student always goes to the same room.
Choosing the Right Algorithm
Your algorithm choice depends on your application's needs:
- Stateless apps? Round robin works well.
- Long-running connections? Least connections.
- Mixed server sizes? Weighted distribution.
- Need session persistence? IP hash.
Key Takeaway: Load balancing algorithms determine how traffic is distributed across healthy targets, with round robin, least connections, weighted distribution, and IP hash offering different trade-offs for traffic routing decisions.