The use of Google cloud platform is not something new nowadays. A large user base are making use of its possibilities to save the device space and access the data anytime they lost their phone data. Have you heard about Google cloud functions, a joint venture of the Firebase and Google Cloud Platform teams?
Back-end code is often required for web and mobile applications to perform actions such as processing long running tasks or sending out notifications. The back end runs on a server in case of conventional approach. This phenomenon is made a lot easier than you can think by using firebase cloud functions in which the back-end code runs in the cloud.
For new users who would like to learn more about firebase cloud functions, here is an overview of its features, working and implementation, capabilities and other advantages that made it the talking point.
What are Firebase cloud functions?
This server less compute solution from Google is ideal for setting up event driven applications. The cloud functions in fact help to run backend code automatically as a reaction to the triggered events. And cloud functions for firebase is exclusively for firebase developers that enable them to add server-side code to integrate its features. A collaboration of HTTPS requests and Firebase features lets you trigger events. The Google’s cloud will store your code and a managed environment runs it. So you can be free from the role of managing and scaling the servers of your own.
Integration with Firebase platform:
The use of cloud functions together with Admin SDK lets the integration across firebase features. For third party services integration, there is option to write web hooks on your own. As the cloud functions lessen the boilerplate code, it gives way for easily using Google Cloud and Firebase within your function.The written functions can respond well to events by other Google Cloud and Firebase features.
Types of triggers:
When you write a function, it can respond to events created by Google Cloud features and Firebase which are termed as triggers.
Some of the most common triggers include:
- Realtime Database Triggers: In this case, users can respond well to changes that occur in the Firebase Real-time Database.
- Firebase Authentication Triggers: At the time a user account is created or deleted, code is executed in response through Firebase authentication. This trigger gets invoked in many cases such as a user sets up an account and password, a user signs in for the initial time with federated identity provider and more.
- HTTP Triggers:At times of an HTTP request, such triggers are invoked.
- Cloud Storage Triggers: A firebase cloud function is executed in case files and folders are uploaded, updated, or deleted in Google Cloud Storage.
A function’s lifecycle
The cycle starts off with writing codes for a novel function by the developer. Followed by that, an event provider will be selected. The conditions are then defined according to which the execution of function happens. The function is then deployed by the developer and Firebase takes the role of connecting to the chosen event provider.
Here are the probable step wise happenings of the rest of the function’s cycle:
- The code gets evoked once the function’s conditions matches the event generated by event provider
- The instances get cleaned up in case the function remains idle
- More instances are created by Google in case many events are handled by functions making them busy
- Once the updated code gets deployed by developer to update function, the older version instances get cleaned up and new instances replace them
- In case the function gets deleted by the developer, it is followed by cleaning up of instances. The connection or link between the event provider and function also gets removed.
This phase involves three main sections including setting up of cloud functions, followed by writing functions and finally deploying and monitoring.
Let us see in detail:
The Firebase CLI is installed at first. In the particular Firebase project, the cloud functions are initialized.
The functions are finally deployed by making use of the Firebase CLI. The Firebase console can be used to see and look for through the logs.
Privacy and security
It is common that developers look to power over application logic in server in order to keep away from interference from the client side. As here it is completely insulated from the client side; that is not a problem with Firebase cloud functions. You can be sure about keeping up the privacy and follow what exactly is needed.
Running code in cloud- key benefits:
When thecode is running in the cloud instead of the traditional approach, you can come across various advantages:
- There is no necessity for you to run your own server and maintain it.
- In case of the back-end code, an isolated code base can be used
- The billing is done only for the code’s real executing time
- High scalability is possible in case of the cloud infrastructure
More use cases with firebase cloud functions:
Apart from the many advantages and benefits when using firebase cloud functions, here you can see the possible user cases:
- User notifications are send out at times of events
- Welcome email is send out at time of a user sign up
- Confirmation emails are send out in case the users subscribe or unsubscribe
- In order to make the data base clean and up to date, Real-time Database Tasks are performed which are automated
- In case a user deletes his account, the contents are deleted from the database
- For a Real-time Database list, the count of elements are tracked
- Intensive tasks are executed in the cloud itself and not in your data base
- At the time of uploading of an image into the database, thumbnails for the same are generated automatically
- Bulk emails can be send to users for particular cases
- Even in cases of third party services, integration is possible
- In case of insertion of text into the Real-time Database, Google Translate service helps with the translation
- Payments are processed in a lot easier way
Firebase cloud functions have in fact set the technology world on fire with its innovative technologies and the way it has positively impacted the whole scenario. In short words, this innovative cloud functions just remain as a folder in your project which contains an index file and their own node modules.
You can simply run your back-end code without giving a second thought. However, organizing them can get messy if you follow an unstructured way. The most accepted solution is to name the files by the way in which it triggers and you can get the most out of this innovative solution.