Multi-Step Processes (Workflows & Sagas)
When: one user action spans several services or slow steps — order → payment → inventory → shipping; a ride's lifecycle; onboarding flows.
- State machine per entity (
created → paid → shipped), persisted, with legal transitions only. - Saga: a sequence of local transactions, each with a compensating action (refund, release inventory) if a later step fails. Orchestration (a coordinator tells each service what to do — easier to reason about) vs choreography (services react to each other's events — looser coupling, harder to trace).
- Durable execution / workflow engines (Temporal, AWS Step Functions, Cadence): write the workflow as code; the engine persists every step, retries with back-off, survives crashes and supports timers ("cancel the hold after 10 minutes").
- Outbox pattern to publish events atomically with the state change; idempotent steps so retries are safe.
- Avoid distributed 2PC across services: it blocks on coordinator failure and couples availability.