Stock Decrement Locking – Latency Spikes During Concurrent Checkouts
23K reputation · 19 Feb 2021, 10:04 UTC
Stock Decrement Locking
WooCommerce’s core stock management uses a row‑level lock (SELECT … FOR UPDATE) when a product’s quantity is decremented during checkout. The lock is intended to serialize concurrent updates to the same product row.
When hundreds of users attempt to purchase the same item simultaneously, the lock can serialize the requests, causing noticeable latency spikes that are only visible under load. In some cases, the lock is released before all updates are committed, which can lead to overselling.
The current implementation does not queue or batch checkout requests, and the REST API for cart updates lacks optimistic concurrency control. Documentation acknowledges potential race conditions but does not prescribe a definitive solution, leaving developers to implement custom strategies.
Is the SELECT … FOR UPDATE lock sufficient to serialize concurrent stock decrements without causing overselling?
What mechanisms does WooCommerce provide to detect and resolve deadlocks during checkout?
Which configuration changes can reduce lock contention and latency for high‑volume stores?