0
0
GCPcloud~5 mins

Organization policies in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Organization policies
O(n)
Understanding Time 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.

Scenario Under Consideration

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 Repeating Operations

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

Each additional project requires one more API call to set the policy.

Input Size (n)Approx. Api Calls/Operations
1010
100100
10001000

Pattern observation: The number of API calls grows directly with the number of projects.

Final Time Complexity

Time Complexity: O(n)

This means the time to apply policies increases linearly as you add more projects.

Common Mistake

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

Interview Connect

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.

Self-Check

"What if we applied the policy at the organization level instead of per project? How would the time complexity change?"