High availability design patterns in AWS - Time & Space Complexity
We want to understand how the effort to keep a system always running grows as we add more parts to it.
How does adding more servers or resources affect the work needed to maintain high availability?
Analyze the time complexity of deploying a multi-AZ load balanced web service.
aws ec2 run-instances --count n --image-id ami-12345678 --subnet-id subnet-abcde
aws elbv2 create-load-balancer --name my-lb --subnets subnet-abcde subnet-fghij
aws elbv2 register-targets --target-group-arn arn:tg --targets Id=i-12345 Id=i-67890
aws elbv2 create-listener --load-balancer-arn arn:lb --protocol HTTP --port 80 --default-actions Type=forward,TargetGroupArn=arn:tg
This sequence launches n instances across availability zones, sets up a load balancer, and connects instances to it.
Look at what repeats as we add more instances.
- Primary operation: Launching EC2 instances (run-instances) and registering them to the load balancer.
- How many times: The launch and registration happen once per instance, so n times.
As you add more instances, you launch and register more servers one by one.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 10 launches + 10 registrations = 20 calls |
| 100 | About 100 launches + 100 registrations = 200 calls |
| 1000 | About 1000 launches + 1000 registrations = 2000 calls |
Pattern observation: The number of calls grows directly with the number of instances added.
Time Complexity: O(n)
This means the work to deploy and connect instances grows in a straight line as you add more servers.
[X] Wrong: "Adding more servers does not increase deployment time because everything happens at once."
[OK] Correct: Each server requires its own setup and registration, so the total work grows with the number of servers.
Understanding how adding resources affects deployment effort helps you design systems that stay reliable without surprises.
"What if we used an auto-scaling group to manage instances instead of launching each manually? How would the time complexity change?"