Idempotency (idempotency key)
An operation is idempotent if doing it twice has the same effect as doing it once. Retries become safe.
Networks fail after the server did the work but before the client heard back, so clients retry. Without idempotency a retry charges the card twice or sends two emails. An idempotency key is a unique id the client sends with the request; the server stores the result under it and returns the same result for a repeat instead of doing the work again.
Related terms
- Webhook: An HTTP request one system sends to another when something happens, instead of the other system asking repeatedly.
- Dead letter queue (DLQ): A separate queue where messages land after failing processing too many times, so they are kept instead of lost or retried forever.
- At-least-once delivery: A queue or broker guarantee that every message arrives, possibly more than once, so consumers must handle duplicates.
- Inbox pattern (idempotent consumer): A consumer records the id of each processed message in the same transaction as its own change, and skips any id it has already seen.
- Retry with exponential backoff and jitter: Retrying a failed call after waits that grow each time, with some randomness added so many clients do not retry at the same moment.
- Runtime validation (Zod): Checking at run time that data from outside (requests, APIs, files, models) matches the type your code assumes.
