Recipe Sync Engine
Deterministic, conflict-free synchronization for distributed recipe graphs.
Overview
The sync engine treats every recipe as a Merkle DAG node. Changes propagate via operation-based CRDTs, ensuring offline edits merge without central coordination. Each client holds a partial replica and gossips state vectors on reconnect.
Core Primitives
- OpLog — append-only journal of insert, update, and delete operations keyed by Lamport timestamp.
- State Vector — compact map of peer ID to last-seen sequence number; exchanged during handshake to compute delta.
- Content Hash — SHA-256 of the normalized recipe body; deduplicates identical nodes across peers.
Merge Strategy
Concurrent edits to the same field resolve via last-writer-wins with a tiebreaker on node ID. Structural conflicts — such as deleting a parent while a child is inserted — are detected through causal stability checks before applying operations.
Transport Layer
Sync payloads travel over WebSocket with a thin framing header: message type, compressed op batch, and sender state vector. The server acts as a stateless relay; all conflict resolution happens client-side.
This document is a living design spec. Implementation details are tracked in the architecture overview.