Bird
Raised Fist0
AWScloud~5 mins

ALB vs NLB decision in AWS - CLI Comparison

Choose your learning style10 modes available
Introduction
When you want to send internet traffic to your applications, you need a way to decide how to send that traffic. AWS offers two main types of load balancers: Application Load Balancer (ALB) and Network Load Balancer (NLB). Choosing the right one helps your app work well and handle users smoothly.
When your app needs to understand the content of web requests and route users based on URLs or headers, use ALB.
When you need to handle millions of requests quickly and want very fast network-level routing, use NLB.
When your app uses HTTP or HTTPS protocols and needs features like user authentication or sticky sessions, ALB is best.
When your app requires TCP or UDP traffic handling with very low latency, NLB is the right choice.
When you want to balance traffic across multiple servers in different availability zones with health checks, both ALB and NLB can be used depending on protocol needs.
Commands
This command creates an Application Load Balancer named 'my-application-lb' in two subnets with a security group. We use ALB for HTTP/HTTPS traffic with advanced routing.
Terminal
aws elbv2 create-load-balancer --name my-application-lb --subnets subnet-12345678 subnet-87654321 --security-groups sg-12345678 --type application
Expected OutputExpected
{ "LoadBalancers": [ { "LoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-application-lb/50dc6c495c0c9188", "DNSName": "my-application-lb-1234567890.us-east-1.elb.amazonaws.com", "CanonicalHostedZoneId": "Z35SXDOTRQ7X7K", "CreatedTime": "2024-06-01T12:00:00.000Z", "LoadBalancerName": "my-application-lb", "Scheme": "internet-facing", "VpcId": "vpc-1a2b3c4d", "State": { "Code": "provisioning" }, "Type": "application", "IpAddressType": "ipv4" } ] }
→
--type - Specifies the load balancer type: application for ALB
→
--subnets - Defines the subnets where the load balancer will be placed
→
--security-groups - Assigns security groups to control traffic
This command creates a Network Load Balancer named 'my-network-lb' in two subnets. NLB is used for fast, low-level network traffic routing.
Terminal
aws elbv2 create-load-balancer --name my-network-lb --subnets subnet-12345678 subnet-87654321 --type network
Expected OutputExpected
{ "LoadBalancers": [ { "LoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/my-network-lb/70dc6c495c0c9188", "DNSName": "my-network-lb-1234567890.us-east-1.elb.amazonaws.com", "CanonicalHostedZoneId": "Z35SXDOTRQ7X7K", "CreatedTime": "2024-06-01T12:05:00.000Z", "LoadBalancerName": "my-network-lb", "Scheme": "internet-facing", "VpcId": "vpc-1a2b3c4d", "State": { "Code": "provisioning" }, "Type": "network", "IpAddressType": "ipv4" } ] }
→
--type - Specifies the load balancer type: network for NLB
→
--subnets - Defines the subnets where the load balancer will be placed
This command checks the status and details of the Application Load Balancer to confirm it is created and ready.
Terminal
aws elbv2 describe-load-balancers --names my-application-lb
Expected OutputExpected
{ "LoadBalancers": [ { "LoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/app/my-application-lb/50dc6c495c0c9188", "DNSName": "my-application-lb-1234567890.us-east-1.elb.amazonaws.com", "State": { "Code": "active" }, "Type": "application" } ] }
This command checks the status and details of the Network Load Balancer to confirm it is created and ready.
Terminal
aws elbv2 describe-load-balancers --names my-network-lb
Expected OutputExpected
{ "LoadBalancers": [ { "LoadBalancerArn": "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/my-network-lb/70dc6c495c0c9188", "DNSName": "my-network-lb-1234567890.us-east-1.elb.amazonaws.com", "State": { "Code": "active" }, "Type": "network" } ] }
Key Concept

If you remember nothing else from this pattern, remember: ALB is for smart web traffic routing, NLB is for fast network traffic handling.

Common Mistakes
Choosing ALB when the app needs TCP or UDP traffic with very low latency.
ALB only supports HTTP/HTTPS protocols and cannot handle raw TCP/UDP traffic efficiently.
Use NLB for TCP/UDP traffic and low latency needs.
Not specifying the correct load balancer type flag when creating the load balancer.
AWS defaults to ALB if type is not specified, which may not match your traffic needs.
Always use --type application for ALB or --type network for NLB explicitly.
Assigning security groups to NLB which does not support them.
NLB operates at the network layer and does not use security groups, so this causes errors.
Do not assign security groups when creating NLB.
Summary
Use 'aws elbv2 create-load-balancer' with --type application to create an ALB for HTTP/HTTPS traffic.
Use 'aws elbv2 create-load-balancer' with --type network to create an NLB for TCP/UDP traffic with low latency.
Verify load balancer creation and status with 'aws elbv2 describe-load-balancers' command.

