The Lost Event: Dual Writes and the Transactional Outbox

An Order Service saves an order in its database and publishes an OrderPlaced event so that the Shipping Service can ship it. Two systems, one business fact - and no transaction that spans both. That gap is called the dual-write problem, and it is one of the most common hidden bugs in event-driven systems and microservices.

Your job in this simulation is to break one simple rule: every committed order gets exactly one shipment, and nothing ships that was never ordered. Then switch strategy and try to break it again.

How It Works

  1. Pick a strategy - write to the database first, publish first, or use a transactional outbox
  2. Place orders and watch the data flow through the system
  3. Inject failures - crash the service between its two writes, take the broker down, or crash the outbox relay
  4. Check consistency - the panel tells you whether orders were lost, shipped twice, or shipped without existing
  5. Complete the challenges to see every failure mode - and the patterns that fix them

Live simulation

Actions

Inject failures

Consumer

Consistency check

✓
Consistent

Challenges 0/5

    Event log

    What You Just Saw

    Strategy Service crashes between the writes Broker is down Duplicates
    Dual write, DB first Order saved, event lost - nothing ships Order saved, event lost Rare
    Dual write, publish first Event out, order rolled back - a ghost shipment Order rejected - the customer sees an error Rare
    Transactional outbox Nothing lost - the event is in the outbox table Orders keep flowing; events are delivered later Possible - consumers must be idempotent

    Why dual writes fail

    Reordering the two writes only changes which inconsistency you get. Database first risks lost events; publish first risks events about things that never happened - and it couples your ability to take orders to the broker's availability. Retries do not help either: a process that crashes cannot retry, and a retry after a timeout cannot know whether the first attempt succeeded.

    How the outbox fixes it

    The service writes the order and the event into its own database in one local transaction. Either both exist or neither does. A separate relay reads unsent rows from the outbox table, publishes them, and marks them as sent. The relay can be a simple poller or change data capture on the database log (for example, Debezium's outbox event router).

    The price: at-least-once delivery

    If the relay crashes after publishing but before marking the row as sent, it publishes the same event again after restarting. The outbox guarantees that no event is lost - not that each event arrives exactly once. That is why the outbox and the idempotent consumer are two halves of one pattern: the consumer records which event IDs it has processed, ideally in the same transaction as its own state change, and ignores repeats.

    Key Takeaways

    Further Reading

    Decision Angle

    "Use a transactional outbox for publishing domain events" is a textbook Architecture Decision Record. The context is the dual-write risk; the consequences include at-least-once delivery, the obligation for idempotent consumers, a relay to operate, and an outbox table to clean up. Writing that down once saves every future team member from rediscovering it in production.

    See also: Event-Driven Architecture · Microservices

    Next: The Double-Click PaymentThe same idea on the API side: retries, lost responses and idempotency keys.
    Also try: CAP Theorem with ATMsCut the network and decide between consistency and availability.