Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conflict resolution?

If 2 or more users are both offline and they are editing the same data, who wins? Or, better yet, is there a conflict/merge resolution?

like image 755
johnnyl Avatar asked Feb 04 '13 23:02

johnnyl


Video Answer


1 Answers

The answer depends on how they're modifying data.

  • set() (and remove, push, setWithPriority, etc.) are last-write-wins. So if a client A and a client B are both "offline" and then later connect to Firebase, if client A successfully connects to Firebase first, his set() will be written to Firebase, but when client B eventually gets connected, his set will overwrite client A's set, so client B will ultimately win.
  • transaction() has built-in conflict resolution. So if client A gets connected to Firebase first, his transaction will succeed on first try (since there's no conflict). Then when client B connects, his transaction will fail on the first try, and therefore his transaction update function will be automatically run a second time (now on the new data that client A previously wrote), and this new data will be written to Firebase (assuming no further conflicts).

So if you don't care who wins, use set(). If you need to ensure some sort of consistency through conflict/merge resolution, use transaction().

like image 54
Michael Lehenbauer Avatar answered Sep 28 '22 02:09

Michael Lehenbauer