Step Functions for workflows in AWS - Time & Space Complexity
When using Step Functions to run workflows, it's important to know how the time to complete grows as the workflow gets bigger.
We want to understand how the number of steps affects the total execution time.
Analyze the time complexity of the following operation sequence.
{
"StartAt": "Step1",
"States": {
"Step1": {"Type": "Task", "Resource": "arn:aws:lambda:...", "Next": "Step2"},
"Step2": {"Type": "Task", "Resource": "arn:aws:lambda:...", "Next": "Step3"},
"Step3": {"Type": "Task", "Resource": "arn:aws:lambda:...", "End": true}
}
}
This workflow runs three tasks one after another, each calling a Lambda function.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Executing each Task state which calls a Lambda function.
- How many times: Once per step in the workflow (3 times in this example).
Each additional step adds one more Lambda call, so the total calls grow directly with the number of steps.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 Lambda calls |
| 100 | 100 Lambda calls |
| 1000 | 1000 Lambda calls |
Pattern observation: The number of operations grows in a straight line as steps increase.
Time Complexity: O(n)
This means the total execution time grows directly in proportion to the number of steps in the workflow.
[X] Wrong: "Adding more steps won't affect total time much because Step Functions run tasks in parallel by default."
[OK] Correct: By default, steps run one after another unless explicitly designed for parallelism, so more steps usually mean more total time.
Understanding how workflow length affects execution time helps you design efficient cloud processes and shows you can think about scaling real systems.
"What if we changed the workflow to run multiple tasks in parallel? How would the time complexity change?"