Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Database concurrent data writing

For writing data in Firebase Database I use setValue() in my android app.

My question is: can a value of a variable change, if at the same time I change the value using the Admin API?

like image 593
Irvin Bridge Avatar asked Dec 18 '22 09:12

Irvin Bridge


1 Answers

All writes to the database from all clients are ordered. It doesn't matter if its from a client app or the admin SDK. If there are two database clients trying to write different values to the same location in the database, the last writer in the order overwrites the previous value, which is then what all the other clients will eventually see.

If you want to decide what to do in the event of a conflict like this, you can use a transaction to make sure that each client gets to know exactly what the prior data was, and what the new data will be. This is how you make things like a counter safe to increment when there are lots of writers trying to increment it.

like image 196
Doug Stevenson Avatar answered Dec 20 '22 22:12

Doug Stevenson