Scrivio Interview library
ScenarioIntermediate8 min read · updated 12 November 2026

In a choreographed saga, an order sometimes stays in PENDING forever. Logs show the payment service failed after reserving funds and the event it should have emitted never arrived. How would you find and prevent stuck sagas?

An order stuck in PENDING means a step in the saga did its work but the event that should have moved the flow forward was never published or never consumed. We find it by following the order id across every service's logs and traces, and we prevent it with a transactional outbox in each service, visible and alerted dead-letter topics, and a timeout on every saga state that triggers a check or a compensation when nothing happens.

Why this question is asked

A saga that stops halfway is one of the worst failures in an event-driven system, because nothing crashes and nothing alerts. The customer simply waits, money may be held, and support finds out from a complaint. Interviewers ask this scenario because it tests whether we understand where events get lost in practice and whether we design for silence rather than only for errors. In this answer, we will recap how a choreographed saga moves forward, trace where the missing event most likely went, show how to investigate one stuck order, and then go through the fixes that stop it happening again, including when to switch to orchestration.

1A Quick Recap of a Choreographed Saga

A saga is a long business process split into local transactions, one per service, where each step is committed on its own and a failure is undone by compensating steps instead of a single rollback. There is no distributed transaction holding locks across services.

In a choreographed saga there is no coordinator. Each service listens for an event, does its local work, and publishes the next event. The order service saves the order as PENDING and publishes OrderPlaced. The payment service hears it, reserves funds, and publishes PaymentReserved or PaymentFailed. The order service hears that and moves the order to CONFIRMED or CANCELLED.

Notice what this means: the only thing that moves the order out of PENDING is an event arriving. If that event is never published, or published and never processed, the order has no reason to change. Nobody is waiting for it, so nobody notices it is missing.

2Where Did the Missing Event Go?

In our logs the payment service reserved funds, then failed, and the event never arrived. The most common cause is a dual write: the service commits the reservation to its database and then, as a separate step, sends the event to Kafka. If the process crashes, the broker is unreachable, or an exception is thrown between those two steps, the database says funds are reserved and no event exists.

The second common cause is that the event was published but the consumer could not process it. With a retry and dead-letter setup, Spring Kafka's DefaultErrorHandler with a DeadLetterPublishingRecoverer for example, a message that fails a few times is moved to a dead-letter topic, a side topic for messages that could not be processed. If nobody watches that topic, the event is effectively lost even though it is safely stored.

Java
// The dual write that loses events
@Transactional
public void reserve(OrderPlaced e) {
reservations.save(new Reservation(e.orderId(), e.amount())); // committed at method end
kafka.send("payments", new PaymentReserved(e.orderId())); // sent before the commit
riskCheck(e); // throws: DB rolls back, event already sent
}
// or the opposite order: commit first, then the process dies before send()
// result: database and topic disagree, and the order stays PENDING

So both directions are possible. Sending before the commit can publish an event for work that was rolled back; sending after the commit can lose the event when the process dies in between. Either way the two systems disagree, and the saga stalls.

3Investigating One Stuck Order

We start from the order id, which every event and log line in the saga should carry as a correlation id. With distributed tracing (Micrometer Tracing exporting to an OpenTelemetry backend, for example) and trace ids propagated in Kafka headers, we can open one trace and see each hop. Without tracing, we search the centralised logs of every service for the order id and line the entries up by time.

The question we are answering is simple: which was the last service that did something for this order, and did it publish its event? Then we check the topic itself. If the event is in the main topic, the consumer side failed, so we look at consumer lag and errors. If it is in the dead-letter topic, we read the exception stored in its headers. If it is nowhere, the producer never sent it, which points straight at a dual write.

Step throughFollowing one order through the saga
Order svcPayment svcKafkaDead-letter topic
OrderPlaced(order 42)
deliver OrderPlaced
reserve funds, commit
crash before send
PaymentReserved never sent
or: consumer fails 3 times, message parked
order 42 still PENDING

7 messages in order. Play them, or step through them one at a time.

The trace shows the last hop that worked. Either the event was never sent, or it is parked where nobody looks.

4Fix 1: An Outbox in Every Service

The transactional outbox removes the dual write. Instead of sending to Kafka inside the business method, we insert the event as a row into an outbox table in the same local transaction as the reservation. Either both are committed or neither is. A separate relay, a scheduled poller or a change data capture tool such as Debezium reading the database log, then publishes outbox rows to Kafka and marks them sent.

Java
@Transactional
public void reserve(OrderPlaced e) {
reservations.save(new Reservation(e.orderId(), e.amount()));
outbox.save(OutboxEvent.of("payments", e.orderId(), new PaymentReserved(e.orderId())));
} // one commit: reservation and event row together, or neither
// relay, running separately
@Scheduled(fixedDelay = 500)
public void relay() {
for (OutboxEvent o : outbox.findUnsent(100)) {
kafka.send(o.topic(), o.key(), o.payload()).join(); // wait for the broker ack
outbox.markSent(o.id()); // a crash here means a resend, never a loss
}
}

Notice that the relay can publish the same event twice if it crashes after sending and before marking the row. That is acceptable because consumers in a saga must be idempotent anyway. We trade a possible duplicate for a guarantee that the event is never lost, and duplicates are much easier to handle.

5Fix 2: Make Dead Letters Loud

A dead-letter topic is useful only if someone reacts to it. We alert when its message count grows, show it on the team's dashboard, and give operators a way to inspect a message, fix the cause and replay it to the original topic. Each team should own the dead-letter topics of its consumers, the same way it owns its error logs.

It is also worth separating retryable failures, such as a timeout calling another system, from permanent ones, such as a message that cannot be parsed. Retryable failures deserve retries with backoff; permanent ones should go to the dead-letter topic at once so the alert fires quickly instead of after minutes of pointless retries.

6Fix 3: A Timeout on Every Saga State

Even with outboxes, some failure we did not imagine will leave an order waiting. So we stop trusting silence. Each saga state gets a deadline: an order in PENDING should leave it within, say, five minutes. A scheduled job, or a delayed message, finds orders whose deadline has passed and acts on them.

Java
@Scheduled(fixedDelay = 60_000)
public void findStuckOrders() {
Instant limit = clock.instant().minus(Duration.ofMinutes(5));
for (Order o : orders.findByStatusAndUpdatedAtBefore(Status.PENDING, limit)) {
PaymentStatus p = paymentClient.statusFor(o.id()); // ask the owner of the next step
switch (p) {
case RESERVED -> orderService.confirm(o.id()); // the event was lost; repair forward
case NONE -> orderService.cancel(o.id()); // nothing happened; compensate
default -> metrics.counter("saga.stuck").increment(); // unclear: alert a person
}
}
}
Step throughWhat the timeout job does with a stuck order
  1. Order PENDING past its deadline?
    YesAsk the payment serviceNoLeave it alone
  2. Funds reserved?
    YesConfirm the order, log the lost eventNoCheck whether anything happened
  3. Nothing reserved?
    YesCancel the orderNoAlert a person
  4. Record a saga.stuck metrichow often the other fixes failed

4 steps in order. Play them, or step through them one at a time.

The timeout first checks the real state rather than assuming failure, because the step may have succeeded and only the event was lost. Depending on the answer it repairs forward, compensates by releasing funds and cancelling, or raises an alert for a human. The count of stuck orders also becomes a metric, which tells us how often the other protections fail.

7When to Move to Orchestration

Choreography spreads the state of a saga across every service, which is exactly why stuck sagas are hard to see. An orchestrator, a component that sends commands to each service and stores the saga's state in one place, knows at every moment which step it is waiting for and since when. Timeouts, retries and compensations live in one piece of code, and finding all stuck orders is a single query.

For a two-step flow where a stuck order costs little, choreography with outboxes and timeouts is enough. For flows where a stuck state holds money, stock or a customer promise, the clarity of orchestration, hand-written or on a workflow engine such as Temporal or Camunda, is usually worth its extra component.

8Follow-up questions

Why not just retry the Kafka send in the payment service?

Retrying helps when the broker is briefly unavailable, but it does not help when the process dies between the commit and the send, because the retry loop dies with it. Only writing the event in the same transaction as the business change, with an outbox, guarantees it survives a crash.

How do we make sure the order id reaches every log line?

We put the order id in the event payload and as a Kafka header, and each consumer adds it to the logging context (MDC) when it starts processing a record. With Micrometer Tracing and observation enabled on the Kafka templates and listeners, trace ids are also propagated through headers, so logs and traces line up automatically.

Could the timeout job and a late event both act on the same order?

Yes, so both paths must go through the same state transition with a guard. Confirming an order that is already CANCELLED must be refused, and the late PaymentReserved then triggers a refund. Using a version column or a conditional update such as UPDATE orders SET status = 'CONFIRMED' WHERE id = ? AND status = 'PENDING' keeps the two from racing.

9Conclusion

In this answer, we saw that a saga stuck in PENDING is almost always a lost event: a dual write that committed the database but never sent the message, or a message parked in an unwatched dead-letter topic. We find the gap by following the order id through traces and logs, and we prevent it with an outbox in each service, alerted dead-letter topics, and a deadline on every saga state that checks and repairs or compensates. Where stuck states are expensive, orchestration keeps the saga's state in one place and makes the problem visible by design.

What to say in the interviewAbout 90 seconds aloud

Open with

First I would follow one stuck order by its id through the traces and logs of each service to see the last step that actually happened. Here the payment service reserved funds and then failed, so I would check whether PaymentReserved exists in the topic or in the dead-letter topic.

Then, if they want more

If it is nowhere, the cause is almost certainly a dual write: the service commits to its database and sends to Kafka as two separate steps, and a crash in between loses the event. If it is in the dead-letter topic, the consumer failed and nobody was watching.

To prevent it I would use a transactional outbox in each service, so the event row is committed together with the business change and a relay publishes it, accepting possible duplicates that idempotent consumers handle. I would alert on dead-letter topics and give teams a way to replay them.

And because some failure will always slip through, I would put a deadline on each saga state: a job finds orders in PENDING for more than a few minutes, asks the payment service what really happened, and either confirms, compensates by releasing funds, or alerts a person.

For flows where stuck orders are costly, I would consider orchestration, because the saga state then lives in one place and stuck instances are a simple query.

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.
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 "In a choreographed saga, an order sometimes stays in PENDING forever. Logs show the...": https://scrivio-interview-library.netlify.app/spring-boot/event-driven-patterns/ae1c6dbdd6/