Skip to main content

Integration pattern

Reviewed 14 October 2026

Save the order and the event in one transaction.transactional outbox pattern

A service saves an order, then publishes an event. If it stops between the two, nobody is told. An outbox closes that gap.

No demo shows an outbox. The injector below is the demo.

Use it when

  • A change in your database must always cause a message elsewhere: orders, stock, payments.
  • The database and the broker cannot share one transaction, which is the usual case.
  • You can make consumers handle a repeat, or you will.

Skip it when

  • Only your own database needs the change: a consumer can read the table, and no broker is involved.
  • Losing the odd event is harmless, or a reconciliation job would find it anyway.
  • Nobody will run and watch a relay. A relay that stops is a silent failure.

Try it

Failure injector

Pick how the service saves and publishes, then stop the process after any step or take the broker down. See what the database, the broker and the consumer end up with. Sample data. Not a measurement.

How the service saves and publishes

What goes wrong

Off: it acts on every copy it receives.

1Database2App3Broker4Consumer1234
  1. 1Database
  2. 2App
  3. 3Broker
  4. 4Consumer

The steps

  1. Save the order (transaction open)Complete

    Done.

  2. CommitWhere it stops

    Done. The process stops here.

  3. Publish “order saved”

    Not reached.

  4. The consumer acts

    Not reached.

Where things stand

Where things stand: the database, the outbox, the broker and the consumer, right after and after the restart
WhereRight afterAfter the restart
Order in the database1 (saved)1 (saved)
Unsent rows in the outbox——
Events in the broker00
Times the consumer acted00
The order is saved. Nobody was told. Nothing remembers that an event was owed.

To repair it. Only a comparison with the database finds this: a reconciliation job.

The worst moment to stop in each design

The worst moment to stop in each design, and what is left after the restart
DesignWhat is left
Save, commit, then publishThe order is saved. Nobody was told. Nothing remembers that an event was owed.
Publish, then commitThe consumer was told about an order that does not exist. The save never committed.
Outbox: save the event with the orderThe order was saved at once. The event went out after the restart, once. Late, not lost.

What is left after the restart, when the process stops right after the commit (publish-then-commit: right after the publish).

What you give up, and how it fails.

Four trades, then six ways it breaks. Pick one for why, and the source.

  • The event exists if and only if the change committed.What it costs: A second table to write, read and clean up. Rows pile up when the relay is down.
  • A broker outage no longer stops orders.What it costs: The event is late by the relay's interval: a scheduler tick or a polling period.
  • No two-phase commit, and any broker works.What it costs: Delivery is at least once. The consumer must cope with a repeat.
  • Order per record can be kept by sequence.What it costs: More than one relay can reorder, and one relay is one more thing to watch.

How it fails

Documented

It can stop after publishing and before it records that it did; on restart it publishes again. The consumer has to recognise the event id.

Documented

It can stop after publishing and before it records that it did; on restart it publishes again. The consumer has to recognise the event id.

Each failure is Documented, with the maker's own page or code, or it Follows from the design. None is a result from a MithTech client project.

In ERPNext and Frappe, and Medusa.

Eight parts, each at a named version. Open one for what it does; build it in five steps.

Read from Frappe v15.123.0 and v16.52.0, ERPNext v15.122.0, Frappe's Ecommerce Integrations app (version-15, commit 3dc8eb81) and Medusa v2.21.2 on 14 October 2026, with the file and line. One Medusa row was read at v1.20.11, for history only. Other systems' names and settings were not checked here.

For an ordinary message, frappe.sendmail saves a row in your transaction (delayed is the default). The scheduler sends rows that are Not Sent or Partially Sent, 500 at a time, locking each one. It marks Sending with a commit, records each recipient as sent, then marks Sent. An error puts the row back with retry plus one until the limit (3 by default), then Error.

Frappe v15 · sendmailFrappe v15 · Email Queue flushFrappe v15 · Email Queue

How to build it

  1. List what must never be lost: the events whose absence a person would notice later.

  2. Save the event in the same transaction as the change, in a table next to the data, with an id, a type, the payload and a created time.

  3. Run a relay: read the oldest unsent rows, publish them, mark them sent. Poll the table (simple) or read the database log (lower delay, more to run).

  4. Make the consumer idempotent: keep the ids you have seen, in the same transaction as the work.

  5. Watch the age of the oldest unsent row. An alert on it is the only way to hear that the relay stopped. Clear sent rows on a schedule.

Questions about transactional outbox

The one most people ask is answered first. Type to find the rest.

What is the transactional outbox pattern?

A service saves each event it must send in a table of its own database, in the same transaction as the change that caused it. A separate relay reads the table and publishes the events. The event exists if and only if the change committed, so a crash cannot leave one without the other.

Start with one conversation

One message, call or WhatsApp is enough. Every line reaches the team directly.

Team away now