13
2017
Firebase – Mobile Application Development – Introduction
Firebase is a mobile and web application development platform, which is made up of complementary features that developers can mix and match to fit their requirements.
What is Firebase?
Building applications for different platforms like iOS, Android, and mobile web users is not an
easy task. Your application may need:
- a back-end server support to store data
- authentication support
- creative ways to get more users and ways to measure their activities in your admin
dashboard - a way to recover the back-end server if there is a crash, etc.
Firebase is a mobile and web application development platform, which is made up of
complementary features that developers can mix and match to fit their requirements. It is evolved
from Envolve, which was a start-up founded by Andrew Lee and James Tamplin in 2011.
Envolve provided an API that enables the integration of online chat functionality to the
developers’ websites. But it was used to sync application data, such as a game state in real time
across their users. Then a real-time database, which provides an API, where developers can store
and sync data across multiple clients was introduced. After Envolve was acquired by Google in
October 2014, Google has expanded its product line to become a full suite for application
development.
Firebase contains features like Analytics, Realtime Database, Messaging and Crash Reporting
which lets you speed up the development process and focus on your users. Since it is built on
top of Google infrastructure, it can scale up automatically even for very large applications. These
features may work individually, but they work even better together as they share data and
insights.
What are the uses for Firebase?
The Firebase products can be mixed and matched to solve common challenges in application development.
- User Authentication – Firebase Authentication allows users to sign in to the application with their Facebook, Twitter, Google or GitHub account quickly. To improve the user experience, it helps to track every step in your flow. To log the events in your application flow or to create funnels to see where users get dropped-off, the Google Analytics in Firebase can be used. Remote Config can be used to make changes to your application to see how it affects the conversions.
- Initial screen customization – The initial screen can be customized based on the user’s preferences, usage history, location or language, where it gives each user the best experience. You can define the audiences based on the user behavior and other analytic variables and the Firebase Remote Config can be used to show specific content to each audience, without submitting new application updates to each audience.
- Launching new features- When launching your next new feature, Google Analytics for Firebase can be used together with Remote Config to select a group of users to test the new feature. It helps to see how it works and how users respond. When you are satisfied with it, Cloud Messaging can be used to invite the rest of your users to try it out. Analytics will help to track the results and Firebase Crash Reporting will help to ensure stability. If you want to disable the new feature, you can quickly roll it back from the Firebase console.
- Use of application on different devices – The user may use an application across different devices – i.e. mobile devices, laptops, tablets, etc. This will be considered as three different users by basic analytics. Google Analytics for Firebase, helps to get a complete picture of application engagement across channels and devices by matching on User ID and exporting your mobile application data to BigQuery.
- Communication between your friends (Chats) – Firebase allows you to chat with your friends without leaving your application. It synchronizes your messages with the Firebase Realtime Database, authenticates with Firebase Authentication and sets up a chat room in its database. If the user is in another application, Firebase Cloud Messaging sends notifications when the user gets new messages.
- Use monetization strategies – Application monetization is a means of making money from a mobile app without charging for it. Users often hesitate to pay for apps because the vast majority of the apps are offered for free. One of the most common ways to monetize an application is to collect user data and send it to third parties, usually advertisers. Based on the user behavior, different users require different monetization strategies. Firebase Remote Config in combination with Analytics gives the correct experience for the matching user in your application. To measure the impact of the user experience by your ads in the application, you can link your Firebase project to AdMob.
- Sharing of photos – Firebase Storage can be used to share the users’ photos in the cloud, where Realtime Database enables the sharing of photos by recording their file paths in it. Its security rules ensure that only the relevant users can view the relevant photos. The original details of the creator’s photo can be maintained by the Cloud Functions for Firebase.
- Third party payment process – The third party payment processing API eliminates complexity and enables the expected speed and security in users’ in-app purchases. The user’s up-to-date payment information will be passed to the Cloud Functions for Firebase and the requests to the API are made over HTTPS. It writes the payment information to the Realtime Database and the user gets a confirmation message.
Where does Firebase fit in your app?
Firebase provides a real-time, scalable backend with tools to build better, collaborative applications for the users. Three common patterns are identified in Firebase powered applications:
100% Firebase-powered applications
Most of the Firebase-powered applications are consisting of client code only, where they need Firebase only as a way to distribute the application. This kind of applications is ideal when:
- you are developing a brand-new application or rewriting an existing application from scratch,
- your application needs minimal integration with legacy systems or other third-party services
- your application does not have heavy data processing needs/ complex user authentication requirements.
These applications store and retrieve their dynamic content and user data from Firebase and only retrieve static content and assets from the application.
(i.e. 100% Firebase-powered applications can handle the user authentication using the Simple Login service, which eliminates writing your own server-side authentication code. In addition to the regular email/password, it supports Facebook, Twitter, GitHub and Google based authentication.)
100% Firebase-powered applications (Source: https://firebase.googleblog.com/2013/03/where-does-
firebase-fit- in-your- app.html)
Firebase-powered application with server-side code
When you
- want your application to integrate with third-party APIs,
- you have advanced authentication requirements,
- your application has computationally intensive code that you cannot run on a client or requires code to run on a trusted server,
It is not possible to get away with the only client-side code. As Firebase sits between the server and the clients, both can communicate with each other by manipulating data in Firebase.The Firebase Security and Firebase Rules language lets you assign full access to your data to your server. Then the server code can listen to any changes to the data being made by the clients and respond accordingly. In such a situation Firebase handles the heavy work of scale and the real-time updates.
Firebase-powered application with server-side code (Source: https://firebase.googleblog.com/2013/03/where-
does-firebase- fit-in- your-app.html)
Existing application with Firebase-powered features
- This method is for if you have an existing full-featured application that has a large code-base but needs to add real-time features without changing the rest of your app.
- In this setup, Firebase sits alongside your existing server and the clients will connect both to your server and Firebase. This will utilize Firebase to power your real-time features, without interfering with the rest of your application.
- Using this pattern, you can add a real-time notification system or a chat system for your website or create a comment feed that updates in real-time.
Existing application with Firebase-powered features (Source: https://firebase.googleblog.com/2013/03/where-does-
firebase-fit- in-your- app.html)
How does Firebase help you to develop your application and grow your business?
Firebase products (Source: – http://assets.searchdiscovery.com/2016/May/Firebase-1463751507363.png)
For developing and testing your application:
Realtime Database
- This is a cloud-hosted NoSQL database that lets the application store and sync data between users in real time. Users can easily access data from any device (mobile/web) from anywhere.
- Realtime database SDK uses the local cache on the device when the user goes offline. The offline data will be automatically synchronized when the user comes back online.
- Database security roles can be used to specify who has access to what data and how the database should be structured. There is no server maintenance or operation as the database is hosted in the cloud.
Authentication
- For the user to be identified, most of the applications are using authentication. Therefore, Firebase allows users to sign in to their applications using sign-in methods such as back-end services, SDKs and ready-made UI libraries including the email address and the password or federated identity providers like Google, Facebook, Twitter, etc.
- Once authenticated, user information is returned to the device, which allows you to personalize the application’s user experience. The information contains a distinct unique id across all providers. Your user sessions are managed by Firebase on Android, iOS, and web as well.
Cloud Storage
- Powerful, simple and cost-effective SDKs are provided by Firebase, where the developers can store the user-generated content such as photos and videos in the Cloud Storage.
- If there is a network connection loss while transferring data, it will pause and resume the transfers automatically after regaining connectivity.
- Regardless of network quality, it provides secure file uploads and downloads for Firebase applications. Firebase is backed by Google Cloud Storage.
Test Lab for Android
- This is a cloud-based infrastructure to test Android applications.
- Applications should be built to satisfy the user experience regardless of the device’s screen size, OS version or the capability of the device to run the features of the application. So instead of buying a stack of devices to test and ensure the quality of the developed application, the Test Lab can be used to fulfill these requirements.
- While testing, it reports errors and application crashes and can even take screenshots of errors, so it makes easy for developers to fix before releasing the application to production.
- To upload and test your application, the Firebase console can be used first. At the time of development , you can deploy your application to the Firebase Test Lab using Android Studio. Then an automated launch test will run Android applications in the play store developer console.
Hosting
- Developers can host production-grade web content and also deploy web applications and static content to a global Content Delivery Network (CDN) with a single command using Firebase.
- It will automatically provision and configure an SSL certificate for each site deployed and can be connected to a custom domain with an easy authentication.
- Therefore, whether you are building a single page web app, mobile app landing page or a progressive-base application, Firebase hosting will have you covered.
Cloud Functions (Develop a back-end without servers)
- Firebase cloud functions automatically run back-end JavaScript code in a Node.js environment deployed in Google’s own cloud infrastructure. It responds to events triggered by Firebase features and HTTP requests.
- These functions are available in both Google Cloud and Firebase as they are built on top of Google Cloud functions.
- Triggers supported by Firebase Cloud functions include real-time database triggers, authentication triggers, analytic triggers and cloud storage triggers, etc.
- You do not need any provision servers to implement, upgrade and scale them up /down to meet the user’s demands. Once the code is written, Firebase handles the maintenance.
Crash Reporting
- This creates a detailed report of the errors in the application by grouping the similar errors and prioritizes them automatically.
- Reporting makes it easy to find the root cause faster as it exposes important information about the application version, OS version, and the model information of the device affected by the crash.
- By integrating Firebase Gradle Plugin in Android, you can enable this feature and no additional lines of code are required to implement it. For iOS, there is CocoaPod, which requires a few lines of code for additional integration.
Performance
- To provide a great service and satisfy the application users, it is always good to monitor the user experience on a wide variety of devices/ networks/ locations all over the world. This can be achieved by integrating performance monitoring SDK provided by Firebase to the application, where it collects performance data from the application and then reviews and analyzes that data in the Firebase console.
- This data can be broken down by country, device type, version or OS.
Growing and engaging your audience:
Analytics
- In order to develop a successful application, analytics is very important. Google Analytics for Firebase provides free unlimited logging and reporting with a great insight of the application usage and user activities.
- By integrating the SDK into the application, it automatically starts generating reports such as:
- demographic report (to identify the user base)
- retention report (to see how regularly users visit the application)
- engagement report (to see how much time the users are spending using the application)
- average revenue report (to see how much money the users have spent on the application
Also detailed information can be retrieved about what users are doing by logging events that are specific to the application.
- Firebase console can be defined based on device data, custom events or user properties. Based on these data, decisions can be made on how to market or improve the quality of the application.
- A group of users known as Firebase Analysis Audience can be used to perform actions according to this information. Notifications for those groups can be sent using Firebase Notification or Firebase In-app Config to modify their in-app experience.
Dynamic Links
- Dynamic links are deep links that work specific to the platform. The behavior of the link can be changed depending on whether the user has installed the application or not. It can take you to any web page and anywhere within the app.
- If the application is not installed, it will take the user to the play/ app store or to a defined website or will be taken directly to the linked content in the user’s native application.
- Dynamic links are good for marketing campaigns (email, social media, banner ads, QR code etc.) and for sharing websites or coupon codes.
- Dynamic link statistics such as how many people have clicked the link and come to the app download page can be viewed on the Firebase console.
Invites
- Dynamic links are the technology that drives the Firebase invites.
- Firebase invites make it easy to share all the aspects of the application like referral codes or content across Android and iOS platforms.
- The content can be shared easily by clicking the share button and it will open a dialog with a list of friends and colleagues with some “smart recommendations” at the top. As such, the friends can be selected from the list to share with and clicking on the send button would send the invitation along with a personal message (via SMS or email depending on the content). The recipient will click the Invite and if the application is already installed, the user will be taken directly to the application or else the user will be taken to the appropriate application on the play store/ app store.
- Through Firebase Analytics, you can see if the user has installed or opened the application through an Invite.
AdMob
- AdMob is a mobile advertising platform that can be used to generate revenue from the application which is included with the Firebase SDK. Its APIs are built to add banners and video advertisements etc.
- AdMob automatically selects the ads that pay you the most. It connects the network around the world to maximize the revenue generated by each user, which brings more advertisers to you.
Cloud Messaging
- Firebase Cloud Messaging (FCM) is a cross-platform free messaging service that allows delivering messages between the server and the device on Android, iOS, and web at no cost. It was formerly known as Google Cloud Messaging (GCM).
- Messages can be delivered immediately or at a future time in the user’s local timezone. Also, messages can be sent to a single or multiple devices or to a messaging topic across many different platforms.
Remote Config
- Firebase Remote Config is a key value store that is in the cloud. It allows you to change the appearance and the behavior of the application through the Firebase console without letting the user download the updates. It is comparable to Google Tag Manager, which manages your analytics and advertising tools remotely from a web interface without having to rebuild and resubmit the application to the app marketplace after your application has been distributed.
- This can also deliver different configuration sets to users based on different factors such as device type, locale or audience defined in Firebase Analytics. This feature is known as Remote Config Audience Segmentation.
- Remote Config is backed by client libraries on iOS and Android that handles important tasks like caching, handling network problems and keeping the network requests lightweight.
App Indexing
- App Indexing helps to re-engage users to the application by getting the application into Google search.
- When users search for some content already in the application, it may appear in the Google search results,from here, the application can be launched directly.
- If the application which is installed on your phone and the relevant site has similar content you associate them with each other. Then the application can receive incoming links from search. In Android, this can be achieved by using standard Android App Links and in iOS, iOS Universal Links.
- Based on how users use the app content, they can use the App Indexing SDK to submit content to the search engine. The search position can be improved when they use the app.
AdWords
- AdWords will put ads for the application in front of the users by displaying the ads when they do searches on Google, YouTube, Google Play, etc.
- You can define custom audiences in the Firebase console based on the device data, custom events or user properties. Then AdWords will display targeted ad campaigns to the specific audiences.
What are some real-world examples and use cases of Firebase?
- Fabulous – Fabulous is a science based application which helps you to build healthy rituals into your life. View Case Study
- National Public Radio (NPR) – National Public Radio (NPR) is a privately and publicly funded American non-profit membership media organization. It serves as a national syndicator to a network of 900 public radio stations in the United States. View Case Study
- Playbuzz –
- Playbuzz is an online publishing platform for publishers, brand agencies and individual content creators to create content in interactive formats such as polls, quizzes, lists, video snippets, slideshows, and countdowns. View Case Study
What are the pros and cons of using Firebase?
Pros
- Using Firebase, users can use all above mentioned features in their applications at no cost (refer Section 4).
- Data is stored as JSON objects in a real-time database. When data is added to the JSON tree, it becomes a node in the existing JSON structure with an associated key.
- The application data stored in the database as JSON is real-time – i.e. every change will automatically update to the connected clients.
- Cross-Platform API
- Firebase SDKs available for Android, JavaScript or iOS enable the application running on different clients to share a single real-time database. Therefore, clients of all the platforms will receive data updates automatically – this is very helpful when building a cross-platform application.
- Firebase is in the cloud, which makes the app and its services readily available everywhere.
Cons
- Firebase is a hosted solution – Use of a hosted solution gives the benefits of not having to maintain your own servers or spend effort scaling the application with a server cluster. However, it also has its limitations. You do not have privileged access to the location where your data is stored. You cannot search for the best-hosting provider to host your application based on your budget. It is harder to migrate to a different service.
- Limitations of Firebase free plan – Firebase free plan is limited to 50 connections and 100MB of storage, means you can have only 50 active users at once and can only store 100MB of your data. Ex: If you have an online web store, then only 50 users can be there at a time and, only 100MB of data (user profile information, price, images of the items, etc) can be stored in the database.
- Firebase uses a NoSQL database – Although this has advantages in terms of scaling, it has disadvantages if you are managing large amounts of highly structured data. With a regular relational database, powerful structured queries can be written in SQL (that include table joins) to quickly get the data you are looking for. Further, for a simple application, NoSQL database might be an overkill.
For additional information related to Firebase, you can refer to the article “Taking Firebase Serverless – Mobile and Web Applications Made Easy” as well.
References:
- https://www.tutorialspoint.com/firebase/firebase_overview.htm
- https://simplifiedios.blogspot.com/2016/10/why-you-should-go-with-firebase.html
- https://firebase.google.com/
- https://medium.com/@leetheguy/firebase-pros-and-cons-ce37c766190a
Authors
- Dilan Fernando
- Nadeesha Kodithuwakku