> ## 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.

# Troubleshooting and known limitations

> This page maps the symptoms you are most likely to see when operating an order service on CockroachDB to their cause and resolution, and then states the known limitations the design works within rather than around.

This page maps the symptoms you are most likely to see when operating an order service on CockroachDB to their cause and resolution, and then states the known limitations the design works *within* rather than around. The symptoms are grounded in this guide's patterns; the resolutions point back to the pages that define them.

## Common symptoms

| Symptom | Likely cause | Resolution |
| - | - | - |
| Transactions fail with `SQLSTATE 40001` (transaction retry error) | Contention under `SERIALIZABLE`; a concurrent transaction invalidated this one's reads | Expected under contention. Implement and verify the client retry loop. Re-run the whole transaction with backoff. See [Order lifecycle and idempotency](https://docs.cockroachlabs.com/docs/cookbook/order-management/order-lifecycle-and-idempotency.md). |
| `CREATE CHANGEFEED` fails: "rangefeeds require the kv.rangefeed.enabled setting" | Rangefeeds are not enabled on the cluster | Run `SET CLUSTER SETTING kv.rangefeed.enabled = true;` before creating the changefeed. See [External integration](https://docs.cockroachlabs.com/docs/cookbook/order-management/external-integration.md). |
| Throughput flat on a popular SKU despite spare cluster capacity | A single hot row serializes all writers on one leaseholder | Lock early with `SELECT ... FOR UPDATE`; for true flash-sale SKUs, shard the counter across N sub-rows. See [Inventory and reservations](https://docs.cockroachlabs.com/docs/cookbook/order-management/inventory-and-reservations.md). |
| A guarded `UPDATE` reports 0 rows affected | Insufficient stock, or a stale/illegal state in the `WHERE` guard | Not an error. It is the designed rejection. Return `OUT_OF_STOCK` (or reject the transition) and do not retry as if it were a fault. |
| `CHECK` constraint violation (e.g. `available >= 0`, `refunded_amount <= amount`) | An invariant backstop fired because a code path tried to break it | Treat as a bug signal, not a tuning problem. Find the path that attempted the illegal write; the constraint correctly prevented corruption. |
| A webhook is processed twice (e.g. a double capture is attempted) | Inbound callbacks are at-least-once; dedupe is missing or keyed wrong | Ensure inbox dedupe on `(provider, provider_event_id)` via `INSERT ... ON CONFLICT DO NOTHING`; acknowledge replays with success. See [Payments and callbacks](https://docs.cockroachlabs.com/docs/cookbook/order-management/payments-and-callbacks.md). |
| Downstream consumer sees duplicate or reordered change events | Changefeed delivery is at-least-once with per-key ordering only | Consumers must dedupe by key plus the `updated` timestamp and tolerate reordering across different keys. See [External integration](https://docs.cockroachlabs.com/docs/cookbook/order-management/external-integration.md). |

### Transaction retry errors (`SQLSTATE 40001`)

Under `SERIALIZABLE` isolation, a transaction whose reads are invalidated by a concurrent committed write is aborted with a transaction retry error so that no lost update or write skew can occur. This is normal and expected under contention, not a defect. The application must wrap every transaction in a retry loop that re-runs the whole transaction with increasing backoff:

```text theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
for attempt in 1..MAX:
  try:    BEGIN; <statements>; COMMIT; break
  except SQLSTATE 40001: sleep(backoff * attempt); continue
```

See the official reference: [https://www.cockroachlabs.com/docs/stable/transaction-retry-error-reference](https://www.cockroachlabs.com/docs/stable/transaction-retry-error-reference)

### Hot-row contention on a popular SKU

When many writers converge on one SKU's inventory row, they serialize on that row's leaseholder and the losers take retries and back off, so throughput on that item flattens even while the rest of the cluster is idle. Reach for the tools in order: first `SELECT ... FOR UPDATE` to queue contenders instead of letting them thrash, then counter sharding for genuine flash-sale SKUs.

See: [https://www.cockroachlabs.com/docs/stable/select-for-update](https://www.cockroachlabs.com/docs/stable/select-for-update)

### Enabling changefeeds

Changefeeds read from rangefeeds, which must be enabled at the cluster level before a changefeed can be created:

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SET CLUSTER SETTING kv.rangefeed.enabled = true;
```

See the change-data-capture overview: [https://www.cockroachlabs.com/docs/stable/change-data-capture-overview](https://www.cockroachlabs.com/docs/stable/change-data-capture-overview)

### Guarded updates affecting zero rows

A reservation decrement or a state transition is written as an `UPDATE` whose `WHERE` clause encodes the precondition (enough stock, or the expected current state). When the precondition does not hold, the statement matches zero rows and makes no change. This is the designed rejection path. Return the appropriate business response (`OUT_OF_STOCK`, or reject the transition) and do not treat it as a database fault to retry.

### `CHECK` constraint violations

Constraints such as `CHECK (available >= 0)` and `CHECK (refunded_amount <= amount)` are backstops: they make an invariant physically unbreakable even if application logic is wrong. A violation means a code path attempted an illegal write and the database refused it. Investigate the offending path; the constraint did its job.

## Known limitations

These are properties of the system to design within, not bugs to fix.

* **A single logical hot row has a throughput ceiling.** Distribution does not remove it. A row has one leaseholder, and all writes to it serialize there. `SELECT ... FOR UPDATE` and keeping transactions tiny raise the ceiling; only splitting the logical row into multiple physical sub-rows (counter sharding) raises aggregate write throughput past the single-row limit.

* **Row-Level TTL deletion is background and batched, not real-time.** Expired rows are removed by a periodic job, so a row can persist past its expiration until the next run. Never let correctness depend on TTL having *already* deleted a row: for example, compute live inventory availability by filtering `expires_at > now()` at read time, and use TTL only to garbage-collect. See [https://www.cockroachlabs.com/docs/stable/row-level-ttl](https://www.cockroachlabs.com/docs/stable/row-level-ttl)

* **Changefeed delivery is at-least-once with per-key ordering only.** Messages for a single key arrive in order, but duplicates are possible and ordering across different keys is not guaranteed. Every consumer must be idempotent (dedupe by key plus `updated`) and must not assume a global order. See [https://www.cockroachlabs.com/docs/stable/change-data-capture-overview](https://www.cockroachlabs.com/docs/stable/change-data-capture-overview)

> [!NOTE]
>
> **Verify version- and release-specific behavior**
> Cluster setting names, default TTL scheduling, changefeed options, and feature availability can change between releases. Confirm anything version-sensitive against the documentation for your target CockroachDB version before relying on it, using the official links above.

## Where to look next

If a symptom here does not match, re-run the targeted checks in [Verification](https://docs.cockroachlabs.com/docs/cookbook/order-management/verification.md) and the [Evaluation tasks](https://docs.cockroachlabs.com/docs/cookbook/order-management/evaluation-tasks.md): they isolate the four highest-risk invariants (no overselling, no double orders, no double charges, no stuck or leaked state) and will usually localize the fault to one page of this guide.
