How Stripe prevents double payments
- They use idempotent APIs to prevent double payment.
- They use UUID as the idempotency key.
- They send the idempotency key through HTTP headers.
- They create a new idempotency key whenever the request payload changes.
- They store the idempotency keys in a database on the server side.
- They query the database with keys to check if a request was processed earlier.
- They process a request only if it’s new and then store its idempotency key in the database.
- They roll back a transaction using the ACID database on a server error.
- They remove the idempotency keys from the database after 24 hours for reuse.
- They use exponential back-off with jitter to avoid the thundering herd problem.
Reference
NOTE - Check it for aspect too