Are we charged for failed Firestore transactions

Viewed 272

If a transaction reads 3 docs and then updates 2 documents successfully but something after this causes the transaction to fail... will I be charged for the 3 reads and 2 writes that were made even though they are rolled back?

Edit---

Also will the get() below only cost 1 read? Where col2 is a subcollection of doc1.

db.collection('col1').doc('doc1').collection('col2').doc('doc2').get();

Edit 2

The firebase website states the following

For example, if a transaction reads documents and another client modifies any of those documents, Cloud Firestore retries the transaction. This feature ensures that the transaction runs on up-to-date and consistent data.

So say my transaction performs 10 reads on 10 different documents. If this gets called and during exectution some of the same documents are updated by other users, which will make the transaction retry, am I going to be hit with 10 * Number of retries for my reads?

Edit 3

I have read more about the transactions here https://firebase.google.com/docs/firestore/transaction-data-contention and it states that the server side transactions will lock the documents and wait for the transaction to finish.

q1) As the transaction is locking and not retrying over and over... will multiple concurrent calls to the firebase function that has a transaction not cost any extra reads/writes and will the functions just take longer to execute because of the lock?

q2) The webpage also has a banner at the bottom stating

Note: Only the server client libraries support transactions with read operations after write operations. For transactions in the mobile/web SDKs, document reads must come before document writes.

I just tried this on my firebase function and recieve the following error...

Error: Firestore transactions require all reads to be executed before all writes.
    at Transaction.get (/srv/node_modules/@google-cloud/firestore/build/src/transaction.js:76:19)

I am using firebase admin version "^8.8.0", is performing reads after writes a feature that has been added in newer versions?

1 Answers

If transactions fail, will I still be charged?

Yes. A read was completed so you are charged for it. (I am unsure if there are any "rollback charges" - as the change now needs to be reversed.)

What is the cost of a sub-collection document read?

The doc1 was not read - so it would not be charged. You are charged for only one read.

I couldn't find a clear text in the documentation and these answers are from my personal usage for Firebase for over a couple years. A Firebasers confirmation would be helpful.

Related