Top 5 Mad Use Cases of Firebase Cloud Functions
If you’ve seen my Getting Started with Cloud Functions post or went through any standard Cloud Functions tutorial, you probably deployed a function that sends a welcome message or something else that’s basic that way.
Then you might be thinking of more cool ways you can integrate Cloud Functions into your app but just can’t come up with anything. Well now we’re going to switch things up and get some ideas going.
Now there’s a whole repository of these on Github that includes tons of examples for different functions. What I’ll be doing here is narrowing them down to what I think are the top 5 most useful functions for Android Developers, in descending order, let’s go.
I recently created an app that involved downloading a ton of sounds and converting them into a format that could retain most its quality without inflating an app with too much space. It certainly was a ride.
If this is a strain for us developers, what more would it be for users? If we have, say, an app that lets users upload and play sound effects, you can easily run into files of different sound formats. Ideally, you’d want it to be consistent, and perhaps manipulate the file a bit to make it take up less storage for the user.
This cloud function automatically converts audio files uploaded to Cloud Storage to FLAC file format with mono-channel audio @ 16000hz. As a learning experience, this is a great Cloud Storage trigger that also deals with file conversion on the cloud.
Galleries, Video Players, Music Players, all sorts of apps make use of thumbnails, but they need to be loaded quickly enough that the app remains seamless and not take up too much storage space.
This is another one that deals with files in Cloud Storage, but instead of conversion, this does image manipulation. On top of that, it makes use of other plugins as well, that being Node.js Stream and Sharp which makes it another great one for learning on top of its practical use.
What did the envelope say to the stamp? “Stick with me and we’ll go places.”
Subscribing to a newsletter, creating an account, accessing a service, you know how many times you faced email confirmation as a basic security measure which you’ll probably want in your app as well.
This function uses a Realtime Database trigger nodemailer to send confirmation emails via Gmail. It’s notable though that Gmail has a quota to how much you can send. If this is a problem, you can switch to other email sending platforms like Sendgrid, Mailjet, or Mailgun. They are however, non-Google services and you would have to enable your Firebase billing to be able to use them.
How do you convince your customers that what you sold them wasn’t a ripoff? You give them incentive to buy another thing! Not only are your customers happier that they bought your item, not only do they want to stay engaged with your app, but they also feel the need to give you more of their good stuff!
This comeback-incentive is what brings this Cloud Function so high in this list. This function doesn’t even require any plugins.
It just basis its use under a couple assumptions, such as your Firebase Analytics User ID must be equal to your Firebase Auth UID and FCM Device Tokens must be saved under users/$uid/tokens, but these can be edited to suit your app’s needs.
While these didn’t quite make it to the top 5 list, they’re still pretty mad and are definitely worth a mention.
And our number 1 top pick for the MADDEST Firebase Cloud Function Sample is…
So the 2nd highest item in this list made its place because it convinced users to give you more of their money but what good is that if you don’t have a way to receive it? That’s why this made the top one spot on this list because what can be madder than getting money!
This is when the internet realises that Eric Decanini was a cheapskate all along…
Now this is sort of a double-entry on this list because you can choose to use either Stripe or Paypal to get the cut. As these both use non-Google services, both of these do require you to enable billing on your Firebase project, but are you really spending money if you’re doing it to get it back and more?
The trigger for these functions is an onRequest trigger, which means your app just needs to send an HTTP request to invoke the function.
Now both Stripe and PayPal make their APIs available for Java, hence it’s available for use directly in Android apps (including all the Kotlin users out there), so why have it as a Cloud Function you might ask? Well are you going multi-platform? Having the function deployed on the cloud means that any device on any platform just needs to send an HTTP request and the payment can be processed. Less bugs, less code, less maintenance, less coffee used up.