Atomic stock reservation (illustrative, PostgreSQL)
-- inventory(sku_id, warehouse_id, on_hand, reserved)
-- available = on_hand - reserved
BEGIN;
UPDATE inventory
SET reserved = reserved + :qty
WHERE sku_id = :sku
AND warehouse_id = :wh
AND on_hand - reserved >= :qty;
-- 1 row updated -> stock reserved
-- 0 rows updated -> not enough stock, nothing changed
INSERT INTO reservations (id, order_ref, sku_id, warehouse_id, qty, expires_at)
VALUES (:id, :order_ref, :sku, :wh, :qty, now() + interval '15 minutes');
COMMIT;
-- A scheduled job releases expired reservations:
-- reserved = reserved - qty, then marks the reservation released.
Because the check and the update are one statement, two buyers cannot both take the last unit. The reservation row records who holds the stock and when it expires. A cache can serve browse pages, but it should never be the thing that decides availability.