Hasty Briefsbeta

CRDT and SQLite: Local-First Value Synchronization

4 days ago
  • #local-first
  • #CRDT
  • #SQLite
  • CRDT-powered local-first apps use SQLite to track, merge, and sync INSERT, UPDATE, and DELETE operations.
  • Sync engines intercept changes via SQLite triggers, breaking them into per-column events for conflict-free merging.
  • Each column change is annotated with metadata like site_id, column_name, row_key, and version clocks to ensure correct ordering.
  • Column-level clocks allow peers to edit different columns of the same row without conflicts.
  • Sync involves diff calculation, operation shipping, and replay in causal order to maintain consistency.
  • UPDATE operations generate new column versions, while DELETEs are marked as tombstones to preserve causality.
  • Local-first apps support offline work, syncing correctly later due to strong eventual consistency provided by CRDTs.
  • SQLite AI offers a production-ready sync engine for local-first applications with SQLite and AI on the Edge.