Engineering Decisions · Middle · Question 14 of 14
A "like" button should feel instant on slow mobile networks. A rare failure isn't harmful and can simply be undone. How do you update the UI?
- 1Refetching the whole list after each click
- 2After the server confirms, showing a spinner
- 3Optimistically, rolling back if the request fails
Show the answer
Correct answer: Optimistically, rolling back if the request fails
Explanation
An optimistic update shows the result at once, and a likes counter can safely roll back on the rare failure. Waiting for the server fits operations where a wrong result hurts, such as payments. Refetching fits data that changes on the server in ways you can't predict, but here it adds a delay and a heavy request per click.