Introduction
A load balancer is a crucial component in a distributed computing as it distributes the incoming load across multiple servers. The primary purpose of load balancer is to ensure that a single server does not get flooded with multiple requests, preventing downtime and performance degradation.
How Load Balancers Work?
When a user sends a request to access a website or an application, the request first reaches the load balancer.
The load balancer manages a pool of servers aka nodes capable of handling the incoming requests. These servers host the application or website.
The load balancer uses a specific algorithm to decide which server from the pool should handle the incoming request.
The selected server is then assigned the task of fulfilling the user request and load balancer forwards the request to the chosen server.
The selected server processes and generates a response and sends it back to the user through the load balancer.
Types of Load Balancer
Physical Load Balancer: Physical devices dedicated to balancing traffic. They often provide high performance.
Software Load Balancer: Implemented as software solutions and can be run on standard server hardware. These are easier to scale than physical load balancer.
Layer 4(Transport Layer) Load Balancer: Operates at the transport layer of the OSI Model and makes decision based on the network-level information such as IP addresses and ports. It just acts like a firewall.
Layer 7(Application Layer) Load Balancer: Operates at the application layer of the OSI Model and makes routing decision based on the content which allows for more advanced load balancing decisions.
Load Balancing Algorithms
Round Robin: Distributes load equally among all the available servers. Each server gets a turn to handle a request.
Least Connection: Directs the traffic to the server with the least active connections. This helps loads more evenly.
Least Response Time: Directs the traffic to the server with the least response time. This can help minimize latency.
IP Hash: Uses a hash of client's IP address to determine which server will handle the request. This ensures that request from the same IP address always go to the same server.
Random: Select a random server to handle each request but it may not guarantee an even distribution of load.
Weighted Round Robin: Similar to Round Robin, but servers are assigned weights. More the weight more will be the requests handle by it.
Weighted Least Connections: Similar to Least Connection, but servers are assigned weights. More the weight less will be the requests handled by it.
Adaptive Load Balancing: Adjusts the load balancing algorithm based on the server's load or performance.