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?

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.

Further reading

Problem with a question

Engineering Decisions · Middle · question 14

Test yourself

Take the Engineering Decisions · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz