Try
↑ ↓ move↵ openesc close
In this lesson · topic 3 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 3

Retry, crash and publish

8 min read

What the lab runs

Two orders arrive each tick. A share of clients send the request a second time, up to 120 ticks later. The service can remember keys for a lifetime you set, or not at all.

For each order the service must publish an event. In the dual write it saves the row and then publishes, and a crash in between loses the event. In the outbox mode it saves both together, and a relay publishes later. The relay can crash after publishing and before marking, which publishes the event twice. The consumer applies every event, or drops those it has seen.

Predict before you press play

You switch from the dual write to the outbox. What happens to lost events?

tick 150dual-write, keys offwrong outcomes: 19% of orders

Retried requests

orders
300
duplicate orders
36
retries absorbed by a key
0
keys stored
0

Some clients send a request twice. Without a key the service cannot tell the second one from a new order. A key that has expired looks new again.

Events

events lost
20
events published twice
0
applied twice downstream
0

A dual write saves the row and then publishes, so a crash in between loses the event. The outbox saves both in one transaction. Its relay may publish twice if it crashes before it marks the row.

Problems so far, last 150 ticks
Problems so far, last 150 ticks. Text version available below the chart.013253850176150recent tickscount

Full-page version with guided experiments: Idempotency keys and the outbox lab.

Things to try

  1. With the dual write, read the lost events.
  2. Switch to the outbox and read the events applied twice.
  3. Set the consumer to drop seen events.
  4. Turn on keys at 600 ticks and read the duplicate orders.
  5. Cut the key lifetime to 30 ticks and read them again.

The full-page lab has a guided experiment for each of these.

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