UX: Immediate Intent vs. Optimistic Update
romshark.github.ioI've grown tired of explaining to frontend devs why "optimistic updates" are harmful and why immediate intent is always better, so I invested a couple hours of my life and some amount of Claude tokens to explain this once and for all.
Let's not make software bad by design, let's make good reliable software we can trust.
P.S. maybe I'm wrong? Challenge me in the GitHub issues!
Your argument is good and I agree.
That said, I have grown tired of over-clauded websites.
Thank you! regarding the over-clauding - reload the page (purge cache!) and check out the new design, I just re-iterated on it and made it less sloppy :)
Awesome example of why "optimistic updates" shouldn't be used outside of games (even then getting shot through walls is incredibly frustrating).
Immediate intent is definitely the way to go.
This is nicely done, I like the animated examples!
I somewhat disagree with the premise. I would distinguish between Web behaviors and App-like behaviors.
On the web, when submitting a form or clicking a "cancel subscription" button, we absolutely need confirmation that the thing we want to do has happened, otherwise it's lost.
When building a web app, the right way to go is generally offline first. I would argue that the behavior you show in the to-do list examples is very much optimistic updates, even when you choose to display that syncing is in progress.
It's also the right way to go for the pill example. What if I take my pill while commuting underground with bad reception. I'd prefer the action to be saved locally and synced later.
The "like" action is an exception here. Ideally it would also be instant and synced later, but the approach most apps take is that they can afford to lose a "like" if something goes wrong. It's not a critical action. They trade off accuracy for simplicity of implementation.
> This is nicely done, I like the animated examples!
Thank you, appreciate it!
> When building a web app, the right way to go is generally offline first.
If the source of truth for that web app is a centralized server then I don't quite agree because IMHO offline-first increases code complexity and it's rarely justified. However, offline-first vs thin-client is a-whole-nother topic :)
> I would argue that the behavior you show in the to-do list examples is very much optimistic updates
It's not optimistic if you're clearly stating that whatever the changes you made are not yet persisted to your source of truth (the server database).
> even when you choose to display that syncing is in progress.
This makes all the difference, you're not being optimistic here, you don't claim it's there, you're being realistic and honest about it being in a premature state.
> The "like" action is an exception here. Ideally it would also be instant and synced later, but the approach most apps take is that they can afford to lose a "like" if something goes wrong. It's not a critical action. They trade off accuracy for simplicity of implementation.
IMHO, this is the wrong trade-off. It takes just as much (or little) code complexity to show immediate intent, as it takes to do proper optimistic updates (because you still need the rollback on failure, otherwise your optimistic update is even more misleading) and I'm happy to be proven wrong if that's not true. So if the cost is roughly the same - why make it worse by design?!
My take is: You don't want software that _appears_ to be fast, you want _fast_ software. And if you can't make fast software, then at least don't make misleading software.
>If the source of truth for that web app is a centralized server then I don't quite agree because IMHO offline-first increases code complexity and it's rarely justified. However, offline-first vs thin-client is a-whole-nother topic :)
IMO that is probably the best reason to do it.
If you know you will be offline first, and you know complexity will be high, then you will more likely focus on abstracting that complexity enough and shifting it forwards in development cycle, so subsequent usages don't have the complexity to deal with only the abstraction. Far too many teams go from easy -> medium -> high, and go "fuck we have to refactor too much, lets slap a tech debt label on it and move on"
btw like the post very simple but effective.
If you can afford that added complexity - go for it, have fun :) I learned to not underestimate the amount of complexity in distributed systems and that in most centralized web apps this complexity simply isn't worth it. You can hide that complexity behind advanced sync engines, but you cannot completely prevent it from coming to bite you eventually. That's my personal opinion, so feel free to disagree :)
forgive my ignorance, but what is the difference between this and pessimistic UI with state?
Good question! There's overlap between immediate intent and pessimistic UI. By my interpretation, pessimistic UI doesn't require any sort of feedback between the invocation of the action and displaying the final result. Pessimistic UI can basically be clicking a button, seeing no changes for a while, and then finally seeing the result (success/error). Immediate intent rules that out and requires immediate feedback on the intent.
That said, I suppose interpretations may differ.
It is the AI generated slope standard page template. Turn me down immediately and for good reason:
You have a wall of text, and image and animations, 2km long, all blinking in my face, when just one graph and 10 lines of text would have carried the same content in a better way.
Awaiting your fork/PR! I'm sure there's many people who have more time and ability to make an even better demo :)
P.S. make sure you're viewing the latest version by purging your browser cache for this site.
Now do why showing the user the actual error is better than "something went wrong" every time.
You can't always be honest on that one because you don't want to expose too much private information to external attackers, right? Anyway, that's another topic :)