Why everyone is using Firebase and Why you should too
What is FireBase?
Firebase is Backend as a Service (BaaS) where it takes care of user authentication, Database and hosting all by itself.
My Experience with Firebase
I have personally built 3 production-level projects using most of the firebase features and I have faced 0 problems with it and the best part I haven't spent a single penny on it.
3 Reasons Why you Should Care about Firebase
- Experience - Firebase has the best documentation and has good support in case you are stuck somewhere.
- Price - It's free for your small/experimental projects and you can pay as you go if the project grows linearly
- Maximize Time - You can implement a lot of features in less time with small code
Go To console.firebase.com and explore by creating a project inside but before that have a look at this article.
What does Firebase offer?
- Firestore (NO SQL Database)
- Cloud Functions
If you have to build an application which has “login” features you definitely know building an authentication system with encryption and other things involved is a pain.
With Firebase authentication you can let users log in with email or even let users log in to your product via Google Sign in with a small piece of Code. Here is the documentation for Google sign in method and email sign in method
If you are a computer science student you might have learnt MYSQL which is a relation based SQL DBMS.
Firestore is No SQL database like Mongo DB which is made of Collections and Documents stored in JSON format. It has its own pros and cons. For beginners, this is very easy to learn, even querying/filtering is so much better.
Let's say that we have to keep information about a user and keep a record of his order history. For that, we will build 2 collections
which will have a document inside with information stored in JSON format.
So you have now built a Web App using Firebase and need to host it somewhere. Well, Firebase has got your back. Make sure that you have a folder with the public as a name which would have your index.html file. Project Structure should look something like this Run the following commands to deploy your web app to firebase.
In Response, you get this
? Are you ready to proceed? Yes ? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. ( ) Database: Deploy Firebase Realtime Database Rules ( ) Firestore: Deploy rules and create indexes for Firestore ( ) Functions: Configure and deploy Cloud Functions >(*) Hosting: Configure and deploy Firebase Hosting sites ( ) Storage: Deploy Cloud Storage security rules ( ) Emulators: Set up local emulators for Firebase features
Choose the services as hosting and select a public folder where you should have your index.html inside. This is how it should look
=== Hosting Setup Your public directory is the folder (relative to your project directory) that will contain Hosting assets to be uploaded with firebase deploy. If you have a build process for your assets, use your build's output directory. ? What do you want to use as your public directory? public ? Configure as a single-page app (rewrite all urls to /index.html)? Yes ? File public/index.html already exists. Overwrite? (y/N) N
After the initialization, you can deploy it with this code
You might want to connect your own domain or might get stuck at something. Refer to the Firebase Hosting Documentation for better reference.
This is one of the favourite things about Firebase is cloud Functions. I might write a few articles down the lane so stay tuned.
And it has a lot of interesting use cases, like:
You can host only 2 cloud Functions for free of cost in a Spark plan, just keep that in mind.
Is Firebase used in tech companies?
Yes. Usually by startups without a lot of time and resources. Firebase is a godsend.
But not in big corporates where securing user data is a bigger priority, they prefer building it inhouse instead of using BaaS like firebase.
(The other reason why few companies don't prefer firebase is that the product they are building might be for global users and we know that some countries have banned google and hence firebase won't work there.)
Don't' worry though . if you understand how NO-SQL works using firebase, It's pretty similar to mongo, so it won't be a challenge.
Firebase is easily the best backend as a service for beginners or freelancers who are just getting off the ground.
I will soon write on how you can integrate Firebase to Flask apps to stay tuned to my newsletter and follow me here on Hashnode.
Interested in reading more such articles from Hrithwik Bharadwaj?
Support the author by donating an amount of your choice.