Load balancing is a core networking solution used to distribute traffic across servers. These servers can be in one or several locations.
In other words, It is the process of evenly spreading incoming network traffic(client) among a collection of backend servers, often referred to as a server farm or server pool.
Why do we use a Load balancer?
Load balancer improves application availability and responsiveness.
It prevents server overload and reduces downtime.
Ensures high availability and reliability by sending requests only to online servers.
Distributes client requests or network load efficiently across multiple servers.
Provides the flexibility to add or subtract servers as demand dictates.
It improves elasticity/scalability.
Some of the Load balancing Algorithms are:-
- Least Connection: This approach takes the actual server load into account. The latest request is forwarded to the site that has the fewest pending requests at any given time.
Hash: Requests are distributed based on a key you choose, such as the client's IP address or the file URL.
IP Hash: The client's IP address is used to decide which server will receive the message.
In Linux, Load balancer features can be implemented by:-
1. Nginx:- It is an open-source Web server. More than just a Web server, it can operate as a reverse proxy server, mail proxy server, load balancer, lightweight file server, and HTTP cache.
2. HAProxy:- It stands for High Availability Proxy. It is an open-source load balancer that provides load balancing, high availability, and proxy solutions for TCP and HTTP-based applications. It is best suited for distributing the workload across multiple servers for performance improvement and reliability of servers. The function of Haproxy is to forward the web request from the end-user to one of the available web servers.
3. Keepalived:- It is an open-source program that supports both load balancing and high availability. It is a routing software and provides two types of load balancing:
Layer 4 ( transport layer)
Layer 7 ( application layer)
Keepalived can perform the following functions:
Health checking (whether the servers are up or not)
Implements VRRP (virtual redundancy routing protocol) to handle load-balance failover.
In conclusion, it is highly recommended to use load balancers if you are expecting high traffic on your website or application.