Types of Load Balancer
Types of Load Balancers
1. Layer 4 Load Balancer (Transport Layer)
- Operates on TCP/UDP by analyzing basic information like IP addresses, ports,.
- Routing traffic based on network-level data without inspecting the content of the actual data.
- Faster (ideal for high vollume traffic), but less flexible (limited feature).
- Less expensive
- Example: AWS NLB, HAProxy in TCP mode.
2. Layer 7 Load Balancer (Application Layer)
- Works with HTTP/HTTPS.
- Can inspect content (URL, headers, cookies).
- Routing decisions based on application-specific data like the content of the data packets, HTTP headers, URLs and cookies etc.
- Slightly slower processing due to content inspection, but more flexible (used for routing rules, caching, SSL termination, etc.).
- More expensive because of many features & processing power.
- Example: NGINX, AWS ALB, Traefik.
Summary of L4 & L7:
Following is the use case for L4 & L7 load balancers.
| Use Case | Protocol | LB Layer | Reason |
|---|---|---|---|
| Online Multiplayer Games | UDP | L4 | Fast routing, no payload inspection |
| Video Streaming | TCP/UDP | L4 | Lower latency, protocol-based routing |
| Chat/WebSocket Apps | TCP | L4 | Long-lived TCP connections |
| Web APIs / Web Apps | HTTP(S) | L7 | Route by path, header, method |
| SaaS with subdomains | HTTP(S) | L7 | Host-based routing |
| A/B Testing / Canary Deploys | HTTP(S) | L7 | Cookie-based or header-based decisions |
| VPN Services | UDP/TCP | L4 | Encryption makes app-layer routing hard |