Skip to content

Latest commit

 

History

History
41 lines (27 loc) · 1.78 KB

File metadata and controls

41 lines (27 loc) · 1.78 KB

Conflict Resolution Concepts (platform-agnostic)

This file is shared by mobile-conflict-resolution-android and mobile-conflict-resolution-ios. Platform-specific code lives in each skill's SKILL.md.

When conflicts occur

A conflict occurs when the same document is modified on two devices while offline, and both changes are synced to Sync Gateway before either device pulls the other's change.

Couchbase Lite detects conflicts automatically. Without a custom resolver, it applies a default resolution (last-write-wins by revision ID — deterministic but arbitrary).

Resolution strategies

Strategy When to use Trade-off
Last write wins (default) Non-critical data, idempotent fields Simple; may lose data
Remote wins Server is authoritative Discards all local changes
Local wins Device is authoritative Discards all remote changes
Merge Both changes matter (e.g., counters, arrays) Complex; requires field-level logic

Auto-purge

When a user loses access to a channel (e.g., document reassigned), Couchbase Lite can automatically purge the document from the local database.

Enable with ReplicatorConfiguration.enableAutoPurge = true (default: true).

Disable if your app needs to retain documents after access is revoked.

Conflict-aware schema design

The best conflict resolution is avoiding conflicts in the first place:

  • Per-user documents: key documents by user ID so two users never write the same doc
  • Append-only arrays: use separate documents for each array entry instead of a shared array
  • Counters: use server-side Couchbase Server atomic counters, not embedded fields
  • Timestamps: include updatedAt so merge logic can pick the newer value per field

See mobile-data-modeling for full schema guidance.