A 200-unit bar split into 110 allocated and 90 shared pool, the 10 units sold out of quotas highlighted inside the 110, and two subtractions below it: the literal reading giving 80 and the production screen giving 90

The Formula in the Ticket Subtracted Sales Twice, and Only Two Screenshots Could Prove It

One SKU. Total intake 200 units. Three campaigns hold quotas of 10, 88 and 12 units, and have sold 1, 9 and 0 out of those quotas. How many units are still available to sell? The ticket said: available = total intake − total allocated − total sold. Plug the numbers in and you get 200 − 110 − 10 = 80. The production screen for that SKU, at the same moment, said 90. ...

September 23, 2026 · 7 min · Hoang Nguyen Thai
Two tables with overlapping auto-increment ids, an import file pointing at one and the code reading the other

The Import That Edited the Wrong Row for Years Because Two Tables Shared the Same IDs

An import feature that adjusts campaign quotas from a spreadsheet had been in production for years. Every manual QA pass looked the same: upload a file, open the campaign, see one quota changed, mark the ticket done. Zero automated tests covered the handler. It was editing the wrong row. Not sometimes — structurally, on every run where the two ids happened to line up, and on the staging database they did. The number of production rows it touched over those years is something I have not measured and will not guess at here. What I can show is the mechanism, why three separate safety nets each let it through, and the one test that would have caught it on day one. ...

September 22, 2026 · 7 min · Hoang Nguyen Thai
A SELECT FOR UPDATE statement dissolving into an empty string on the sqlite driver

The Lock I Dropped During a Refactor, and the 1184 Green Tests That Didn't Notice

QA filed a one-line gap: no concurrency tests on the stock pool. I opened the file expecting to write four tests and close it in an afternoon. Instead I found that the lock those tests were supposed to cover was not there anymore. What can go wrong here The system is a promotions backend. Several campaigns draw from one shared stock pool per SKU. Before a campaign can reserve units, a service reads the pool balance, subtracts what is already reserved, and writes an allocation. ...

September 21, 2026 · 6 min · Hoang Nguyen Thai