Should I use a local database and switch to Firestore after an in-app purchase?

Viewed 532

I am developing a personal health record management app for Android which currently uses Firestore as its backend.

I want to offer a free version of the app which stores data only on the device.

Once the user purchases a monthly subscription I would like to switch back over to Firestore.

What's the best way to implement such a setup? Even if it was possible, it doesnt seem like a good idea to force Firestore to use its offline cache all the time.

Should I use a second database to store data on device and migrate the data to Firestore after the in-app purchase? If so, what can I do in terms of database choice and system architecture to make my life easier?

2 Answers

What's the best way to implement such a setup?

The best way would be to use an additional database to store the data locally.

Even if it was possible, it doesnt seem like a good idea to force Firestore to use its offline cache all the time.

Cloud Firestore was not built as an offline database, is an online database that continues to work when you're offline from short to longer periods of time. When offline, pending writes that have not yet been synced to the server are held in a queue. If you do too many write operations without going online to sync them, that queue will grow fast and it will not slow down only the write operations it will also slow down your read operations.

If so, what can I do in terms of database choice and system architecture to make my life easier?

In my opinion a good choice might be Room Persistence Library which is apart of Android Jetpack.

A good aproach in your case could be to Maintain local db in device. After purchase , push db records to firestore using workmanager to sync server db with local db. Next onwards insert the record first in local db and then send request to workmanager queue to upload the record to server. This way for the app your local db is the single source of truth.

sync records from server to device for existing or new user when user request for sync manually.This gives the a option to user to get his database records in any device.

Keeping sever db sync with local is workmanager job and handled smoothly when you specify appropriate job request trigger conditions.

Hope this helps.

Related