Skip to main content

Conflict detection and resolution

A conflict exists when local edit was based on version V while server has advanced beyond V.

Detect with versions​

PATCH /notes/42
If-Match: "version-7"

Server returns updated version or 412/409. Version counters/ETags are stronger than device wall-clock timestamps.

Resolution strategies​

StrategyGood forRisk
server winsauthoritative permissions/pricesloses local work
client winspersonal setting where latest intent acceptedoverwrites other device
last-write-winslow-value whole recordclock skew/data loss
field mergeindependent fieldssemantic cross-field invariants
operation merge/CRDT-likecounters/sets/collaborationprotocol complexity
user-assistedvaluable text/design conflictsUX burden

Last-write-wins warning​

Device clocks are untrusted/skewed and can move backward. Server-assigned ordering is safer but arrival order still means offline older semantic intent may win. Use LWW only when loss is acceptable and document tie-break.

Three-way merge​

Compare base, local, and remote:

field unchanged locally -> take remote
field unchanged remotely -> take local
both changed same way -> take value
both changed differently -> conflict/policy

Cross-field rules (start < end, currency + amount) require domain validation after merge.

Version vectors overview​

Per-replica counters can detect causality/concurrent updates better than one timestamp, but metadata grows and server/client protocol is complex. Useful in true multi-master collaboration, excessive for simple server-authoritative data.

Conflict persistence​

Store base/local/remote or enough recovery data, status, and operation IDs durably. Do not hold conflict only in dialog state. User may leave/process may die.

Testing​

Two devices edit same field/different fields, clock skew, delayed packets, duplicate retry, delete-versus-edit, permission revoked, server normalization, and process death during resolution.

Business decision

Conflict policy is product semantics. Engineers cannot safely choose “last write wins” globally just because it is easy.

Exercises​

  1. Three-way merge a contact edited on two devices.
  2. Choose policy for cart quantity, note text, and permission role.
  3. Explain why timestamps do not prove causality.