Learn

VISUAL GUIDE · APIS & QUEUES

When a job runs twice

Step 5 of 10: The lease runs out

STEP 5 / 10ORIGINAL SKETCH
enqueuelease jobdebit order 42Checkout APIJob queuelease 30 sjob 7 visible againWorker ALedger 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.
5 / 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 5 OF 10 · TIMEOUT

The lease runs out

Thirty seconds pass with no acknowledgement. The queue cannot tell "worker crashed before charging" from "worker charged and then crashed". Both look like silence.

Redelivering is the only safe choice for the queue. Dropping the job would lose charges whenever a worker died early.

Why it matters. The queue picks redelivery because losing work is usually worse than repeating it. That choice moves the duplicate problem to the handler.