0
0
AWScloud~5 mins

Cross-zone load balancing in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Cross-zone load balancing
O(n)
Understanding Time Complexity

When using cross-zone load balancing, requests are distributed across multiple zones. We want to understand how the number of requests affects the work done by the load balancer.

How does the load balancer's effort grow as more requests come in?

Scenario Under Consideration

Analyze the time complexity of request distribution with cross-zone load balancing enabled.


// Enable cross-zone load balancing on a Network Load Balancer
aws elbv2 modify-load-balancer-attributes \
  --load-balancer-arn arn:aws:elasticloadbalancing:region:account-id:loadbalancer/net/my-load-balancer/50dc6c495c0c9188 \
  --attributes Key=load_balancing.cross_zone.enabled,Value=true

// Incoming requests are distributed evenly across all registered targets in all zones
// Each request triggers a routing decision by the load balancer
    

This setup evenly spreads incoming requests across all targets in every zone, balancing the load.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Routing each incoming request to a target in any zone.
  • How many times: Once per incoming request.
How Execution Grows With Input

Each new request causes the load balancer to pick a target across zones. More requests mean more routing decisions.

Input Size (n)Approx. Api Calls/Operations
1010 routing decisions
100100 routing decisions
10001000 routing decisions

Pattern observation: The number of routing operations grows directly with the number of requests.

Final Time Complexity

Time Complexity: O(n)

This means the load balancer's work grows linearly with the number of incoming requests.

Common Mistake

[X] Wrong: "Cross-zone load balancing reduces the number of routing decisions the load balancer makes."

[OK] Correct: The load balancer still routes every request; cross-zone balancing only changes how targets are chosen, not how many routing operations happen.

Interview Connect

Understanding how load balancers handle requests helps you design systems that scale well. This skill shows you can think about how cloud services behave as demand grows.

Self-Check

"What if cross-zone load balancing was disabled? How would the time complexity of routing requests change?"