TL;DR
Is there any benefit to batched writes over transactions other than offline availability?
That is assuming that transactions are safer than batched writes.
Why transactions
I am thinking about migrating Cloud Functions code from batched writes to transactions. The initial idea was that it would be safer.
I was worried that the Cloud Function would not catch when a batched write failed and it is crucial that all of the writes (changing many documents accross different collections) are actually applied.
I read this answer and was glad to hear the following:
If you don't need or want to be able to write while offline just use a regular transaction: it will handle checking whether or not you're online and will fail if you're offline. You're not obligated to read anything in the transaction.
This basically says that the only point of batched writes is offline availability. This confirmed my initial thoughts, however, I also read documents.
Why batched writes
The "Transaction and batched writes" documentation points out that batched writes "have fewer failure cases than transactions".
Confusion
Now, I am slightly confused. The only valid concern regarding transaction failure for my case was the following:
The transaction read a document that was modified outside of the transaction. In this case, the transaction automatically runs again. The transaction is retried a finite number of times.
As the write operations that are used my Cloud Functions are exclusively update
operations, I am wondering if this even applies to my case, i.e. if the batched write would ever encounter such an issue. The way I imagine it, the batched write just updates, say, a thousand documents and all of these updates only modify a single field.
When the transaction does the same, when would this failure ever occur?
And since I am using Cloud Functions, which I know is always online, would batched writes ever encounter any kind of issue?
+ Transactions: Safer, will not fail
+ Batched writes: Fewer failure cases, will not fail
Can you see what my confusion is from this?
Regarding simplicity of code: I think batched writes looks more concise, however, it is actually more code in my case. Hence, it does not matter to me.