4Oh4
4Oh4

Reputation: 2161

What is the advantage of Android Room over Cloud Firestore for persistent local storage?

My Android app uses a non-trivial amount of structured data to provide suitable recommendations to the user, so a local database would seem appropriate. Room/DAO/ViewModel looks like a good architecture and has sufficient abstraction of the underlying implementation. The data within isn't going to change very often, and when it does it only flows one-way: from the server down to the local database in the users device, never the other way; It makes sense for the majority of queries to be served from local data, even though the app is likely to be regularly online.

I'm using Google Firebase to handle the backend services, and the Cloud Firestore database to store the data server-side. Firestore provides a local cache of user data, for offline use - which would be much simpler than implementing and syncing my own database. Are there good reasons to avoid this approach?

There are a few similar questions, such as: How reliable is Firestore as an offline persistence mechanism? or Partial offline sync in Firebase Cloud Firestore. I think this is different, as I'm not looking for long-term offline persistence, but a reliable local copy to avoid unnecessary data transfer.

Upvotes: 7

Views: 6131

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 138834

There is a huge difference between those two types of databases. The Room persistence library provides an abstraction layer over SQLite to allow for more robust database access while Cloud Firestore is a flexible, scalable realtime database for mobile, web, and server development.

Firestore is not designed to be used as an only offline database as you can use Room, it's really designed as an online realtime database that can work for short to intermediate periods of being disconnected. Cloud Firestore uses SQLite for its persistence mechanism. So if you say that your users will be mostly online, you shouldn't have problems with performance or durability.

The data within isn't going to change very often, and when it does it only flows one-way:

If at one point in time you decide to change this flow, keep in mind that when the user's device goes 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.

So if you consider using Cloud Firestore's offline persistence feature, note that this is actually enabled by default on Android and iOS, so there is nothing you need to do.

And to answer your initial question:

What is the advantage of Android Room over Cloud Firestore for persistent local storage?

I already said, both databases are different and are used for different purposes but for your use-case (considering using in a reasonable limit) the cached copy of your Firestore database will help you with that.

Upvotes: 10

Related Questions