Load balancers are technology designed to evenly distribute network or application traffic across a number of servers. The aim of this is to prevent any single server from becoming overworked, which could degrade performance. Load balancing improves responsiveness and increases the availability and reliability of applications.
There are different types of load balancers based on the method they use to direct network traffic, including:
1. **Round Robin**: Round Robin load balancing is one of the simplest methods for distributing client requests across a group of servers. When a request comes in, the round robin algorithm routes it to the next server in the list. The algorithm loops through the server list until it reaches the end. When it does, it starts again at the top. It decides the order of request processing based on a list or cyclic order.
Example: If there are 3 servers, the first request goes to Server 1, the second request to Server 2, the third request to Server 3, then the fourth request goes back to Server 1, and so on in a cyclical order.
2. **Least Connections**: In this method, the load balancer maintains a record of how many connections each server has. When a new request comes in, the load balancer routes the request to the server with the fewest connections.
Example: If Server 1 has 2 active connections, Server 2 has 3 active connections, and Server 3 has 1 active connection, the next client request would be sent to Server 3.
3. **IP Hash**: The IP Hash load balancing algorithm maps IP addresses to the available servers. The load balancer creates a unique hash key based on the client and server’s IP addresses, then assigns the connection to a server, relying on the key value. This allows specific client IP addresses to always reach the same server, as long as no change in server availability occurs.
With the IP Hash method, an IP address, say ‘192.165.1.2‘, is hashed to a server. Even if this client goes offline and comes back, it’s still mapped to the same server.
4. **Least Response Time**: This method routes new requests to the server with the fewest active connections and the lowest average response time.
5. **URL Hash**: This load balancing method uses the hashes of the URL requested by the user to determine which server will handle the request. This is useful for balancing requests for a specific set of URLs especially in a caching situation where remaining consistent in which server the request goes to helps improve caching efficiency.
The use of load balancers also implies the use of health checks – mechanisms for the load balancer to know if a server is ready to receive requests and respond in expected timing. If a server fails health checks, typically the load balancer stops sending traffic to the failing server.
By distributing the work evenly, load balancers prevent any single server from becoming a bottleneck, thereby increasing overall service availability and response times. Which type of load balancer to employ depends largely on the nature of the traffic and the specific needs of the application.