DEV Community

Wakeup Flower
Wakeup Flower

Posted on

Compare NLB & ALB with metaphor

🔹 How Application Load Balancer (ALB) works

Metaphor: Think of ALB as a restaurant receptionist.

  • You (the customer) arrive at the restaurant (the ALB).
  • The receptionist greets you, asks: “What do you want?” (parses your HTTP request).
  • Depending on what you ask for (e.g., menu section: sushi vs. pizza), the receptionist decides which waiter/kitchen section to send you to (routing rules: path-based, host-based).
  • You don’t walk directly into the kitchen — the receptionist terminates your request, figures it out, and then forwards it on your behalf.
  • Because the receptionist handled your order, the waiter/kitchen may see the receptionist’s name, not yours — unless the receptionist leaves a note (the X-Forwarded-For header with your original IP).

Key idea:

  • ALB = layer 7 (application-aware), reads your request.
  • It acts as a middleman and may hide your original IP (unless passed in headers).

🔹 How Network Load Balancer (NLB) works

Metaphor: Think of NLB as a highway traffic cop at a busy junction.

  • Cars (client requests) are flying in millions per second.
  • The cop doesn’t care about who’s inside the car or what you’re carrying (no parsing of HTTP).
  • The cop just looks at the car’s license plate (IP/port info at layer 4), then waves it directly into the correct lane (the EC2 instance private IP).
  • The cop does not open the trunk, check your documents, or slow things down.
  • Because the cop just redirects the car, when it arrives at the destination (EC2 instance), the driver’s original identity (the client’s real IP) is still intact.

Key idea:

  • NLB = layer 4 (transport-level only), blind to the contents of the request.
  • It’s designed for speed, scale, and preserving the client IP.
  • It routes directly to the target’s private IP, staying entirely in AWS’s backbone network.

🔹 Core Difference (Metaphor Summary)

Feature ALB (Receptionist) NLB (Traffic Cop)
Layer Layer 7 (Application) Layer 4 (Transport)
Understands request? Yes — parses HTTP headers, URLs, cookies No — only cares about IP address + port
Adds overhead? Yes — terminates and re-creates connections Minimal — just forwards at lightning speed
Client IP preserved? No (unless X-Forwarded-For header used) Yes — client IP is preserved automatically
Best for Smart routing (websites, APIs, microservices) Massive scale (gaming, IoT, VoIP, TCP apps)

Top comments (0)