I'm trying to understand the way the conflict resolution works in firebase for which I need some help.
Assuming that I've json object saved in a node in firebase realtime:
{
"shape": "rectangle",
"stroke": 10,
"color": "black"
}
I've defined a test page which reads this data and displays and also listens to the changes happening on node with key in realtime. I've added a provision to update the data which eventually updates the specific key value alone.
Sample used case
client 1 - loads the page
data - {"shape": "rectangle", "stroke": 10, "color": "black"}
client 2 - loads the page
data - {"shape": "rectangle", "stroke": 10, "color": "black"}
client 2 goes offline
client 2 updates stroke value to 20
data - {"shape": "rectangle", "stroke": 20, "color": "black"}
* data is yet to sync to the server
client 1 makes a change after client 2 has already done with its changes and changes stroke to 5
data - {"shape": "rectangle", "stroke": 5, "color": "black"}
* data gets synced to the server immediately
client 2 comes online and pushes its changes and overrides the changes made by client 1
data - {"shape": "rectangle", "stroke": 20, "color": "black"}
Ideally since the client 1 made the change at a later point of time than client 2 the client 1 changes should be retained when client 2 data gets synced.
I would be very glad if somebody can suggest me a way to such type of conflict resolution in firebase(may be by defining some rules and some extra logic).