Conflict resolution?

If two or more users are both standalone and they are editing the same data, who will win? Or, better yet, is there a resolution to the conflict / merger?

+8
conflict firebase offline
source share
1 answer

The answer depends on how they modify the data.

  • set () (and delete, push, setWithPriority, etc.) are last-write-wins. Therefore, if client A and client B are โ€œstandaloneโ€ and then connect to Firebase, if client A successfully connects to Firebase, its set () will be written to Firebase, but when client B eventually connects, its set will overwrite the client recruitment, so customer B will ultimately win.
  • transaction () has built-in conflict resolution. Therefore, if client A first connects to Firebase, his transaction will be successful on the first try (since there is no conflict). Then, when client B connects, his transaction will not work on the first attempt, and therefore his transaction update function will automatically be run a second time (now on the new data that client A previously wrote), and this new data will be written to Firebase (when lack of further conflict).

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

+12
source share

All Articles