0
0
AWScloud~5 mins

High availability design patterns in AWS - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: High availability design patterns
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As you add more instances, you launch and register more servers one by one.

Input Size (n)Approx. Api Calls/Operations
10About 10 launches + 10 registrations = 20 calls
100About 100 launches + 100 registrations = 200 calls
1000About 1000 launches + 1000 registrations = 2000 calls

Pattern observation: The number of calls grows directly with the number of instances added.

Final Time Complexity

Time Complexity: O(n)

This means the work to deploy and connect instances grows in a straight line as you add more servers.

Common Mistake

[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.

Interview Connect

Understanding how adding resources affects deployment effort helps you design systems that stay reliable without surprises.

Self-Check

"What if we used an auto-scaling group to manage instances instead of launching each manually? How would the time complexity change?"