简体   繁体   中英

Do multiple, concurrent update of individual fields in the same document require a transaction?

I am building a flutter app with firebase backend in which I require multiple clients to update the same document simultaneously. But the fields that each client updates are different. So would there be any benefit if I use transaction to update rather than updating the document normally?

You would want to use a transaction if a client is updating a field using the contents of the other fields for reference. So if field2 needs to be computed consistently based on the contents of field1, you would need a transaction to ensure that there is no race condition between the update of either field.

If each field is entirely, logically separate from each other, and there is no race condition between their updates (they can all change independently of each other) then it should be safe to update them each without a transaction. But bear in mind that each document has a sustained max write rate of 1 per second. So if you have a lot of concurrent updates coming in, those updates could fail. In that case, you'd want each field to exist in its own document.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM