Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firestore pricing clarifications for offline cached data

It seems odd to me that Firestore would charge me for read queries to locally cached data, but I can't find any clarification to the contrary in the Firestore Pricing document. If I force Firebase into offline mode and then perform reads on my locally cached data, am I still charged for each individual entity that I retrieve?

Second, offline users in my app write many small updates to a single entity. I want the changes to persist locally each time (in case they quit the app), but I only need eventually consistent saves to the cloud. When a user reconnects to the internet and Firestore flushes the local changes, will I be charged a single write request for the entity or one per update call that I made while offline?

Firestore could potentially fit my use case very well, but if offline reads and writes are charged at the same rate as online ones it would not be an affordable option.

like image 517
Andy Miller Avatar asked Nov 08 '17 11:11

Andy Miller


People also ask

Does firebase firestore work offline?

Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data.

How can I reduce firestore costs?

We can reduce the cost by a lot by using Firebase cloud functions. I love Cloud Firestore triggers! This does your job so smoothly and makes your app/website a lot faster.

Is firestore more expensive than Realtime Database?

The realtime database only charges for bandwidth and storage but at a higher price. Cloud Firestore, on the other hand, charges primarily on operations performed in your database (Read, write, delete) and at a lower rate, bandwidth and storage. It also supports daily spending limits for Google App Engine projects.


2 Answers

As the offical documentation says,

Cloud Firestore supports offline data persistence. This feature caches a copy of the Cloud Firestore data that your app is actively using, so your app can access the data when the device is offline. You can write, read, listen to, and query the cached data. When the device comes back online, Cloud Firestore synchronizes any local changes made by your app to the data stored remotely in Cloud Firestore.

So, every client that is using a Firestore database and sets PersistenceEnabled to true, maintains it's own internal (local) version of the database. When data is inserted/updated, it is first written to this local version of the database. As a result, all writes to the database are added to a queue. This means that all the operations that where stored there will be commited on Firebase servers once you are back online. This also means that those operations will be seen as independent operations and not as a whole.

But remeber, don't use Firestore as an offline-only database. It is really designed as an online database that came work for short to intermediate periods of being disconnected. While offline it will keep queue of write operations. As this queue grows, local operations and app startup will slow down. Nothing major, but over time these may add up.

If Google Cloud Firestore priceing model does not fit your use case very well then use Firebase Realtime Database. As mentioned also in this post from the Firebase offical blog, one the reasons you still might want to use the Realtime Database is:

As we noted above, Cloud Firestore's pricing model means that applications that perform very large numbers of small reads and writes per second per client could be significantly more expensive than a similarly performing app in the Realtime Database.

So it's up to you which option you choose.

like image 76
Alex Mamo Avatar answered Oct 10 '22 01:10

Alex Mamo


According to this If you want to work completely offline with Cloud Firestore you can disable network by :

FirebaseFirestore.getInstance().disableNetwork()

but firestore will cause client offline error for first user get request, that you must consider this error as empty response.

like image 29
Hossein Avatar answered Oct 10 '22 02:10

Hossein