CRDT Engine
The CRDT engine provides conflict-free replication for offline-first applications. Locally, writes are available immediately (AP). Globally, deltas are committed through Multi-Raft consensus (CP). SQL constraints are enforced at sync time.
How It Works
- Device writes locally — available immediately, no network required
- Write produces a CRDT delta (Loro)
- When connectivity returns, delta syncs to Origin via WebSocket
- Origin validates SQL constraints (UNIQUE, FK, CHECK) at Raft commit
- If constraints pass, delta is committed and replicated
- If constraints fail, Origin sends a typed
CompensationHintback to the device
Conflict Resolution
Declarative conflict policies per collection:
-- Last-writer-wins (default)
CREATE COLLECTION notes WITH (conflict_policy = 'lww');
-- Rename suffix for UNIQUE conflicts
CREATE COLLECTION profiles WITH (conflict_policy = 'rename_suffix');
The PolicyRegistry stores per-collection resolution strategies. Available policies: lww (last-writer-wins), rename_suffix (append suffix on UNIQUE conflict), cascade_defer (retry with backoff for FK violations), custom (webhook), escalate_to_dlq (send to dead-letter queue).
Constraint Validation
SQL constraints are checked on Origin at sync time, not on the device:
- UNIQUE — duplicate key →
CompensationHint::RenameorCompensationHint::Merge - FK — dangling reference →
CompensationHint::CreateParentorCompensationHint::Discard - CHECK — constraint violation →
CompensationHint::Adjust
The application handles compensation — no silent data loss.
Dead-Letter Queue
Deltas that persistently fail constraint validation are routed to a dead-letter queue with diagnostic metadata. Operators can inspect, replay, or discard them.
Related
- CRDT Sync — Full sync protocol and offline patterns
- Document Engine — Schemaless documents with CRDT sync