Quick revision
The short answer
An order saga runs three local transactions: reserve stock, charge payment, book shipping. With choreography each service reacts to the previous service's event; with orchestration an order saga orchestrator sends commands and stores the saga's state. If a later step fails, earlier steps are undone by compensations, which are new business actions such as releasing stock and refunding the payment, and every step and compensation must be idempotent, retryable and recorded in persisted saga state.
What to remember
In this answer, we designed an order saga with three steps ordered from easiest to hardest to undo, and we defined compensations as new business actions such as releasing stock and refunding. We compared choreography, where events chain the services with no coordinator but the flow is hard to see, with orchestration, where one component sends commands and stores state so the flow is explicit and easy to monitor. Whichever we choose, each step and compensation must be idempotent and retryable, the saga state must be persisted, and the intermediate statuses must be designed into the UI and into every consumer.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
An order saga runs three local transactions: reserve stock, charge payment, book shipping. With choreography each service reacts to the previous service's event; with orchestration an order saga orchestrator sends commands and stores the saga's state. If a later step fails, earlier steps are undone by compensations, which are new business actions such as releasing stock and refunding the payment, and every step and compensation must be idempotent, retryable and recorded in persisted saga state.
Why this question is asked
Placing an order is the classic example of a business process that crosses several services, each with its own database. We cannot wrap it in one database transaction, and two-phase commit across services is rarely available or wanted. Interviewers ask this design question to see whether we can split the process into steps, plan what happens when each step fails, and choose sensibly between the two ways of coordinating a saga. In this answer, we will recap what a saga is, design the happy path, design the compensations, compare choreography with orchestration, and cover the practical rules that make the design work: idempotency, persisted state, and statuses the user can see.
1A Quick Recap of Sagas
A saga is a sequence of local transactions, one per service. Each one commits on its own, so the overall process is not atomic. If step three fails, steps one and two have already committed, and we cannot roll them back. Instead, we run compensating transactions that semantically undo their effect.
This is the key mental shift. A compensation is not a rollback. A rollback makes it as if the change never happened. A compensation is a new business action that happens later and leaves a trace: a refund is a new payment going the other way, and the customer may see both the charge and the refund on their statement.
2Designing the Steps and Their Compensations
We order the steps so that the ones easiest to undo come first and the one hardest to undo comes last. Reserving stock is cheap to undo, charging a card is undoable with a refund, and booking a courier may cost a cancellation fee. So the order is stock, then payment, then shipping.
| Step | Service | If a later step fails | Kind |
|---|---|---|---|
| Create order as PENDING | Order | Mark order CANCELLED | compensatable |
| Reserve stock | Inventory | Release the reservation | compensatable |
| Charge payment | Payment | Refund the charge | pivot: retry forward first |
| Book shipping | Shipping | none needed, last step | retriable |
| Confirm order | Order | none | retriable |
Notice that shipping, the last step, needs no compensation in this saga, because nothing after it can fail. Notice also that payment is where the saga commits to going forward in practice: once the card is charged, we try hard to finish, retrying shipping or booking another carrier before we refund. A step like this, after which the saga no longer compensates but only retries forward, is called the pivot transaction.
3Option 1: Choreography
In choreography each service listens for an event and publishes the next one. Order publishes OrderPlaced, Inventory reserves stock and publishes StockReserved, Payment charges and publishes PaymentCharged, Shipping books and publishes ShipmentBooked, and Order marks itself CONFIRMED. For failures, Payment publishes PaymentFailed, Inventory hears it and releases the stock, and Order hears it and cancels.
The strength is loose coupling and no central component to run. The cost shows up as the flow grows: the process exists only as the sum of who listens to what, so nobody can read it in one place. Adding a fraud check between stock and payment means changing which events two services listen to. And when an order is stuck, we have to ask every service what it last saw.
4Option 2: Orchestration
In orchestration an order saga orchestrator, often inside the order service, drives the flow. It sends a command to each service, ReserveStock, ChargePayment, BookShipment, waits for the reply event, stores the new state, and decides the next command or the compensation.
7 messages in order. Play them, or step through them one at a time.
Shipping is never contacted: the saga compensates the steps that committed and stops.
Notice that the orchestrator persists its state and writes the next command through an outbox in the same transaction, so a crash never leaves it unsure of what it already asked for. The flow is explicit in one class, monitoring is a query over the saga table, and changing the order of steps touches one service. The cost is a central component that knows about every participant, which some teams see as coupling.
5Idempotency, Retries and Persisted State
Messages can arrive twice and replies can be lost, so every participant must handle the same command more than once without doing the work twice. ReserveStock for order 42 should create one reservation however many times it arrives, which we achieve with the order id as a unique key or a deduplication table. Compensations need the same care: releasing a reservation that is already released must succeed quietly, and refunding must use the original charge id as an idempotency key with the payment provider.
Retries also need a limit and an outcome. If ChargePayment gets no reply, the orchestrator retries with the same id, and after a deadline it asks the payment service for the status before deciding to compensate. All of this needs the saga state persisted, never kept in memory, because the process running the saga may restart at any moment.
6Designing for Visible Intermediate States
Because the steps commit one at a time, the outside world can see the saga in the middle. The customer may refresh the page while stock is reserved and payment is still running. So we design statuses for it, PENDING, CONFIRMED, CANCELLED and maybe PAYMENT_FAILED, and the UI shows them honestly: 'We are confirming your order' rather than a success page that later turns into a cancellation email.
Other services must also treat PENDING orders correctly. Reporting should not count them as revenue, and a warehouse should not pick stock for an order until it is CONFIRMED. This lack of isolation between sagas is the price of not holding locks across services, and we pay it by being explicit about states.
7Follow-up questions
What is a pivot transaction in a saga?
It is the step after which the saga stops compensating and only moves forward. Steps before the pivot are compensatable, steps after it must be retriable until they succeed. In our order saga the payment charge plays that role: once money is taken, we prefer to retry or reroute shipping rather than refund, and we order the steps so that everything after the pivot is very unlikely to fail permanently.
Which would you choose for this order flow?
For three participants with real money involved, I would lean to orchestration, because the state of each order is in one table, timeouts and compensations live in one place, and support can see where an order is. I would keep choreography for simple reactions where a missed step is cheap, such as sending a notification when an order ships.
Why not use a distributed transaction across the three services?
Two-phase commit needs every participant and the broker to support it, holds locks while waiting for the slowest service, and fails badly when the coordinator is unavailable. Most modern services and SaaS payment providers do not offer it at all. Sagas accept temporary inconsistency in exchange for availability and independence.
8Conclusion
In this answer, we designed an order saga with three steps ordered from easiest to hardest to undo, and we defined compensations as new business actions such as releasing stock and refunding. We compared choreography, where events chain the services with no coordinator but the flow is hard to see, with orchestration, where one component sends commands and stores state so the flow is explicit and easy to monitor. Whichever we choose, each step and compensation must be idempotent and retryable, the saga state must be persisted, and the intermediate statuses must be designed into the UI and into every consumer.
Open with
I would model the order as a saga of local transactions: reserve stock, charge payment, book shipping, then confirm the order. I order them from easiest to hardest to undo, so payment is effectively the pivot, and after it we only retry forward.
Then, if they want more
For compensations, if payment fails we release the stock and cancel the order, and if shipping fails permanently we refund the payment and release the stock. I would stress that compensations are new business actions, a refund appears on the statement, not rollbacks.
With choreography, each service reacts to the previous event, there is no coordinator, but the flow is spread across services and hard to change or monitor. With orchestration, a saga orchestrator sends commands, waits for replies, and stores the state per order, so the flow is in one place and stuck orders are a query.
For this flow with money involved I would choose orchestration. Either way every command and compensation must be idempotent, keyed by order id, retried with limits, sent through an outbox, and the saga state must be persisted. Finally, the order is visible as PENDING while the saga runs, so the UI and other consumers need to treat that status explicitly.
About this answer
- Last updated
- 12 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- Apache Kafka documentation, Spring for Apache Kafka reference
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design a saga for placing an order that reserves stock, charges payment and books...": https://scrivio-interview-library.netlify.app/spring-boot/event-driven-patterns/3bec7da4e8/