practiceExperience & interface

Optimistic UI

Optimistic UI shows the expected result before a server confirms it, then reconciles success, correction, or rollback without hiding uncertainty.

Download Markdown (.md)

01What it means

Optimistic UI temporarily updates the interface as though an asynchronous action will succeed. The client records a pending mutation, renders the expected state, and later reconciles it with the authoritative response. On failure or conflict, the product restores or amends state and explains what happened.[1][2][3]

A provisional interface state reconciled with authority Show the expected result immediately, then confirm, amend, or recover
  1. Confirmed stateThe client begins from known authoritative data
  2. Pending mutationRecord identity and render the expected result
  3. Request in flightSend idempotently and prevent duplicate effects
  4. Confirmed successMerge canonical server fields into the view
  5. Conflict or failureRollback or preserve a draft with clear explanation
  6. Safe retryReconcile before repeating the intended action

The reconciled response becomes the next confirmed state

Optimism suits reversible, likely-successful actions. Money, stock, authorization, and irreversible operations generally require authoritative confirmation.

02Why it matters

For common, low-risk actions, waiting for a round trip makes an interface feel slow. Optimism preserves momentum and can make remote systems feel direct. Done well, it separates perceived responsiveness from latency without pretending uncertain, high-impact operations are complete.

03When to use it

Use it when success is highly likely, the result is predictable, and failure can be reversed—for example liking, reordering, or renaming. Avoid or qualify it for payments, inventory, access grants, legal submissions, and irreversible side effects.

04How it works

  1. Define a client-generated mutation identity and exact optimistic state.
  2. Mark state as pending when uncertainty matters, while keeping the interface usable.
  3. Send an idempotent request and prevent accidental duplicate side effects.
  4. On success, merge canonical server data rather than assuming every field matched.
  5. On failure or conflict, rollback or preserve a draft, explain the issue, and offer safe retry.

05A practical example

Example

When a user renames a project, the new name appears immediately with a pending indicator. A successful response replaces local timestamps and casing; a conflict keeps the entered value in an editor, restores the saved label elsewhere, and offers specific correction.

06Where it breaks

Optimism increases state complexity and can briefly show information that is not true. Rollback may confuse after users act on provisional results, and concurrent edits invalidate assumptions. Security, authorization, money, stock, and irreversible operations generally require authoritative confirmation.

Common mistakes

  • Using optimistic success for payments or permission changes
  • Rolling back silently after the user continued from provisional state
  • Ignoring duplicates, conflicts, and canonical server fields

07Sources

  1. useOptimisticReact · Official documentationuseOptimistic
  2. Optimistic stateFlutter · Official documentationOptimistic state
  3. Optimistic UpdatesTanStack Query · Official documentationOptimistic Updates
View saved topics

Start typing to search titles, definitions, categories, and frameworks.