Skip to content
WebsiteHosting.com

procedure Backend & software

Transactional outbox dual-write crash windows

A transactional outbox saves the business change and its event record together. A relay can still send the same event twice if it crashes after sending but before recording its progress.

Latest recorded source check · P0131

What it means

A transactional outbox commits a business change and a record of the event to publish in the same database transaction. If an order commits, its OrderPlaced event record commits with it. If the transaction aborts, neither record commits. A separate publisher, called a relay, sends the event later. The database guarantees that the two records go together, not that the message will be sent exactly once.

This matters when an application would otherwise save an order and then send a message. A crash between those steps can leave a saved order with no record that anyone still needs to send the message. With an outbox, the relay has a committed record to work from even if the application stops immediately after commit.

Try it

Simulation: follow one synthetic order. Count the business row and outbox record at the database, sends at the relay, and durable effects at the consumer. Think of one effect as creating one packing task for the order.

Transactional outbox dual-write crash windows

Explain atomic database state plus outbox record versus independent message publish

Simulation
Modeled outcome: Delivered

At least one message published; crash may cause duplicate delivery.

Transactional outbox dual-write crash windows: synthetic scenario inputs
Replaces all inputs with the documented starting example and the indicated change. Reset restores the starting example.
Transaction boundary and relay gap

Database transaction

  1. Business row1
  2. Outbox record1
  3. Transactioncommit

Outside the transaction

  1. Crash positionafter-send-before-mark
  2. Relay sends2
  3. Consumer policyatomic
  4. Durable effects1
Committed event records1 count
Sends2 count
Effects1 count

The row and outbox record share one atomic transaction. Sends and durable consumer effects are separate counts. Pending is a snapshot before sending, not a forecast of the eventual relay.

Evaluated inputs

Required scenario evidence
provided
DB transaction
commit
Publisher crash position
after-send-before-mark
Consumer dedup
atomic

One local transaction, publisher resumes once after selected crash; no operational SQL, broker or external send.

About this model

The controls set only a local, bounded scenario. The computed branch is not a verdict about a live system. Inputs listed as not evaluated did not participate in this branch after validation.

Reset restores the original inputs. It does not change the open or closed state of help or FAQ answers.

Start with DB transaction set to commit, Publisher crash position to after-send-before-mark, Consumer dedup to atomic, and Required scenario evidence to provided. The result is delivered: 1 business row, 1 outbox record, 2 sends, 1 consumer effect. The relay sends the event, crashes before recording that it sent it, and sends the same event again on restart. The consumer recognizes the repeat.

Change only Consumer dedup to none. There are still two sends from the same outbox record, but now there are two packing tasks. Deduplication changed what the consumer did, not what the relay sent. Reset restores all four starting choices and the original result. Without interactive controls, these two cases give the same comparison in text.

What the relay knows after a crash

Consider two stopping points with exactly the same committed order and outbox record:

  • before-send: The relay stops before sending anything. The result is pending, with zero sends and zero effects. This is a snapshot before the relay resumes; the consumer setting is not evaluated.
  • after-send-before-mark: The first send has happened, but the relay has not marked the event as sent. An unmarked record is not proof that no message went out. In this case the relay retries once, accounting for the second send. With no crash, the simulation counts just one send.

In the atomic example, the consumer keeps a record that it handled this event together with the local change that creates the packing task. On seeing the same event again, it does not create another task. That is a second transaction boundary, distinct from the one that saved the order. The simulation counts the effect under that assumption; it does not inspect a real consumer.

Now change the database outcome instead. With abort, there is no committed order or outbox record for this transaction. Sends and effects are both zero; neither the crash position nor the consumer choice contributes to that result. By contrast, choosing missing for the required evidence gives unknown, not zero. The simulation has no basis to say whether the transaction committed. An incomplete or unsupported input is an input error, not an earlier result carried forward.

Notice that the aborted and before-send cases can both display zero sends and zero effects. The difference is inside the database boundary: the aborted case has no committed business row or outbox record, whereas the pending case has both. To decide whether work remains, inspect that boundary rather than interpreting the zero send count alone.

In practice

Start with a read-only check: identify the business write and its matching event record, and verify where their shared transaction begins and ends. Stop if you cannot establish whether a real transaction committed. Do not replay an order or resend a message to find out. First seek the database outcome for that specific order and event; a missing relay mark alone does not settle it.

For an authorized rehearsal outside the simulation, use an isolated environment with a known database and relay version, one identifiable test event, and a destination that cannot trigger real work. Preserve the starting state and a way to restore it before testing. If the scope, permissions, or rollback path are unclear, stop. Check an abort for the absence of both records. For a committed event sent twice, compare the relay’s sends with the consumer’s durable tasks for that same event. If atomic duplicate handling is expected and you find two tasks, stop rather than replay again. Restore the isolated test state and verify it against the starting state. The simulation’s Reset changes only local inputs; it cannot retract a message.

Transaction boundaries matter even with a transactional broker. Kafka 4.3 describes processing that can commit a consumer’s position and its output records together within Kafka. That transaction does not automatically include an order or packing task in an external database. Nor does a one-event rehearsal establish the order of multiple events; define which events must stay in order and how the relay and consumer will preserve that order across retries.

Use the outbox record to answer “Was the event recorded with the order?” To answer “Was it sent, and what did it cause?”, follow the same event through relay progress and consumer records. Each observation answers a different question.

Frequently asked questions

Editorial questions based on the listed sources and explicitly labeled local examples.

Why not publish before DB commit?

The message could escape even if the transaction aborts.

Can a committed outbox be delayed?

Yes. Committing the event record does not synchronously publish it. A relay or change-data-capture process may publish it later or retry delivery.

Does outbox guarantee order globally?

No. An outbox addresses the transaction boundary, not a universal ordering contract. Define the ordering scope, relay sequence and consumer behavior separately; retries and delivery across multiple streams need their own guarantees.

What is safe to verify before adoption?

Use an isolated, authorized example. Verify that an abort leaves neither committed record, a committed pending event can be found before sending, and a repeated event does not create an extra durable effect under the intended consumer policy. Preserve the before-state and test recovery separately.

Sources & model boundaries

Primary references used for this explanation. The interactive example is an educational model, not a live check.

  1. AWS transactional outbox pattern

    Issues and considerations: duplicate delivery and ordering. An outbox addresses a transaction boundary. Duplicate delivery and ordering are separate requirements for the relay and consumer.

    Checked .

  2. Apache Kafka design: message delivery semantics

    Message Delivery Semantics. Kafka transactional processing can couple offsets and outputs within Kafka; coordinating external outputs requires additional design. It does not automatically make a database outbox exactly once.

    Checked .

Report an issue. Include the article URL and ID, not passwords or access keys.