Because each service owns its own database, ShopNexus cannot use a single ACID transaction
across services. The Saga pattern coordinates a business transaction as a sequence of
local transactions, each with a compensating action to undo its effect on failure.
Styles
Choreography
Orchestration
Each service reacts to events and emits the next event. No central coordinator.
- Decentralized and loosely coupled.
- Harder to follow the end-to-end flow as steps grow.
A coordinator tells each service what step to run and reacts to the outcome.
- Centralized flow that is easy to trace and change.
- The orchestrator becomes a component to design and operate carefully.
Compensation
When a step fails, previously completed steps are rolled back with compensating
transactions (e.g. release reserved stock, refund a payment) rather than a database
rollback.
Sagas provide eventual consistency, not isolation. Design steps to be idempotent and handle
out-of-order or duplicate messages.