← Back to Glossary

Load Balancing Algorithms

by Iwan Price-Evans on Load Balancing • May 6, 2022

Intelligent load balancers determine how to distribute requests to servers in a cluster, or to locations or clouds in a multi-location network. Load balancer functions can use different load balancing algorithms to distribute requests in different ways. Here we'll highlight some commonly used load balancing algorithms and their suitability for certain scenarios. 

What are the algorithms used in load balancing?

Here is a summary of load balancing algorithms.

  • Road-robin load balancing
  • Weighted round-robin load balancing
  • Least connections load balancing
  • Weighted least connections load balancing
  • Random load balancing
  • IP Hash load balancing

Types of load balancing algorithms

Round-robin load balancing

Round robin is the most widely used load balancing algorithm because it's easy to implement and easy to understand. It is suited to server clusters that contain servers that have identical specifications.

So how does round-robin load balancing work? Say you have two servers waiting for requests behind a load balancer. When the first request arrives, the load balancer forwards it to the first server. When a second request arrives, likely from a different client, it's forwarded to the second server. The second server is the last in this cluster, and so the next request that's received, the third request, is forwarded to the first server. The next request, the fourth, is forwarded to the second server, and so on. With a round-robin algorithm, requests are processed cyclically by the load balancer.

The method is very simple but isn't suitable for all scenarios. If the servers in the cluster have different resource capacities, such as CPU and memory, the load balancer will treat the servers equally. Therefore, the load balancer will not share the requests based on the server's capacity, and this gives rise to the possibility of lower capacity servers in the cluster getting overloaded. This is why round-robin is suitable for use with clusters of identical servers.

Weighted round-robin load balancing

An alternative to standard round-robin load balancing is weighted round-robin. Weighted round-robin load balancing can receive and forward requests to servers of differing capacities. 

Weighted round-robin still uses a cyclical approach to processing requests but it can assign a greater number of requests to servers with higher capacity.

A weighted round-robin load-balancing algorithm is setup up by assigning weights to each server node when you create the cluster. Higher specification servers are assigned a greater weight. Weights are usually specified based on equivalent server capacities. For example, if server one has three times more capacity than server two it can be assigned a weight of three, and server two a weight of one. When the first three requests arrive they are forwarded to server one, and the fourth request is forwarded to server two. The same cyclical approach is followed for subsequent requests: the fifth, sixth and seventh requests will go to server one, and the eighth to server two.

Server capacity isn't the only factor used when this algorithm decides how to forward requests. You may want to configure a weighting based on business requirements. For example, if one of the server nodes is running business-critical applications, the load balancer can be configured to ensure fewer requests are forwarded to that node so that it doesn't get overloaded.

Least connections load balancing

Even if each server node in a cluster has identical specifications it is possible for a single node to get overloaded faster than another. For example, this can be because clients stay connected to server one longer than clients connecting to server two. This means that the number of concurrent connections to server one gets higher and higher, while server two's connections remain the same as its clients connect and disconnect over the same time period.

In this scenario, a least connection load balancing algorithm is a good solution. Least connections load balancing will consider the number of connections each server node is handling before it forwards more requests. When a client requests a connection, the load balancer will determine which server has the least number of current connections and forward the request to that server.

Weighted least connections load balancing

The weighted least connections algorithm is similar to the weighted round-robin algorithm in that it introduces a weight to the server node based on its capacity.

Similar to the weighted round-robin algorithm, server nodes must be assigned a weight when you create the cluster. A weighted least connection load balancer will take into consideration the weight, or capacity, of each server, and the number of concurrent connections to each server before assigning additional requests.

Random load balancing

Client requests can be forwarded to servers randomly using a random number generating algorithm. If a load balancer receives a large number of requests, a random algorithm is able to distribute these requests more evenly to the server nodes. 

Similar to a round-robin load balancer, a random load balancer is suited to server clusters that have identical server specifications.

Resource based load balancing

Resource based load balancing takes into account the available resources on every server in the cluster. This method uses an agent on every server that reports server and application telemetry to the load balancer. The load balancer distributes new requests to the servers with the best health check status. Server and application health can be based on telemetry metrics such as the number of connections, latency, error count, spare capacity, and more.

IP Hash load balancing

An IP hash algorithm uses a mathematical function to convert incoming request source and destination IP addresses into a unique hash key. The load balancer will then use this hash key to assign the request to a specific server.

This type of algorithm is suited to client connections that, if broken, must re-connect to the same server. If the connection is broken the hash key can be regenerated to allow the client to reconnect to a session that is still active.

What load balancing method is the best?

Choosing the best load balancing method depends on your application architecture and what you want to prioritize. However, as a general principle, the best load balancing method is the one that allows you to achieve the best reliability, performance, and user experience (UX) for your application.

Load balancing algorithms with more contextual awareness of servers, applications, real-time telemetry and health checking, and user sessions, are most likely to deliver on those goals of reliability, performance, and UX.

In that regard, a combination of weighted least connections, resource based, and IP hash load balancing is likely the best.

When choosing a load balancer, look for one that supports the right mix of load balancing algorithms providing the most contextual awareness and intelligence.