Right-sizing resources in AWS - Time & Space Complexity
When we right-size resources in AWS, we adjust the size or capacity of services to fit the workload.
We want to know how the time to complete this adjustment changes as the number of resources grows.
Analyze the time complexity of resizing multiple EC2 instances.
for instance_id in instance_list:
stop_instance(instance_id)
modify_instance_type(instance_id, new_type)
start_instance(instance_id)
wait_until_running(instance_id)
This sequence stops each instance, changes its type, restarts it, and waits until it is running again.
Look at what repeats for each instance.
- Primary operation: Stopping, modifying, and starting each instance.
- How many times: Once per instance in the list.
Each instance requires the same set of steps, so the total time grows as we add more instances.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 10 sets of stop, modify, start, wait |
| 100 | About 100 sets of stop, modify, start, wait |
| 1000 | About 1000 sets of stop, modify, start, wait |
Pattern observation: The total operations increase directly with the number of instances.
Time Complexity: O(n)
This means the time to right-size grows in direct proportion to how many instances you have.
[X] Wrong: "Changing the size of many instances takes the same time as changing one."
[OK] Correct: Each instance needs its own stop, modify, and start steps, so more instances mean more total time.
Understanding how operations scale with resource count helps you plan and explain cloud changes clearly.
"What if we resized instances in parallel instead of one by one? How would the time complexity change?"