DmitrySharabin / mavo-firebase-firestore

Firebase backend plugin for Mavo. Store and sync app data in milliseconds. Store and serve files at Google scale. Authenticate users simply and securely. All the Google Firebase powers are at your fingertips.
https://plugins.mavo.io/plugin/firebase-firestore
MIT License
6 stars 0 forks source link

A way to handle merge conflicts (when using real-time updates) #12

Open DmitrySharabin opened 4 years ago

DmitrySharabin commented 4 years ago

Thoughts from #10

As soon as new data been pushed from the server, the local data updates immediately, regardless of whether an end-user changes data or not. Unfortunately, the plugin doesn't respect a user's local data now. I know it's unacceptable, but for now, it is what it is.

For now, I don't know what the best way to handle merge conflicts is. What do we expect? Some sort of a dialog where an end-user sees that something went wrong, and they need to decide what changes to accept: the ones they made or the ones came from the server? Or we can let a mavo author specify the desired behavior via some attribute? mv-firebase-changes? mv-firebase-changes-source? Like so: mv-firebase-changes="server" or mv-firebase-changes-source="local"?

David's thoughts:

I don't have a strong opinion yet about the "right" thing to do here. I don't think we have a good merging solution. For typical currently-imagined mavo applications it isn't a big deal since there's only a single user writing, which makes write conflicts unlikely unless they're using two devices. And if you're only reading not writing it isn't a problem. Long term we may need to move to an operational-transform model of the data (like google docs) to better handle collaboration.

karger commented 4 years ago

For "slow" multi-user apps It might be a good short-term solution to notify the user if a push will overwrite changes they've made. If changes are slow, there won't be many such----a user's data will save when they change it, and any updates that arrive before their next change can just replace the data they've already written. ie, we silently accept updates when the data is clean from last save but dialog with the user if the data is changed.

For the realtime multi-user app I've been building, I have each user writing to a separate database and only reading other databases, so merge conflicts cannot happen. I think this might be a useful design pattern generally for such multi-user apps, and right now mavo doesn't support it so I had to do it with my own js. I'd love to make it available generally (per user storage with read aggregation) but I'm not sure it generalizes to any platform other than firebase (none of the other platforms we currently support provides any kind of update notifications) so it might be premature.

Longer term, the right way to deal with merge conflicts is like github does---keep a record of the changes made locally and replay any that are missing from the data sent from the server.