Many serverless processes involve several steps: validate an order, reserve stock, charge a card, send a confirmation, notify the warehouse. You can write that sequence as code in one Lambda function, chain functions with events, or model it as an AWS Step Functions state machine. This guide explains the trade-offs and gives a practical rule for choosing.
Option 1: orchestration inside one Lambda function
The simplest approach is a handler that calls each step in order.
It works well when:
- the whole process finishes comfortably within the function timeout (15 minutes at most, and API-facing functions much less),
- steps are fast and rarely fail,
- there is no need to wait for external events or people, and
- partial failure is easy to undo or harmless.
Its weaknesses appear as processes grow: you pay for the function while it waits on slow calls, retries and timeouts are hand-written, a crash halfway leaves no record of which steps completed, and the logic is only visible by reading code.
Option 2: choreography with events
Each step publishes an event when it finishes, and the next step's function reacts to it (for example, OrderPlaced → payment function → PaymentCaptured → shipping function). This keeps services loosely coupled and is ideal when different teams own the steps and new consumers appear over time. The downside: nobody owns the process. Answering "where is order o-123 stuck?" means piecing together logs across services, and timeouts ("payment never answered") need extra machinery. See EventBridge vs SQS vs SNS for the messaging side.
Option 3: orchestration with Step Functions
Step Functions models the process as a state machine defined in Amazon States Language, with tasks, choices, parallel branches, maps, waits, and error handling.
What you get:
- Built-in retries and catches per step, with backoff and jitter, declared rather than coded.
- Timeouts and heartbeats for every task.
- Waits from seconds to up to a year without paying for idle compute (in Standard workflows).
- Human-in-the-loop steps with task tokens: the workflow pauses until a callback approves or rejects.
- Parallel branches and Map states, including Distributed Map for processing millions of items from S3.
- Direct SDK integrations with more than 200 AWS services, so many steps need no Lambda function at all.
- A visual execution history showing every step's input, output, and error — the answer to "where is order o-123 stuck?".
Standard vs Express workflows
- Standard: up to one year per execution, exactly-once execution of each step, full execution history, priced per state transition. Use for business processes, long waits, and anything that needs an audit trail.
- Express: up to five minutes, at-least-once execution, priced per request and duration, much higher throughput. Use for high-volume, short workflows such as event transformation or synchronous API orchestration.
Sagas: undoing partial work
When a process changes several systems, a failure halfway needs compensation: refund the card if shipping fails, release the stock if payment fails. In Step Functions, each step's Catch routes to compensating steps, making the saga explicit and testable. In plain code, the same logic tends to be scattered and incomplete.
Cost considerations
- A Lambda function that waits on downstream calls pays for that waiting time; a workflow waiting in a
Waitstate or on a callback does not. - Standard workflows bill per state transition, so very chatty, high-volume workflows can get expensive — that is what Express workflows are for.
- Direct service integrations remove Lambda invocations entirely for steps that only call an AWS API.
Testing and development
Workflows can be defined in AWS CDK with typed constructs, tested with the Step Functions TestState API for individual states, and exercised end to end in a development account. Keep business logic in small Lambda functions with unit tests, and let the state machine handle sequencing, retries, and error paths.
A rule of thumb
- One quick step, or a few fast steps that rarely fail → plain Lambda code.
- Independent teams reacting to business facts → choreography with events.
- A process with retries, timeouts, waits, human approvals, compensation, or audit needs → Step Functions.
Many systems combine them: services publish events, and a Step Functions workflow orchestrates the critical process that consumes them.
Summary
Code is fine for short, simple sequences. As soon as a process needs reliable retries, long waits, human steps, compensation, or visibility, Step Functions turns hidden control flow into an explicit, observable workflow — often with less code and lower cost. Our event-driven architecture service helps model and build these workflows.