AWS global infrastructure (regions, AZs) - Time & Space Complexity
When working with AWS global infrastructure, it's important to understand how the number of regions and availability zones affects operations.
We want to know how the effort or calls grow as we add more regions or zones.
Analyze the time complexity of listing all availability zones across all AWS regions.
// Pseudocode for AWS SDK calls
regions = ec2.describeRegions()
for region in regions:
azs = ec2.describeAvailabilityZones({RegionName: region})
print(azs)
This sequence fetches all regions, then for each region fetches its availability zones.
Look at what repeats as input grows.
- Primary operation: API call to describe availability zones per region.
- How many times: Once per region.
As the number of regions increases, the number of calls to get availability zones also increases.
| Input Size (n = regions) | Approx. API Calls |
|---|---|
| 10 | 1 (describeRegions) + 10 (describeAvailabilityZones) = 11 |
| 100 | 1 + 100 = 101 |
| 1000 | 1 + 1000 = 1001 |
Pattern observation: The number of API calls grows linearly with the number of regions.
Time Complexity: O(n)
This means the effort grows directly in proportion to the number of regions.
[X] Wrong: "Fetching availability zones is a single call regardless of regions."
[OK] Correct: Each region has its own availability zones, so you must call the API separately for each region.
Understanding how operations scale with AWS regions helps you design efficient cloud solutions and shows you think about real-world system growth.
"What if we cached availability zones for each region instead of calling every time? How would the time complexity change?"