Skip to content
Web Design & Development

Idempotent API Requests, Done Properly

Designing requests so that repeating them has the same effect as sending them once, usually with an idempotency key.

Marcus Adeyemi Technical Director 2 min read 22 views
Idempotent API Requests, Done Properly

At a glance

  • Idempotency keys let servers recognize repeated requests
  • Safe methods GET and PUT are expected to be idempotent
  • Retries clients and proxies retry automatically
  • Storage keys must be stored with the original result

Why it matters

Why it matters: Networks fail mid-request, and clients retry, which can create duplicate orders or double charges.

Best practice

  • Accept idempotency keys on create operations
  • Store keys with their responses
  • Return the original result for repeated keys
  • Set a sensible key expiry
  • Document retry behavior for clients
What to do and what to avoid with idempotent API requests, side by side
Good practice against the usual mistakes, from the sources listed below.

Common pitfalls

Watch out for:

  • Non-idempotent payment endpoints
  • Keys accepted but ignored
  • Different results for the same key
  • Retry logic with no server-side protection

When to call in a specialist

Bottom line Bring in help when APIs create payments or orders.

Where this comes from

The figures and practices above come from the sources listed.

Working on something like this?

We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.

Where to go next

Spotted something wrong? Report an error on this page. We correct on the page and say what changed.

All services

The work behind this article, and what it costs.

Marcus Adeyemi

Builds and maintains the web work. Writes about front-end architecture, performance, accessibility and the unglamorous parts of keeping a site alive.

Keep reading

More in Web Design & Development