# Firebase

## Summary


Modern web and mobile apps are typically built with a mix of backend services and frontend frameworks. Wouldn't it be nice if there was a way for developers to focus on just the frontend and user experience, and let someone else take care of all backend requirements? It's exactly in this context that **Backend-as-a-Service (BaaS)** has emerged. 

Firebase started as a BaaS but after its acquisition by Google in 2014, it's now more deeply integrated to some parts of Google Cloud Platform. Since then, Firebase is described as "a comprehensive mobile development platform". The idea is to build apps faster without managing infrastructure.

## Discussion

### Why should I adopt Firebase for my next web/mobile app?

Firebase provides easy-to-use workflows common to many apps. Examples include onboarding flow, customizing the "welcome back" screen, progressively rolling out new features, following the user journey across devices, adding chat to your app, optimizing ads based on user behaviour, enabling users to share and resize photos, processing third-party payments, and more. These typically involve significant development on the server side. Instead, Firebase offers out-of-the-box and easily deployable solutions to do these. 

As developers, you don't have to worry about server-side software. Mobile and web SDKs enable this. The main offering is real-time sync of data between client apps and Firebase via **Realtime Database** and **Cloud Firestore**. Using **Authentication**, user authentication feature is easy to build, even if it involves third-party providers such as Facebook or Twitter. Messaging and notifications are efficiently done using **Firebase Cloud Messaging (FCM)**. Unlike native apps updated via app stores, **Remote Config** can update Firebase apps without asking users to update their installation. Using **Crashlytics** and **Performance Monitoring** app stability and performance can be improved. There's good integration with Adwords and Admob. Even UI testing across multiple devices is simplified via **Test Lab**. 


### What are the products offered by Firebase?

Firebase products can be grouped into three categories: 

    + Build: Helps developers build more powerful, secure and scalable apps. Products include Cloud Firestore, ML Kit, Cloud Functions, Authentication, Hosting, Cloud Storage, Realtime Database.
    + Improve: Gives developers insights into app performance and stability. Products include Crashlytics, Performance Monitoring, Test Lab.
    + Grow: Helps your app to grow. Products include In-App Messaging, Google Analytics, Predictions, A/B Testing, Cloud Messaging, Remote Config, Dynamic Links, App Indexing.

### What exactly is Firebase Hosting?

With the rise of powerful frontend frameworks (Angular) and static site generators (Jekyll) it's become possible to develop web apps without much server-side processing. For hosting such web apps, Firebase Hosting is a suitable solution. It serves content over secure connections, delivers content quickly due to caching on solid-state devices at CDN edges, enables rapid deployment and supports one-click rollbacks. CDN edge servers ensure global availability of your app. SSL certificates are free and automatically provisioned even for custom domains. 

It's also easy to deploy a sophisticated Progressive Web App (PWA). While Firebase Hosting serves static content, dynamic content can be served using Cloud Functions for Firebase or Google's Cloud Run. 


### What's a suitable deployment architecture when using Firebase?

With Firebase, a web/mobile app can be deployed without running your own backend server. However, Firebase can also co-exist with an app server.

If the app requires only client-side code or doesn't require complex processing, then all the backend needs can be served by Firebase. If the app needs more complex processing or integration with third-party APIs, then Firebase can sit between clients and the app server. Clients access Firebase data and the server listens to changes to the data. Server manipulates data in Firebase, to which clients are notified. In another deployment architecture, Firebase sits logically next to the app server. Clients communicate to both. This architecture is ideal for large legacy apps where some parts (such as real-time features) are served by Firebase while older parts are served by the legacy server code. 

Given that Firebase supports server-side execution (Cloud Functions since March 2017, Cloud Run since April 2019 ), it's possible that even when an architecture requires an app server, it could be offloaded to the serverless cloud infrastructure.


### Could you share more details on Firebase Cloud Messaging (FCM)?

FCM a cross-platform messaging solution that can be used for pushing new data to client apps or notifying users. Instant messaging has a payload limit of 2KB. From client to server, acknowledgments, chats, and other messages can be sent. 

FCM consists of **FCM servers** managed by Google and an app server or other trusted environment such as **Cloud Functions for Firebase**. All message go via FCM servers. Developers can use raw protocols (HTTP/XMPP) or use Admin SDK. HTTP is synchronous and downstream. XMPP is asynchronous and both downstream and upstream. HTTP supports multicast as well. 

