Skip to main content
Blueprint · Works on: Cockroach Continuum, CockroachDB Cloud, self-hosted · Verified on: CockroachDB v26.2.8 · Code: blueprints/order-management v1.0.0

What you’ll build

An order service where placing an order is one SERIALIZABLE transaction. It claims the caller’s idempotency key, reserves stock with a guarded update, records the order and its audit event, and writes the outbox message that tells downstream systems. Payment callbacks, fulfillment, returns, and cancellation follow the same rules. The reference implementation’s tests are the acceptance criteria:
  • 50 buyers competing for the last unit get exactly one order.
  • A retried request with the same idempotency key creates nothing new.
  • An order that can’t reserve every line holds nothing.
  • A capture that arrives before its authorization still counts.
  • A capture that arrives after cancellation requests exactly one refund and ignores its duplicate.

Get the code

The code is in the Cockroach Cookbook repository. To fetch only this Blueprint:

Run it

You need CockroachDB v26.2.7 or later and Python 3.10 or later.
Create a cluster by following the Continuum quickstart, create a SQL user, and run CREATE DATABASE ordermgmt;. Apply reference/schema.sql and reference/seed.sql, then set DATABASE_URL to the cluster’s connection string with /ordermgmt as the database and sslmode=verify-full.
Then run the tests and the accounting checks as described in reference/README.md. The tests truncate the order tables, so run them only against a database created for them. To watch the same scenarios against your own cluster, run the demo (Node.js 20 or later):

Read the design

Why CockroachDB for order management

The workload, why it exceeds many databases’ guarantees, and what keeps it correct.

Architecture and request flow

The end-to-end picture the rest of the guide fills in.

Data model

The complete reference schema.

Inventory and reservations

Guarded stock updates, hot SKUs, and reservation deadlines.

Payments and callbacks

Callbacks that arrive late, early, or twice.

Multi-region and scale

Regional placement, survival goals, and sale-day peaks.
The full guide is in the sidebar: best practices, then build and verify, then the evaluation tasks for AI agents.

Scope

The reference is one merchant per database, USD with an explicit currency column, one full-capture payment attempt per order, all-or-nothing initial reservations, split shipments, inspected returns, and unpaid whole-order cancellation. Backorders, partial capture, multiple payment attempts, replacement orders, and multiple stock locations are extensions it doesn’t implement. reference/VALIDATION.md records what was run and on which release.

Recipes this Blueprint uses

Talk to an engineer about your order workload

Reach an engineer who knows this workload.