E-commerce and payments
What is Idempotency?
An idempotent operation produces the same result whether it runs once or many times. In payments it is what prevents a retried request from charging a customer twice, and what stops a redelivered webhook sending two confirmation emails.
Also called: idempotent request · idempotency key
Where it is required
- Payment creation, using the provider’s idempotency key so a retry returns the original result
- Webhook handling, by recording the event id and skipping anything already processed
- Stock decrementing, which is the other place double-processing does visible damage
- Any operation a network timeout might cause a client to repeat
The implementation detail people miss
Recording the event id in a separate step from the fulfilment leaves a race: two deliveries can both check, both find nothing, and both proceed. The record and the work must happen in the same transaction.
How to test it
Replay the same webhook twice deliberately and confirm exactly one order, one email and one stock movement result. It takes two minutes and it is almost never done.
Where this is covered in depth
A definition can only go so far. Stripe checkout integration, and the four failure modes nobody tests for covers this properly — 3 minutes, free, no email required.
Who wrote this
Anas Bin Masud builds e-commerce sites and does technical SEO for businesses in the UK, Canada and Pakistan. These definitions come from client work rather than from a content brief — where an entry describes a mistake, it is usually one found on a real site. More about how I work.