NLB vs ALB - sudo-arshia/tips_and_tricks GitHub Wiki

NLB (Network Load Balancer) and ALB (Application Load Balancer) are two load balancing options offered by Amazon Web Services (AWS). They serve the purpose of distributing incoming network traffic across multiple targets, such as EC2 instances or containers. While both NLB and ALB share this goal, they have distinct features and use cases. Let's compare them in detail:

Feature NLB ALB
Layer Transport Layer (Layer 4) Application Layer (Layer 7)
Routing Algorithm 5-tuple hash or Source IP HTTP/HTTPS routing, Host-based routing
Protocol Support TCP, UDP, TLS HTTP, HTTPS, WebSocket
Connection State Stateless Stateful
Health Checks TCP/UDP checks at the instance level HTTP/HTTPS checks at the target group level
SSL/TLS Termination TCP/SSL pass-through SSL/TLS offloading
WebSockets Support No Yes
Target Group Stickiness IP-based (for Lambda targets) Cookie-based
Access Logs No Yes
Request Tracing No Yes
Integration with ECS/EKS No Yes
Performance Scaling Higher throughputs, lower latency Flexible scaling based on request rate

Layer

  • NLB operates at the transport layer (Layer 4) of the OSI model, focusing on routing traffic based on IP addresses and ports.
  • ALB operates at the application layer (Layer 7), allowing inspection and routing of traffic based on application-level information such as HTTP headers.

Routing Algorithm

  • NLB uses a 5-tuple hash or Source IP as the routing algorithm, distributing traffic based on the hash of the source and destination IP addresses, ports, and protocol.
  • ALB supports HTTP/HTTPS routing and host-based routing, allowing more granular control over routing decisions based on application-level information.

Protocol Support

  • NLB supports TCP, UDP, and TLS protocols.
  • ALB supports HTTP, HTTPS, and WebSocket protocols, making it suitable for web applications that require advanced HTTP-level features.

Connection State

  • NLB is stateless, meaning it does not maintain the state of the connections it routes.
  • ALB is stateful and can maintain the state of connections, allowing features like connection multiplexing and request-based routing decisions.

Health Checks

  • NLB performs TCP/UDP health checks at the instance level, ensuring that traffic is routed only to healthy instances.
  • ALB performs HTTP/HTTPS health checks at the target group level, providing more granular health monitoring for different endpoints within a target group.

SSL/TLS Termination

  • NLB supports TCP/SSL pass-through, meaning SSL/TLS termination happens at the backend instances.
  • ALB supports SSL/TLS offloading, handling SSL/TLS termination at the load balancer itself, reducing the workload on backend instances.

WebSockets Support

  • NLB does not provide native support for WebSockets.
  • ALB offers built-in support for WebSockets, making it suitable for applications that utilize real-time bidirectional communication.

Target Group Stickiness

  • NLB supports IP-based target group stickiness, primarily used for maintaining session affinity with Lambda targets.
  • ALB supports cookie-based stickiness, allowing the load balancer to route requests from the same client to the same target, maintaining session state if required.

Access Logs

  • NLB does not generate access logs. To log traffic, you need to rely on other mechanisms such as CloudWatch Logs.
  • ALB generates detailed access logs, capturing information about each request, including the source IP, request path, response codes, and more.

Request Tracing

  • NLB does not offer built-in support for request tracing.
  • ALB supports request tracing through integration with AWS X-Ray, providing insights into the end-to-end latency and performance of requests.

Integration with ECS/EKS

  • NLB does not have direct integration with Amazon Elastic Container Service (ECS) or Amazon Elastic Kubernetes Service (EKS).
  • ALB integrates seamlessly with ECS and EKS, providing native support for dynamic target registration and automatic scaling based on container or pod availability.

Performance Scaling

  • NLB is known for its high throughputs and low latencies, making it suitable for use cases that require handling large volumes of traffic with minimal overhead.
  • ALB offers flexible scaling based on request rate, allowing you to automatically scale the load balancer based on the number of incoming requests.

In conclusion, NLB and ALB are both powerful load balancing options with different strengths and capabilities. NLB excels in handling high-throughput traffic and operating at the transport layer, while ALB offers advanced application-level routing, SSL/TLS termination, and extensive features for web applications. Understanding your specific requirements will help you choose the most suitable load balancer for your AWS environment.