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

# Verification

> Executable checks for correctness, concurrency, and recovery.

Executable checks for correctness, concurrency, and recovery. Each check states its expected outcome so that results can be validated automatically.

## Correctness

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
-- A created order has a matching audit event
SELECT count(*) FROM orders o
  WHERE NOT EXISTS (SELECT 1 FROM order_events e WHERE e.order_id=o.id);
-- Expected: 0
```

## Concurrency: no overselling

Run N concurrent buyers against a SKU with `available = 1`.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT available FROM inventory WHERE sku='SKU-HOT';
-- Expected: 0  (exactly one buyer wins; the rest get OUT_OF_STOCK)
SELECT count(*) FROM reservations WHERE sku='SKU-HOT';
-- Expected: 1
```

## Idempotency: retried create

Send the same `Idempotency-Key` twice.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT count(*) FROM orders WHERE customer_id=$c AND created_at > now()-INTERVAL '1m';
-- Expected: 1  (second call returns the first order, creates nothing)
```

## Duplicate callback

Deliver the same payment callback twice.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
SELECT count(*) FROM payment_events WHERE provider_event_id=$eid;
-- Expected: 1  (second delivery is a no-op; no double capture)
```

## Recovery: partial external failure

Simulate capture failing after reservation.

```sql theme={"theme":{"light":"catppuccin-mocha","dark":"catppuccin-mocha"}}
-- Expected: a compensation event releases the reservation; inventory returns to prior level
SELECT to_state FROM order_events WHERE order_id=$o ORDER BY seq DESC LIMIT 1;
-- Expected: 'cancelled'  (or reservation released)
```
