Skip to main content
The reference implementation lives in 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 in idempotency_keys in the same transaction as the effect. Reserves each line with a guarded UPDATE 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 the payment_events inbox, locks the payment row with FOR 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_reservation and cancel_order: release an unpaid hold exactly once. See Inventory & reservations.
  • ship and return_items: guarded per-line writes that enforce shipped + cancelled <= ordered and returned <= shipped; a resellable return increases on_hand once. See Fulfillment & returns.
  • claim_outbox: claims unsent outbox rows with FOR 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 allow ROLLBACK TO SAVEPOINT after a 40001 restart, so the full rollback is the correct pattern and still guarantees no partial allocation.

The core transaction

Every column and table name here matches the Data model page and schema.sql.

Running it

From Setup steps 1 and 2 you have a cluster and the ordermgmt database. Then:
Each test maps to an evaluation task and asserts the expected outcome from Verification. For a browser-based walkthrough against your own cluster, use the agent-demo/ app.