When to use Firebase Cloud functions?

Recently I got a question from one of the Indie makers that, when to use Firebase Cloud Functions?

This question triggered me to go deeper to understand the whole purpose and justification for using the Cloud functions. As a developer, you may be having the urge to learn any new technology just to have the feel. But as a business owner or as an Indie maker, you are not ready to take any technology until and otherwise, you see the business value in it.

So I am going dive deep to explain the purpose of Cloud functions and when to use it in real business cases. Some of the real situations are as follows,

Realtime notification

Business case

You need to send a notification to your app users when someone likes or follows him. This is one of the major use-cases for your business application to engage better with your users. The notification should be in near-realtime for giving a high-level engaging experience through the application.

Solution

You can write a cloud function that should watch a particular data change of the followers or likes. The cloud function will be triggered and send a notification to the target users based on the data change. You can have any kind of notification through cloud functions. A few examples would be, sending an email or in-app notification or push it to the Slack channel. It is up to the real need and you can solve it through cloud functions.

Data Sanitization

Business case

Data sanitization is one of the important activities to keep our application data in sync with the changes happening at any layer. I believe as a young entrepreneur or Indie makers, you already have some basic understanding of the GDPR compliance. Without this compliance, you are not allowed to do business with the European continent. In short, you should not have the user’s personal data after they deleted their account with your application.

Solution

You can write a cloud function to anonymous the user’s personal information available with your application. This cloud function should watch on the user delete operation. Whenever a user is deleted from your application, the respective callback function will handle the anonymous operation to eliminate the trace from your data set.

Off-load App Workload

Business case

It is always good that you should separate the CPU intensive tasks out of the main application. This means you should off-load the heavy workload to any other operation which should operate asynchronously without blocking the main application.

Your business app requires to generate thumbnail in different sizes from the uploaded image. So there are 3 operations involved in the whole process.

  • Upload image from your app
  • Create thumbnail in various sizes from the uploaded image
  • Store those thumbnails in the datastore for the future

Solution

You should create a cloud function to create the thumbnails in various sizes from the source image. This function should watch on image upload operation in Firebase Cloud Storage. When the image is uploaded in a specific path, then your cloud function will be automatically triggered and do the job. The newly created thumbnails can also be stored back to the Firebase Cloud Storage based on your use-case. This way you can delegate some of the heavy lifting operations to cloud functions.

External API integration

Business case

One of the key use-case for cloud function is to have the integration with external APIs and services. The business use-case is to have a Stripe payment gateway integration with your application. When someone subscribes through your application, you should create a subscription plan with a Stripe payment gateway for the future payment schedule.

Solution

To solve the above problem, you can write a cloud function that should consume the Stripe APIs to have the integration. Then the cloud function should watch on the user subscription event. Once this is tied together, the external integration will work seamlessly.

I hope this would have cleared your doubts on when to use Firebase Cloud functions. Let me know if you have any questions or feedback. Please share it with your friends if you feel this would help them as well.

{ Happy coding }

API Evangelist | Chief Hustler @workrituals.com | Habit Coach | Madras Java User Group Leader
81FollowersFollow
0SubscribersSubscribe

Latest articles

Jakarta Tech Talk: Build Microservice using Microprofile + Helidon

Recently I gave a presentation on Jakarta Tech Talk series on 'Building a Microservice using Microprofile + Helidon. Enjoy watching the presentation...

Serverless REST APIs made simple with Cloud functions

Introduction Serverless is one of the top keyword in the integration space right now. Everyone is talking about the...

How to get started with Google cloud functions?

The 'Cloud Functions' is a Google technology bundled as part of the Firebase platform. It is a serverless backend to support our...

Why Firebase is a great technology for ‘Indie Makers’...

Firebase is a technology developed by Google. In this article, I am going to explore why Firebase is a great technology for...

Helidon: 2x productivity with Microprofile REST Client

We have already many articles before on how to write Microservice using the Helidon framework. We are going to further enhance our...

Similar articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here