How Stripe prevents double payments

  1. They use idempotent APIs to prevent double payment.
  2. They use UUID as the idempotency key.
  3. They send the idempotency key through HTTP headers.
  4. They create a new idempotency key whenever the request payload changes.
  5. They store the idempotency keys in a database on the server side.
  6. They query the database with keys to check if a request was processed earlier.
  7. They process a request only if it’s new and then store its idempotency key in the database.
  8. They roll back a transaction using the ACID database on a server error.
  9. They remove the idempotency keys from the database after 24 hours for reuse.
  10. They use exponential back-off with jitter to avoid the thundering herd problem.

Reference

NOTE - Check it for aspect too

  1. https://www.rahuldhar.me/p/idempotent-keys-explained-how-stripes