Home > Software design >  How do you speed up frontend response to user actions that require backend actions?
How do you speed up frontend response to user actions that require backend actions?

Time:07-18

This question isn't specifically for flutter, but it's what I'm learning at the moment, so I'm tagging it as such.

I'm writing a flutter app where the user can "favourite" a note, which changes the state of that note's icon. I'm using firebase as backend. The way I've implemented it is to update the state of the icon whenever the note object gets updated, but that of course takes time between the button press and the update.

This got me thinking about how do apps eliminate time between user action and feedback, when there's usually supposed to be time needed for the request to be sent to the backend, an update coming back to the app, etc?

For example: When a user upvotes a post on reddit, they can see the upvote button change state immediately, and the post's upvote counter updates accordingly, without any delay.

Do apps cache these user actions and have some way of mixing using cached information and actual backend(live) data, so that the user gets this nice immediate feedback?

CodePudding user response:

Use Optimistic UI pattern. Optimistic UI immediately switches to the final state while the real operation is still in-progress. If the operation fails, rollback to the previous state and possible show error. Details how to implement Optimistic UI depends on the use case.

  • Related