With a variety of server-side technologies that are on the market today, developers have a tough job of deciding what kind of backend is most suitable for their app.
In this post, we will explore one of these choices that goes by the name of Firebase š„, and all the tools and services that it provides.
Firebase is a mobile and web app development platform that provides developers with a plethora of tools and services to help them develop high-quality apps, grow their user base, and earn more profit.
Back in 2011, before Firebase was Firebase, it was a startup called Envolve. As Envolve, it provided developers with an API that enabled the integration of online chat functionality into their website.
Whatās interesting is that people used Envolve to pass application data that was more than just chat messages. Developers were using Envolve to sync application data such as a game state in real time across their users.
This led the founders of Envolve, James Tamplin and Andrew Lee, to separate the chat system and the real-time architecture. In April 2012, Firebase was created as a separate company that provided Backend-as-a-Service with real-time functionality.
After it was acquired by Google in 2014, Firebase rapidly evolved into the multifunctional behemoth of a mobile and web platform that it is today.
Firebase Services can be divided into two groups:
Develop & test your app
Grow & Engage your audience
The Firebase Realtime Database is a cloud-hosted NoSQL database that lets you store and sync between your users in realtime.
The Realtime Database is really just one big JSON object that the developers can manage in realtime.
Realtime Database => A Tree ofĀ Values
With just a single API, the Firebase database provides your app with both the current value of the data and any updates to that data.
Realtime syncing makes it easy for your users to access their data from any device, be it web or mobile. Realtime Database also helps your users collaborate with one another.
Another amazing benefit of Realtime Database is that it ships with mobile and web SDKs, allowing you to build your apps without the need for servers.
When your users go offline, the Realtime Database SDKs use local cache on the device to serve and store changes. When the device comes online, the local data is automatically synchronized.
The Realtime Database can also integrate with Firebase Authentication to provide a simple and intuitive authentication process.
Firebase Authentication provides backend services, easy-to-use SDKs, and ready-made UI libraries to authenticate users to your app.
Normally, it would take you months to set up your own authentication system. And even after that, you would need to keep a dedicated team to maintain that system. But if you use Firebase, you can set up the entire system in under 10 lines of code that will handle everything for you, including complex operations like account merging.
You can authenticate your appās users through the following methods:
Using Firebase Authentication makes building secure authentication systems easier, while also improving the sign-in and onboarding experience for end users.
Firebase Authentication is built by the same people who created Google Sign-in, Smart Lock, and Chrome Password Manager.
Firebase Cloud Messaging (FCM) provides a reliable and battery-efficient connection between your server and devices that allows you to deliver and receive messages and notifications on iOS, Android, and the web at no cost.
You can send notification messages (2KB limit) and data messages (4KB limit).
Using FCM, you can easily target messages using predefined segments or create your own, using demographics and behavior. You can send messages to a group of devices that are subscribed to specific topics, or you can get as granular as a single device.
FCM can deliver messages instantly, or at a future time in the userās local time zone. You can send custom app data like setting priorities, sounds, and expiration dates, and also track custom conversion events.
The best thing about FCM is that there is hardly any coding involved! FCM is completely integrated with Firebase Analytics, giving you detailed engagement and conversion tracking.
You can also use A/B testing to try out different versions of your notification messages, and then select the one which performs best against your goals.
Firebase has simplified the process of retrieving specific data from the database through queries. Queries are created by chaining together one or more filter methods.
Firebase has 4 ordering functions:
Note that you will only receive data from a query if you have used the on()
or once()
method.
You can also use these advanced querying functions to further restrict data:
In SQL, the basics of querying involve two steps. First, you select the columns from your table. Here I am selecting the Users
column. Next, you can apply a restriction to your query using the WHERE
clause. From the below-given query, I will get a list of Users whose name is GeekyAnts
.
You can also use the LIMIT
clause, which will restrict the number of results that you will get back from your query.
In Firebase, querying also involves two steps. First, you create a reference to the parent key and then you use an ordering function. Optionally, you can also append a querying function for a more advanced restricting.
Firebase Storage is a standalone solution for uploading user-generated content like images and videos from an iOS and Android device, as well as the Web.
Firebase Storage is designed specifically to scale your apps, provide security, and ensure network resiliency.
Firebase Storage uses a simple folder/file system to structure its data.
Firebase Test Labs provides a large number of mobile test devices to help you test your apps.
Firebase Test Labs comes with 3 modes of testing:
These are tests that you written specifically to test your app, using frameworks like Espresso and UI Automator 2.0
This test is for people who just want to relax and let Firebase worry about tests. Firebase Test Labs can simulate user touch and see how each component of the app functions.
Test Labs support game app testing. It comes with a beta support for using a ādemo modeā where the game app runs while simulating the actions of the player.
Remote config essentially allows us to publish updates to our users immediately. Whether we wish to change the color scheme for a screen, the layout for a particular section in our app or show promotional/seasonal optionsāāāthis is completely doable using the server side parameters without the need to publish a new version.
Remote Config gives us the power to:
To get your appās content indexed by Google, use the same URLs in your app that you use on your website and verify that you own both your app and your website. Google Search crawls the links on your website and serves them in Search results. Then, users whoāve installed your app on their devices go directly to the content in your app when they click on a link.
Deep links are URLs that take you to a content. Most web links are deep links.
Firebase can now modify deep links into Dynamic Links! Dynamic Links allow the user to directly come to a particular location in your app.
There are 3 fundamental uses for Dynamic Links
Cloud Firestore is a NoSQL document database that lets you easily store, sync, and query data for your mobile and web appsāāāat a global scale.
Though this may sound like something similar to the Realtime Database, Firestore brings many new things to the platform that makes it into something completely different from Realtime Database.
Where Realtime Database stores data in the form of a giant JSON tree, Cloud Firestore takes a much more structured approach. Firestore keeps its data inside objects called documents. These documents consist of key-value pairs and can contain any kind of data, from strings to binary data to even objects that resemble JSON trees (Firestore calls it as maps). The documents, in turn, are grouped into collections.
Firestore database can consist of multiple collections that can contain documents pointing towards sub-collections. These sub-collections can again contain documents that point to other sub-collections, and so on.
You can build hierarchies to store related data and easily retrieve any data that you need using queries. All queries can scale with the size of your result set, so your app is ready to scale from its first day itself.
Firestoreās queries are shallow. By this, I mean to say that in Firestore, you can simply fetch any document that you want without having to fetch all of the data that is contained in any of its linked sub-collections.
You can fetch a single document without having to grab any of its sub-collections
Imagine that you have created a collection in Firestore that contains a list of Cities. So, before you can send out a query, you will have to store the database inside a variable.
Here, citiesRef
is that variable that contains your collection of cities. Now, if you want to find a list of capital cities, you would write a query like this:
Hereās another example of queries in Firestore. Say you want to see only 2 of cities from your database whose population is more than 100,000.
But Cloud Firestore can make querying even easier! In some cases, Cloud Firestore can automatically search your database across multiple fields. Firestore will guide you towards automatically building an index that will help Firestore to make querying extremely simple.
Though Firebaseās Realtime Database is capable of scaling, things will start to get crazy when you app becomes really popular or if your database becomes really massive.
Cloud Firestore is based on Googles Cloud infrastructure. This allows it to scale much more easily and to a greater capacity than the Realtime Database.
In Firestore, your data is automatically copied to various regions. So if one data center goes offline due to some unforeseen reason, you can be sure that your appās data is still safe somewhere else.
Firestoreās multi-region database also provides strong consistency. Any changes to your data will be mirrored across every copy of your database.
The Realtime Database charges its users based on the amount of data that you have stored in the database.
Cloud Firestore also charges you for the same, but the cost is significantly lower than that of Realtime Database and instead of basing the cost on the amount of data stored, Firestoreās pricing is driven by the number of reads/writes that you perform.
Check out this blog post to know more about Cloud Firestore:
Cloud Firestore for Realtime Database Developers_Hey, did you hear the big news? We just announced the beta release of Cloud Firestore -- the new database that lets youā¦_firebase.googleblog.com
You can also go through this codelab to better understand how Cloud Firestore works:
Cloud Firestore Web Codelab_We're almost there--before we can write documents to Firestore we need to open up Firestore's security rules andā¦_codelabs.developers.google.com
Firebase Test Labs have this amazing service called Robo Test that allows us to test our app with having to write any test scripts. With Robo Test, you can have Firebase test your app completely, even fill in specific form fields and push buttons!
Now Firebase has come up with another cool testing feature called Robo Scripts. With Robo Scripts, you can record a series of actions for Firebase to take in you app.
When you run a Robo Test with a Robo Script attached to it, Firebase first steps through the your recorded actions from the Robo Script and then explores the app as usual.
Firebase now comes with machine learning, with it uses to analyse your appās data and create dynamic user groups based on the userās predicted behavior.
Firebase Predictions can work with Remote Config to increase conversions by providing a customized experience based on each of your userās behavior.
Or, it can work with the Notifications composer to deliver the right message to the right user group.
Firebase Predictions can also work hand-in-hand with A/B testing to evaluate the effectiveness of your prediction based strategies.
I am Rajat S, a Technical Content Writer at GeekyAnts. Aspiring Coder who has a long way to go. A Die-Hard DC Comics Fan who loves Marvel Movies. š Follow me on Twitter and Facebook to know about all the amazing things that are happening at GeekyAnts.
Thanks to Aditya Srivastava and Rahul Raj for helping with this post and for helping me understand everything about Firebase and Cloud Firestore. Both Aditya and Rahul are Software Developers working at GeekyAnts.
And thanks to you for reading this 11 minutes long post! Please do š if you liked it.