I know this question has been asked before and the firebase official documentation also suggests that both these have exactly the same effect.
However I have confusion in perceiving both as same because of a few things:
- transactions are retried on abortion automatically while there is no mention in the documentation that FieldValue.increment() does the same.
- as mentioned in the documentation The maximum write rate of a firestore document is one write per second, so one can not update a single counter more than once a second using FieldValue.increment(). But what the documentation does not mention is that what happens in this case? For Example if FieldValue.increment() is called twice in one second, does the second call to FieldValue.increment() fails completely, or it is blocked untill that one second is passed and then gets executed after that or some other thing happens.
- If two identical transactions for updating the same counter are run by two different clients at the exact same time, will one of the transactions get aborted and retried?
Considering the above points, I feel that transactions are more safe for updating counters particularly in a case where for example multiple clients can update a single counter, so if the above assumptions are true FieldValue.increment() will fail whenever two or more clients try to update the counter within a span of one second. But doing the same with transactions there will be the advantage of automatic retrying upon abortion due to concurrency.
So what I want to know is that are my assumptions correct? If not then in what way exactly the above 3 things are done? Also considering the example of multiple users updating a single counter, is there an advantage of using transactions over FieldValue.increment().