1
votes

There are several questions related to firestore cost, but I couldn't find the one which clarify the question in my head.

I have two cases, and I'd like to know the estimated cost, the document read count, in each case.

Let's assume that I have a one page app which shows 10 users. Opening the app attaches the listener to the userList collection and listens 10 documents from that collection, and closing the app detach the listener from firestore.

Case 1: If there is no update on any document, I open and close the app, and open it again within 30 minutes. What the document read count would be? 10, 20, or any other?

Case 2: I open and close the app; one document is updated, and I open it again within 30 minutes. What the document read count would be? 11, 21, or any other?

1
Questions: Are you trying to do something specific with the Firebase API or are you seeking advice on optimizing your app's usage, such as storage space or bandwidth, for specific Firebase products? - MrTech
@MrTech I just want to know the estimated read count in the above cases because it wasn't clear for me. - user12208004

1 Answers

1
votes

It depends on what you mean by "close the app".

If you have a listener that gets cut off due to loss of network connectivity, but the app process is still running, the listener will automatically reattach when the network comes back. If the network comes back within 30 minutes, you are not charged for updates. If the network comes back after 30 minutes, you are charged for new query.

If you have a listener that gets cut off because the app process was terminated by the OS, and later gets reattached when the app is launched again, you will be charged for another query.

If the app is simply backgrounded but not terminated, and the listener is still active in the background, there are no changes in behavior, but you are still paying for document updates during the time it is still added but before the app process eventually loses network and is terminated completely.

If your code removes a listener and adds it again, you will be charged for a new query.

You will have to figure out which of these situations apply. The SDK doesn't track the user's intent. It just tracks the behavior of the network, and is affected by the state of the process, as managed by the OS. The user's action of "closing an app" could involve any number of details which are not immediately obvious.