Overview
Info
Network Load Balancer (NLB) operates at Layer 4 (Transport Layer) and routes traffic based on TCP, UDP, or TLS. It is designed for ultra-low latency, high throughput, and non-HTTP workloads.
When to Use NLB?
Use an NLB when your application requires:
- Static IP addresses (Elastic IPs)
- Ultra-low latency
- Millions of concurrent TCP/UDP connections
- Non-HTTP protocols (TCP, UDP, TLS)
- Source IP preservation
- AWS PrivateLink integration
Tip
If you need static IPs for a web application:
NLB provides Elastic IPs 3. IP Addresses in AWS
You can place an ALB behind an NLB (or use AWS Global Accelerator) to combine:
Static IPs
Layer 7 routing
HTTP/HTTPS features
ALB vs NLB
| Feature | NLB | ALB |
|---|---|---|
| OSI Layer | Layer 4 (TCP, UDP, TLS) | Layer 7 (HTTP, HTTPS, WebSocket) |
| Routing | IP + Port | URL, Host, Headers, Cookies |
| Protocols | TCP, UDP, TLS | HTTP, HTTPS, WebSocket |
| Static IP | ✅ Elastic IP | ❌ |
| Preserve Client IP | ✅ Native | Via X-Forwarded-For |
| Performance | Ultra-high | High |
| Latency | Very Low | Higher (HTTP inspection) |
| TLS Termination | ✅ | ✅ |
| Advanced Routing | ❌ | ✅ |
| AWS WAF | ❌ | ✅ |
| PrivateLink | ✅ Required | ❌ |
| Target Types | EC2, IP, ALB | EC2, IP, Lambda |
Why Do We Need NLB If We Already Have ALB?
Because ALB only get use to understands HTTP/HTTPS traffic.
NLB is required for workloads using protocols like:
- MySQL
- PostgreSQL
- Redis
- Kafka
- MQTT
- DNS
- SSH
- VPN
- Gaming servers
ALB cannot inspect or route these protocols.
Rule of thumb: HTTP is just one application-layer protocol 80 / 443. Many backend systems define their own optimized protocols over TCP, which is why a Layer 4 load balancer (NLB) is essential for those workloads.
Layer Difference
flowchart LR Client --> NLB NLB -->|TCP / UDP / TLS| Backend
- Does not inspect application data.
- Simply forwards packets based on IP + Port.
flowchart LR Client --> ALB ALB -->|"/users"| UserService ALB -->|"/orders"| OrderService ALB -->|"/payments"| PaymentService
- Reads the HTTP request.
- Supports path-based and host-based routing.
Common Use Cases
| Use NLB For | Reason |
|---|---|
| Gaming Servers | UDP + Low latency |
| Kafka / RabbitMQ | TCP traffic |
| Databases | Native TCP connections |
| Redis | TCP |
| VPN / SSH | Layer 4 protocols |
| AWS PrivateLink | Required |
| Firewall Whitelisting | Static IP support |
Architecture
flowchart LR Client -->|"TCP / UDP"| NLB NLB --> EC2_1 NLB --> EC2_2 NLB --> EC2_3
DNS Lookup
nslookup <your-nlb-dns-name>.elb.<region>.amazonaws.comKey Interview Points
- Operates at Layer 4 (Transport Layer).
- Routes using IP Address + Port.
- Supports TCP, UDP, and TLS.
- Provides Elastic (Static) IPs.
- Preserves the original client IP.
- Designed for ultra-low latency and high throughput.
- Required for AWS PrivateLink.
- Does not support URL- or host-based routing (use ALB for that).
Resources
