Workflows: orchestration vs choreography
Coordinate multi-step processes across services, with sagas and compensation instead of distributed transactions.
20 min readBusiness processes span services
Placing an order means reserving stock, charging a card, booking a courier and sending a confirmation, each owned by a different service with its own database. There is no transaction across all of them, and some steps take seconds while others (waiting for a warehouse to pack) take days. You need a way to run the steps in order, retry the ones that fail transiently, and undo completed steps when a later one fails for good.
Choreography
In choreography there is no coordinator. Each service listens for events and reacts: Orders publishes OrderPlaced, Inventory reserves stock and publishes StockReserved, Payments charges and publishes PaymentSucceeded. Services stay loosely coupled and new reactions are easy to add. But the process exists only implicitly, spread across subscriptions in several codebases. Answering 'where is order 42 stuck?' means correlating events from every service, and with more than a handful of steps the flow becomes hard to change safely.
Orchestration and durable execution
In orchestration a coordinator owns the process. It tells each service what to do, waits for the result and decides the next step, recording progress in a persisted state machine. The flow is explicit, visible and easy to time out. Durable execution engines such as Temporal and AWS Step Functions make this robust: they record every step's result in a history, so after a crash the workflow resumes where it stopped, and a timer can wait for three days without holding a thread. The risk is an orchestrator that accumulates business logic belonging to the services it calls.
Sagas and compensation
A saga is a sequence of local transactions where each completed step has a compensating action that semantically undoes it.
- Reserve stock is compensated by releasing it; charge card by issuing a refund
- Compensations must be idempotent and retryable, because they can fail too
- Some steps cannot be undone (an email sent, a parcel shipped), so place them after the last step that can fail
- Intermediate states are visible to others: show 'payment pending' rather than pretending the order is complete
Key takeaways
- Multi-service processes cannot use one transaction; use sagas with compensating actions
- Choreography keeps services decoupled but hides the flow; it suits short processes
- Orchestration makes the flow explicit, and durable execution engines survive crashes and long waits
- Put irreversible steps last and make every step and compensation idempotent
Sign in to track lessons and earn badges.