Types of Load Balancing Algorithms
Follwoing is the load balancing algorithms:
-
Round Robin: Requests are distributed sequentially without taking into account the current server load & it’s capacity. Each server can have different computing resources and the ones that have less compute can become overloaded with requests.
-
Weighted Round Robin: In this each server have a weight representing their processing power. Requests are distributed based on the weight score, so server with high score will receive more requests compared to other server and does not consider current load of the server.
-
Least Connections: It considers current load of the server and requests are distributed to servers with least not of active connections.Load balancer maintains a state of the server connections and has to perform calculations to determin the server with least connection and this increases overhead on the load balancer itself.
-
IP Hash: Generate a hash value of the client IP address and based on the hash value allocate the request to a specific server. All request from same IP will be forwarded to the same server since the ip hash value generated will be same for all requests.
-
Random: Randomly distrubutes the requests to the servers using random number generator. Does not considers server capacity or current state and hence some server can receive more request than the other because of the random nature.
| Algorithm | Description |
|---|---|
| Round Robin | Requests are distributed sequentially. |
| Weighted Round Robin | Servers get proportionally more traffic based on their capacity. |
| Least Connections | New requests go to the server with the fewest active connections. |
| IP Hash | Client IP is hashed to determine the server. |
| Random | Requests sent to a randomly chosen server. |
Where can we put load balancers?
Wherever we have multiple servers to distribute the traffic load we can put a load balancer their.
- Client and frontend web servers.
- Between frontend web server and backend servers.
- Between backend application server and cache servers.
- Between backend application server and db servers.
- Between cache servers & db servers.
- Between backend application & websocket servers.
And many more places in distributed systems.