← Back to portfolio

React Native · State management

Making like, comment and cart actions feel instant without lying to the user

A social feed felt sluggish even though the API was fast enough. The fix wasn’t a faster backend — it was applying the user’s action to the UI immediately and only reconciling with the server afterward, with a rollback path for when the server disagrees.

Context

A feed screen let users like posts, add quick comments and adjust a cart quantity. Each action went through a standard request/response cycle: disable the control, show a spinner, wait, update state. On a good connection this was barely noticeable; on a flaky mobile connection — the normal case for a lot of real usage — every tap had a visible, variable delay before anything on screen moved.

Problem

The app wasn’t actually slow; it was honest in a way that read as slow. Waiting for a server round trip before changing a heart icon or a counter means the perceived latency of every interaction is the network latency, every time, even for actions that succeed almost all of the time. The deeper risk sat on the other side of the fix: once you update the UI before the server confirms anything, you need a real plan for what happens when the request fails, times out, or comes back with a different value than what the user tapped — otherwise “optimistic” just means “eventually wrong.”

Approach — apply, track, reconcile, roll back

Illustrative outcome

Figures below are illustrative, from working through this pattern on a representative feed screen — not a specific client’s production metrics.

What I took from it

Optimistic UI is a trade: you buy back perceived latency by taking on the responsibility of being right eventually, not just immediately. The pattern only earns its complexity for actions that are cheap to be wrong about and quick to correct visually — a like, a comment count, a quantity stepper — and it needs an explicit snapshot-and-rollback path from day one, not bolted on after the first bug report about a count that “sometimes doesn’t match.”

The interactive demo below makes the mechanism visible: toggle between optimistic and pessimistic strategies on the same feed, dial up latency and failure rate, and watch what rollback actually looks like when a request comes back negative.

Try the optimistic updates demo →