100
votes

Cloud Functions and Firebase Functions (or "Cloud Functions for Firebase") both look the same. Please describe the use case of each.

Both use HTTP functions.

In the Cloud Functions:

exports.helloHttp = function helloHttp (req, res) {
  res.send(`Hello ${req.body.name || 'World'}!`);
};

And in the Firebase Functions:

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
});

What is difference between these?

4
The term for Firebase is actually Cloud Functions for Firebase, which is pretty much just Cloud Functions integrated with Firebase Services.AL.
So there is no difference between both?Muhammad chhota
Would like to add a simple point not exactly answers your question. You can code in different languages (NodeJS, Python. Heard Go is coming) using Google Cloud Functions.viggy28

4 Answers

179
votes

There is no product called Firebase Functions.

There are three separate things:

  1. Google Cloud Functions, which allow you to run snippets of code in Google's infrastructure in response to events.
  2. Cloud Functions for Firebase, which triggers Google Cloud Functions based on events in Firebase (such as database or file writes, user creation, etc)
  3. Firebase SDK for Cloud Functions, which includes a library (confusingly called firebase-functions) that you use in your Functions code to access Firebase data (such as the snapshot of the data that was written to the database)

So Firebase provides a (relatively thin) wrapper around Google Cloud Functions, to make the latter product easier to use and integrate it with Firebase. In that senses it is similar to how Firebase integrates Google Cloud Storage into "Cloud Storage for Firebase" (formerly known as Firebase Storage).

If you're using Google Cloud Platform without Firebase, then you should use plain Google Cloud Functions. If you're on Firebase or if you're a mobile developer interested in Cloud Functions, you should use Cloud Functions for Firebase.

6
votes

There is an additional difference: Firebase Functions can only be implemented in JS or Node.JS, while Cloud Functions also allow the use of Python and Go.

There is also a small difference in terms of how they are priced, if you are on the Spark Plan. Check this out https://firebase.google.com/pricing vs. https://cloud.google.com/functions/pricing if you are on the Blaze plan, the pricing is the same.

I happen to use both for my Firebase project.

5
votes

Google Cloud Platform, GCP, has an article addressing this question, Google Cloud Functions and Firebase.

Google Cloud Functions and Firebase

Google Cloud Functions is Google's serverless compute solution for creating event-driven applications. It is a joint product between the Google Cloud Platform team and the Firebase team.

For Google Cloud Platform developers, Cloud Functions serve as a connective layer allowing you to weave logic between Google Cloud Platform (GCP) services by listening for and responding to events.

For Firebase developers, Cloud Functions for Firebase provides a way to extend the behavior of Firebase and integrate Firebase features through the addition of server-side code.

Both solutions provide fast and reliable execution of functions in a fully managed environment where there's no need for you to worry about managing any servers or provisioning any infrastructure.

...

Cloud Functions for Firebase is optimized for Firebase developers:

  • Firebase SDK to configure your functions through code
  • Integrated with Firebase Console and Firebase CLI
  • The same triggers as Google Cloud Functions, plus Firebase Realtime Database, Firebase Authentication, and Firebase Analytics triggers
0
votes

Official Google Video Describing the difference: GCP vs. Firebase - Functions & Firestore

  1. Firebase will offer you to wrap your functions into callable functions which can be invoked via firebase SDK
  2. language support, GCP also supports Go, Python and java
  3. GCP could be deployed both via console or CLI, but firebase functions only via CLI