Load Balancer

  1. Balance incoming traffic to multiple servers.
  2. Software or Hardware based.
  3. Used to improve reliability and scalability of application.
  4. Nginx, HAProxy, F5, Citrix

Basic Load Balancer Setup

Load Balancer Routing Methods

  1. Round Robin.
    1. Simplest type of routing.
    2. 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.
  2. Least Connections.
    1. Routes based on number of client connections to server.
    2. Useful for chat or streaming applications.
  3. Least Response Time.
    1. Routes based on how quickly servers respond.
  4. IP Hash.
    1. Routes client to server based on IP.
    2. Useful for stateful sessions.
    3. 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.
    4. 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.

Load Balancer Types

  1. Layer 4 (L4)
    1. Only has access to TCP and UDP data.
    2. Faster.
    3. Lack of information can lead to uneven traffic. This is because it doesn’t have full access to the request.
    4. 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.
    5. So most of data center will first allow all incoming traffic through a L4 load balancer before allowing it further into your application.
  2. Layer 7 (L7)
    1. Full access to HTTP protocol and data.
    2. SSL termination, decrypt traffic.
    3. 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.
    4. Smarter routing options.
    5. It’s more CPU-intensive to run a L7 load balancer.

Production Load Balancer Setup

Redundant Load Balancer Setup