Why Stripe sends the same event twice
Stripe retries a webhook when your endpoint is slow, times out, or answers with anything other than 2xx — and sometimes delivers twice even when it succeeded. Two copies can arrive at the same moment, so a handler that checks 'is this order paid?' and then marks it paid can run twice before either write lands. The result: two shipments, two credits, two confirmation emails.
The fix: make the handler idempotent
Store every processed event ID (event.id) with a unique constraint, and do the order update in the same transaction. If the insert fails because the ID already exists, acknowledge with 200 and stop. Answer quickly (do slow work in a queue) so Stripe has no reason to retry, and never rely on 'check then write' without a lock or unique key.
Test it before your customers do
MockCard's duplicate scenario fires the same signed event twice, concurrently — the exact race that breaks handlers. Run it in CI with the GitHub Action or an SDK, and add an assertion that the order was fulfilled exactly once. If a refactor removes the idempotency check, the build fails instead of your checkout.