Auto Scaling with ELB integration in AWS - Time & Space Complexity
When using Auto Scaling with an Elastic Load Balancer (ELB), it is important to understand how the number of operations grows as the number of instances changes.
We want to know how the system's work increases when more servers are added or removed.
Analyze the time complexity of the following operation sequence.
# Create Auto Scaling group with ELB integration
aws autoscaling create-auto-scaling-group \
--auto-scaling-group-name my-asg \
--launch-configuration-name my-launch-config \
--min-size 1 --max-size 10 --desired-capacity 3 \
--load-balancer-names my-elb
# Scale out by increasing desired capacity
aws autoscaling set-desired-capacity \
--auto-scaling-group-name my-asg \
--desired-capacity 5
This sequence creates an Auto Scaling group linked to an ELB and then increases the number of instances to be managed and balanced.
- Primary operation: Launching or terminating EC2 instances as the Auto Scaling group changes size.
- How many times: Once per instance added or removed during scaling.
- Secondary operation: Registering or deregistering each instance with the ELB.
- How many times: Once per instance added or removed.
Each time the desired capacity changes, the system launches or terminates instances and updates the ELB registration for each instance.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 10 instance launches/terminations and 10 ELB registrations/deregistrations |
| 100 | About 100 instance launches/terminations and 100 ELB registrations/deregistrations |
| 1000 | About 1000 instance launches/terminations and 1000 ELB registrations/deregistrations |
Pattern observation: The number of operations grows directly with the number of instances added or removed.
Time Complexity: O(n)
This means the work grows linearly with the number of instances being scaled.
[X] Wrong: "Adding more instances does not increase the number of API calls because the ELB handles them automatically."
[OK] Correct: Each instance must be individually launched and registered with the ELB, so more instances mean more operations.
Understanding how scaling operations grow helps you design systems that respond well to demand changes and explain your reasoning clearly in discussions.
"What if the Auto Scaling group used target tracking policies instead of fixed desired capacity? How would the time complexity change?"