ALB vs NLB decision in AWS - Performance Comparison
When choosing between Application Load Balancer (ALB) and Network Load Balancer (NLB), it's important to understand how the number of requests affects the load balancer's operations.
We want to know how the processing work grows as more requests come in.
Analyze the time complexity of handling incoming requests with ALB and NLB.
// Pseudocode for ALB and NLB request handling
for each incoming request {
if using ALB {
parse HTTP headers;
route request based on content;
} else if using NLB {
forward TCP/UDP packet to target;
}
}
This sequence shows how ALB inspects and routes HTTP requests, while NLB forwards packets without deep inspection.
Each incoming request triggers operations:
- Primary operation: ALB parses HTTP headers and routes; NLB forwards packets.
- How many times: Once per request, repeated for every incoming request.
As the number of requests increases, the load balancer performs its operations for each one.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 parsing or forwarding operations |
| 100 | 100 parsing or forwarding operations |
| 1000 | 1000 parsing or forwarding operations |
Pattern observation: The work grows directly with the number of requests.
Time Complexity: O(n)
This means the processing time increases in direct proportion to the number of requests.
[X] Wrong: "The load balancer processes all requests instantly regardless of count."
[OK] Correct: Each request requires processing, so more requests mean more work and time.
Understanding how request volume affects load balancer work helps you explain real-world system behavior clearly and confidently.
"What if the load balancer added caching for repeated requests? How would the time complexity change?"
Practice
Solution
Step 1: Understand ALB routing capabilities
ALB can route HTTP/HTTPS traffic based on content like URL paths or host headers.Step 2: Compare with NLB capabilities
NLB routes at the network level and does not inspect HTTP content for routing.Final Answer:
Application Load Balancer (ALB) -> Option DQuick Check:
Content-based routing = ALB [OK]
- Choosing NLB for HTTP content routing
- Confusing Classic Load Balancer with ALB
- Assuming NLB can inspect HTTP headers
Solution
Step 1: Identify NLB protocol support
NLB is designed to handle TCP and UDP traffic for fast, low-latency connections.Step 2: Exclude HTTP/HTTPS protocols
HTTP/HTTPS are application layer protocols handled by ALB, not NLB.Final Answer:
TCP/UDP -> Option AQuick Check:
NLB = TCP/UDP traffic [OK]
- Selecting HTTP/HTTPS for NLB
- Confusing FTP or SMTP as NLB protocols
- Assuming NLB supports application layer protocols
Solution
Step 1: Check hostname-based routing support
ALB supports routing based on hostnames, which is needed here.Step 2: Confirm SSL termination capability
ALB can terminate SSL connections, simplifying certificate management.Final Answer:
Application Load Balancer (ALB) -> Option CQuick Check:
Hostname routing + SSL termination = ALB [OK]
- Choosing NLB which lacks hostname routing
- Assuming Classic Load Balancer supports advanced routing
- Confusing Gateway Load Balancer with ALB
Solution
Step 1: Understand NLB routing capabilities
NLB operates at the network layer and cannot inspect HTTP content like URL paths.Step 2: Identify why HTTP content inspection fails
Routing based on URL paths requires application layer inspection, which only ALB supports.Final Answer:
NLB cannot inspect HTTP content for routing decisions -> Option BQuick Check:
NLB lacks HTTP content inspection [OK]
- Thinking NLB supports HTTP path routing
- Confusing TCP support with HTTP inspection
- Assuming SSL certs fix routing issues
Solution
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.Step 2: Combine load balancers for best performance
Use NLB for TCP traffic and ALB for HTTP traffic to meet both needs efficiently.Final Answer:
Use NLB for TCP connections and ALB for HTTP routing -> Option AQuick Check:
TCP low latency + HTTP routing = NLB + ALB [OK]
- Using only ALB for TCP traffic causing latency
- Using only NLB missing HTTP routing features
- Choosing Classic Load Balancer for modern needs
Ready to prove it?
Pass the test and this pattern moves unknown
