Layer 7 load balancing describes traffic distribution at the application layer of the Open Systems Interconnection (OSI) model, which is where human-application interaction occurs and where applications access network services.
Layer 7 load balancers base their routing decisions on protocol-specific information (such as the URL the client is requesting) and information available on lower layers (such as client IP address, ports, etc). They function as proxies by maintaining separate TCP connections with both the client and server.
Generally, Layer 7 load balancing is marginally slower than at Layer 4 since packets are reassembled and inspected. However, Layer 7 acceleration features such as caching, improved routing, and others generally compensate.
How does Layer 7 load balancing work?
Layer 7 load balancing occurs at the highest level within the OSI model. It primarily uses HTTP/HTTPS header content, message content, cookie information, and URLs to determine routing behaviors. The process works like this:
The load balancer negotiates a TLS connection with the client (for secure traffic), enabling it to read the contents of the message itself.
The load balancer inspects each message's contents
The load balancer opens a new TCP connection with the backend server (negotiating TLS encryption if configured) and routes the request in conjunction with a number of rules and algorithms.
Because of this deeper traffic inspection, Layer 7 load balancing is considered more sophisticated or intelligent than simple Layer 4 load balancing.
What makes Layer 7 load balancing useful?
Since Layer 7 load balancers work at the application layer, they can help mitigate application performance degradation or attacks with the inclusion of integrated security features—such as web application firewalls (WAFs), bot management tools, and rate limits. Other benefits include:
TLS termination and bridging support
Application-aware load balancing
Sticky session support through cookie injection or inspection, effectively routing all client requests to a single server
Header-based redirects and content serving
Greater overall visibility and performance optimization (caching, etc.)
While Layer 7 load balancing is powerful and highly configurable on its own, organizations should employ Layer 7 and Layer 4 load balancing to comprehensively manage traffic across all protocols and applications. Overall, Layer 7 load balancers do a great job of reducing application overhead to boost uptime and measurable performance at scale.
Does HAProxy support Layer 7 load balancing?
Yes! HAProxy supports both Layer 7 and Layer 4 load balancing. This enables functions such as NAT, direct server return (DSR), IP tunneling, reverse proxying, and transparent proxying. To learn more about our various Layer 7 controls within HAProxy, check out our Layer 7 overview and related tutorials within our documentation.