Firebase

Enes Yilmaz
8 min readJan 21, 2023

--

  1. What is firebase

Firebase was launched in April 2012 and acquired by Google in 2014 to provide the solution for backend developers. The feature combination in Firebase accelerates the cloud database integration in both web and mobile app. Firebase is a BaaS (Backend as a Service) , which reduces configuration and setting up logically without time consumption. In summer of 2016, Google released Firebase officially for the goals of earning income for developers, building a successful application and promoting the growth of the business. Firebase can be called an enhancement or upgrade for APIs, which allows extended functions such as messaging, and service authentication. Consequently, this minimizes the cost and consumed time to build these services. Firebase provides new technology for business to advance via linking or referrals. Then, the system is connected by anallysing the platform and is easy to integrate into the application.

figure 1.1

It is not complex to create a Firebase application from scratch. As in figure 1.1, there are three features can be applied to the application: develop, grow, and earn. .Developers are not required to use all three pillars; they are chosen depending on different purposes. Some technologies are at no cost such as Cloud Messaging, Crash Reporting, Remote config or Dynamic Links.

2. Firebase Authentication

figure 2.1

At present, many web services use authentication to identify users and secure the data by controlling access to their content. For instance, Google asks for account and password to log in some applications.
The authentication is more complicated due to a third-party authentication — APIs.Hence, it is a goal of the Firebase team to complete the authentication to support developers by supplying with the convenient API which lets users log in or sign in from federated providers. It cooperates also with the real-time database to control the access, as in figure 2.
The common federated providers are Google, GitHub, Facebook and Twitter. If developers manipulate Firebase, it is not necessary to repeat the sign-in process, because it is already integrated with the authentication system of these providers. If the user has an existing account it will instantly connect to the authentication system. Firebase supports standard functions such as forgotten password, and users’ verification via Firebase console. Users can anonymously sign in with temporary account and then the federated provider-base account is linked to that user. It also assists Smart Lock, which can automatically remember and sign-in by using the credentials. The email address is an essential credential to sign in, which then is passed to Firebase authentication SDK. Firebase back end server will verify these authentications, then reply to the client. User’s information can be determined when the user has the access to Firebase product or to control or verify their identity.

Firebase Auth is the least time-consuming option to integrate into programming. The actual project that supports Firebase authentication consumes longer time to write code than FirebaseUI Auth. It is an online library which allows clients to customize the common Firebase scenarios to provide the implementation for user authentication, which consists of user interface screens. FirebaseUI Auth covers many practices to authenticate on web, and mobile phone and is easy to handle. There are three main steps to integrate user authentication into apps on FirebaseUI Auth: Set up Sign-in methods, customize the sign-in UI, and use FirebaseUI to perform the sign-in flow. Firebase Authentication SDK takes more time than the previous one. Also, it provides the verification for authentication process over full controlling the outlook. Eventually, this option maintains a complete version of authentication including many steps to identify the user’s account. It is used to provide several tasks from signing in and out, logging in automatically to update the new user’s data to the app. Firebase Authentication SDK moreover federates identity provider integration and anonymous authentication. To approach Firebase Auth, Firebase Authentication SDK is applied primarily. There are some steps that should be considered: Set up Sign-in method, implement UI flows for your sign-in methods and pass the user’s credentials to the Firebase Authentication SDK.

figure 2.2

To take advantage of the benefits that Firebase provides, we first need to activate it.

figure 2.3
figure 2.4

3. The Real-time Database

figure 3.1

The classic real-time database demonstrates the database system that overcomes the real-time restriction to consolidate a reliable database system. This is the key product of Firebase since it is a simple feature utilizing API. It syncs new information as JSON across all devices, in which real-time database collaborates the web and mobile version in the same device and shares with another device in milliseconds. Additionally, this product optimizes the offline service to save and store user information in the local cache and uses database SDKs so when the user is online, the data is synced automatically. The Realtime Firebase defines data structure and it is secured upon the Firebase Database Security Rules specifying people who can access particular information. With a few codes by clients, it describes who can see specific information. It is not necessary to exist operation or maintenance server because the cloud service hosts a real-time database (NoSQL — based database). Like other products, the Real-time database is available for Android, IOS, Web, C++, Unity Platform and JavaScript. Real-time Database can scale up to 100 000 concurrent connections and 1 000/second for each database.

figure 3.2
figure 3.3
figure 3.4
figure 3.5

The data set is changed and upgraded due to the dissimilar database, and integration real-time database with Cocoa Pods, or Gradle to promote the access time with clients. This implementation also provides the written ability while offline but still keeps the security for clients. These four steps are the basic paths to create a Firebase Real-time Database: Integrate the Firebase Realtime Database SDKs, create Realtime Database References, set Data and Listen for Changes, enable Offline Persistence and secure data.

4. Cloud Storage for Firebase

Videos, photos and documents are stored online through Firebase Cloud Storage service that is backed up on Google Cloud Storage. A simple API is applied to build and manage an infrastructure to deal with large files. Hence, documents are shared with particular users with the Realtime Database Rule. It means this storage is cached since it is integrated with Firebase Authentication. Through Firebase SDKs, it is effortless to upload and share files on mobile devices that are accessible for both Google Cloud and Firebase. Moreover, it is not necessary to transfer the document to another provider due to the automatic scale on Cloud Storage. Firebase declarative security is available according to file types, filename or size. Firebase SDKs applies robust operation even when the network is disqualified, if a video is not successfully uploaded, when the internet connection is qualified, it will continue to transmit that video depending on where it stopped.

figure 4.1

To comprehend this task, Firebase SDKs platform is built to interact with Firebase Cloud service. Admin SDK allows to read, programmatically send, access and generate Firebase Auth communicating with Firebase from the privileged environment. The following steps indicate how the Cloud Storage functions: integrate the Firebase SDKs for Cloud Storage, create a reference, upload or download and secure your Files.

5. Cloud Firestore

Cloud Firestore is a service provided by Firebase exclusively for client applications and deeply integrated with other firebase products, including Google’s cloud functions serverless platform.

Cloud Firestore is a fully managed NoSQL database hosted in a serverless cloud made available by Google. It allows us to create a database in minutes. We don’t have to worry about server management and scalability and we can also build high performance service using Firestore.

Cloud Firestore is the successor to the firebase real-time database with greater flexibility and scalability. Cloud Firestore is used for mobile, web and IoT applications development to instantly sync data across devices using real-time listeners. Mobile, web and IoT apps can access database directly using native SDKs provided by Firebase.

  • Cloud Firestore uses a “Document and Collection” based structure to store data and does not contain any rows and tables.
  • Data will be stored in documents organized into collections. The document supports key-values (the field can be any primitive data type, for example: int, string, etc.), complex and nested objects (called maps).
  • All documents should be stored in collections and depending on your data model we may create sub-collections in documents.
  • We cannot create a document within a document and it is the same as a collection.
  • A document cannot exist independently and always belongs to a collection.
  • We can easily refer to any document or collection in a database by its unique name.
  • A collection contains documents only and cannot contain any key-values or sub-collections.
  • If you’re trying to add documents to a collection that doesn’t exist, it creates the collection for you.
  • If you delete all documents in a collection, that collection will be deleted automatically.

Conclusion

In this article, we learned firebase, real-time database, cloud storage and cloud firestore. Thank you. See you in the next article…

Sign up to discover human stories that deepen your understanding of the world.

--

--

Enes Yilmaz
Enes Yilmaz

Written by Enes Yilmaz

Fırat University Software Engineer

No responses yet

Write a response