Organization policies in GCP - Time & Space Complexity
When applying organization policies in GCP, it's important to understand how the time to enforce these policies changes as you add more projects or resources.
We want to know how the number of policy checks or API calls grows when managing many resources.
Analyze the time complexity of the following operation sequence.
# Apply an organization policy to multiple projects
for project in projects_list:
gcloud org-policies set-policy \
--project=$project \
--policy=policy.yaml
This sequence applies the same organization policy to each project in a list one by one.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Setting the organization policy on each project via API call.
- How many times: Once per project in the list.
Each additional project requires one more API call to set the policy.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 |
| 100 | 100 |
| 1000 | 1000 |
Pattern observation: The number of API calls grows directly with the number of projects.
Time Complexity: O(n)
This means the time to apply policies increases linearly as you add more projects.
[X] Wrong: "Applying one policy automatically updates all projects instantly without extra calls."
[OK] Correct: Each project requires its own API call to apply the policy, so time grows with the number of projects.
Understanding how operations scale with resource count helps you design efficient cloud management strategies and shows you can think about system behavior as it grows.
"What if we applied the policy at the organization level instead of per project? How would the time complexity change?"