What are Load Balancers?
Tags: cloud, webdev
Published: 2023-04-10 03:51:49

Load Balancer helps in distributing network traffic across multiple servers. This ensures no single server bears too much demand. By spreading the work evenly, load balancing improves application responsiveness, availability of applications, and websites for users.

Typically a load balancer sits between the client and the server accepting incoming network and application traffic and distributing the traffic across multiple backend servers. By balancing requests across multiple servers, a load balancer reduces individual server load and prevents any one server from becoming a single point of failure, thus improving overall application availability and responsiveness.


![Load Balancers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xg2recyjlyu6pheqvfll.png)



Load Balancer also keeps track of the status of all the servers while distributing requests. If a server is not available to take new requests or is not responding, it will stop sending traffic to such a server.

How does the load balancer choose the server?
Load balancers consider two factors before forwarding a request to a backend server. They will first ensure that the server they choose is actually responding appropriately to requests and then use an algorithm to select one from the set of healthy servers.

**Load Balancing Algorithms**
There are various load balancing methods, which use different algorithms best suited for a particular situation.

- Round Robin Method — rotates servers by directing traffic to the first available server and then moves that server to the bottom of the queue. When it reaches the end of the queue, it starts over at the beginning. Most useful when servers are of equal specification and there are not many persistent connections.

- Least Connection Method — directs traffic to the server with the fewest active connections. Most useful when there are a large number of persistent connections in the traffic unevenly distributed between the servers.

- Least Response Time Method — directs traffic to the server with the fewest active connections and the lowest average response time.

- IP Hash — a hash of the IP address of the client is calculated to redirect the request to a server.

**Redundant Load Balancers**
The load balancer can be a single point of failure. To overcome this, a second load balancer can be connected to the first to form a cluster. Each Load Balancer monitors the health of the other and since both of them are equally capable of serving traffic and failure detection, in the event the main load balancer fails, the second load balancer takes over.


![Redundant Load Balancers](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nf97jhuk2y383n2vd7nu.png)



**Load Balancing Benefits**

- Users experience faster, uninterrupted service. Users won’t have to wait for a single struggling server to finish its previous tasks.

- Service providers experience less downtime and higher throughput. Even a full server failure won’t affect the end-user experience as the load balancer will simply route around it to another server.

- Smart load balancers provide benefits like predictive analytics that determine traffic bottlenecks before they happen. As a result, the smart load balancer gives an organization actionable insights. These are key to automation and can help drive business decisions.