Skip to main content

Triple-Write Orchestrator

The TripleWriteOrchestrator (lib/triple-write-orchestrator.ts) is a Saga-pattern implementation that coordinates multi-step write operations with automatic rollback on failure.

The Three Steps

Every user action that modifies data must write to three independent systems in strict sequence:

Usage


Per-Step Timeouts

Each step races against its own timeout via Promise.race. If a Convex mutation hangs due to a slow network, the timeout fires and the orchestrator skips to the rollback phase.

Rollback Behavior

Steps are rolled back in reverse order. If Step 2 fails, Step 1’s compensating function runs. If a compensating function itself fails, the rollbackFailed flag is set, signaling HydrationSync to perform a full reconciliation on the next cycle.

Saga Tracking

Each orchestrator instance generates a unique saga ID for log correlation: