Scrivio Interview library
DebuggingIntermediate6 min read · updated 12 November 2026

In a choreographed order saga, some orders stay in PAYMENT_PENDING forever. Payments and Orders communicate through Kafka topics. Walk through how you would find the cause.

We start from one stuck order and follow its correlation id across logs and traces to find the last event emitted and consumed. Then we check whether the payment event was published at all, or went to another topic or key; whether the Orders consumer is lagging, failing on deserialization or parking events in a dead-letter topic; and whether it rejected the event as a duplicate or out of order by mistake. Finally we add a saga timeout job that finds orders pending too long and queries Payments or compensates.

Why this question is asked

A choreographed saga has no component that knows where each order is, so when orders get stuck, nothing complains; they simply stop. Customers notice before engineers do. Interviewers ask this debugging question because it tests a systematic method across service boundaries, knowledge of where Kafka consumers lose messages, and the instinct to add a safety net so the problem cannot hide again. In this answer, we will set out the expected flow, trace one stuck order, check each place the event can be lost, and then add a saga timeout and the metric that would have warned us.

1The Flow We Expect

The order service creates an order in PAYMENT_PENDING and publishes OrderCreated. The payment service consumes it, charges the card and publishes PaymentCompleted or PaymentFailed to a payments topic. The order service consumes that event and moves the order to PAID or CANCELLED. Every event carries a correlation id, here the order id, that ties the whole flow together.

An order stuck in PAYMENT_PENDING forever means the order service never applied a payment result. Either the payment service never produced one, it produced one that did not reach the order service, or the order service received it and threw it away. We want to find out which, for real stuck orders, rather than guess.

2Trace One Stuck Order

We pick a few stuck orders and search for their order id. With distributed tracing, for example OpenTelemetry with trace context propagated in Kafka headers, one trace shows the whole flow. Without it, we search the logs of both services for the correlation id. The question is simple: what was the last thing that happened to this order?

If the payment service logs show the card was charged and an event was sent, the problem is between the topic and the order service. If the payment service never logged receiving OrderCreated, the problem is earlier. If it charged but never logged a send, publication failed. This one search usually halves the problem in minutes.

Step throughWhere did order 4711 stop?
  1. Payment service received OrderCreated?
    YesCheck its outcomeNoCheck OrderCreated publication
  2. Payment event published?look in the topic by key
    YesCheck Orders consumerNoDual write lost it
  3. Orders consumer received it?lag, errors, DLT
    YesCheck handler decisionNoFind lag or poison record
  4. Handler applied it?
    YesLook for overwriteNoWrong duplicate or order check

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

Each answer moves the search one hop along the flow.

3Was the Payment Event Published at All?

A frequent cause is a dual write in the payment service: it commits the charge in its database and then sends the event to Kafka in a separate step. If the send fails, times out, or the pod dies between the commit and the send, the charge exists and the event never does.

Java
@Transactional
public void on(OrderCreated e) {
paymentRepository.save(Payment.charged(e.orderId(), chargeCard(e)));
kafkaTemplate.send("payments", e.orderId(), new PaymentCompleted(e.orderId()));
} // DB commits even if the send failed asynchronously -> order stuck forever

We check by looking in the payments topic for the order id as key, with a console consumer or a tool such as kcat. While there, we check the details: is it the topic the order service actually subscribes to, is the event type one it understands, and is the key the order id? A renamed topic in one service's configuration, or a new event type the consumer ignores, produces exactly this symptom.

4Is the Orders Consumer Lagging, Failing or Parking Events?

If the event is in the topic, we look at the order service's consumer group. Consumer lag per partition shows whether it is behind. A partition with steadily growing lag while others are at zero points to a poison record, often a deserialization error after the payment team changed the event schema. Depending on the error handler, that record is retried forever, blocking the partition, or sent to a dead-letter topic (DLT) after a few attempts.

So we also look at the DLT. Records there were never applied, and by default nothing replays them. A Spring Kafka DefaultErrorHandler with a DeadLetterPublishingRecoverer that quietly parks payment events will produce stuck orders with no error in the main logs beyond a warning.

5Did the Consumer Reject It by Mistake?

