The support agent timed out at eight minutes, and the job runner retried it, as configured. The customer received two refunds and one apology.

Nothing in that sequence was a bug in the usual sense, since every component did what it was told. The system had simply never been given semantics for doing the same work twice.

Move long agent work off the request path

Agent work is long, bursty and full of calls that can hang. Running it inside the request that triggered it means the browser tab, the load balancer and the process lifetime all become part of your reliability story, and the first deploy during a busy hour kills every in-flight task.

Push it onto a queue with a worker pool and the run gains something it did not have: an identity that outlives any single process. It can be inspected, resumed, cancelled and counted. That identity is what justifies the extra machinery. A queue which redelivers when a worker dies also gives you at-least-once delivery, so some jobs will run twice.

The idempotency key must come from the work, not the worker

A key generated when a worker picks up a job is a new key on every attempt, which is the same as having none.

Derive it from the intent, meaning this user, this order, this action and this logical request. Then have the side-effecting system enforce it, whether that is a unique constraint, a conditional write, or a provider that accepts an idempotency header. Enforcement in the agent's own memory does not survive the crash you are protecting against.

Design this before the duplicate refund, which means before enabling retries. Retries are trivial to turn on, so they usually get switched on first.

Timeouts, cancellation, and the half-finished job

Every long job needs a maximum runtime, and cancellation that actually reaches the worker rather than just marking a row as cancelled while the process keeps spending money.

Then decide what a partially complete run means. If three of five steps committed, is the job resumable from step four, or must it be compensated and restarted? Both answers are defensible, and both have a price. Resuming needs a record of every committed step, compensating needs an undo for each one, and a sent email has none. Not choosing means the answer varies by whichever code path failed.

Backpressure is a cost control

Treat queue depth as a budget metric first and a latency metric second. Expensive jobs piling up during an incident quietly build a bill that arrives well after the incident is closed.

Give operators depth, oldest message age, failure rate and spend per queue, plus concurrency limits per tenant so one workspace cannot consume the pool. Users need the same visibility at their own scale: queued, running, failed, retrying.

Before you switch retries on

For each tool with a side effect, write down the key the target system deduplicates on, whether it keeps that key longer than your longest retry window, and where a job goes after its final attempt fails. That last answer should be a dead-letter queue with an owner. Without one, a refund that failed for good disappears and nobody is told.

Live · Retries lab

Try it: the retries lab shows what retries do to success rate, cost, worst-case time and duplicate side effects, with and without idempotency keys.

Try

Retries rescue almost every run, and quietly start repeating side effects.

Runs succeed, but about 1 run in 21 repeats a side effect: an email sent twice, a record written twice. Add idempotency keys.
Runs that finish
99.99%
+40 pts vs no retries
Calls per run
10.5
+5.3% vs no retries
Expected time
18 s
+1.4 s vs no retries
Worst case
270 s
budget 300 s
Duplicate side effects
1 run in 21

One run, step by step

A run from the simulation that met at least one failure.

123456789100 s21 s
AttemptFailed, timed outBackoffSide effect repeatedStep with a side effect
Open the full lab, with every control

About this explainer

Format
Explainer
Level
Practitioner
Read
2 min read
Published
Aug 4, 2026

Short mental models: one idea, why it matters, what to do about it.