Attributed metadata history
Up to 100 retained publisher events per page for 850eabe340b59dc46a53d38b0dea9e0e117cff77bb79f4b6fc39871da08820b3. Withdrawals and unavailable references remain attributed to their publishers.
intelligence_src_6dc544294b7f21f98a
observed · 2026-11-26 17:53:03 UTC
Two customers. One kurta left. Both press Place order within the same second. In many stores, both orders go through. Somebody finds out later, usually the shop owner, on the phone, apologising. I'm building ShopKit PK, a platform that runs many online shops for Pakistani sellers from one codebase. Most of those sellers ship cash on delivery, where every wrong order becomes a refused parcel. So "never sell what you don't have" was a hard requirement, not a nice-to-have. Here's how it works, and the mistakes it avoids. The bug everyone writes first The obvious version reads stock, checks it, then writes: const level = await db.inventoryLevel.findUnique({ where: { variantId } }); if (level.onHand - level.reserved < qty) throw new OutOfStock(); await db.inventoryLevel.update({ where: { variantId }, data: { reserved: { increment: qty } }, }); Between the findUnique and the update, another request can do exactly the same check, see the same stock, and also pass. Two orders, one item. You can patch this with SELECT ... FOR UPDATE and a transaction, but there's a simpler way that needs no explicit lock at all. Make the check and the write one stat
Fingerprint: e8ece988b30d3314992ef4cd60b272dc6674c948388f7baaa0bde1a8a8624ca5
intelligence_src_6dc544294b7f21f98a
observed · 2026-10-12 11:01:03 UTC
available
Fingerprint: 2faf9469031bd0e00603457ab86d15e2040aea06ef98482184945872c5cb389f