From the course: Firebase Essential Training

What are Cloud Functions? - Google Cloud Tutorial

From the course: Firebase Essential Training

Start my 1-month free trial

What are Cloud Functions?

- [Instructor] So we've kind of reached the limits of what we can do in our example application using Firestore alone. In order to go further and implement the really exciting and important parts of our application, such as allowing users to actually make reservations, we're going to move on to learning about something called cloud functions. So first of all, what are cloud functions, exactly? Well, cloud functions are Firebase's answer to other serverless platforms such as AWS Lambda. Basically, they allow us to run a back end without worrying about running and managing servers. So instead of having to write server code and adding specific routes to our server to handle specific requests, and then dealing with keeping servers up to date, serverless functions allow us to simply write functions that are called when a certain event takes place, such as an HTTP request or a database operation. Cloud functions generally serve as a sort of workhorse of many Firebase projects. Just like the servers that they take the place of, cloud functions are where we put much of the logic for tying together authentication, databases, emails, and other interactions, as well as where we put code that's not safe to send to the client side such as code that contains private keys and logic that we don't want the user to tamper with. Another major benefit of using serverless functions is that they allow us to pay on a per-request basis instead of paying to have a server up and running constantly and spending most of its time just sitting there waiting for requests. A metaphor for this is that regular servers are sort of like if you were to have your car running constantly, just waiting for you to drive somewhere, instead of only starting it up whenever you need it. Seen in this light, regular servers don't really seem to make that much sense, do they? Pay-per-request means that you only end up paying once you have enough site users, at which point you're probably at least making enough money to cover your costs. So to sum all of that up, cloud functions mean that we can write individual pieces of server functionality that only run when we need them to, and that we only pay for when they run. Generally, serverless functions are win-win.

Contents