Payments · Pattern

Idempotency

Designing an operation so that doing it twice has the same effect as doing it once, so a retry can never charge a customer or ship an order twice.

How it works · updated

How it works

Networks fail at awkward moments: a request times out, the app retries, and the first attempt had actually worked. With an idempotency key, the client sends a unique id with the request (Stripe uses an Idempotency-Key header); the server stores the result against that key and returns the same result for any repeat instead of acting again.

The same idea protects webhook handlers, since gateways retry deliveries and may send an event more than once: record each event or payment id, skip ones already processed, and back that with a unique constraint in the database so two copies arriving together cannot both win. In HTTP, GET, PUT and DELETE are meant to be idempotent; POST is not, unless you make it so.

More in Payments

How it works

All 13 Payments terms

Crafted in the dark. Shipped to the world.

Tell us what you are building. You get a private project space with a proposal and a line-by-line quote within a day.