Hacker News new | ask | show | jobs
by dutchCourage 2 days ago
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.

1 comments

> 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.

> It takes just as much (or little) code complexity to show immediate intent

I think this depends on how optimistic updates are implemented. There's no reason why the logic to handle a request in the server can't be reused to produce optimistic updates in the client. I've built systems that way. Whereas the immediate intent is actually a slightly different code path and does require more code. But I agree that the rollback logic is needed in either case (and it should be structurally guaranteed, not something hand-written per request).

I really like your website though, I'll be bookmarking it. I'd love to see a lot more offline apps exist, because I think on principle I want all my devices and all their applications to be usable so long as they have power. But I think developers and users are so used to online-only apps, we need to spend time thinking through what a good UX is for offline apps, and this is a great illustration of the importance of that UX.

"optimistic updates" aren't less optimistic if you indicate that the UI is being synced. It's not about telling the truth or not. It's about giving instant feedback and showing the UI state as it would be if the action went through, which is exactly what you do in your to-do list example. That allows the user to keep doing more actions before they've received confirmation from the server that their first action was accepted.

For the "like" action, it's just more satisfying if it feels instant.

> For the "like" action, it's just more satisfying if it feels instant.

Lies are sweet, aren't they? :) Again, I believe you should make the software fast, not make it pretend to be fast. You can absolutely make the like be confirmed sub 100ms and in that case you can skip the immediate intent because it's fast enough (see demo). Even if you have an 80ms ping, you can still do the job of putting the like in a durable queue server-side under 20ms.

Yet instead what people do is lie to the user and risk losing data and this bad practice just became normal practice over time. The like just goes straight into /dev/null, and at best there's a rollback which only makes the user wonder "what the ?! I just pressed it!".

IMHO, we keep treating symptoms without addressing the root causes.

>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 :)
So in an offline first app how do I know my bid/booking has actually gone through? You don't. Unless, you do immediate intent/show in progress. At that point what has all the additional complexity of offline first bought you?
This is not a valid use case for optimistic updates or offline first. You need external confirmation that the action went through. No app will show "payment accepted, booking confirmed" unless it actually happened.
> At that point what has all the additional complexity of offline first bought you?
Instant navigation, instant actions and an app you can use offline. I'd hate for my to-do list or my podcast app to have to make network calls for any action I take. It doesn't mean that all actions should happen offline. Some actions are inherently online.

Take the case of an email app: Mark as read: complete the action offline and sync later. Move to folder: same. Send an email: very much an online action, save the draft and send later. Don't show an email as sent if it isn't.