Learn

VISUAL GUIDE · APIS & QUEUES

When a job runs twice

Step 10 of 10: Pass the key along when the effect is elsewhere

STEP 10 / 10ORIGINAL SKETCH
enqueuelease jobredelivercharge + keyCheckout APIJob queuelease 30 sWorker AWorker BLedger DBwallets + done keysCard providersame key: same result
A checkout API enqueues a charge job; worker A leases it and writes to the ledger database but its acknowledgement is lost; the queue redelivers to worker B, which writes again unless an idempotency key stops it; an external card provider can also receive the key.
10 / 10
  1. Enqueue
  2. Lease
  3. Side effect
  4. Ack lost
  5. Timeout
  6. Redelivery
  7. At-least-once
  8. Dedupe key
  9. Conditional write
  10. External effects

STEP 10 OF 10 · EXTERNAL EFFECTS

Pass the key along when the effect is elsewhere

If the money moves at a card provider instead of in your database, you cannot share a transaction with it. Send the same key with the request instead; providers that support idempotency keys return the first result for a repeated key rather than charging again. They only remember keys for a limited time (often a day or more), so retries must arrive within that window.

For effects with no such support, such as some email providers, record "sent" after the call and accept that a crash in between can still cause a rare duplicate. Say that trade-off out loud.

Why it matters. Idempotency has to reach the system that performs the effect. A key that stops at your own database cannot protect a charge made somewhere else.