Sync / Replicated state

When things go wrong

ScenarioBehavior
OfflineEdits apply and save locally; pending grows; retries on backoff
Server rejects editDropped from outbox; rest replayed; UI reverts
Local storage write failsEdit reverted; onPersistenceFailure updates UI
Concurrent edit on serverBase advances; local pending edits rebase on top
Retried operationopId deduplicated from journal history
Replica far behindCatches up via more pages or compacted checkpoint
Server history wipedNew epoch resets replica from 0 and resends outbox
Actor mismatch on replicaDurable rejects operations from another actor
Browser storage evictedReplica syncs from server; unsent outbox edits lost
Two tabs share one storageCAS fails stale writer instead of corrupting history
Unknown storage versionFails loudly preserving bytes for migration
Old message formatUpcast via declared migrations
Malformed server answerFails exchange; local outbox preserved
Crash after external effectProvider call repeats with same key via effect ledger

When a server lost its history (epoch changed), a replica that never observed an epoch fails until storage is cleared. For external side effects (emails, charges), pair Durable's runEffect/recover ledger with provider idempotency keys; see external effects.

Deployment responsibilities you keep

  • Authentication: Validate tokens/cookies per socket connection and close expired connections.
  • Compaction and retention: Schedule compact and vacuum, and reject operations older than retained deduplication windows.
  • Effect idempotency keys: Provide stable semantic keys to external providers.
  • Parked reactions: Monitor and manually resolve reactions parked after repeated permanent failures.
  • Schema migrations: Author migrations for durable Messages and coordinate shared snapshot upgrades.
  • Storage eviction: Request persistent browser storage and warn users before clearing site data with unsent edits.

Using Sync or Durable on their own

  • Sync without Durable: Implement the exchange contract (cursor validation, deterministic rejections, deduplicated appends, pagination/checkpoints, and epochs) on any server.
  • Durable without Sync: Supply your own operation and snapshot codecs, empty state, reducer, and ID extractor; see the Durable README.

When to use another tool

  • Online-only state without multi-device offline sync: plain Foldkit or foldkit-remote.
  • Leaderless peer-to-peer merging across every node without a server: a CRDT (Sync.lww.register handles per-field LWW within Sync).
  • Arbitrary ad-hoc SQL querying: store and query tables with Drizzle and Remote; Durable is an operation log.

Next