1 min read

Load Balancing


Load balancing is a technique used to distribute workloads across multiple servers to improve performance by optimizing the resource utilization.

Strategies

Round Robin

It done sequentially there is no logic to this, each request is assigned to the next available server in a circular order. This strategy distributes the load evenly across all servers. Example we have three servers A,B and C; first request will be handled A, then B and then C, this will go on in a circular pattern.

Least Connections

Server which has the least active connection at the time of request, will handle the coming request. This can help improve the overall performance of the system by directing requests to the most responsive servers

IP Hash

IP address of the client is used to determine which server should handle the request. This ensures that requests from the same client are always directed to the same server, which can help maintain session state and improve in memory cache efficiency.

Weighted Round Robin

It's basically a RR, but you need to configure a weight, example you have three servers A, B and C with weights 3, 2, 1 respectively. So, first three request will go to A, next two to B and last one request to 1. Weight can be decided based on the server size/capacity.

URL Hash

A hash function is applied to the request URL to generate a hash value, which is then used to select an available server. The advantage of this approach is that requests for the same URL are always directed to the same server.

Apart from this there are other strategies to like Least response time, Dynamic load balancing etc.