Skip to content
Preptima
hardScenarioDesignMidSeniorStaff

A payment API times out and the client retries. How do you guarantee the customer is not charged twice?

Prevent a double charge on payment retry with an idempotency key tied to the purchase intent, a unique constraint, atomic charge recording, honest in-flight retry responses and settlement reconciliation.

6 min readUpdated 2026-08-15

Answer

Short answer

The client must reuse one idempotency key for the purchase intent, not create a new key per HTTP attempt. The server claims that key with a unique constraint, records the charge and replayable response atomically where possible, returns a clear in-flight answer for overlapping retries, and reconciles provider settlements afterward.

Was this answer helpful?

Likely follow-ups

  • What do you return when the same key arrives with a different request body?
  • How long do you keep idempotency records, and what breaks when one expires?
  • The process dies after the provider call and before your commit. What state is the payment in, and who repairs it?
  • How would you stop a user double-charging themselves by submitting the form twice in two tabs?

Related questions

Masterclass guide

Further reading