firebasegoogle-cloud-firestorebilling

Confirmation over automatic re-queries for billing


I read in the official documentation that if the app is terminated or if a session has been inactive for more than 30 minutes that despite if a local/non stale cache is present, the query will be recomputed and fetched directly from the server.

Can anyone please confirm, if a non-stale cache exists, will Firebase still attempt read off this after the inactivity window?

Example: if I have a query that returns 10 documents, and it’s cached automatically by Firebase. The user is inactive for 30+ minutes, returns to the session, would Firebase either

A) re query and charge me 10 reads Or B) re-query but smartly fetch from cache if available and thus only charge me 1 read as default

I really need to know the answer to this so I can factor in my structure on advanced caching if needed.

I’ve tried analysing the Firebase usage to get an answer on this but I see inconsistent results and I need to know a definite answer to this.


Solution

  • I am assuming you're referring to this documentation, with the only part referring to "30 minutes" that says:

    If offline persistence is enabled and the listener is disconnected for more than 30 minutes (for example, if the user goes offline), you will be charged for documents and index entries read as if you had issued a brand-new query.

    I think you are probably misinterpreting the scenario covered by this part of the documentation.

    This only covers the situation with a query listener (not a normal one-time query) that starts offline, then goes offline and comes back online again. If a query listener retrieves documents, then is disconnected for some reason (the network goes away) and is later reconnected, it will used the previously cached documents for up to 30 minutes as a starting point for continued updates without performing the query again.

    This does not cover the behavior of normal queries. If you perform a normal (non-listening) query, then perform the same query again, it will not use any cache. You will be charged for all of the documents read for both queries. The cache is only used for normal queries when you tell the query to use the cache, or if the client application is fully offline.

    I suggest reading this for more details: https://firebase.google.com/docs/firestore/manage-data/enable-offline