L7 Load Balancing
Load balancing at the application layer (HTTP). Can route based on URL path, headers, cookies, and request content. Smarter but slower than L4. Powers CDN edge routing decisions.
Full Explanation
L7 load balancing understands HTTP. It can inspect the URL, read headers, parse cookies, and make intelligent routing decisions. Send /api/* to your API servers, /static/* to cache, /ws to the WebSocket cluster. This is how CDN edges route requests internally.
L7 balancers terminate TLS (they have to, to read the HTTP content), which means they handle certificate management and can do things like HTTP-to-HTTPS redirects, header manipulation, and request rewriting before forwarding to backends.
The cost: L7 is slower per-request than L4 because of the parsing overhead. But for CDN operations, you need L7 intelligence. Cache routing, origin selection, A/B testing, canary deployments, rate limiting by path. These all require understanding the HTTP layer.
Examples
# Nginx L7 routing
upstream api_servers {
server 10.0.1.10:8080;
server 10.0.1.11:8080;
}
upstream static_servers {
server 10.0.2.10:80;
server 10.0.2.11:80;
}
server {
listen 443 ssl;
location /api/ {
proxy_pass http://api_servers;
}
location /static/ {
proxy_pass http://static_servers;
add_header Cache-Control "public, max-age=86400";
}
location / {
proxy_pass http://api_servers;
}
}
Video Explanation
Frequently Asked Questions
Load balancing at the application layer (HTTP). Can route based on URL path, headers, cookies, and request content. Smarter but slower than L4. Powers CDN edge routing decisions.
# Nginx L7 routing
upstream api_servers {
server 10.0.1.10:8080;
server 10.0.1.11:8080;
}
upstream static_servers {
server 10.0.2.10:80;
server 10.0.2.11:80;
}
server {
listen 443 ssl;
location /api/ {
proxy_pass http://api_servers;
}
location /static/ {
proxy_pass http://static_servers;
add_header Cache-Control "public, max-age=86400";
}
location / {
proxy_pass http://api_servers;
}
}
Related CDN concepts include:
- Edge Server — A CDN server located at the network edge, close to end users. Handles caching, SSL …
- L4 Load Balancing — Load balancing at the transport layer (TCP/UDP). Routes connections based on IP and port without …
- Rate Limiting — Restricting the number of requests a client can make within a time window. Protects origins …
- WAF (WAF) — Web Application Firewall. Inspects HTTP requests at the CDN edge and blocks malicious traffic: SQL …