Skip to content
Preptima
hardConceptDesignMidSeniorStaff

A client times out and retries your POST /payments call. How do you make that endpoint idempotent?

5 min readUpdated 2026-08-15

Answer

Short answer

Take an idempotency key from the client and store it in a uniquely-constrained row written in the same transaction as the effect, so the dedupe record and the work commit together.

Was this answer helpful?

Likely follow-ups

  • How does this change when the effect is a call to a third-party payment provider you cannot enrol in your transaction?
  • Should the client or an edge gateway generate the key, and what breaks if a client reuses one across logically different requests?
  • How would you make a consumer of an at-least-once queue idempotent when there is no header to carry a key?
  • What does the idempotency table cost you on the write path, and how would you prune it without a long-running delete?

Related questions

Masterclass guide

Further reading