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?
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?
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:
the persistence class, which is responsible for storing the data on the local disk
the local store class, which handles (a.o.) the reading from both the local cache and the local mutations.
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.
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.