more of an aspiration than a claim

Firebase Overview and Tips

What is Firebase?

Firebase was original a company that created what is now called the Firebase Realtime database. Google bought Firebase in October 2015 and expanded the scope of Firebase. Firebase is now a suite of products to help you create mobile apps and websites, so Firebase is a Backend-as-a-Service product.

Firebase appear to target their product at mobile app developers, but it also works with websites. Firebase APIs are provided for Web, Android and iOS.

Firebase is highly integrated with Google Cloud and the Firebase and Google Cloud teams work closely together.

How much does Firebase Cost?

Firebase has 3 plans.

Spark

  • Free to get started and includes generous quotas.
  • Firebase Functions have changed in how they are billed and its seems will no longer be available unless you have billing enabled: “Cloud Functions for Firebase relies on some paid Google services: Cloud Build, Container Registry, and Cloud Storage. Usage of these services will be billed in addition to existing pricing.”

Flame

  • Fixed at $25/month with set quotas.

Pay as you go

  • You get the free quota as per the Spark plan, but then you pay for some products when you exceed those quotas.

You can check the latest Firebase pricing and quotas here. The page also includes a plan calculator to help you estimate likely costs.

Firebase Realtime Database

Competitors: Cloud Firestore, AppSync, Gun

This was the original Firebase product. Realtime database is a NoSQL cloud hosted store that can sync data and provide realtime updates of data changes within milliseconds.

Data is available if offline, but I believe any offline changes are only stored in memory and will be lost unless a connection is re-established.

See Cloud Firestore for a newer Firebase NoSQL database that tries to improve on many of the Realtime databases weaknesses.

Firebase Cloud Firestore

Competitors: Firestore Realtime Database, AppSync, Gun

Cloud Firestore is a newer implementation of a NoSQL store, that is based on Google Cloud Store and was a collaboration between the Firebase and Google Cloud teams to try improve on the Realtime product.

Realtime Database or Cloud Firestore?

Pricing is very different for Realtime vs Firestore. Check the prices here to compare. Firestore charges per read, write and delete, so perhaps can end up more expensive if you make a lot of small operations. Realtime charges more for storing data and for downloaded data.

Realtime, as the name suggests, is better at syncing data in realtime with lower latency than Firestore.

Realtime may require new databases to handle connections, where Firestore can scale better for connections.

The Firestore API has been improved to try make it easier to use than Realtime with a focus on easier and faster querying.

Firestore organises data in collections of documents where Realtime uses a large JSON tree. Realtime is harder to organise complex and hierarchical data at scale. Firestore generally requires less denormalisation and flattening of data.

Firestore can support offline for web, whereas Realtime cannot. Both support iOS and Android offline.

Check here for in depth differences between Realtime and Firestore.

Firebase Hosting

Competitors: Now

A way to serve static and dynamic content with a CDN (content delivery network) built in. Integrates well with Cloud Functions for Firebase and currently there is beta integration with Cloud Run.

The Firebase CLI (command line interface) can be used to manage and perform tasks like deploying your sites.

You can use your own domains for free and HTTPS support is used to securely host your site.

Cloud Functions for Firebase

Competitor: AWS Lambda

Allows you to run JavaScript functions in an Express like API. You pay only when the functions are called, but there is a delay if the functions are not currently loaded.

This product is a wrapper around Google Cloud Functions that allows integration with other Firebase products.

What Languages Does Cloud Functions for Firebase Support

Cloud Functions for Firebase only work with Javascript. See Cloud Run if you want to be able to run other languages in a Kubernetes based Docker container (using Knative or Google Kubernetes Engine) that can spin down to 0 cost and still integrate with Firebase Hosting. Cloud Run has a free quota but requires enabling billing, unlike Cloud Functions for Firebase that have a free quota out of the box without billing enabled.

Sharing Code Between Cloud Functions for Firebase

Private npm modules are supported as explained here.

If you don’t pay for private npm packages, you can try various ways to package your code into local files that would get included as part of the deployment. One idea I had was creating a script to use file system links and share JavaScript, or transpiled code.

Another idea is to try package a local version of the package and include that with the deployment. An idea about using git+ssh dependencies is outlined in this StackOverflow answer to do this.

Cloud Run (Currently in Beta)

Competitor: AWS Fargate bills minimum per hour versus Cloud Run per second.

Whilst a Google Cloud product, details of Cloud Run integration with Firebase Hosting can be found here.

When you hit a HTTP endpoint, you can run a stateless container that fulfils the request. If there are no further incoming requests, the container will spin down to zero resource use and cost.

Billed time is from the first request starting to the last request ending, rounded up to the nearest 100 milliseconds. Check here for more details on Cloud Run pricing.

Reports seem to suggest around 1.5 seconds to start up from cold.

Features:

  • Autoscaling: from zero to N depending on incoming requests
  • Managed Service
  • Flexible Languages: Create your own container and run a language of your choice.
  • Redundancy: regional services that can be replicated across multiple zones.

The vendor lock in is lower as it is quite flexible on where you can run the container as it using Kubernetes and Docker technology.

Cloud Run Unsupported Services

Find a table of services that currently do not work with Cloud Run, including Cloud SQL :(.

Firebase Auth

Competitors: Amazon Cognito, Auth0

Firebase Auth provides many different options to create and authenticated users on your site. Mix and match from passwords, phone numbers, to federated identities like Google, Facebook and Twitter.

Firebase Auth also can provide auth integration using tokens like JWT (JSON Web Tokens).

Firebase Auth is free to use, apart from Phone Auth that costs money per verification after your free quota is finished.

There are FirebaseUI libraries for Web, Android and iOS that provide out of the box auth screens. You can also make you own custom screens if you need the flexibility.

User account information storage is very limited, so normally you combine it with something like Firestore, Realtime, Cloud SQL, etc, to store data like email subscription settings.