Search code examples
firebasegoogle-cloud-firestoresnapshotbilling

Are only the changes being charged on Firestore onSnapshot?


I have a snapshot listener on my collection. When I add a document to this collection, every document inside the whole collection gets returned. Do I have to pay for every document or only 1 read of the newly added document? I don't understand how the reads are counted for billing in that case. I would appreciate a link where this behavior is documented.

I am on the blaze plan and I'm not sure if I have to replace the snapshot listeners with regular get() calls to have fewer reads.

If my collection is 100 documents big and I will have to pay for 100 reads on the first load. Now when I add 1 document, my snapshot listener will return 101 documents and I will have to pay for 100+1 reads. So in the end I will have paid for 201 reads. Is this correct?


Solution

  • The firebase documentation on this subject say that :

    When you listen to the results of a query, you are charged for a read each time a document in the result set is added or updated. You are also charged for a read when a document is removed from the result set because the document has changed. (In contrast, when a document is deleted, you are not charged for a read.)

    So to answer you question, you will get charged for 100+1 reads and not for 201.