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

The retry that charges twice

3 min read

Why clients retry

A client sends an order and the reply never comes. The request may have been lost. It may have run and the reply was lost. The client cannot tell, so it sends the request again. That is the right thing to do. A client that never retries loses orders.

If the service treats the second request as new, the customer has two orders. In the lab, with one request in five retried and no protection, the service ended up with 133 duplicate ordersmeasured in 400 ticks.

The second half

A service that creates an order usually also tells others. It writes a row and publishes an event. These are two systems with no shared transaction. If the service crashes between them, the row exists and the event never goes out. With a crash chance of 5 percent per order, 55 eventsmeasured were lost in the lab.

Both problems come from the same fact. Between two systems, a crash can leave you with one done and the other not, and a retry cannot tell which. This lesson covers a fix for each. Idempotency keys make requests safe to repeat. The transactional outbox makes the write and the event one transaction.

Predict first

A client times out on a payment request and sends it again. What is the risk?

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