#Persistence & Crash Recovery
Version: 0.33.0 Updated: 2026-03-15 Applies to: ranvier-runtime Category: Deep Dives
Production-grade workflow durability and saga-style compensation.
#Recovery Flow
- Append: Runtime saves a checkpoint after every successful step.
- Crash: External state remains committed; process state is lost.
- Resume: Restarted process loads trace and resumes from the last cursor.
#Durable Adapters
| Backend | Characteristics |
|---|---|
| PostgreSQL | ACID compliant, multi-process durable storage |
| Redis | High-throughput, sub-millisecond ephemeral checkpoints |
| InMemory | No dependencies, ideal for tests and local development |
#Saga Pattern
- Compensation: Define rollback hooks for irreversible side effects.
- Idempotency: Ensure compensation runs exactly once per trace.
- Auto-Trigger: Runtime kicks off hooks automatically on Fault.
#Quickstart
// Cargo.toml: feature persistence-postgres
let store = PostgresPersistenceStore::new(pool);
store.ensure_schema().await?;
bus.insert(PersistenceHandle::from_store(store));#Workflows
- Insert
PersistenceHandleinto Bus at ingress boundary. - Define
CompensationHookfor transitions with side effects. - Configure retention (TTL/Purge) based on compliance requirements.
- Monitor
checkpoint_failures_totalmetrics in production.
#Key Types
| Type | Description |
|---|---|
| PersistenceStore | Main trait for storing and resuming workflow events |
| PersistenceEnvelope | Minimal record containing trace_id, step, and outcome |
| CompensationHook | Protocol for defining saga-style rollback logic |
| IdempotencyStore | Contract for preventing duplicate compensation execution |