Imagine this scenario: A customer buys a $200 item on your checkout page. They hit "Pay Now". Their browser sends an HTTP POST request to your payment gateway. Your server successfully charges their credit card with Stripe or Adyen, but right before sending the HTTP 200 response back, the clientβs mobile connection drops.
To the customerβs browser, the request timed out. Naturally, the customer hits "Pay Now" again. Or worse, an automated client-side SDK retries the request with exponential backoff.
If your payment API is not idempotent, that customer just got charged twice.
Request 1 (Drop) ββ> [ Charge $200 ] ββX (Network Drop) Request 2 (Retry) β> [ Charge $200 ] ββ> Customer billed $400! π¨
Enter fullscreen mode
Exit fullscreen mode
In payment engineering, duplicate requests are not an edge caseβthey are an absolute certainty.β¦