Course contentsShow
← System Design
Lesson 88 of 1,9193. Load BalancingFree lesson

Weighted Least Connections

Combines least connections with server weights, accounting for both capacity and current load.

Weighted Least Connections

What you'll learn: How to route traffic to servers based on both their capacity and current workload.

The Core Idea

Weighted Least Connections combines two concepts you've already learned: Least Connections (routing to the server with fewest active connections) and Weighted Round Robin (accounting for different server capacities). This hybrid algorithm directs traffic to servers based on a ratio that considers both how busy each server currently is and how powerful it is.

How It Works

Instead of simply choosing the server with the fewest connections, the load balancer calculates a score for each server by dividing its current connections by its assigned weight. The server with the lowest ratio receives the next request.

Formula: score = current_connections / weight

Example in Plain English

Imagine you have two servers:

  • Server A: Weight = 3, Current connections = 6 → Score = 6/3 = 2
  • Server B: Weight = 1, Current connections = 1 → Score = 1/1 = 1

Even though Server A has more connections (6 vs 1), Server B gets the next request because its score (1) is lower than Server A's (2). Server A can handle 3x more load, so it can sustain more connections before becoming overloaded.

When to Use This

This algorithm shines when you have heterogeneous servers (different hardware specs) and requests that hold connections for varying durations. It dynamically adapts to both server capacity differences and real-time load patterns.

Key Takeaway: Weighted Least Connections routes traffic by comparing the ratio of current connections to server capacity, ensuring powerful servers handle proportionally more load while avoiding overloading weaker ones.