Load balancer types comparison in GCP - Time & Space Complexity
When using different types of load balancers, it's important to understand how their work grows as more requests come in.
We want to know how the number of operations changes when traffic increases.
Analyze the time complexity of handling incoming requests with different GCP load balancers.
// Example: Using HTTP(S) Load Balancer
for each incoming request {
check URL and headers
route to backend service
backend processes request
}
// Example: Using TCP Proxy Load Balancer
for each incoming TCP connection {
route connection to backend instance
backend handles connection
}
This sequence shows how requests or connections are processed by different load balancers.
Look at what happens repeatedly as traffic grows.
- Primary operation: Routing each incoming request or connection to a backend.
- How many times: Once per request or connection received.
As the number of requests increases, the load balancer must handle more routing operations.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 routing operations |
| 100 | 100 routing operations |
| 1000 | 1000 routing operations |
Pattern observation: The number of routing operations grows directly with the number of requests.
Time Complexity: O(n)
This means the work grows linearly with the number of incoming requests or connections.
[X] Wrong: "Load balancers handle all requests instantly, so time does not grow with more traffic."
[OK] Correct: Each request still needs routing, so more requests mean more work for the load balancer.
Understanding how load balancers scale with traffic helps you design systems that stay reliable as they grow.
What if the load balancer caches routing decisions? How would that affect the time complexity?
Practice
Solution
Step 1: Understand the traffic type
HTTP and HTTPS traffic require Layer 7 (application layer) handling with SSL termination.Step 2: Match load balancer capabilities
HTTP(S) Load Balancer supports global distribution and SSL termination for web traffic.Final Answer:
HTTP(S) Load Balancer -> Option DQuick Check:
HTTP/HTTPS + SSL termination = HTTP(S) Load Balancer [OK]
- Confusing TCP Proxy with HTTP(S) for web traffic
- Choosing Network Load Balancer for HTTPS termination
- Using Internal Load Balancer for global traffic
Solution
Step 1: Identify the traffic and forwarding rule type
TCP and UDP traffic with regional forwarding rules indicates a Layer 4 load balancer.Step 2: Match with GCP load balancer types
Network Load Balancer supports TCP/UDP traffic regionally without SSL termination.Final Answer:
Network Load Balancer -> Option BQuick Check:
TCP/UDP + regional + no SSL = Network Load Balancer [OK]
- Choosing HTTP(S) Load Balancer for UDP traffic
- Confusing TCP Proxy with Network Load Balancer
- Selecting Internal Load Balancer for external traffic
client -> GCP LB -> backend instances (TCP with SSL offloading)
Solution
Step 1: Analyze traffic and SSL offloading need
TCP traffic with SSL offloading requires Layer 4 proxy with SSL termination.Step 2: Match with GCP load balancer types
TCP Proxy Load Balancer supports global TCP traffic with SSL offloading.Final Answer:
TCP Proxy Load Balancer -> Option AQuick Check:
Global TCP + SSL offloading = TCP Proxy Load Balancer [OK]
- Choosing Network Load Balancer which lacks SSL offloading
- Selecting HTTP(S) Load Balancer for TCP traffic
- Using Internal Load Balancer for external traffic
Solution
Step 1: Understand Internal Load Balancer scope
Internal Load Balancer is designed for traffic inside a VPC or connected networks only.Step 2: Identify access limitation
Clients outside the VPC cannot reach Internal Load Balancer because it does not expose external IPs.Final Answer:
Internal Load Balancer only supports traffic inside the VPC -> Option AQuick Check:
Internal LB = VPC-only traffic [OK]
- Assuming Internal LB supports global forwarding
- Thinking Internal LB supports external TCP traffic
- Confusing Internal LB with HTTP(S) Load Balancer
Solution
Step 1: Analyze requirements for multi-region HTTP/HTTPS app
Needs global load balancing, SSL termination, low latency, and failover.Step 2: Match load balancer features
HTTP(S) Load Balancer supports global distribution, SSL termination, health checks, and automatic failover.Step 3: Exclude other options
Network Load Balancer is regional and lacks SSL termination; Internal Load Balancer is internal-only; TCP Proxy is for TCP, not HTTP/HTTPS.Final Answer:
HTTP(S) Load Balancer because it offers global load balancing with SSL termination and health checks -> Option CQuick Check:
Multi-region HTTP/HTTPS + failover = HTTP(S) Load Balancer [OK]
- Choosing Network Load Balancer for HTTP/HTTPS global traffic
- Using Internal Load Balancer for external multi-region access
- Selecting TCP Proxy Load Balancer for HTTP traffic
Ready to prove it?
Pass the test and this pattern moves unknown
