Learn

VISUAL GUIDE · APIS & QUEUES

When a job runs twice

Step 7 of 10: Expect every job more than once

STEP 7 / 10ORIGINAL SKETCH
enqueuelease jobackdebit order 42redeliverdebit order 42Checkout APIJob queuelease 30 sWorker AWorker Bmust be safe to rerunLedger DBwallets + done keys
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.
7 / 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 7 OF 10 · AT-LEAST-ONCE

Expect every job more than once

You could acknowledge before doing the work. Then a crash loses the charge entirely: that is at-most-once delivery. Acknowledge after, and a crash repeats it: at-least-once.

No setting on the queue makes the debit and the acknowledgement happen as one step, because they live in different systems. So production systems pick at-least-once and make the handler safe to run again.

The operation that must be safe to retry is the side effect, the debit. Repeating the lease or the acknowledgement is already harmless.

Why it matters. Once you accept at-least-once as normal, the design question changes from "how do I stop retries" to "how do I make a retry harmless".