An order service can save an order, but the inventory service might be slow or unreachable. A reliable design does not pretend the two services commit at the same instant. Start by defining what the user sees while the outcome is uncertain: for example, an order accepted for processing is not yet a confirmed order.
Choose what the caller can wait for
1. Why not retry every timeout?
A timeout does not say whether the remote service did the work. Retry only when the operation is safe to repeat and the request still has time to succeed. Use bounded attempts, backoff, and jitter. Avoid independent retries at every level: three layers with three total attempts each can turn a single outer request into as many as 27 attempts on the last dependency. Distinguish between transient failure and a permanent rejection such as an unavailable item.
2. When is a synchronous dependency the wrong contract?
If a response must include a current inventory decision, a synchronous call can be appropriate, but its budget is part of the end-to-end budget. If the caller can accept a pending state, put that state in the API and process the decision asynchronously. This avoids holding a request open but adds a status lookup, delayed completion, and a way to resolve stuck orders. A queue changes where work waits; it does not make the work disappear.
- Commit locallyStore the pending order and its outbox event in one transaction.
- RelayPublish the event; allow for publication more than once.
- Apply onceMake the inventory effect idempotent and acknowledge after committing it.
- ResolveConfirm or reject the order and monitor how long it remains pending.
Trace the gaps between commits
3. What failure does a transactional outbox prevent?
Writing an order and publishing an event directly are two writes to different systems. If the process crashes after the database commit but before the publish, the event can be lost. An outbox records the intent to publish in the same transaction as the order. A relay can still publish twice if it crashes after publishing but before recording completion. Handle duplicates at the consumer, for example by storing a unique processed event ID in the transaction that applies the inventory effect.
4. Can a compensating action undo anything?
No. A compensation is a new domain action. Releasing allocated inventory may compensate for an abandoned order, but it does not undo a notification already read by a customer. Give the compensation its own retry and idempotency rules. Define how you reconcile an order when a late success arrives after the workflow has already scheduled a release.
5. Which metrics distinguish a slow workflow from a broken one?
Track the age of the oldest pending order, relay backlog, retry volume, and how long orders take to reach a terminal state. Correlate these with downstream timeouts and saturation. A short HTTP acceptance latency can coexist with an hours-long processing backlog. Decide who owns recovery and how they can retry a particular operation without applying it twice.
Practice a failure timeline
- Put a crash on either side of the order commit, event publish, and inventory commit.
- For each crash, state what the user sees, which work repeats, and where that repetition becomes safe.
- Replace an immediate confirmation requirement with a pending state and list the new controls the product needs.
Compare the HTTP boundary in the REST API retry walkthrough, then use Mentaro's free practice demo to rehearse drawing a failure timeline from memory.