Difficulty: Intermediate
What is the difference between an Application Load Balancer (ALB) and a Network Load Balancer (NLB), and how do you choose between them?
An Application Load Balancer works at Layer 7 (HTTP/HTTPS): it reads the request and can route on path, host, headers, query strings, or methods, terminate TLS, and authenticate users. A Network Load Balancer works at Layer 4 (TCP, UDP, TLS): it forwards connections without looking at HTTP, handles very high throughput with very low latency, preserves the client IP, and gives you a static IP per Availability Zone. Use ALB for web apps and APIs, NLB for raw TCP/UDP, extreme performance, or when clients need fixed IPs.
ALB terminates the client connection, parses the HTTP request, evaluates listener rules in priority order, and opens its own connection to a target in the matching target group. Because it understands HTTP, it can do things like send /api/ to one service and /images/ to another, or route payments.example.com and orders.example.com to different backends from a single load balancer.
NLB picks a target using a flow hash (protocol, source and destination IP and port) and forwards packets for that connection to the same target. It does not inspect HTTP, so it cannot route by path. It scales to millions of requests per second and is designed for sudden spikes.
| Feature | ALB | NLB |
|---|---|---|
| OSI layer | 7 (HTTP, HTTPS, gRPC, WebSocket) | 4 (TCP, UDP, TLS) |
| Routing | Path, host, header, query, method, source IP | Port and protocol only |
| Static IP | No (DNS name only; use Global Accelerator for static IPs) | Yes, one per AZ, can use Elastic IPs |
| Client IP at target | Via X-Forwarded-For header | Preserved natively (for instance/IP targets) |
| Target types | Instance, IP, Lambda | Instance, IP, ALB |
| Extras | AWS WAF, OIDC/Cognito auth, sticky sessions, redirects, fixed responses | PrivateLink endpoint services, TLS passthrough |
| Cross-zone load balancing | On by default | Off by default |
aws elbv2 create-rule \
--listener-arn arn:aws:elasticloadbalancing:ap-south-1:111122223333:listener/app/shop-alb/abc/def \
--priority 10 \
--conditions Field=path-pattern,Values='/api/*' \
--actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:ap-south-1:111122223333:targetgroup/api-tg/123
# NLB: a plain TCP listener, no rules to evaluate
aws elbv2 create-listener \
--load-balancer-arn arn:aws:elasticloadbalancing:ap-south-1:111122223333:loadbalancer/net/mqtt-nlb/xyz \
--protocol TCP --port 8883 \
--default-actions Type=forward,TargetGroupArn=arn:aws:elasticloadbalancing:ap-south-1:111122223333:targetgroup/mqtt-tg/456
The ALB rule matches on HTTP path; the NLB listener just forwards TCP connections on a port, which is all a Layer 4 balancer can do.
Application Load Balancer, Network Load Balancer, Layer 7 Routing, Layer 4, Target Groups