vishal patel
Applied in productionIntermediateUpdated 2026-09-23

Idempotency

Doing an operation twice has the same effect as doing it once. The foundation of safe retries, at-least-once messaging and reliable APIs.

api-designreliabilityretriesmessaging

Why it matters

Networks time out after the server did the work. The client retries. Without idempotency you get double charges, duplicate entries, and the same item added twice to a release. Message brokers deliver at least once, so every consumer has to cope with duplicates.

Techniques

diagram
TechniqueUse for
Natural idempotencyPUT full state, DELETE, "set X = 5"Most updates; prefer these designs
Idempotency key — client-generated key, server stores the resultCreates and payments; any non-idempotent POST
Unique constraints / upserts — on business keys (releaseId + entryId + locale)Adding items to collections
Dedupe table — processed eventIds with a TTLMessage consumers
Version / ETag checksIf-MatchPreventing lost updates
Where I've used it

For release items, adding the same (entry, version, locale) twice has to be a no-op, not a duplicate row. Bulk add was designed to skip invalid or duplicate items and add the rest, while the synchronous add API fails all-or-none and names the offending locale or entry. Two endpoints, two consciously different semantics, both safe to retry.

Checklist

  • Is every POST either naturally idempotent or keyed?
  • Do consumers dedupe on event ID?
  • Does a retry return the same response, not a 409 that confuses clients?
  • Are keys scoped per tenant and given a TTL?

Sources & further learning

Videos, courses, docs and books I recommend for this topic.

Related topics