Practice

(1/5)
1. Which AWS load balancer should you choose if you want to route HTTP requests based on URL paths?
easy
A. Gateway Load Balancer
B. Network Load Balancer (NLB)
C. Classic Load Balancer
D. Application Load Balancer (ALB)

Solution

  1. Step 1: Understand ALB routing capabilities

    ALB can route HTTP/HTTPS traffic based on content like URL paths or host headers.
  2. Step 2: Compare with NLB capabilities

    NLB routes at the network level and does not inspect HTTP content for routing.
  3. Final Answer:

    Application Load Balancer (ALB) -> Option D
  4. Quick Check:

    Content-based routing = ALB [OK]
Hint: Use ALB for HTTP content routing, not NLB [OK]
Common Mistakes:
  • Choosing NLB for HTTP content routing
  • Confusing Classic Load Balancer with ALB
  • Assuming NLB can inspect HTTP headers
2. Which protocol is primarily supported by Network Load Balancer (NLB) for fast, low-latency traffic?
easy
A. TCP/UDP
B. FTP
C. HTTP/HTTPS
D. SMTP

Solution

  1. Step 1: Identify NLB protocol support

    NLB is designed to handle TCP and UDP traffic for fast, low-latency connections.
  2. Step 2: Exclude HTTP/HTTPS protocols

    HTTP/HTTPS are application layer protocols handled by ALB, not NLB.
  3. Final Answer:

    TCP/UDP -> Option A
  4. Quick Check:

    NLB = TCP/UDP traffic [OK]
Hint: NLB handles TCP/UDP, ALB handles HTTP/HTTPS [OK]
Common Mistakes:
  • Selecting HTTP/HTTPS for NLB
  • Confusing FTP or SMTP as NLB protocols
  • Assuming NLB supports application layer protocols
3. You have a web application that requires routing requests based on hostnames and needs SSL termination. Which load balancer will correctly handle this?
medium
A. Network Load Balancer (NLB)
B. Gateway Load Balancer
C. Application Load Balancer (ALB)
D. Classic Load Balancer

Solution

  1. Step 1: Check hostname-based routing support

    ALB supports routing based on hostnames, which is needed here.
  2. Step 2: Confirm SSL termination capability

    ALB can terminate SSL connections, simplifying certificate management.
  3. Final Answer:

    Application Load Balancer (ALB) -> Option C
  4. Quick Check:

    Hostname routing + SSL termination = ALB [OK]
Hint: SSL termination and hostname routing need ALB [OK]
Common Mistakes:
  • Choosing NLB which lacks hostname routing
  • Assuming Classic Load Balancer supports advanced routing
  • Confusing Gateway Load Balancer with ALB
4. A developer configured a Network Load Balancer to route HTTP traffic and expects it to inspect URL paths for routing. Why is this setup incorrect?
medium
A. NLB does not support TCP traffic
B. NLB cannot inspect HTTP content for routing decisions
C. NLB requires SSL certificates for HTTP routing
D. NLB only supports routing based on IP addresses

Solution

  1. Step 1: Understand NLB routing capabilities

    NLB operates at the network layer and cannot inspect HTTP content like URL paths.
  2. Step 2: Identify why HTTP content inspection fails

    Routing based on URL paths requires application layer inspection, which only ALB supports.
  3. Final Answer:

    NLB cannot inspect HTTP content for routing decisions -> Option B
  4. Quick Check:

    NLB lacks HTTP content inspection [OK]
Hint: NLB works at network layer, no HTTP content routing [OK]
Common Mistakes:
  • Thinking NLB supports HTTP path routing
  • Confusing TCP support with HTTP inspection
  • Assuming SSL certs fix routing issues
5. You need to design a system that handles millions of TCP connections with very low latency and also routes HTTP requests based on URL paths. What is the best load balancer setup?
hard
A. Use NLB for TCP connections and ALB for HTTP routing
B. Use only an Application Load Balancer (ALB) for all traffic
C. Use only a Network Load Balancer (NLB) for all traffic
D. Use Classic Load Balancer for both TCP and HTTP traffic

Solution

  1. Step 1: Identify requirements for TCP and HTTP traffic

    Millions of TCP connections need low latency, best handled by NLB. HTTP routing by URL paths requires ALB.
  2. Step 2: Combine load balancers for best performance

    Use NLB for TCP traffic and ALB for HTTP traffic to meet both needs efficiently.
  3. Final Answer:

    Use NLB for TCP connections and ALB for HTTP routing -> Option A
  4. Quick Check:

    TCP low latency + HTTP routing = NLB + ALB [OK]
Hint: Combine NLB for TCP and ALB for HTTP routing [OK]
Common Mistakes:
  • Using only ALB for TCP traffic causing latency
  • Using only NLB missing HTTP routing features
  • Choosing Classic Load Balancer for modern needs
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard