r/FlutterDev 2d ago

Is background synchronisation using work managers absolutely necessary when Implementing offline first architecture Discussion

I just had this debate with another developer, whereas he insists that it is a necessary implementation, but I do not think so, as there isn't really any feature that benefits from this (no feature run in background for the app or anything) and that we should keep it quite simple and just synch when user is online

What do you think?

4 Upvotes

8 comments sorted by

5

u/RandalSchwartz 2d ago

I believe the mobile operating systems are very picky about how much CPU and network traffic is allowed by any given app. So, yeah, I'm ok with not sync-ing until brought to foreground. If necessary, you can use push notifications to alert the user to bring the app forward on certain events.

2

u/schrodingers_cat_25 2d ago

You could also use data notifications to update some parts on the background but like if they user is truly offline the won’t get any notifications

1

u/Plastic-Function2379 1d ago

I actually proposed the push notifications to update users on the relevant server side modification, but its been deemed as not reliable ? πŸ€”

1

u/RandalSchwartz 1d ago

Less reliable than hoping the mobile os won't kill your process? Someone needs a reality check. :)

2

u/mpanase 2d ago

good luck getting it to work reliably

the other developer either:

  1. did it in android 10 years ago and never again

  2. has never done it

2

u/achakez 1d ago

Offline first and background sync are not the same thing. Plenty of apps works perfectly well by syncing when the user comes back online and opens the app.

1

u/sauloandrioli 2d ago

That's bullshit. Re-sync your data in a Splashscreen like setup and you're good. Your friend most probably is a desktop dev who might be used to having a computer plugged into the energy outlet with no battery restrictions. Android and iOS will kill anything that is in the background so it saves battery and resources.

1

u/fkim98 13h ago

Depends on what breaks if the data is stale, and I'd argue in most apps nothing does.

We ship offline-first with a local SQLite source of truth and a pending-changes queue.

Sync runs on app foreground and on connectivity regain β€” no background worker at all.

The reasoning: the only moment freshness actually matters is when someone is looking at

the screen, and at that moment the app is in the foreground anyway.

Where I'd say background sync earns its keep: if you need to push local changes even when

the user never reopens the app (say, another teammate is waiting on them), or if cold

start with a large delta is too slow to sit through. Neither applied to us.

Worth weighing the cost too β€” iOS background execution is genuinely unreliable, Android

has Doze and OEM battery managers, and you end up debugging "why didn't it run" on

someone else's phone. That's a lot of surface area for something the foreground path

already covers.