Order fulfillment
An order is several writes: stock, payment, shipment. If payment fails after stock is reserved, the stock row and the order row can disagree, and a retry can reserve the same units twice.
Without Causet
POST /api/orders
→ insert order
→ decrement stock
→ charge the card
→ crashThe next worker sees a reserved SKU and an order that never shipped. Nothing records that the charge was the step that stopped.
How Causet fits
examples/order-fulfillment compiles. On 2026-11-20 the compiler reported 2 streams, 5 intents, 22 rules, 8 listeners, and the saga fulfillment_saga.
PLACE_ORDER on order_stream checks the SKU with LOOKUP_FIELD, rejects SKU_NOT_FOUND, OUT_OF_STOCK, or INVALID_QUANTITY, then emits ORDER_PLACED and submits RESERVE_STOCK on inventory_stream.
FULFILL_ORDER continues after that reservation. The flag simulate_payment_failure is an input on the intent. It is not a crashed processor.
- op: if
expr: 'intent.simulate_payment_failure == true'
then:
- op: emit
event_type: PAYMENT_FAILED
- op: submit
intent_type: RELEASE_STOCK
target_stream: inventory_stream
target_entity: entity.sku
- op: emit
event_type: INVENTORY_RELEASED
- op: emit
event_type: ORDER_CANCELLED
- op: emit
event_type: FULFILLMENT_COMPLETEThe saga steps that match those events are placed → inventory_reserved → payment_failed → inventory_released → cancelled → complete. The success branch is payment_captured → shipped → complete.
Failure behavior
| Condition | Result in the spec |
|---|---|
| Unknown SKU, no stock, or quantity ≤ 0 | Preflight reject on PLACE_ORDER. No ORDER_PLACED. |
simulate_payment_failure: true | The fulfill intent emits PAYMENT_FAILED, submits RELEASE_STOCK, and emits ORDER_CANCELLED. |
| Flag absent or false | The same intent emits PAYMENT_CAPTURED and ORDER_SHIPPED. |
What you gain
Stock reservation and the order live on named streams, and the cancel path is a committed sequence instead of a catch block. You can see whether PAYMENT_FAILED was emitted before INVENTORY_RELEASED.
Limits
simulate_payment_failure does not call a card processor and does not prove a timeout. RELEASE_STOCK is a submitted intent. Running FULFILL_ORDER again is a new execution and can release stock again. Stream replay does not submit that intent again.
- Catalog rows have to exist first (
INIT_INVENTORY). The lookup reject is only as good as that data. - Cross-stream
submitis ordered by each entity’s cursor, not by one global transaction across order and inventory. - Projection queries (
list_inventory,recent_orders) can lag the snapshots.