ALB vs NLB vs CLB: Key Differences and When to Use Each
ALB (Application Load Balancer) for HTTP/HTTPS traffic with advanced routing, NLB (Network Load Balancer) for ultra-fast TCP/UDP traffic handling, and CLB (Classic Load Balancer) as a legacy option supporting basic load balancing. Choose ALB for web apps, NLB for high-performance network traffic, and CLB only for older setups.Quick Comparison
This table summarizes the main features and differences of ALB, NLB, and CLB.
| Feature | Application Load Balancer (ALB) | Network Load Balancer (NLB) | Classic Load Balancer (CLB) |
|---|---|---|---|
| Protocol Support | HTTP, HTTPS, WebSocket | TCP, UDP, TLS | HTTP, HTTPS, TCP |
| Layer | Layer 7 (Application Layer) | Layer 4 (Transport Layer) | Layer 4 and Layer 7 (Basic) |
| Routing | Advanced routing (path, host-based) | Static IP, fast routing | Basic round-robin or sticky sessions |
| Performance | Good for web apps, moderate throughput | High throughput, low latency | Moderate, legacy performance |
| Use Case | Web applications, microservices | High-performance network traffic | Legacy apps, simple load balancing |
| Health Checks | HTTP/HTTPS health checks | TCP health checks | HTTP, TCP health checks |
Key Differences
ALB works at the application layer (Layer 7), which means it understands web traffic like HTTP and HTTPS. It can route requests based on URL paths or hostnames, making it ideal for modern web apps and microservices that need smart routing.
NLB operates at the transport layer (Layer 4), handling raw TCP or UDP traffic. It is designed for extreme performance with very low latency and can handle millions of requests per second. It also supports static IP addresses, which is useful for certain network setups.
CLB is the oldest and simplest load balancer. It supports both Layer 4 and basic Layer 7 but lacks advanced routing features. It is mostly used for legacy applications that do not require modern features or high performance.
ALB Code Example
resource "aws_lb" "example_alb" { name = "example-alb" internal = false load_balancer_type = "application" subnets = ["subnet-12345", "subnet-67890"] security_groups = ["sg-123456"] enable_deletion_protection = false } resource "aws_lb_target_group" "example_tg" { name = "example-tg" port = 80 protocol = "HTTP" vpc_id = "vpc-123456" health_check { path = "/health" protocol = "HTTP" matcher = "200-299" interval = 30 timeout = 5 healthy_threshold = 5 unhealthy_threshold = 2 } } resource "aws_lb_listener" "example_listener" { load_balancer_arn = aws_lb.example_alb.arn port = 80 protocol = "HTTP" default_action { type = "forward" target_group_arn = aws_lb_target_group.example_tg.arn } }
NLB Equivalent
resource "aws_lb" "example_nlb" { name = "example-nlb" internal = false load_balancer_type = "network" subnets = ["subnet-12345", "subnet-67890"] enable_deletion_protection = false } resource "aws_lb_target_group" "example_tg" { name = "example-tg" port = 80 protocol = "TCP" vpc_id = "vpc-123456" health_check { protocol = "TCP" interval = 30 timeout = 10 healthy_threshold = 3 unhealthy_threshold = 3 } } resource "aws_lb_listener" "example_listener" { load_balancer_arn = aws_lb.example_nlb.arn port = 80 protocol = "TCP" default_action { type = "forward" target_group_arn = aws_lb_target_group.example_tg.arn } }
When to Use Which
Choose ALB when you need smart routing for HTTP/HTTPS traffic, such as path-based or host-based routing for web apps and microservices.
Choose NLB when you require ultra-fast, low-latency handling of TCP or UDP traffic, or need static IP addresses for your load balancer.
Choose CLB only if you maintain legacy applications that do not support newer load balancer types or need simple load balancing without advanced features.