Why load balancing matters in GCP - Performance Analysis
We want to understand how the work done by load balancing changes as more users or requests come in.
Specifically, how does the number of operations grow when traffic increases?
Analyze the time complexity of the load balancer distributing requests.
// Pseudocode for load balancer handling requests
for each incoming request {
select a healthy backend instance;
forward the request to that instance;
wait for response;
}
This sequence shows how each request is handled by choosing a backend and forwarding the request.
Look at what repeats as requests increase.
- Primary operation: Selecting a backend instance and forwarding the request.
- How many times: Once per incoming request.
Each new request causes one selection and forwarding operation.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 selections and forwards |
| 100 | 100 selections and forwards |
| 1000 | 1000 selections and forwards |
Pattern observation: The work grows directly with the number of requests.
Time Complexity: O(n)
This means the load balancer does one main operation for each request, so work grows linearly as requests increase.
[X] Wrong: "Load balancing work stays the same no matter how many requests come in."
[OK] Correct: Each request needs to be handled separately, so more requests mean more work for the load balancer.
Understanding how load balancing scales with traffic helps you design systems that stay responsive as users grow.
"What if the load balancer cached backend selections for groups of requests? How would the time complexity change?"