Learn

VISUAL GUIDE · APIS & QUEUES

When a job runs twice

Step 2 of 10: Worker A leases the job

STEP 2 / 10ORIGINAL SKETCH
enqueuelease jobCheckout APIJob queuelease 30 sWorker Ahas 30 s
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.
2 / 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 2 OF 10 · LEASE

Worker A leases the job

Worker A pulls job 7. The queue does not delete it. It hides it for 30 seconds, the visibility timeout. Think of it as a lease: worker A has 30 seconds to finish and say so.

If worker A acknowledges in time, the queue deletes the job. If not, the job becomes visible again for someone else.

Why it matters. Hiding instead of deleting is what makes the queue survive worker crashes. A deleted job would vanish with the worker that held it.