blueprints/order-management/reference/ in the Cockroach Cookbook repository. It implements the core path end-to-end as Python handlers over CockroachDB, with a regression suite and cross-table accounting checks. It was executed against CockroachDB v26.2.8: 12 regression tests pass and all accounting checks return zero rows. See its VALIDATION.md for the exact environment and what was and was not verified.
Layout
Handlers
Every write runs through a@serializable_retry wrapper that retries the whole transaction on 40001 with bounded backoff and jitter (see Transactions & SQL).
create_order: idempotent create. Stores the request fingerprint and cached response inidempotency_keysin the same transaction as the effect. Reserves each line with a guardedUPDATE inventory SET reserved = reserved + :qty WHERE sku = :sku AND on_hand - reserved >= :qty. If any line matches zero rows, the whole transaction rolls back, so there is no partial hold.capture_payment: deduplicates callbacks through thepayment_eventsinbox, locks the payment row withFOR UPDATE, and advances state monotonically. A capture that arrives after cancellation or expiry records the outcome and requests one compensating refund rather than reviving released stock. See Payments & callbacks.expire_reservationandcancel_order: release an unpaid hold exactly once. See Inventory & reservations.shipandreturn_items: guarded per-line writes that enforceshipped + cancelled <= orderedandreturned <= shipped; a resellable return increaseson_handonce. See Fulfillment & returns.claim_outbox: claims unsentoutboxrows withFOR UPDATE SKIP LOCKED, with a note on sharding for high volume. See External integration.
[!NOTE] No partial hold, no savepoint after retry An out-of-stock line rolls back the entire transaction rather than a nested savepoint. CockroachDB does not allowROLLBACK TO SAVEPOINTafter a40001restart, so the full rollback is the correct pattern and still guarantees no partial allocation.
The core transaction
schema.sql.
Running it
From Setup steps 1 and 2 you have a cluster and theordermgmt database. Then:
agent-demo/ app.
