Cloud databases

The cloud

When developing apps, eventually you will want a cloud hosted database, often referred to as Backend as a Service (BaaS) or Database as a Service (Daas). It is quite difficult and time consuming to understand the pros and cons of the different options and it may also be extremely difficult to change once you are far down your development road on a project.

Firebase Firestore

Firestore is the default cloud hosted database. It has some great features, such as local caching of the database for offline usage. Probably, the best advice which I have come across is to model your document’s “schema” according to the screen in your UI. Then allow data to be duplicated across multiple collections in order to facilitate this.

Firestore has pros and cons which you can read about here, but the issues which I have come across are:

Firstly, it is a NOSQL database, which can make complex queries difficult.

There are also no server side joins on Firestore, so you need to do the joins on the client side. Alternatively, you could run a google cloud function to do joins or something similar for you. However, since you pay per firestore document, not query time, careful data planning is required. Firestore charges you for the following, although there is a free tier:

  • Each document read, write, or delete.
  • The amount of storage that your database uses, including overhead for metadata and indexes.
  • The amount of network bandwidth that you use. This means that it is better to have one document containing lists of information, rather than many smaller documents, provided you dont hit the max document size limit.

Also, currently, there is no indexing on the local database, so offline queries are often unacceptably slow, although better database design can solve this. This effectively means that firestore is offline-also, rather than offline-first.

Additionally, Firestore doesnt support full text search, although this is possible if you use a service such as Algolia.

Finally, the pricing model is a little difficult to understand. This can result in large bills, see here on advice on how to avoid this.

The net result may be that you need to significantly rethink your firestore database structure in order to deal with these challenges. But, it should also be noted that some of the challenges are simply characteristics of NOSQL databases and not firestore in particular.

Firestore ui

Alternatives

AWS Amplify

Amplify is Amazon’s alternative to Firebase and DataStore would be the direct competitor to Firestore. DataStore has SDKs for Android, iOS and Flutter (Preview).

MongoDB Realm

Realm is currently in beta, but looks promising because of its ability to sync across multiple devices.

According to one user: From a performance and UI perspective, Firestore uses the cloud as the single source of truth and has better querying / indexing there, local is a fallback. Realm treats the local storage as single source of truth and has better on-device indexing, querying, performance, and scaling capabilities.

SDKs for Android, iOS and React Native - not Flutter (Although there is an unofficial one)

Couchbase

Couchbase has a mobile-sync offering which looks interesting. There is an unofficial Flutter SDK

Appwrite

Appwrite is an open source Flutter and other mobile platform cloud db, with paid options.

ParsePlatform

Parse was developed by Facebook and has now been opensourced. It provides much of the Firestore functionality, including object and file storage, user authentication, push notifications. It has iOS, Android and Xamarin SDKs, but no Flutter SDK.

Back4App

Back4App have built on top of Parse, and have a simple pricing model. They have an Android, iOS and Xamarin SDK, but no Flutter. They also have publically accessible cloud databases for different types of information, such as cities, countries - which may be useful for developing apps. All South African cities looks cool

SpaceCloud

SpaceCloud presents itself as an openSource alternative to Firebase, including cloud hosted databases.

ElephantSQL

ElephantSQL is a cloud hosted SQL database.

On Device DBs

I know that this is supposed to be a post about cloud DBs, but anyways.

Hive

Hive is a Flutter, NoSQL db. Here is a tutorial about getting setup.

Comments