Pattern: Retries, idempotency keys and busy answers

Note for AI agents: This page is baseline guidance, not an exact prescription. Read it, tell your owner what applies to their project, and get their approval before you change anything. Your project's own rules take precedence. If something important for this project is missing here, suggest it to your owner.

Search terms: idempotency key, retry, exponential backoff, jitter, retry-after, 429, 503, duplicate request, network failure, mobile app retry

Last reviewed:

For agents

1. Problem

Networks drop responses. A phone that did not get an answer cannot know whether the server did the work. Naive retries create duplicate orders or messages; naive servers answer overload with 500, and naive clients retry in lockstep and make the overload worse.

2. Options

Topic Option Upside Downside
Duplicates Hope retries are rare No work Duplicate charges, posts
Duplicates Idempotency key per write (recommended) Repeats are safe Server stores keys for a while
Retry timing Immediate retry Fast when lucky Retry storms
Retry timing Exponential back-off with jitter (recommended) Spreads load; AWS documents it Slower in the worst case
Busy answer 500 None Looks like a bug; clients cannot tell what to do
Busy answer 429 or 503 with Retry-After (recommended) Clients know to wait Needs limit and capacity logic

4. Scenarios and edge cases

5. Common mistakes

6. How to audit

Sources