Workflows for orchestration in GCP - Time & Space 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.
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 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.
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 |
|---|---|
| 10 | 10 HTTP calls |
| 100 | 100 HTTP calls |
| 1000 | 1000 HTTP calls |
Pattern observation: The number of calls grows linearly as you add more steps.
Time Complexity: O(n)
This means the total time and calls increase directly in proportion to the number of workflow steps.
[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.
Understanding how workflow steps add up helps you design efficient cloud processes and answer questions about scaling tasks.
"What if the workflow steps ran in parallel instead of sequence? How would the time complexity change?"