Layer 4 vs Layer 7 Load Balancing (Differences Explained)

This page tries to answer frequently asked questions about Load Balancing, application optimization, and acceleration.

What Does Layer 4 Mean?

Layer 4 is related to the fourth layer of the OSI model: the transport level. For example, TCP and UDP protocols are transport levels.

What Does Layer 7 Mean?

Layer 7 is related to the seventh layer of the OSI model: application level. For example, HTTP, FTP, SMTP, and DNS protocols are application levels.

What is Layer 4 Load Balancing?

A layer 4 load balancer makes routing decisions based on IPs and TCP or UDP ports. It has a packet view of the traffic exchanged between the client and a server which means it takes decisions packet by packet.
The layer 4 connection is established between the client and the server.

It is really fast but can’t perform any action on the protocol above layer 4. The fastest layer4 load balancers use an ASIC to make a routing decision.

What is Layer 7 Load Balancing?

A layer 7 load balancer makes routing decisions based on IPs, TCP or UDP ports, or any information it can get from the application protocol (mainly HTTP). The layer 7 load-balancer acts as a proxy, which means it maintains two TCP connections: one with the client and one with the server.

The packets are re-assembled, and then the load balancer can make a routing decision based on the information it can find in the application requests or responses. Even if this kind of processing seems slow, it is not that much: less than a millisecond.

Architectures with Layer 4 Load Balancers

Mainly three architectures are doable, depending on your needs:

Architectures with Layer 7 Load Balancers

Only one: Proxy mode, but two main modes of it are available:

Subscribe to our blog. Get the latest release updates, tutorials, and deep-dives from HAProxy experts.