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

FeatureNLBALB
OSI LayerLayer 4 (TCP, UDP, TLS)Layer 7 (HTTP, HTTPS, WebSocket)
RoutingIP + PortURL, Host, Headers, Cookies
ProtocolsTCP, UDP, TLSHTTP, HTTPS, WebSocket
Static IP✅ Elastic IP
Preserve Client IP✅ NativeVia X-Forwarded-For
PerformanceUltra-highHigh
LatencyVery LowHigher (HTTP inspection)
TLS Termination
Advanced Routing
AWS WAF
PrivateLink✅ Required
Target TypesEC2, IP, ALBEC2, 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 ForReason
Gaming ServersUDP + Low latency
Kafka / RabbitMQTCP traffic
DatabasesNative TCP connections
RedisTCP
VPN / SSHLayer 4 protocols
AWS PrivateLinkRequired
Firewall WhitelistingStatic 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.com

Key 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