Based on our experience, we believe Round Robin may not be an effective load balancing algorithm, because it doesn’t equally distribute traffic among all nodes. You might wonder, how is this possible?
How Does Round Robin Algorithm Work?
Round Robin algorithm sends requests among nodes in the order that requests are received. Here is a simple example.
Let’s say you have three nodes: node-A, node-B and node-C.
- First request is sent to node-A.
- Second request is sent to node-B.
- Third request is sent to node-C.
The load balancer continues sending requests to servers based on this order. It makes it sound like traffic would get equally distributed among the nodes. But that isn’t true.
What is the Problem with Round Robin Algorithm?
Let’s pick up a simple example: Let’s say you launched your web application with a load balancer and it has two nodes (node-A, node-B) behind it. The load balancer is configured to run with Round Robin algorithm, and sticky-session load balancing is enabled. Let’s say 200 users are using your application currently. Since the Round Robin algorithm is enabled in load balancer, each node will get 100 users requests.
A few minutes later, you are adding node-C. Now, an additional 100 users start using the application. Since it’s Round Robin algorithm, load balancer will distribute new users’ requests equally to all 3 nodes (i.e., 33 users request to each node). But remember node-A and node-B is already processing 100 users requests each. So now node-A and node-B will end up processing 133 users requests each (i.e., 100 original users requests, plus 33 new users requests), whereas node-C will process only 33 (new) users requests. Now, do you see why Round Robin isn’t equally distributing the traffic?
In the Round Robin algorithm, the older nodes in the pool will always end-up processing more requests while newly added nodes will end up processing less amount of traffic. The load is never evenly distributed. For maintenance, patching and installation purposes, you have to continually keep adding and removing nodes from the load balancer pool. If you instrumented auto-scaling in place it gets worse, because in auto-scaling nodes are more dynamic. They get added and removed even more frequently.
What Algorithm to Use?
There are a variety of load balancing algorithms: Weighted Round Robin, Random, Source IP, URL, Least Connections, Least Traffic, Least Latency. Given the shortcoming in Round Robin, you can consider trying other choices. One choice you may consider is: Least Connections algorithm. As per this algorithm, the node which has the least number of connections will get the next request. So, as per our earlier example, when 100 new users start to use the application, all new user requests will be sent to node-C. Thus, load will be equally distributed among all nodes.