0
0
GCPcloud~5 mins

Workflows for orchestration in GCP - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Workflows for orchestration
O(n)
Understanding Time Complexity

When using Workflows to organize cloud tasks, it's important to know how the time to complete grows as you add more steps.

We want to understand how the number of steps affects the total time and calls made.

Scenario Under Consideration

Analyze the time complexity of the following workflow definition.


main:
  steps:
  - step1:
      call: http.get
      args:
        url: https://example.com/api/resource
  - step2:
      call: http.get
      args:
        url: https://example.com/api/resource2
  - step3:
      call: http.get
      args:
        url: https://example.com/api/resource3
    

This workflow calls three HTTP endpoints in sequence, each step waiting for the previous to finish.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: HTTP call to an external API endpoint.
  • How many times: Once per step, so as many times as there are steps.
How Execution Grows With Input

Each added step adds one more HTTP call, so the total calls grow directly with the number of steps.

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

Pattern observation: The number of calls grows linearly as you add more steps.

Final Time Complexity

Time Complexity: O(n)

This means the total time and calls increase directly in proportion to the number of workflow steps.

Common Mistake

[X] Wrong: "Adding more steps won't affect total time much because calls run instantly."

[OK] Correct: Each step waits for the previous to finish, so total time adds up with each call.

Interview Connect

Understanding how workflow steps add up helps you design efficient cloud processes and answer questions about scaling tasks.

Self-Check

"What if the workflow steps ran in parallel instead of sequence? How would the time complexity change?"