Optimistic updates

An optimistic update shows the result before the server confirms it. It cut the feedback p99 from 202 ms to 2 ms in the mini board. The price is a promise: keep each action in a durable outbox, retry it, and undo it if the server refuses.

Play a level

See it on the board

The same traffic runs on two boards. The simulator measured both when this page was built.

Board to show
HTTP/2TCPMobile usersNode API1 vCPU · 1 GBKey-value s…1 vCPU · 1 GB
HTTP/2TCPMobile use…Node API1 vCPU · 1 GBKey-value…1 vCPU · 1 GB
Tap waits for the server: misses a goal
AMQPHTTP/2TCPMobile usersMessage bro…1 vCPU · 1 GBNode API1 vCPU · 1 GBKey-value s…1 vCPU · 1 GB
AMQPHTTP/2TCPMobile use…Message br…1 vCPU · 1 GBNode API1 vCPU · 1 GBKey-value…1 vCPU · 1 GB
Tap shows the result, outbox sends it: meets the goals
See it on the board
Measure Goal Tap waits for the server Tap shows the result, outbox sends it
p99 latency under 100 ms 202 ms Fail 2.2 ms Pass
Lost writes none 0 Pass 0 Pass
Error rate under 0.1% 16.7% Fail 0% Pass
Monthly cost 8 USD/mo 12 USD/mo

Key numbers

Network and part values from the catalog. The mini board has a 4G link and an API outage of 15 s.
NumberValue
Mobile 4G round trip, fast end40 ms
Mobile 4G round trip, slow end90 ms
Default delivery tries5 tries
Read and write quorumsLeft and right arrows change R. Tap to change W.

W 3 + R 3 of 5 · every read sees the last write

How it works

A like button feels slow if it waits for the server. On a 4G link with a 65 ms round trip, the user waits 65 ms plus the server time, and the p99 passes 100 ms. An optimistic update does not wait. The app shows the heart at once and sends the request in the background.

This changes what the app promises. The screen now shows a state that the server has not confirmed. If the request fails, the screen is wrong. So the app needs three things.

First, a durable outbox. The app saves each action on the phone before it sends it. If the app closes, the action is still there. Second, retries. If the API is down, the outbox sends the action again later, with backoff. Third, an undo path. If the server refuses the action, the app must remove the heart and tell the user.

In the mini board the API is down for 15 s at 0:20 while 120 likes/s arrive. Without retries, 1,800 likes are lost. With the outbox, none are lost, and no tap fails.

Make each action safe to repeat, because a retry can send it twice. Use optimistic updates for actions that rarely fail. Do not use them for payments.

In the levels you choose how the app sends an action and check feedback time and lost actions.