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)Soroush’s Product Wiki · https://wiki.soroush.uk/topic/optimistic-ui/
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]
- Confirmed stateThe client begins from known authoritative data
- Pending mutationRecord identity and render the expected result
- Request in flightSend idempotently and prevent duplicate effects
- Confirmed successMerge canonical server fields into the view
- Conflict or failureRollback or preserve a draft with clear explanation
- 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
- Define a client-generated mutation identity and exact optimistic state.
- Mark state as pending when uncertainty matters, while keeping the interface usable.
- Send an idempotent request and prevent accidental duplicate side effects.
- On success, merge canonical server data rather than assuming every field matched.
- On failure or conflict, rollback or preserve a draft, explain the issue, and offer safe retry.
05A practical 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
- useOptimisticReact · Official documentationuseOptimistic
- Optimistic stateFlutter · Official documentationOptimistic state
- Optimistic UpdatesTanStack Query · Official documentationOptimistic Updates