0
0
AwsComparisonBeginner · 4 min read

ALB vs NLB vs CLB: Key Differences and When to Use Each

AWS offers three main load balancers: 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.

FeatureApplication Load Balancer (ALB)Network Load Balancer (NLB)Classic Load Balancer (CLB)
Protocol SupportHTTP, HTTPS, WebSocketTCP, UDP, TLSHTTP, HTTPS, TCP
LayerLayer 7 (Application Layer)Layer 4 (Transport Layer)Layer 4 and Layer 7 (Basic)
RoutingAdvanced routing (path, host-based)Static IP, fast routingBasic round-robin or sticky sessions
PerformanceGood for web apps, moderate throughputHigh throughput, low latencyModerate, legacy performance
Use CaseWeb applications, microservicesHigh-performance network trafficLegacy apps, simple load balancing
Health ChecksHTTP/HTTPS health checksTCP health checksHTTP, 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

terraform
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
  }
}
Output
Creates an Application Load Balancer with HTTP listener forwarding to target group on port 80.
↔️

NLB Equivalent

terraform
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
  }
}
Output
Creates a Network Load Balancer with TCP listener forwarding to target group on port 80.
🎯

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.

Key Takeaways

ALB is best for HTTP/HTTPS with advanced routing at the application layer.
NLB handles high-performance TCP/UDP traffic at the transport layer with low latency.
CLB is a legacy option with basic load balancing and limited features.
Use ALB for modern web apps, NLB for network-heavy workloads, and CLB only for old setups.
Health checks and protocol support differ significantly among ALB, NLB, and CLB.