> ## Documentation Index
> Fetch the complete documentation index at: https://docs.cockroachlabs.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Cockroach Cookbook

> Blueprints, recipes, and migrations for building real workloads on CockroachDB, each with working code, failure behavior, and honest trade-offs.

The Cookbook shows how to build on CockroachDB. Every entry runs, says how it fails, and states what its choices cost.

* **Blueprints** are complete workload designs: the data model, the transactions, and what happens when things fail, as a working application with tests.
* **Recipes** are single patterns you can run in 15 to 20 minutes.
* **Migrations** move an existing application to CockroachDB and show each change it needed.

All the code is in one place, the [Cockroach Cookbook repository](https://github.com/cockroachlabs/cockroach-cookbook). Each project there has its own README and tests, and CI runs those tests against the latest CockroachDB every week.

## Blueprints

> [card] [Order management](https://docs.cockroachlabs.com/docs/cookbook/order-management.md)
>
> Stock, idempotency keys, payment callbacks, and the outbox stay correct under concurrent orders and retries. A 21-page design guide, a Python reference implementation, and a live demo.

> [card] [Payments ledger](https://docs.cockroachlabs.com/docs/cookbook/payments-ledger.md)
>
> A double-entry ledger that stays correct under concurrent transfers, with no overdrafts and no double moves. FastAPI and SQLAlchemy.

> [card] [Multi-tenant SaaS](https://docs.cockroachlabs.com/docs/cookbook/multi-tenant-saas.md)
>
> Row-level security keeps each tenant's data apart, then the same app grows to three regions. Next.js and Prisma.

### Coming soon

> [card] Wallets
>
> **Coming soon.** Spends with idempotency keys, holds and captures, refunds and transfers, shared wallets, and wallets kept in their home region.

> [card] Per-tenant estates
>
> **Coming soon.** Many small, isolated databases, one per tenant, with agent state management and agent sandboxes built on top.

## Recipes

| Recipe | What it shows | Time |
| - | - | - |
| [Make writes idempotent with `ON CONFLICT`](https://docs.cockroachlabs.com/docs/cookbook/idempotent-writes) | A retried request records a payment and debits an account exactly once, in one statement | 15 min |
| [Find and fix transaction contention](https://docs.cockroachlabs.com/docs/cookbook/transaction-contention.md) | Reproduce a `40001` retry error and a blocked write, find the blocker, and fix the transaction | 20 min |
| [Find and fix a full table scan](https://docs.cockroachlabs.com/docs/cookbook/fix-full-table-scans.md) | Read the plan and the index recommendation, then add the index that reads only the rows you need | 15 min |
| [Transaction patterns](https://docs.cockroachlabs.com/docs/cookbook/transaction-patterns.md) | Write skew, `SERIALIZABLE`, `READ COMMITTED`, and a retry loop for `40001`, in Python, TypeScript, Go, and Java | 20 min |

## Migrations

| Migration | What it moves |
| - | - |
| [Port Miniflux to CockroachDB](https://docs.cockroachlabs.com/docs/cookbook/miniflux-port.md) | Miniflux 2.3.5, an open-source Go feed reader written for PostgreSQL, ported as 13 patches and checked with its own tests, plus a MOLT move of an existing database |

## How the Cookbook works

* **Every entry runs.** Recipes name the release their SQL was run on. Blueprints and migrations are tested in CI against the latest CockroachDB.
* **Every entry says how it fails.** Each one covers what happens on retries and failures, and what its choices cost.
* **Every entry works with agents.** Every project in the repository has an `AGENTS.md` for coding agents, and the Order management Blueprint ships an agent skill.
* **Versions are pinned.** Each project is tagged in the repository, and each page links to the tag it describes.

> [card] [Learn it hands-on in Cockroach University](https://learn.cockroachlabs.com/?utm_source=docs\&utm_medium=cookbook)
>
> Several Cookbook projects go with free courses.
