Workflowscore
Retries & idempotency
Retry transient failures with backoff — and make sure retrying can’t do things twice.
What it is and why it exists
LLM and tool calls fail transiently (429, 5xx, timeouts). Retry with exponential backoff and jitter, honour Retry-After, cap attempts. But a timeout doesn’t mean the call didn’t happen: retrying “issue refund” can refund twice unless the call carries an idempotency key the server deduplicates on.
Quick prototype
for i in range(3): try: … except: sleep(1).
In production, at scale
Retry policies per dependency (which errors, how many times, backoff with jitter), idempotency keys on every side effect, dedup tables with unique constraints, and retry budgets so outages don’t turn into retry storms.
Vendors and tools
| tenacity / backoff (Python) | Retry decorators |
|---|---|
| Stripe-style Idempotency-Key headers | Server-side dedup |
| Provider SDKs | Built-in retries on 429/5xx |
On AWS: Step Functions Retry/Catch; SDK retry modes (standard, adaptive); Powertools for Lambda idempotency utility.
How it fails
- Duplicate refunds after a timeout
- Every client retrying in lockstep (no jitter)
- Retrying 400s that will never succeed
What the interviewer asks next
Why add jitter?
Without it, all clients that failed at the same moment retry at the same moments, hammering the recovering service in waves.
How does an idempotency key work?
The client sends a unique key per logical operation; the server stores key → result and returns the stored result on repeats instead of acting again.