In April 2018, Google deprecated its **Google Cloud Messaging (GCM)** service. GCM APIs will be available only till April 2019. Since GCM and FCM cannot coexist in an app, developers must migrate to FCM. FCM inherits GCM infrastructure and adds many new features. For more details, refer to the GCM/FCM FAQ.


### How's the pricing of Firebase products?

Firebase gives following services under free tier: A/B Testing, Analytics, App Indexing, Authentication (except Phone Auth), Cloud Messaging (FCM), Crashlytics, Dynamic Links, Invites, Performance Monitoring, Predictions, and Remote Config. With free tier, you get some free access to other products with limits on storage, bandwidth, number of reads/writes/deletes/uploads/downloads/tests, etc. Realtime Database allows only 100 simultaneous connections. 

Besides the free tier, there's a fixed price per month and pay-as-you-go plans. With the latter, the pricing of Realtime Database, Cloud Firestore, Storage, Phone-Auth, Hosting, Test Lab, ML Kit, Use of BigQuery & other IaaS, is based on the use. 


### What are some criticisms of Firebase?

Since 2016, developers have noted many problems with Firebase. While it's good for enabling real-time apps with client-side logic, running complex database queries is almost impossible. Firebase Realtime Database is nothing more than a large JSON file. Data is duplicated since the benefits of relationships in a relational database are absent. Filtering or paginating records are not possible.  More recently, the situation has improved with Cloud Firestore that manages data using collections and documents. 

Your data is on a server that you don't control. There's no easy way to import/export data. Firebase is also not open source. If the service is discontinued, you have no choice but to rework your app. While initial development may be faster, scaling up later may prove difficult. Moving business logic from client to server won't be trivial. When you scale, the cost of using Firebase will be higher than adopting a platform-as-a-service. 

Developers can't work with a local installation. Network connection is required. They're also at the mercy of Firebase's upgrade cycles. 

## Milestones

Sep  
2011

Firebase starts as a startup named **Envolve**, founded by James Tamplin and Andrew Lee. It provides developers an API to integrate online chat functionality into their websites.

Apr  
2012

It's noticed that some apps using Envolve are doing things beyond chat. They use Envolve's capability for synchronizing app data in real time. This prompts its creators to separate chat functionality from the underlying framework that enables real-time communications. The latter could now be offered as a standalone service. Thus, Firebase as a separate company is born. 

Oct  
2014

Google acquires Firebase. In following years, other Google acquisitions of Fabric/Crashlytics, Divshot, and LaunchKit add value to Firebase portfolio of products. 

May  
2016

Google announces Firebase at Google I/O as a unified platform for mobile developers. Firebase now integrates deeply with some of Google cloud tools. The user base of Firebase is now 470,000, up from about 110,000 when Google acquired it. 

Mar  
2017

Firebase releases **Cloud Functions for Firebase**. This makes is possible to execute JavaScript (Node.js) on the server side, on Google's cloud infrastructure. Cloud Functions has integrations with many components of Firebase. Projects that needed to deploy servers until now, can migrate to Cloud Functions and become completely server-free. 

Oct  
2017

Firebase team announces a beta release of **Cloud Firestore**, a fully managed NoSQL document database. Built in close collaboration with Google Cloud Platform team, it's replicated across regions and offers strong consistency. However, for special use cases where cost and latency are important, Firebase Realtime Database may be preferred. 

May  
2018

As a beta release, **ML Kit** becomes available on Firebase. This allows developers to add machine learning features into their apps. Use cases supported are recognizing text, detecting faces, scanning barcodes, labelling images and recognizing landmarks. For advanced use cases, developers can also import *TensorFlow Lite* models. 

Oct  
2018

It's reported that over 1.5 million apps are using Firebase every month. India's *Hotstar* entertainment app is a Firebase-based app with over 150 million monthly active users. 

Apr  
2019

Firebase announces integration with Google's **Cloud Run** service. Whereas Cloud Functions is limited to Node.js backend, Cloud Run enables developers write server-side functionality in any language. This requires a docker image that can respond to HTTP requests on the configured port. 

Sep  
2019

At the fourth annual Firebase Summit, Firebase launches Firebase Extensions, Firebase App Distribution and integration with Google Analytics. **Firebase Extensions** could to be a time saver, particularly for independent developers. These extensions implement common tasks. Examples include image resizer, URL shortener and text translation. As on August 2021, there are 11 extensions and many more experimental extensions.