Charged the customer, failed to pay the merchant: done or failed?
transcript
The customer's card was charged. The merchant was never credited. Your idempotency record needs a status. Done, or failed?
One payment, one idempotency key. But two steps inside. Step one: charge the customer. Success. Step two: credit the merchant. It fails. Now write the record. What do you put?
Mark it completed? Every retry gets a cached success. And the merchant is never paid. The record hides it. Mark it failed? Failed records allow a retry. So the retry charges the customer a second time. Worse.
Here's the twist. The record isn't the problem. The operation is half done. No status can paper over that. You have to make it whole.
One: an atomic transaction, both or neither. But only if both are writes in your own database. You can't roll back a bank charge. Two: a saga. The credit failed? Refund the customer, then mark it failed. Now a retry is safe. Three: record each step as it completes. A retry skips the charge and resumes at the credit.
For multi-step work, give each step its own key, derived from the payment's key. Then every step is idempotent. And half done can always be finished.
Full breakdown in the lecture.