Dev.to
7/22/2026

How missing idempotency keys cause duplicate charges on API retries
Original: Your API Retried the Request. Your Customer Got Charged Twice.
Short summary
When a payment API response is lost and the client retries, the backend may process a second valid charge—creating duplicates for orders, emails, subscriptions, and more. The fix is an idempotency key: a unique value per logical operation that the client generates and reuses across retries. The server stores the operation state and original response in a PostgreSQL table so retries receive the same outcome without re-executing the business action.
- •Retries are only safe when the server can distinguish repeated operations from new ones
- •Idempotency keys tie multiple network attempts to one business action
- •Server must store operation state, response body, and fingerprint to safely replay results
Generated with AI, which can make mistakes.
Is this a good recommendation for you?



