Both channels share one cart. Stock is per variant and limited: no overselling, and no stock locked by idle carts.
TL;DR
NDA note: a shared cart that checks availability on add, and holds stock only when the buyer opens the checkout summary.
live trace · Opening checkout summaryfrom the original diagram
01
Buyer → Summary APIopen summary of cart lines
02
API → Checkout sessionlock existing or create session
03
API → Variantlock row, check on hand minus held
04
API → Stock holdcreate hold, active
05
API → Variantheld = held + quantity
06
API → Buyertotals and expiry
…
01
Background
+
Both channels share one cart. Stock is per variant and limited. The goal: no overselling, but no stock
locked by idle carts.
02
How it works
+
Add to cart checks live availability but does not reserve stock.
Opening the checkout summary creates a session and a hold per
line. Each hold locks the variant row, checks on_hand - held >= qty, then increments
held.
Re-opening the summary with the same selection reuses the session and only adjusts holds whose quantity
changed.
Leaving checkout releases the holds. A scheduled job expires stale holds and summary sessions.
On checkout the hold is consumed and on-hand stock decreases. On
cancel or expiry it is released and only held
decreases.
03
Design decisions
+
Hold at checkout summary, not at add-to-cart or place-order.
Holding at add-to-cart lets idle carts block stock; holding at place-order lets a buyer reach checkout
and then find the item gone.
Separate held counter. On-hand stock only changes on a real sale
or return, which keeps stock reports honest.
Same lock order everywhere (variant, then hold) to avoid
deadlocks.
Idempotent transitions: releasing a hold that is no longer active
does nothing, so overlapping expiry runs cannot double-release.