Volume 10 · Chapter 6 — Messaging and Event-Driven Architecture
Orchestration with Step Functions
6.1 Introduction
Events and queues connect services, but some business processes are multi-step workflows with sequencing, branching, error handling, and retries that become messy to coordinate through scattered events alone. AWS Step Functions provides orchestration - defining and running these workflows as a coordinated state machine. This chapter covers orchestration versus choreography, how Step Functions manages multi-step processes (including sagas), and when to reach for it - a valuable distinction for designing complex flows and a senior interview topic.
6.2 Orchestration vs Choreography
There are two ways to coordinate a multi-service process. Choreography is event-driven and decentralized: each service reacts to events and emits its own, with no central coordinator - the flow emerges from services responding to each other’s events. It’s loosely coupled and works well for simple flows, but for complex, multi-step processes it can become hard to understand and track, because the overall flow isn’t defined anywhere - it’s implicit in how services react. Orchestration is centralized: a coordinator explicitly defines and drives the sequence of steps, calling each service in turn and handling the flow. It makes the process explicit, visible, and easier to manage, at the cost of a central coordinator. The choice depends on complexity: choreography for simple, loosely-coupled reactions; orchestration for complex processes that benefit from an explicit, managed flow.
stateDiagram-v2 [*] --> ReserveFunds ReserveFunds --> RecordPayment: success ReserveFunds --> [*]: failure RecordPayment --> PostToLedger: success RecordPayment --> CompensateReserve: failure PostToLedger --> Complete: success PostToLedger --> CompensatePayment: failure CompensatePayment --> CompensateReserve CompensateReserve --> [*] Complete --> [*]
6.3 What Step Functions Provides
Step Functions lets you define a workflow as a state machine - a series of steps with transitions, branching, parallel execution, error handling, and retries - and runs it reliably, coordinating the services at each step. It handles the plumbing of a multi-step process: sequencing steps, branching on results, retrying failed steps with backoff, catching errors, and tracking the state of each execution, with a visual representation of the workflow and its progress. This turns a complex process that would otherwise be tangled across many services and events into an explicit, managed, observable workflow. You get built-in error handling and retries per step, visibility into where each execution is, and a single place that defines the process - which is exactly what complex multi-step flows need.
6.4 Orchestrating Sagas
Step Functions is a natural fit for the saga pattern from Volume 7 - a multi-step cross-service operation with compensating actions on failure. You define the saga as a state machine: each step performs a local action, and on failure the workflow transitions to compensating steps that undo the prior actions. A payment saga might reserve funds, record the payment, and post to the ledger, with the workflow orchestrating each step and, if a later step fails, running compensations to release the reservation and void the payment. Step Functions’ built-in error handling, retries, and explicit flow make it much easier to implement a saga correctly and observably than coordinating it through scattered events, because the compensation logic and the whole flow are defined and visible in one place rather than implicit across services.
6.5 When to Use Orchestration
You reach for orchestration (Step Functions) when a process is genuinely multi-step and complex - with sequencing, branching, error handling, retries, and a need to track and reason about the overall flow - especially cross-service workflows and sagas where correctness and visibility matter. You stay with choreography (events) for simpler, loosely-coupled reactions where the decentralization is fine and a central coordinator would be unnecessary overhead. Many systems use both: event-driven choreography for the overall loose coupling between services, and orchestration for specific complex multi-step processes within that. The judgment is to use an explicit orchestrated workflow when the complexity of a process makes an implicit event flow hard to understand and manage, and to keep simple flows choreographed - matching coordination style to process complexity.
6.6 Banking Production Scenario
A bank orchestrates its complex loan-disbursement and multi-step payment processes with Step Functions. A cross-account transfer is defined as a state machine implementing a saga: reserve funds, record the payment, post to the ledger, each with retries and error handling, and compensating steps (release reservation, void payment) if a later step fails - all explicit and observable in one workflow, with the bank able to see exactly where each execution is. This is far clearer and more reliable than coordinating the same flow through scattered events. For simpler reactions - notifying services that a payment happened - the bank uses event-driven choreography via SNS/SQS and EventBridge. It orchestrates the complex, correctness-critical multi-step processes and choreographs the simple loosely-coupled ones, matching the coordination style to each process’s complexity.
6.7 Troubleshooting: Workflow Coordination Problems
Coordination problems point to the wrong style or missing orchestration. A complex multi-step process that’s hard to understand or track because it’s spread across many reacting services means it should be orchestrated explicitly with Step Functions rather than choreographed. A saga implemented through scattered events with error-prone, hard-to-follow compensation logic is much cleaner as an orchestrated state machine. Difficulty knowing where a process is or why it failed means there’s no central, observable workflow - orchestration provides that visibility. Conversely, adding a heavy orchestrator for simple loosely-coupled reactions is unnecessary overhead - use events there. Steps failing without retries or compensation mean the workflow’s error handling isn’t defined. The discipline is orchestration for complex, multi-step, correctness-critical flows (explicit, observable, with retries and compensation) and choreography for simple loosely-coupled reactions.
What's the difference between orchestration and choreography, and when would you use Step Functions?
Orchestration and choreography are two ways to coordinate a multi-service process, differing in whether there’s a central coordinator. Choreography is event-driven and decentralized: each service reacts to events and emits its own, with no central coordinator, so the overall flow emerges implicitly from services responding to each other’s events. It’s loosely coupled and works well for simple flows, but for complex multi-step processes it becomes hard to understand and track, because the overall flow isn’t defined anywhere - it’s implicit in how services react, so nobody can point to “the process” or easily see where an execution is or why it failed. Orchestration is centralized: a coordinator explicitly defines and drives the sequence of steps, calling each service in turn, handling branching, errors, and retries. It makes the process explicit, visible, and easier to manage and reason about, at the cost of having a central coordinator. AWS Step Functions provides orchestration by letting you define a workflow as a state machine - a series of steps with transitions, branching, parallel execution, error handling, and retries - and running it reliably while coordinating the services at each step, with built-in per-step retries and error catching, tracking of each execution’s state, and a visual representation of the workflow and its progress. I use Step Functions when a process is genuinely multi-step and complex - needing sequencing, branching, error handling, retries, and the ability to track and reason about the overall flow - especially cross-service workflows and sagas where correctness and visibility matter. It’s a natural fit for the saga pattern: I define the saga as a state machine where each step performs a local action and, on failure, the workflow transitions to compensating steps that undo prior actions - a payment saga reserving funds, recording the payment, and posting to the ledger, with compensations to release the reservation and void the payment if a later step fails - which is far easier to implement correctly and observably than coordinating the same flow through scattered events, because the compensation logic and the whole flow are defined and visible in one place. I stay with choreography, using events, for simpler loosely-coupled reactions where decentralization is fine and a central coordinator would be unnecessary overhead - like simply notifying several services that a payment happened. Many systems use both: event-driven choreography for the overall loose coupling between services, and orchestration for specific complex multi-step processes within that. So the judgment is to orchestrate with Step Functions when a process’s complexity makes an implicit event flow hard to understand, manage, and get right - gaining an explicit, observable, reliably-executed workflow with error handling and compensation - and to choreograph simple flows with events, matching the coordination style to the process’s complexity.
Chapter Revision Notes
- Choreography: decentralized, event-driven, services react to each other’s events - loosely coupled, good for simple flows but implicit and hard to track when complex.
- Orchestration: a central coordinator explicitly defines and drives the steps - explicit, visible, manageable, at the cost of a coordinator.
- Step Functions runs a workflow as a state machine with branching, retries, error handling, and execution tracking.
- It’s a natural fit for sagas - each step a local action, compensating steps on failure - defined and observable in one place.
- Orchestrate complex, multi-step, correctness-critical flows; choreograph simple loosely-coupled reactions; often use both.