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

Articles

Tiếng Việt · English

Why 5 seconds cancels an order

October 14, 2026 · about 7 min read

A booking is sent to three services at once. The table service answers "done", payment answers "done", and the kitchen says nothing at all. No error, no "done" either. How long should the system wait? At dine, the answer is 5 seconds. This article is about why you need a limit like that, and why the number itself is nothing special.

Silence is not the same as an error

When a service reports an error, order knows one thing for sure: that service did nothing. The next move is clear: cancel the order, undo the services that already finished.

When a service goes silent, order knows nothing. It could be that:

From where order stands, these three cases look exactly the same: no news. This is a basic fact of distributed systems: over a network, you cannot tell a dead service from a slow one. All you can do is pick a deadline, and decide when it arrives.

You cannot wait forever

Without a deadline, the order would sit in "processing" indefinitely. Worse, whatever has already been done stays held: a held table that nobody else can book, money that has been charged while the guest has no idea whether the order went through. One dead service ends up stalling the healthy ones too.

A timeout does not bring the dead service back to life. It only lets the system make a decision instead of waiting: if there is still no news when time is up, treat it as a failure, and handle it like any other failure.

Timeline of the sample order "One service goes silent": payment finishes at 0.3 seconds, the table at 0.5 seconds, the kitchen never answers; at about 5.6 seconds order treats the kitchen as failed and cancels the order; payment and the table are undone before 6.1 seconds. reservation kitchen payment took the command, then silence… 5 seconds ⏱ 5.6s 0.5s 0.3s Green square: done. Red square with ⏱: timed out, treated as failure. Blue ring: undone.
The sample order "One service goes silent". Two services finish within the first half second; the kitchen never answers. Past the 5-second mark, order treats the kitchen as failed, cancels the order and undoes the table and the payment.

Picking the number: 5 seconds is dine's choice

There is no timeout value that is "right" for every system. 5 seconds is the number I picked for dine, based on what dine does and how its services behave. Another project, with a different business, will need a different number, and may have to adjust it over time.

The way to think about it is fairly simple: it is a balance between two kinds of mistake.

At dine, holding the table, taking the stock and charging the money are all internal jobs that normally finish in under 1 second. 5 seconds is well above that, leaving room for the usual slow moments, without making the guest wait long. dine started out with 30 seconds. When the "Incident test" feature was built, the number came down to 5 seconds: the services already finish in under 1 second, so waiting 30 seconds only made the person testing sit through half a minute for nothing.

Elsewhere, the number can be very different:

StepA sensible limit might beWhy
Holding a seat, taking stock inside your own systema few secondsInternal work, usually very fast.
Payment through an external gatewaytens of seconds to a few minutesDepends on a third party; the customer may even have to confirm an OTP.
Waiting for staff approval, a warehouse confirming stockhours, daysA person is involved; it cannot be measured in seconds.

You can also set a separate limit for each step instead of one shared number. dine only needs one, since all three steps are alike.

Implementation: one polling loop, nothing fancy

"A timeout for every order" makes it tempting to think each order needs its own timer. dine does not do that. Every step of an order is already recorded in the database with its creation time and status, so all it takes is one background task that asks the database a single question every second:

"Is there any step still waiting for a reply, created more than 5 seconds ago, whose order has no outcome yet?"

For each step it finds, the task does two things:

  1. Mark the silent step as failed, just as if that service had reported an error itself.
  2. Cancel the order, and undo if needed. If some services have already reported done, the order moves to "undoing" and those services receive an undo command (the article Compensation is not rollback covers this in detail). If none has finished, the order is simply cancelled, with nothing to undo. The silent service does not receive an undo command, because nobody knows what it did.

This approach has a few advantages:

The trade-off is a little less precision: since the scan runs once a second, an order is actually cancelled after about 5 to 6 seconds, not exactly 5.0. For booking a table, being off by a second makes no difference.

If the silent service comes back

If the kitchen really did die, the command sent to it is still sitting in Kafka. When the kitchen comes back, it reads on, processes it, and answers. By then the order has been cancelled:

In other words, the timeout does not have to guess right. When it guesses wrong (the service was only slow), the system still rebalances itself, at the cost of one extra undo. Picking a sensible number is about making wrong guesses rare.

In short: a timeout does not fix a dead service. It only keeps the system from hanging along with it. The dead service still needs to be monitored and restarted; that is a job for operations, not for the saga.

See it for yourself

To try it yourself, log in, press Book a table, turn on “Incident test” and set one service to “No reply”. That service will take the command and stay silent, like a service dying at that very moment. Count about 5 seconds, and you will see the order cancelled.

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.