Load Balancer and its Algorithms
What is Load Balancer?
A load balancer is a device or software service that distributes application traffic across multiple servers. Its main goal is to ensure that no single server is overwhelmed, thus improving overall performance, reliability, and availability of applications. Load balancers play a crucial role in handling high traffic loads, preventing server downtime, and scaling applications.
Types of Load Balancer:
- Network load balancer (L4 balancer) — It reads TCP/UDP protocol. IP address, src& destination. This is faster.
- Application load balancer (L7 balancer) — It reads from header, session, cookies, cache, response. This is much more advanced.
Types of Network load balancer Algorithm:
- Static Algorithm:
a. Round Robin
b. Weighted Round Robin
c. IP Hash - Dynamic Algorithm:
a. Least Connection
b. Weighted Least Connection
c. Least Resposne time
1.a. Round Robin :
The Round Robin algorithm is a simple static load balancing approach in which requests are distributed across the servers in a sequential or rotational manner.
Advantages:
- Very easy to implement.
- Equal load distribution to all the servers.
Disadvantages:
- One server with high capacity and another with low capacity, both will be treated as same.
- Chance that low capacity server will go down because of overload of request.
Cons:
If there are two servers, Server A and Server B, and we distribute the requests equally between them, Server B may become overloaded if it takes 10 times longer than Server A to process a request.
This is where weighted round robin comes into play.
1.b. Weighted Round Robin:
The Weighted Round Robin algorithm is also a static load balancing approach which is much similar to the round-robin technique.
The only difference is, that each of the server in a list is provided a weighted score. Depending on the weighted score the request is distributed to these servers.
Advantages:
- Low capacity server, will get saved from receiving the large number of request.
- Easy to implement as Weights are static, no dynamic computation.
Disadvantages:
- If request have different processing time, then its possible that low capacity server get high processing request and get overburdened.
1.c. IP Hash:
The Source IP Hash Load Balancing Algorithm is a method used in network load balancing to distribute incoming requests among a set of servers based on the hash value of the source IP address. This algorithm aims to ensure that requests originating from the same source IP address are consistently directed to the same server.
If the load balancer is configured for session persistence, it ensures that subsequent requests from the same source IP address are consistently directed to the same server. This is beneficial for applications that require maintaining session information or state.
Advantages:
- Good for use caes, where same client needs to connect to the same server.
- Easy to implement
Disadvantages:
- Can’t ensure equal distribution
- If client request is coming through PROXY, then all the clients will have the same source IP address, and this will overload one server.
2.a. Least Connection:
Least connection load balancing is a dynamic load balancing algorithm where client requests are distributed to the application server with the least number of active connections at the time the client request is received.
Advantages:
- Dynamic, as it consider the load on each server, so chance of over burdened of one server is less when each server has equal capacity.
Disadvantages:
- TCP connections can be ACTIVE but possible have no traffic. So, purpose is failed.
- No Difference between low capacity and hight capacity server. Chance that low capacity will get over burdened.
2.b. Weighted Least Connection/Resource-based Algorithm:
Weighted least connection is a load balancing algorithm that distributes requests to application servers based on their weight and number of active connections. It’s used to efficiently distribute traffic to the server that can best handle the request.
Advantages:
- Dynamic, as it consider the load on each server, so chance of over burdened of one server is less when each server has equal capacity.
Disadvantages:
- Complex Implementation: Requires continuous monitoring of server resources, which can add complexity.
- TCP connection can be active but have no traffic.
2.c. Least Response time:
The Least Response method is a dynamic load balancing approach that aims to minimize response times by directing new requests to the server with the quickest response time.
If two server have same response time then, it follows Round robin.
Advantages:
- Least Response time technique, helps to increase the availability time of servers.
Disadvantages:
- Too much computation logic is required.
Finishing off with the article here. I really hope, I made the article worth your while and you learned a great deal from it🥳
Let’s connect on LinkedIn