Stock Row Looked Consistent, Yet the Last Unit Was Sold Twice
A developer describes an oversell bug where a customer support ticket revealed two people were promised the same last unit, even though the stock row showed OnHand 1, Reserved 1, and Available 0. The stock table appeared internally consistent, with no negative values, constraint violations, or logged exceptions. The root cause is a lost update: the code reads a counter and writes an absolute value, so concurrent requests overwrite each other's changes. The reservation records, not the stock counter, reveal the true promised quantity, so comparing the two is the way to detect such errors. The author also shows how a barrier-based test hook can reliably reproduce the race condition in a test run instead of relying on flaky timing.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in