Quick revision
The short answer
The orchestrator keeps each booking's saga in a table, with saga id, current step, status per step and correlation ids, and updates it in the same transaction as the outbox row that sends the next command. Every command carries the saga id and an idempotency key, and replies drive the state machine forward. On failure it compensates completed steps in reverse order with idempotent, retryable commands; after a crash it reloads in-flight sagas and resumes from the recorded step, with timeouts for lost replies. A non-refundable pivot step allows only forward recovery, and a workflow engine is worth considering when flows are long-running or change often.
What to remember
In this answer, we designed an orchestrated travel booking saga in Spring Boot. The saga state lives in a table with step statuses, correlation ids and a deadline, and changes in the same transaction as the outbox command. Commands carry the saga id and a stable idempotency key, replies advance the state machine, compensations run in reverse order and are idempotent, and after a crash the orchestrator resumes from the recorded step with deadlines catching lost replies. Pivot steps such as a non-refundable flight go last and allow only forward recovery, and a workflow engine is the better choice when flows are long-running or change often.
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.
The orchestrator keeps each booking's saga in a table, with saga id, current step, status per step and correlation ids, and updates it in the same transaction as the outbox row that sends the next command. Every command carries the saga id and an idempotency key, and replies drive the state machine forward. On failure it compensates completed steps in reverse order with idempotent, retryable commands; after a crash it reloads in-flight sagas and resumes from the recorded step, with timeouts for lost replies. A non-refundable pivot step allows only forward recovery, and a workflow engine is worth considering when flows are long-running or change often.
Why this question is asked
Travel booking is the textbook saga: three providers, three reservations, and a customer who expects either a complete trip or nothing. It is a good design question because every hard part of sagas shows up at once: persistence, retries, compensation order, crashes and steps that cannot be undone. Interviewers at the ten-year level want to see a design that survives failures, not just a happy path. In this answer, we will define the state model and its table, show how commands and replies flow through an outbox, handle retries and compensation, walk through recovery after an orchestrator crash, deal with pivot steps, and finally discuss when a workflow engine is the better choice.
1The State Model
The orchestrator is a Spring Boot service, the booking service, that drives a state machine for each trip. The steps are reserve flight, reserve hotel and reserve car. Each step can be PENDING, DONE, FAILED, COMPENSATING or COMPENSATED, and the saga as a whole is RUNNING, COMPLETED, COMPENSATING, COMPENSATED or NEEDS_ATTENTION. We persist this in a table so that the state survives restarts and can be queried.
Notice the version column. Two replies for the same saga could arrive at the same time, for example a late reply and a timeout firing, and optimistic locking with JPA's @Version makes sure only one of them changes the state; the other retries with fresh data.
2Commands Through an Outbox, Replies Driving the Machine
When the saga advances, it must record its new state and send the next command, and both must happen or neither. So the state update and an outbox row with the command are written in one local transaction, and a relay publishes the outbox to the services' command topics. Each command carries the saga id, so replies can be matched, and an idempotency key such as <sagaId>-FLIGHT-RESERVE, which stays the same on every retry.
10 messages in order. Play them, or step through them one at a time.
Compensations run in reverse order, only for the steps that completed.
The hotel service uses the idempotency key to recognise a repeated ReserveHotel and return the reservation it already made, rather than booking a second room. That is what makes retries safe.
3Retries and Compensation
Transient failures, a timeout or a 503 from a provider, are retried with backoff, reusing the same idempotency key, up to a limit such as five attempts. A business failure, such as no cars available, is not retried; it starts compensation. The orchestrator walks back through the completed steps in reverse order, cancel hotel then cancel flight, sending each compensation through the outbox and waiting for its reply.
Compensations must be both retryable and idempotent. A CancelHotel may be delivered twice, and the hotel service must confirm the cancellation the second time without error. It must also handle a cancel for a reservation it never made, which happens when the reserve command timed out and we compensate to be safe; the right answer is to confirm that nothing is reserved.
4When the Orchestrator Crashes Mid-Flow
Because the saga state is in the database, a crash loses nothing that was committed. When the service restarts, or another pod takes over, a recovery job loads sagas in RUNNING or COMPENSATING state and resumes each one from its recorded step. If the outbox row for the current step was committed, the relay will still send it. If the reply arrived while the service was down, it is waiting in the topic and will be consumed.
The one case left is a reply that was truly lost. The deadline_at column covers it: a scheduled job finds sagas whose deadline has passed and re-sends the current command with the same idempotency key. The receiving service either performs it or returns the result it already produced. After the retry limit, the saga starts compensation or moves to NEEDS_ATTENTION.
5Pivot Steps and Forward Recovery
Some steps cannot be undone. If the flight fare is non-refundable, once it is booked we cannot compensate it by cancelling. Such a step is called the pivot: before it, the saga can still go back; after it, it can only go forward. So we order the steps to put the pivot as late as possible, for example reserve the hotel and the car first, as holds that can be cancelled, and book the non-refundable flight last.
After the pivot, failures are handled by forward recovery: keep retrying the remaining steps, try an alternative such as another car provider, or hand the case to a person, but never try to roll back. The state model reflects this with a flag that marks the pivot as passed, so compensation is no longer allowed for that saga.
- Was the failure transient?timeout, 503YesRetry with same keyNoBusiness failure
- Pivot already passed?non-refundable flight bookedYesForward recovery onlyNoCompensate in reverse order
- Compensation succeeded?YesSaga COMPENSATEDNoNEEDS_ATTENTION, alert
3 steps in order. Play them, or step through them one at a time.
6Hand-Written Orchestrator or Workflow Engine?
Everything above, state tables, deadlines, retries with backoff, recovery jobs, is what workflow engines provide out of the box. Temporal lets us write the saga as ordinary Java code whose state is persisted by the engine; Camunda models it as a BPMN process. They become worth their cost when flows are long-running, hours or days waiting for a human approval or a provider callback, or when the business changes the flow often, because versioning running instances is hard to build ourselves.
For a three-step booking that completes in seconds and rarely changes, a hand-written orchestrator in Spring Boot is reasonable and keeps the dependency count low. If we expect ten more such flows, a shared engine pays for itself.
7Follow-up questions
How do you handle a compensation that keeps failing?
First, retry it with backoff, since most failures are transient and compensations are idempotent. If it still fails after the limit, for example the hotel API rejects the cancellation, the saga moves to NEEDS_ATTENTION, raises an alert and appears in a support queue with the full history. A person then resolves it, perhaps by calling the hotel, and marks the step compensated through an admin action. What we must not do is drop it silently, because then the customer pays for a room they did not get.
How would you show a support engineer the state of one saga?
Through a read-only admin page or endpoint that, given a booking or saga id, shows the saga row, every step's status and provider reference, and an ordered history of commands sent and replies received with timestamps. Keeping a saga_event history table alongside the state makes this simple. Linking each entry to its trace id lets the engineer jump to the logs. With a workflow engine, its UI already shows this.
8Conclusion
In this answer, we designed an orchestrated travel booking saga in Spring Boot. The saga state lives in a table with step statuses, correlation ids and a deadline, and changes in the same transaction as the outbox command. Commands carry the saga id and a stable idempotency key, replies advance the state machine, compensations run in reverse order and are idempotent, and after a crash the orchestrator resumes from the recorded step with deadlines catching lost replies. Pivot steps such as a non-refundable flight go last and allow only forward recovery, and a workflow engine is the better choice when flows are long-running or change often.
Open with
I would make the booking service the orchestrator and keep a saga table with the saga id, overall status, current step, status and provider reference for flight, hotel and car, an attempt count, a deadline and a version for optimistic locking.
Then, if they want more
Every state change is committed in the same transaction as an outbox row holding the next command, so state and command can never disagree. Each command carries the saga id and an idempotency key like saga id plus step, so the flight, hotel and car services return the existing result for a repeated command. Replies drive the state machine forward.
Transient failures are retried with backoff using the same key. A business failure, like no cars, starts compensation: I cancel the completed steps in reverse order, hotel then flight, and each cancel is idempotent and also safe when nothing was reserved.
If the orchestrator crashes, nothing is lost because the state is in the database; on restart it loads running sagas and resumes, and a deadline job re-sends the current command when a reply is lost. A non-refundable flight is a pivot step, so I put it last; after it, only forward recovery is allowed, retrying or escalating to a person.
If these flows became long-running or changed often, I would move to a workflow engine such as Temporal or Camunda instead of maintaining this myself.
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
- Spring Cloud documentation, Resilience4j documentation
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 an orchestrated saga in Spring Boot for a travel booking that reserves a flight...": https://scrivio-interview-library.netlify.app/spring-boot/distributed-data/262dd991a4/