The last place is the handler's own logic. Idempotent consumers deduplicate by event id; if the payment service reuses an id, for example the order id as event id, then PaymentCompleted is discarded as a duplicate of an earlier event for the same order. Version or ordering checks can misfire too: if the order service ignores events older than its stored version, and the payment service sends a version from its own counter, the comparison means nothing and valid events are dropped.

Logging every skipped event with the reason, duplicate or stale, makes this visible. A burst of skips right after a deployment points straight at the change.

6Add a Saga Timeout as a Safety Net

Whatever the root cause, a saga that can wait forever will eventually do so. A choreography needs an explicit timeout. A scheduled job in the order service finds orders in PAYMENT_PENDING longer than a limit, for example 15 minutes, and asks the payment service directly what happened to that order. If it was paid, the job applies the result; if there is no payment, it cancels the order and runs compensations such as releasing stock.

Java
@Scheduled(fixedDelay = 60_000)
void resolveStuckOrders() {
Instant limit = Instant.now().minus(Duration.ofMinutes(15));
for (Order o : orders.findByStatusAndCreatedBefore(PAYMENT_PENDING, limit)) {
stuckOrders.increment();
switch (paymentsClient.statusOf(o.id())) {
case PAID -> o.markPaid();
case FAILED -> o.cancel();
case NOT_FOUND -> o.cancel(); // compensations follow from the cancel
case PENDING -> { } // still in progress, check again later
}
}
}

Notice the counter. The job repairs orders, but every repair is a symptom of a bug upstream, so we count them and alert, instead of letting the job hide the problem.

7Follow-up questions

What metric would have alerted you before the customer did?

The number of orders in PAYMENT_PENDING older than a threshold, for example 10 minutes, published as a gauge. In a healthy system it is close to zero, so any sustained value above zero is a clear alert. Supporting metrics are consumer lag per partition on the payments topic, the size of the dead-letter topic, and the rate of skipped duplicate or stale events. The age of the oldest pending order is the most direct, because it measures the symptom the customer feels.

Would switching to an orchestrated saga avoid this?

It would make it easier to see, because an orchestrator stores each saga's state and usually has timeouts built in. It would not remove the causes: lost publications, poison records and wrong dedup logic can break an orchestrator's replies too. The fixes are the same, an outbox, sane error handling and timeouts.

How would you fix the dual write in the payment service?

With a transactional outbox: save the payment and the PaymentCompleted event row in the same database transaction, and let a relay or CDC publish it. Then a committed charge always produces its event at least once.

8Conclusion

In this answer, we debugged orders stuck in PAYMENT_PENDING by following one order's correlation id to its last event. We checked whether the payment event was published, since a dual write can lose it, or sent to the wrong topic or key; whether the order consumer was lagging, blocked by a poison record or parking events in a dead-letter topic; and whether its duplicate or ordering checks rejected a valid event. Then we added a saga timeout job that resolves stuck orders by querying Payments or compensating, and an alert on the age of pending orders.

What to say in the interviewAbout 90 seconds aloud

Open with

I would start from data, not theory: take a few stuck orders and follow their correlation id, ideally the order id, through traces or logs in both services, to find the last event that was emitted and the last one consumed.

Then, if they want more

That tells me which hop failed. If Payments charged the card but no event appears in the payments topic under that key, it is probably a dual write, committing the database and then sending to Kafka separately, so a failed send or a crash loses the event. I would also check it was the right topic, key and event type.

If the event is in the topic, I look at the Orders consumer: lag per partition, deserialization errors from a schema change, a poison record retried forever, or records parked in the dead-letter topic that nobody replays.

If it was consumed, I check the handler's own logic, for example deduplicating by an id that is not unique per event, or a version check that compares unrelated counters and drops valid events.

Whatever the cause, I would add a saga timeout: a scheduled job that finds orders pending longer than, say, fifteen minutes, asks Payments for the real status and applies it or cancels and compensates. And I would alert on the age of the oldest pending order, so we hear about it before customers do.

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 order saga, some orders stay in PAYMENT_PENDING forever. Payments and...": https://scrivio-interview-library.netlify.app/spring-boot/distributed-data/ab23da7fb8/