Try
↑ ↓ move↵ openesc close
In this lesson · topic 6 of 7
  1. 1. The retry that charges twice
  2. 2. Keys and the dedup table
  3. 3. Retry, crash and publish
  4. 4. Keys that expire
  5. 5. Two writes and a crash between them
  6. 6. Publishing twice on purpose
  7. 7. Keys, the outbox and repeats

Topic 6

Publishing twice on purpose

5 min read

The gap again

The relay faces the same gap the service had. It publishes to the broker, then marks the row as sent. If it crashes between the two, it restarts, finds the row unmarked and publishes again. It cannot be made safe without a transaction that spans the broker.

So the guarantee is at least once. In the lab, with the outbox and a 5 percent crash chance, 53 eventsmeasured went out more than once. A plain consumer applied each repeat, and 53 eventsmeasured were applied twice.

Idempotent consumers

Each event carries a stable id, made when the outbox row is written. The consumer keeps a table of ids it has applied, and writes to it in the same transaction as its own effect. A second delivery finds the id and does nothing. In the lab, a consumer that drops seen events applied 0 eventsmeasured twice.

This is the same idea as the request key, one hop later. At every hop, delivery is at least once and the receiver removes repeats.

Putting the three together

With a dual write and no protection, 24%measured of the orders had a problem, counting duplicates, lost events and double applies together. With keys, the outbox and a consumer that drops repeats, it was 0%measured. Nothing in the chain is exactly once. The effect is, because each hop is at least once and each receiver is idempotent.

Predict first

The relay publishes an event and crashes before marking it sent. What happens on restart?

Your progress is saved in this browser. Sign in to keep it on every device. Privacy · Terms