Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to synchronize sembast? #174

Open
guenth39 opened this issue Jun 5, 2020 · 3 comments
Open

Question: How to synchronize sembast? #174

guenth39 opened this issue Jun 5, 2020 · 3 comments

Comments

@guenth39
Copy link

guenth39 commented Jun 5, 2020

Is there a proven method how to synchronize the sembast database of my flutter app with a backend? Would be nice to have a tutorial for that.

@guenth39 guenth39 changed the title synchronize sembast Question: How to synchronize sembast? Jun 5, 2020
@alextekartik
Copy link
Collaborator

Not than I am aware of. Synchronization is a complex algorithm that depends on the backend. Whether you use sembast or any other local database does not make much difference.

One common algorithm:

  • Store a server id for each synchronized record
  • Store a dirty flag for local changes for each synchronized record.

Full sync:

  • Get all server records
  • Get server records
  • Compare and handle conflict (typically server wins)
  • Add local changes

Incremental sync:

  • Get all modified/deleted records since xxx
  • Add local change/deletion since xxx
  • Compare and handle conflict (typically server wins)

@tobinharris
Copy link

Is the data modified on both back-end and the phone?

I'm toying with just beaming the entire local JSON .db file up to MongoDb, stored against a user. This is good for a "backup" although there's absolutely no sync logic going on.

For sync, I wonder if CouchDB could be worth a look because it's also a key/value store and works with JSON.

@alextekartik
Copy link
Collaborator

Is the data modified on both back-end and the phone?

(I'm assuming If instead of is).
That can happen, that is where you need some resolution strategy (local wins, server wins, last change wins, user prompt...)

I don't recommend storing the whole db file itself. At least save the export using exportDatabase instead of the whole file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants