dine. a kitchen run by sagas Book a table
Log in with Google (coming soon)

Articles

Tiếng Việt · English

What a saga does when a reply arrives

October 16, 2026 · about 7 min read

The idempotency article stopped at the point where the three services finish their work and send a reply back, sometimes more than once. This one goes to the other side: order, the saga orchestrator, receives those replies and decides what to do. The short answer: it only needs to look at two things.

Before the four cases, one thing is always true: replies to order also travel through Kafka, so they can arrive more than once. That means every time order handles a reply, it has to be idempotent: receiving the same reply twice must still give one result. If you haven't read it yet, Receiving a command twice without doing it twice explains why and how.

Where the replies go

When seating, kitchen or payment finishes its work, it sends a message to the saga-step-responses topic on Kafka. The message is small: the order's saga ID, the step name (reservation, kitchen or payment), whether it succeeded or failed, and the error if there was one.

The interesting part is that the three services have no idea what a saga is. They don't know how many steps an order has, whether the other two are done, or what happens after their reply. They know exactly one thing: when the work is done, send the result to that topic. Every decision lives in order.

The three services reservation, kitchen and payment send replies to the saga-step-responses topic; only order reads that topic and makes decisions. The three services know nothing about the saga. reservation kitchen payment Kafka saga-step-responses order reads, checks records, then decides The services only send results to the topic. They don't know how many steps there are or what comes next.
Each service only does its own job and reports back. The only one who knows the whole story is order.

Order only looks at two things

Every time a reply arrives, order doesn't need to know much more. It looks at exactly two things:

  1. The saga's state, from its own records: is the order still running, or already cancelled?
  2. The step's result, from the reply: did that service succeed, or fail?

Two things with two possibilities each make exactly four cases:

The four cases. Saga running and step succeeded: record it, and the order succeeds once all 3 steps are done. Saga running and step failed: cancel the order and undo the finished steps. Saga cancelled and step succeeded: undo just this step. Saga cancelled and step failed: do nothing. step result ↓ saga state → running cancelled done failed 1 record the step as done count finished steps: at 3/3 the order succeeds 3 late success the work really happened: undo just this step 2 cancel the order now undo the finished steps, don't wait for the others 4 do nothing this step changed nothing, so there is nothing to undo
The saga's whole "brain" for handling replies fits in these four boxes.

1. Order running, step succeeded

order marks that step as done in its records, then counts how many steps are done. Each dine order has three steps. With one or two done, it does nothing more and keeps waiting. Once all three are done, it marks the saga as successful: the booking is confirmed.

Counting finished steps: after the first reply it is 1 of 3, after the second 2 of 3, after the third 3 of 3 and the saga succeeds. payment done1/3 reservation done2/3 kitchen done3/3 saga succeeded booking confirmed The order of the replies doesn't matter and differs for every order. All three just have to arrive.
The three services run in parallel and whoever finishes first reports first. order just counts.

This ties straight back to the idempotency article: replies are recorded by the pair of saga ID and step name, so if the kitchen sends "done" twice, the records still hold a single "kitchen done" row. order counts rows in its records, not messages, so it can never reach "3/3" just because one service reported three times.

2. Order running, step failed

order marks that step as failed, then cancels the order immediately, without waiting for the remaining steps to reply. It looks up the steps already reported as done and sends undo commands to exactly those services: release the table, return ingredients to stock, refund the payment. The service that failed needs no undo, because it hasn't done anything. Compensation is not rollback covers this in detail: why only the finished steps are undone, and how undo commands go through the outbox.

3. Order cancelled, step succeeded

This is the strangest case: the order is already cancelled, yet a service reports "done". It happens because in case 2, order cancels without waiting for anyone. Services still working simply finish and report back. The work really happened (the table is held, the money is taken), so order can't ignore it: it reopens the order and sends an undo command just to the service that reported done. Late success explains why dine chooses "decide fast, clean up later" over waiting for all three.

4. Order cancelled, step failed

The order is already cancelled, and this service didn't manage to do anything, so there is nothing to undo. order just records it and does nothing more.

What about replies to undo commands?

Undo commands get replies too, on the same topic, and order handles them against its own records as well:

What if a service dies and never replies?

All four boxes above start with "when a reply arrives". But what if the kitchen takes the command and then dies for good, never replying? No message arrives, so no box is triggered, and the order would sit at "running" forever, holding a table and holding money for an order that goes nowhere.

order can't wait forever. It has a deadline: if a service is still silent past it, it is treated as if it had reported a failure, and the order goes into box 2. At dine that number is 5 seconds, and Why 5 seconds cancels an order explains why.

In short: the services know nothing about the saga and only send their results to a topic. order takes each result, looks at the saga's state in its records and the step's result, and picks one of four boxes: record and count, cancel and undo, undo just the late step, or do nothing. Silence is turned into a "failed" reply by the deadline.

See it for yourself

On the order detail page, the "How order reacts to each reply" section shows which box each reply landed in and what order decided.

Spotted a mistake, or have a question? Write to [email protected].

dine is a personal project about distributed systems, written in Go: orchestrated sagas, transactional outbox, Kafka. More articles.