Least Connections Algorithm
What you'll learn: How the Least Connections load balancing algorithm routes traffic based on active connections rather than simple rotation.
The Core Idea
While Round Robin and Weighted Round Robin distribute requests in a predetermined pattern, the Least Connections Algorithm makes routing decisions based on real-time server load. It directs each incoming request to whichever backend server currently has the fewest active connections.
Why This Matters
Not all requests complete in the same amount of time. Imagine a customer service desk with multiple representatives:
- Round Robin would send every 5th customer to desk #5, regardless of whether that desk is still helping someone from 30 minutes ago
- Least Connections checks which desk has the fewest people waiting and sends the next customer there
This approach prevents overwhelming servers that are handling long-running requests (like video uploads, database queries, or file downloads) while others sit idle.
When to Use Least Connections
This algorithm shines when your application has:
- Long-lived sessions (WebSocket connections, streaming)
- Variable request duration (some queries take 10ms, others 10 seconds)
- Persistent connections (database connection pools, chat servers)
The load balancer tracks how many active connections each server maintains and continuously routes new requests to the least busy server.
The Trade-off
Least Connections requires the load balancer to maintain connection state and perform lookups for every routing decision—slightly more overhead than simple Round Robin, but worth it when connection duration varies significantly.
Key Takeaway: The Least Connections Algorithm routes requests to the server with the fewest active connections, making it ideal for applications with long-lived or variable-duration sessions where simple rotation would create imbalanced load.