Stripe · Opend practice case · Updated
Can two checkout retries create one payment?
Order A17 costs $48. A slow checkout causes a browser retry at the same moment a worker retries a timed-out API call. Neither caller knows whether the first request succeeded. Describe what your service records before it talks to Stripe.
Short answerGive a logical payment attempt one durable identity. Replay that attempt with its original key and parameters, and reconcile its payment state when the outcome is ambiguous.
- Browser and worker
Both request payment for order A17, attempt 1.
- One durable attempt
A unique order-and-attempt record owns the key, amount, currency and status.
- One downstream identity
Every replay reads that row. The provider response or a reconciled event resolves it.
Separate a retry from a second purchase
Start with the business invariant. Two tabs can send different HTTP request IDs for the same checkout. Have the service assign the attempt identity and compare the requested amount and currency with the saved record. Concurrent inserts race on a unique constraint. The loser loads the winning row and returns its status. A customer deliberately starting a second payment after a declined attempt follows a separate business transition.
Explain the limit of the provider key
For Stripe API v1, an idempotent replay can return the original error response, including a 500 after execution began. Generating a fresh key to clear that error risks another operation. Retrieve the known payment object when possible and keep unresolved attempts available for reconciliation. Keep the order-to-payment mapping beyond the provider’s key retention window so a late client retry cannot silently become a fresh purchase.
Stripe API v1 idempotency semantics ↗Fulfil the order once
Webhook delivery introduces a second duplication boundary. Store the event durably, acknowledge it and process it asynchronously. Make fulfilment conditional on the order’s current state and payment identity. Separate events may describe the same business outcome, so checking the event ID alone is insufficient. Test a successful payment followed by a late notification for an earlier state. The receipt should remain issued exactly once.
Stripe webhook delivery and event ordering ↗| Input | Attempt record | Decision |
|---|---|---|
| A17 · $48 · timeout | A17-1 exists | Recover original result |
| A17 · $84 · same key | Amount differs | Reject the conflict |
| A18 · $48 · new order | New instruction | Create its own attempt |
Try the follow-upWhat if the payment succeeded and the process crashed before sending the receipt?
Recover the payment identity, then transition the order to paid and create a uniquely keyed fulfilment task in one database transaction. The task needs its own delivery semantics. Charging safely does not by itself make sending an email or issuing a ticket idempotent.