Create Serverless Application With Firebase Cloud Functions
Till now in Firebase, all business logic had written at client side(mobile/web). When there is need to do compute intensive business logic or which is changes frequently, developer had to change the client code and has to resubmit the app on app store. Recently introduced Cloud function has removed this barrier. Now developer can write the business logic at server side in cloud function.
Cloud Functions for Firebase lets you run mobile backend code that automatically responds to events triggered by Firebase features and HTTPS requests. Your code is stored in Google’s cloud and runs in a managed environment. There’s no need to manage and scale your own servers.
Cloud function triggered by Firebase products, such as changes to data in the Realtime Database, uploads to Cloud Storage, new user sign ups via Authentication, and conversion events in Analytics. The ability to extend and connect Firebase features using Cloud Functions makes Firebase more powerful, allowing you to do even more with your app.
Run your mobile backend code without managing servers
Deploying your code to our servers requires just one command. After that, Cloud Functions automatically scales up computing resources to match the usage patterns of your app. You never worry about SSH credentials, server configuration, provisioning new servers, or decommissioning old ones.
Keeps your logic private and secure
In many cases, application logic is best controlled on the server in order to avoid tampering on the client side. Cloud Functions are fully insulated from the client so you can be sure they are private and secure and can’t be reverse engineered.
Use Cases of Firebase Function
1.Notify users when something interesting happens
Developers can use Cloud Functions to keep the user engaged and up to date with relevant information about an app. Consider, for example, an app that allows users to follow one another’s activities in the app. In such an app, a function triggered by Realtime Database writes to store new followers could create Firebase Cloud Messaging notifications to let the appropriate users know that they have gained new followers.
1. The function triggers on writes to the Realtime Database path where followers are stored.
2. The function sends a message via FCM.
3. FCM sends a notification message to the user’s device.
Other interesting similar notification use cases
- Send confirmation emails to users subscribing/un-subscribing to a newsletter
- Send a welcome email when a user completes signup
- Send an SMS confirmation when a user creates a new account
2.Perform Realtime Database sanitization and maintenance
With Cloud Functions database event handling, you can modify the Realtime Database in response to user behavior, keeping the system up to date and clean. For example, in a chat room app built on Realtime Database, you could monitor write events and scrub inappropriate or profane text from users’ messages. Here’s how that could work:
1. The function’s database event handler listens for write events on a specific path, and retrieves event data containing the text of any chat messages.
2. The function processes the text to detect and scrub any inappropriate language.
3. The function writes the updated text back to the database.
Other similar Realtime Database sanitization and maintenance use cases
- Purge a deleted user’s content from Realtime Database
- Limit the number of child nodes in a Firebase database
- Track the number of elements in a Realtime Database list
- Copy data from Realtime Database to Google Cloud BigQuery
- Convert text to emoji
- Manage computed metadata for database records
3.Execute intensive tasks in the cloud instead of in your app
Developers can take advantage of Cloud Functions to offload to the Google cloud resource-intensive work (heavy CPU or networking) that wouldn’t be practical to run on a user’s device. For instance, you could write a function to listen for image uploads to Storage, download the image to the instance running the function, modify it, and upload it back to Storage. Your modifications could include resizing, cropping, or converting images. ImageMagick command line tools are provided for use with Cloud Functions to make this work easy.
1. A function triggers when an image file is uploaded to Storage.
2. The function downloads the image and creates a thumbnail version of it.
3. The function writes that thumbnail location to the database, so a client app can find and use it.
4. The function uploads the thumbnail back to Storage in a new location.
Other similar examples of batch jobs in the Firebase cloud
- Periodically delete unused Firebase accounts
- Automatically moderate uploaded images
- Send bulk email to users
- Aggregate and summarize data periodically
- Process a queue of pending work
4.Integrate with third-party services and APIs
Cloud Functions can help your app work better with other services by calling and exposing web APIs. For instance, an app used for collaboration on development could post GitHub commits to a workgroup chat room.
1. An HTTPS function triggers via the GitHub webhook API when someone commits to a GitHub repo.
2. The function sends a notification of the commit to a team Slack channel.
Other ways to integrate with third-party services and APIs
- Use Google’s Cloud Vision API to analyze and tag uploaded images.
- Translate messages using Google Translate
- Use auth providers like LinkedIn or Instagram to sign in users
- Send a request to a webhook on Realtime Database writes
- Enable full-text search on Realtime Database elements
- Process payments from users
- Create auto-responses to phone calls and SMS messages
- Create a chatbot using Google Assistant
If you want create Serverless Application With Firebase Cloud Functions contact byPeople Technologies and get quote.