Designing Optimistic Mutations with Rollback and Conflict Recovery

You tap a checkbox and it ticks instantly. A moment later, the server says no, because someone else edited the same record, the session expired, or the network dropped. What happens next decides whether your app feels fast and trustworthy or fast and unreliable.

That is the real engineering problem behind optimistic updates. Showing the change early is the easy part. The hard part is everything that follows: undoing the change safely, detecting that two people edited the same thing, merging their work without silently destroying either version, and doing all of that while requests overlap, retry and arrive out of order.

This guide walks through a complete design for optimistic mutations with rollback and conflict recovery, using React and TanStack Query v5 for the examples. The principles apply to any stack. By the end you will have:

  • A clear mental model of confirmed, optimistic and conflicted state
  • A mutation that snapshots, patches and reverts without clobbering concurrent edits
  • Versioned writes using ETag and If-Match for server-side conflict detection
  • A three-way merge that resolves harmless conflicts automatically
  • A retry strategy that is safe because writes are idempotent
  • A UI contract for pending, failed and conflicted states