19

I'd like to use just a single method of persistence in my app, and am using Cloud Firestore for my premium/paying users.

Is it possible to also use Firestore in offline only mode for free users so that I don't incur costs?

siburb
  • 4,880
  • 1
  • 25
  • 34
brucemax
  • 754
  • 8
  • 15
  • 3
    This is not a supported use case for Firestore. – Doug Stevenson Feb 19 '18 at 18:14
  • Can you please tell, how did you solve this use case. I'm at the same junction as of now. – Prithvi Sep 21 '20 at 04:51
  • Obviously Frank has answered about why you _shouldn't_ do this, but if you wanted to test just how bad the performance would get, you could set an unreachable host property - e.g. "myunreachablehost.unreachable.con" - in the `FIRFirestoreSettings` when initialising Firestore. – siburb May 21 '21 at 07:38
  • Actually, this is now easily doable via `disableNetwork()`. Source: https://firebase.google.com/docs/firestore/manage-data/enable-offline – Grzegorz D. Apr 15 '23 at 22:35

3 Answers3

18

Cloud Firestore is an online database that continues to work when you're offline for short or longer periods of time. But it's still primarily an online database, and should not be used as a fully offline database.

One reason for this is that Firestore keeps the local mutations in a separate queue until they've been committed to the server. When a query/read hits the local data, the Firestore client combines the cached reads that it got from the server, with the local mutations. As the queue of local mutations grows, this operation gets slower. As long as the client occasionally synchronizes the data to the server, this slow down won't be significant. But if you use Firestore as a fully offline database, it will become prohibitive over time.

For a good explanation of how the Firestore client works under the hood, have a look at these (long) code comments in the Firestore JavaScript SDK:

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • 1
    Actually, this is now easily doable via `disableNetwork()`. Source: https://firebase.google.com/docs/firestore/manage-data/enable-offline – Grzegorz D. Apr 15 '23 at 22:34
14

If you need offline database, do not use Firebase. Firebase will cost you huge money in the future. Read this full article from an unhappy Firebase customer with 3+ years Firebase usage experience.

Sadly, We've been using Firebase for our Goal Meter app (Android and iOS), Weight Meter app (Android). Our users have grown over years and now we have about 100,000 active users for our Goal Meter app. About %95 of them are free users. The cost of Firebase database is growing rapidly and we cannot prevent free user data from syncing into Firebase online database. We've decided to change to another company for our future project. Don't make the same mistake that we did. If your app needs offline database (I guess most apps do need it), then by any means avoid using Firebase. Move to other solutions such as AWS.

I've already contacted the Google Firebase team regarding this ridiculous issue. I can only imagine one scenario why Google Firebase team is preventing the full offline capabilities. The reason is because Firebase team is greedy. After all, if the database is offline, how can they make you pay? We've been in love with every single product from Google. We even produce Android version before iOS one, in order to support Android and Google. Firebase product is amazing, but this "purposefully" disabling offline capabilities is a shame. A shame for Firebase team and Google in general.

Sajad Rahmdel
  • 177
  • 3
  • 6
  • 4
    What do you recommend to manage data without internet, and then you can upload to a server? – Igmer Rodriguez Jan 26 '19 at 02:16
  • I am leaving Firebase because of this too... Way to expensive to NOT include offline capabilities. I would recommend going with app write or mongodb atlas. – Walter Monecke Sep 15 '21 at 09:41
  • Actually, this is now easily doable via `disableNetwork()`. Source: https://firebase.google.com/docs/firestore/manage-data/enable-offline – Grzegorz D. Apr 15 '23 at 22:34
0

An alternative approach is allow users to create accounts and offer a trial period. If they decide to sign up for premium access, all the data is already synced to Firestore. This doesn't solve your want to have local only access, but could be a different option you could take.

Eric Larson
  • 509
  • 3
  • 14