core practice · implementation task

Implement idempotency keys

Add idempotency-key handling to a mutating endpoint: first request executes and stores the result; duplicates replay the stored result.

The mechanism

Networks make retries inevitable, and retrying a POST can charge a card twice. An idempotency key lets the client say 'this is the same operation' — the server stores the first result and replays it for duplicates.

Study Idempotency

Expected evidence

Two identical requests with the same key cause one effect.

Try this drill in the practice workspace →

Hints when you need them
  • Store key → result with an expiry.
  • Guard against two concurrent requests with the same key.

Watch for these mistakes

  • Assuming GET-only idempotency and leaving POST unsafe
  • No expiry on stored idempotency keys
  • Race between two concurrent requests with the same key

Check the sources

Browse all practice briefs