Hand-drawn scheduling field-notes cover: 'the same order, almost processed twice' — a 'just locking isn't enough' race condition on the left, 'correctness must rest on DB constraints' with a unique index on the right, plus the partial unique index and state-machine takeaways.

Worried the Factory Might Build the Same Order Twice? I Thought a Lock Would Fix It — Turns Out It Was a Design Problem

To go faster, software runs many processes in parallel. But if two flows grab the same order and each sends it to production, that’s a real, physical loss for the company — scrapped goods. I thought ‘just add a lock’; it turned out I needed an idempotency key. The chase ran to an Oracle partial unique index — and the real fix was more than the index: a status column whose single value secretly meant two different things.

June 2, 2026 · 20 min · Ching