0

When I subscribe to a collection that results in 100 documents, a couple of days later, I start my app again. I am offline. I see all 100 documents because Firestore cached them for me. Then I go online. In my collection, 5 documents have changed, and I have received the updated data.

So the first query returned 100 documents. The second query also returned 100 documents, but only 5 were sent from the server to the client.

Do I have to pay for 105 documents or for 200 documents?

2
  • 1
    (not a downvoter) Firestore doesn't charge for just accessing a document in its cache. But it all depends on how you implement this use-case (words are imprecise here, as the API allows all kinds of usage). If you want to measure the exact charges: puf.io/posts/counting-document-reads-in-firestore Commented Aug 2 at 3:38
  • I'm not sure why you got a downvote, as it's a very legit question, so please check my answer below. Commented Aug 2 at 4:29

1 Answer 1

0

Does Firebase Firestore charge for loading cached documents?

No. There is no charge when you read documents that come from the local cache. However, it's very important how you read the data. Please note that the local cache is only used when you cannot access the Firebase servers, in other words, when your app is offline, or if you are explicitly using the source option to read the data from the cache, instead of getting data from the Firebase servers. You get this behavior when you perform a get() call.

According to the linked official documentation:

By default, a get call will attempt to fetch the latest document snapshot from your database. On platforms with offline support, the client library will use the offline cache if the network is unavailable or if the request times out.

You can specify the source option in a get() call to change the default behavior. You can fetch from only the database and ignore the offline cache, or you can fetch from only the offline cache.

And to answer your question:

Do I have to pay for 105 documents or for 200 documents?

If you're using a get() call, you'll have to pay 200 document reads, even if only 5 documents are changed on the server. That's because, in order to determine if some documents are changed on the Firebase server, the client SDK needs to read those documents from the server. And hence you'll have to pay for those reads.

For more information, I recommend you check my answer from the following post:

P.S. Try to use a Firestore real-time listener, so you can pay for read operations only for what's new.

Sign up to request clarification or add additional context in comments.

1 Comment

Hey Witek. Can I help you with other information?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.