Menu

The Anatomy of Payment Idempotency: Preventing Double Charges without Redis
πŸ“°

The Anatomy of Payment Idempotency: Preventing Double Charges without Redis

DEV Community: postgresΒ·Raziq DinΒ·12 days ago
#TF3ckX8S
#devtopostgresql#devto#dev#request#idempotency
Reading 0:00
15s threshold

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.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.