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
An orphaned row still counted against a shared stock pool with no screen to release it

Ghost Quota: How a Missing Foreign Key Quietly Lowers a Sales Ceiling

A table called campaign_product_variants had no foreign key, no ON DELETE CASCADE, and no deleted_at. Before the shared pool existed, that was a cosmetic problem: a handful of rows pointing at SKUs that no longer existed made a report look a few units smaller than reality. I never saw anyone treat that as a bug, and I did not go back through old tickets to check. Then we shipped a shared stock pool — several campaigns drawing quota from one pool per SKU — and the same orphaned rows stopped being cosmetic. On a dev database I could still poke at, 14 orphan rows were locking 294 units out of sale, permanently, with no admin screen that could select and release them. The missing foreign key had turned pre-existing technical debt into a lowered sales ceiling. ...

September 22, 2026 · 5 min · Hoang Nguyen Thai