In this lesson · topic 1 of 7
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