Why load balancing matters in AWS - Performance Analysis
We want to understand how the work done by load balancers changes as more users or requests come in.
How does the number of requests affect the load balancer's operations?
Analyze the time complexity of the following operation sequence.
// Create a load balancer
aws elbv2 create-load-balancer --name my-load-balancer --subnets subnet-12345 subnet-67890
// Register targets (servers) to the load balancer
aws elbv2 register-targets --target-group-arn arn:aws:elasticloadbalancing:... --targets Id=i-1234567890abcdef0 Id=i-0abcdef1234567890
// Incoming requests are distributed by the load balancer
// Each request is routed to one of the registered targets
This sequence sets up a load balancer and registers servers to handle incoming requests evenly.
- Primary operation: Routing each incoming request to a target server.
- How many times: Once per incoming request.
As the number of requests grows, the load balancer routes each one individually.
| 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 the load balancer does grows in a straight line as requests increase.
[X] Wrong: "The load balancer handles all requests at once, so time stays the same no matter how many requests come in."
[OK] Correct: Each request needs to be routed separately, so more requests mean more work.
Understanding how load balancers handle growing traffic helps you design systems that stay fast and reliable as more people use them.
"What if the load balancer had to check the health of each target before routing every request? How would the time complexity change?"
Practice
Solution
Step 1: Understand load balancer role
A load balancer shares user traffic across servers to keep apps fast and reliable.Step 2: Identify main function
Its main job is to distribute incoming traffic evenly to avoid overloading one server.Final Answer:
To distribute incoming traffic evenly across multiple servers -> Option CQuick Check:
Load balancer = distribute traffic [OK]
- Confusing load balancer with data storage
- Thinking it only monitors CPU
- Assuming it creates backups
Solution
Step 1: Identify AWS services
Amazon S3 stores files, RDS manages databases, Lambda runs code, ELB manages load balancing.Step 2: Match service to load balancing
Elastic Load Balancing (ELB) is the AWS service designed to create load balancers.Final Answer:
Elastic Load Balancing (ELB) -> Option BQuick Check:
Load balancer service = ELB [OK]
- Choosing storage or compute services instead of ELB
- Confusing Lambda with load balancing
- Selecting database services
LoadBalancer -> TargetGroup -> EC2 Instances Listener listens on port 80 and forwards to TargetGroup
Solution
Step 1: Understand listener role
The listener listens on port 80 and forwards requests to the target group.Step 2: Understand target group role
The target group contains multiple EC2 instances and the load balancer distributes traffic evenly among them.Final Answer:
It forwards traffic on port 80 to all EC2 instances evenly -> Option AQuick Check:
Listener + TargetGroup = distribute traffic [OK]
- Thinking it blocks traffic
- Assuming it stores data
- Believing it sends traffic to only one instance
Solution
Step 1: Check target group configuration
If only one instance is registered in the target group, all traffic goes to that instance.Step 2: Verify listener and load balancer existence
Listener forwarding on wrong port or missing load balancer would cause no traffic or errors, not single server traffic.Final Answer:
Target group has only one instance registered -> Option DQuick Check:
Single server traffic = one target instance [OK]
- Assuming listener port causes single server traffic
- Thinking load balancer absence sends traffic
- Blaming security group for traffic routing
Solution
Step 1: Understand traffic spike handling
Handling spikes requires scaling resources automatically to meet demand.Step 2: Match setup to scaling needs
Using a load balancer with multiple target groups and auto-scaling EC2 instances allows dynamic resource adjustment and balanced traffic.Final Answer:
Use a load balancer with multiple target groups and auto-scaling EC2 instances -> Option AQuick Check:
Auto-scaling + load balancer = handle spikes [OK]
- Relying on single instance for heavy traffic
- Using fixed instances without scaling
- Disabling load balancer reduces reliability
Ready to prove it?
Pass the test and this pattern moves unknown
