Two cashiers, one last bottle of kecap: fixing overselling in a Laravel POS with row locks
One of my clients is a small minimarket chain, 4 stores, 6 cashiers per store at peak. Last Lebaran, the day before the holiday, the stock report showed -14 bottles of kecap manis . Negative stock. The owner asked me, very politely, how we sold 14 bottles that do not exist. Good question, mas. The bug $product = Product::find($id); if ($product->stock < $qty) { throw new OutOfStock($product); }…
- confirm saving. our bank had the same race in a voucher redemption table, someone fixed it with an app-level mutex on one server. then they scaled to 3 servers lah. alamak