Dev.Lib
arrow_backBack to Blogs
LEVEL_066.10June 27, 20261 min read

Offline conflict resolution

Web Security

Offline writes sync later — last-write-wins loses data; need versioning, CRDTs, or server merge.

Summary

Offline writes sync later — last-write-wins loses data; need versioning, CRDTs, or server merge. UI shows conflict UI for unmergeable edits. IndexedDB + SW background sync patterns. E-commerce inventory cannot blindly LWW — business rules decide.


Code example

async function syncOfflineQueue() {
  const pending = await db.getAll('outbox');
  for (const op of pending) {
    try {
      await api.apply(op);
      await db.delete('outbox', op.id);
    } catch (err) {
      if (err.status === 409) await showConflictUI(op);
    }
  }
}

Key points

  • Offline writes sync later — last-write-wins loses data; need versioning, CRDTs, or server merge.
  • UI shows conflict UI for unmergeable edits.
  • IndexedDB + SW background sync patterns.
  • E-commerce inventory cannot blindly LWW — business rules decide.

Further reading

Related concepts