Can result in uneven traffic. For certain applications, not all requests are the same, some can have very database queries and results could be just by chance.
Least Connections.
Routes based on number of client connections to server.
Useful for chat or streaming applications.
Least Response Time.
Routes based on how quickly servers respond.
IP Hash.
Routes client to server based on IP.
Useful for stateful sessions.
There are certain applications that the client needs data that’s stored on a particular server. So the way you do that is to hash their IP address, and that way every time that user sends a request it will always go to the same server.
An example of a use case like that would be shopping cart. So on Amazon there are tens of thousands of different servers, they’s going to have your shopping cart stashed on one particular server so that they want to make sure that when you refresh a page, your request is sent to the same server that holds that data.
Lack of information can lead to uneven traffic. This is because it doesn’t have full access to the request.
A good benefit is that it’s good on the edge of your data center or of your network, because it can look at your IP address. For example, if you’re getting like a denial of service attack (DDoS), instead of wasting your computational power to let them go through your network, you can just toss that request at the edge.
So most of data center will first allow all incoming traffic through a L4 load balancer before allowing it further into your application.
Layer 7 (L7)
Full access to HTTP protocol and data.
SSL termination, decrypt traffic.
Check for authentication. So if a user send a request they’re not logged in they’re trying to get to a certain page. Instead of letting that go to your application server, right at the load balancer you could redirect these people.
Smarter routing options.
It’s more CPU-intensive to run a L7 load balancer.