L4/L7 Load Balancers

Bealfan
3 min readJan 9, 2023

--

Load balancing is the process of distributing network traffic across multiple servers to ensure that no single server becomes overwhelmed and that all servers are used efficiently. In the context of the OSI (Open Systems Interconnection) model, load balancing occurs at the transport layer

At the transport layer, a load balancer receives incoming network traffic and forwards it to one of the servers in a pool of servers. The load balancer can use various algorithms to determine which server to send the traffic to. Some common algorithms include round-robin, least connections, and least response time.

The load balancer can also monitor the health of the servers in the pool and redirect traffic away from servers that are experiencing problems. This helps to ensure that the network remains available and responsive to client requests.

Overall, load balancing is an important technique for improving the performance, scalability, and reliability of networked systems. It is often used in high-traffic web applications, e-commerce sites, and other applications that require the ability to handle large numbers of concurrent connections.

  1. Protocol agnostic: L4 load balancers are not aware of the content of the traffic they are forwarding. They simply distribute traffic based on the source and destination IP addresses and port numbers, regardless of the protocol being used.
  2. Connection-oriented: L4 load balancers maintain a connection table to track the state of each connection. This allows them to forward traffic based on the connection state, rather than just the source and destination addresses.
  3. Fast: L4 load balancers operate at a relatively high layer in the OSI model, which means they can forward traffic quickly. This makes them well-suited for high-bandwidth, low-latency applications.
  4. Limited visibility: Because L4 load balancers operate at a high layer, they have limited visibility into the content of the traffic they are forwarding. This can make it difficult to use them for more advanced load balancing scenarios that require deeper inspection of traffic.
  5. Scalable: L4 load balancers can handle a large number of concurrent connections, making them well-suited for high-traffic applications.

Some examples of L4 load balancers are:

  • Linux Virtual Server (LVS): an open-source L4 load balancer that runs on Linux
  • F5 BIG-IP: a commercial L4 load balancer that runs on various operating systems
  • AWS Network Load Balancer (NLB): a cloud-based L4 load balancer offered by Amazon Web Services
  • HAProxy: an open-source L4 load balancer that runs on Linux
  • Citrix ADC: a commercial L4 load balancer that runs on various operating systems

L7 load balancer, on the other hand, is a network device that operates at the application layer (layer 7) of the OSI model. It is able to make load balancing decisions based on the content of the traffic it receives, rather than just the source and destination IP addresses and port numbers as L4 load balancers do.

To do this, L7 load balancers typically inspect the header of each incoming request to determine the content type, protocol, and other characteristics. They can then use this information to forward traffic to the appropriate server or servers in a pool.

L7 load balancers are often used in more advanced load balancing scenarios that require more fine-grained control over traffic distribution. For example, they can be used to distribute traffic based on the type of content being requested (e.g., images, HTML, etc.), the protocol being used (e.g., HTTP, HTTPS, etc.), or the hostname of the request.

L7 load balancers are generally slower than L4 load balancers because they need to inspect the content of each incoming request. However, they offer more flexibility and can be used in a wider range of load balancing scenarios.

Some examples of L7 load balancers are:

  • HAProxy: an open-source L7 load balancer that runs on Linux
  • F5 BIG-IP: a commercial L7 load balancer that runs on various operating systems
  • AWS Elastic Load Balancer (ELB): a cloud-based L7 load balancer offered by Amazon Web Services
  • NGINX Plus: a commercial L7 load balancer and web server that runs on various operating systems
  • Envoy: an open-source L7 load balancer and proxying solution developed by Lyft.

L4/L7 Comparison

Feature and Use case comparison for L4 & L7 load balancers.

--

--