One writer, one lock: a race-proof FIFO stock ledger on plain PostgreSQL
Two POS terminals sell the last unit in the same second. Inventory survives that only if every stock mutation goes through one function, one advisory lock, and one idempotency key — and if sub-cent rounding residue dies the moment stock hits zero.