Firebase is a suite of tools for building apps and managing infrastructure on top of the google cloud platform. James Tamplin and Andrew Lee founded it in 2011.
After discovering that developers were using their chat software to manage non-chat application data, this inspired them to create a real-time database. This JSON database automatically stays in sync with your front-end application.
It was later expanded to support user authentication and website hosting as a complete backend service in 2014.
It was acquired by Google, where it was further expanded with serverless computing via cloud functions, push notifications via cloud messaging, and other google services like analytics and AdMob in 2017.
Google acquired Fabric from Twitter and launched a new document database called firestore to support it.
Most importantly, a more comprehensive range of applications through firebase provides software development kits for virtually every platform to manage and scale this infrastructure with little to no backend code to build a full-stack application.
Create a free firebase project, open up some code for your favorite front-end platform, install the firebase SDK, and connect it to the cloud with your project credentials once initialized.
You can start interacting with your backend resources. First, we might want to know if the user is logged in or not. We can listen to the current user with the on-off state changed function.
The user will be null at first, but we can log them in with their Google account using the sign-in with pop-up function. Now that we have a user logged in, we might want to store something in a database we can make a reference to a document in firestore.
Then write JSON data while referring to the current user’s user id. Still, the fantastic thing is that we can listen to updates to that data in real-time by simply referencing the document using the snapshot function.
Anytime the data changes on the server, it’ll be reflected in the UI with zero latency thanks to optimistic updates out of the box, but that doesn’t seem very secure.
How do we control who has access to the database FireStore?
Security rules allow you to define access control logic in a simple, readable format with common expression language.
You can do almost everything from the front end, but when you need to run server-side code, firebase cloud functions provide a tightly integrated serverless backend.
Not only does it allow you to create HTTP endpoints, but functions can also be triggered in the background based on events that happen in your project, like rights to the database user authentication events file uploads, and many others.
Firebase has an emulator suite to run and test your code in a mock environment when developing locally. When it’s time to deploy, run the firebase deploy command to push your code to the cloud and allocate infrastructure to run it at any scale.