Cloud Functions are Google’s offering for serverless architecture (similar to AWS lambdas).
What is serverless?
Before we look into how to use Cloud Functions, we should understand some things about it.
Code needs servers to run, so
serverless doesn’t mean there are no servers, it means that we don’t need to manage those servers ourselves.
In a usual server based architecture, we might create a service and deploy it to a machine. This service will be running in the machine all the time waiting for requests. This has the disadvantage that even if there are no requests, the machine would need to be up, and incurring cost.
On the other hand, if we use Cloud Functions, we write a service and register it with Google. Google will then listen to the endpoint this service cares about and will only start it when there are requests. If it detects that there haven’t been requests for some time, it will stop the service again.