# Optimistic UI

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

- Type: practice
- Domain: Experience & interface
- Level: Advanced
- Last reviewed: 2026-09-21
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/optimistic-ui/>)

## What 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.

## Why 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.

## When 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.

## How 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.

## A 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.

## Where 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

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/optimistic-ui/#visualization-optimistic-ui>)

## Sources

1. [useOptimistic](<https://react.dev/reference/react/useOptimistic>) — React · Official documentation
2. [Optimistic state](<https://docs.flutter.dev/app-architecture/design-patterns/optimistic-state>) — Flutter · Official documentation
3. [Optimistic Updates](<https://tanstack.com/query/latest/docs/framework/react/guides/optimistic-updates>) — TanStack Query · Official documentation

## Related topics

- [Loading State](<https://wiki.soroush.uk/topic/loading-state/>)
- [Direct Manipulation](<https://wiki.soroush.uk/topic/direct-manipulation/>)
- [Error Recovery](<https://wiki.soroush.uk/topic/error-recovery/>)
