Load Balancing Algorithms and Strategies
Load Balancing
Load balancing is an essential part of building distributed systems, where network traffic is spread across multiple servers to efficiently manage requests and prevent overload.
Types of Load Balancing Algorithms
Press enter or click to view image in full size

1. Static Algorithms
Static Algorithms distributes requests based on predefined rules without considering real time server information. Static Algorithms are simpler to implement but they can have some limitations.
1.1 Round Robin
Requests are assigned to servers in a sequential loop (e.g., S1 → S2 → S3 → S1 → S2 → S3).
It is easy to implement and works well when all servers have similar capacities.
Press enter or click to view image in full size

Round Robin
Round Robin Edge Case
Get Anubhav Ghosh’s stories in your inbox
Join Medium for free to get updates from this writer.
Subscribe
Remember me for faster sign in
Consider a scenario where we have two servers with different CPU capacities:
Server 1 (S1) has 4 CPUs
Server 2 (S2) has 1 CPU
Using Round Robin, requests are distributed equally, even though S2 is weaker, potentially overloading it. This is a key limitation of basic Round Robin.
1.2 Weighted Round Robin
To address the unequal server capacity issue, Weighted Round Robin assigns a weight to each server based on criteria such as CPU power, memory, or network bandwidth.
A server with a higher weight receives more requests compared to a lower-weight server.
Press enter or click to view image in full size

Edge Case for Weighted Round Robin
The weights must be manually configured, which can be challenging in large or dynamic systems where server capacity changes frequently.
1.3 Hash-Based Load Balancing
Requests are assigned to servers based on a hash function applied to a request attribute, such as IP address, session ID, or URL.
This method ensures that the same client request is always directed to the same server, providing session persistence.
Press enter or click to view image in full size

2. Dynamic Algorithms
Dynamic Algorithms uses real time information to efficiently distribute requests to the server.
2.1 Least Connection
Load balancer keep track of the active connections to the server and then distributes the load to the server with the least number of connection.
Edge Case
Press enter or click to view image in full size

Consider we have 2 servers having 4 and 1 CPU respectively and the server having 4 CPU has 2 connection and server having 1 CPU has 1 connection then the load balancer will send request to the server with 1 CPU that will overload the server.
2.2 Weighted Least Connection
Weighted Least Connection is an advanced load balancing algorithm that improves upon the Least Connection method by considering both:
The number of active requests a server is currently handling.
The assigned weight of each server, which represents its capacity (e.g., CPU power, memory, or bandwidth).
Press enter or click to view image in full size

How It Works
The load balancer tracks the number of active requests each server is handling.
Each server has a weight assigned based on its capacity.
When a new request arrives, it is assigned to the server with the lowest (active connections ÷ weight) ratio.
This ensures that higher-capacity servers handle more requests, preventing overload on weaker servers.
Comments
Leave a comment
Enjoyed this?
Subscribe to get new posts from Anubhav Ghosh in your inbox.