Today we’ll discuss Google Cloud Functions. Cloud Functions is a new part of Google Cloud Platform and was announced to go in public Beta at Google Cloud Next.
So what is Cloud Functions and what problems might it solve? We at Fourcast had been given alpha access to Cloud Functions so we had some experience with it before we came to Google Cloud Next 2017.
Microservices
When talking about Cloud Functions it’s useful to involve microservices. Most applications are the opposite of microservices, namely monoliths. In a monolithic application all of your code is put together and an error in one part of the system might influence other parts of your application as well. Microservices are a solution to this: they divide your application into small pieces of functionality that are independent and do a single thing, and do it well. Since each functionality is a small application, they can be deployed and updated separately, and any bugs that might have slipped in will not influence any of the other microservices.
Cloud Functions go hand in hand with this approach as they are small pieces of functionality that can be triggered on certain events.
Serverless
Cloud Functions are serverless. In a more traditional environment the developers have to take servers into account, configuring the server, managing the infrastructure.. In a serverless environment, developers do not have to think about a server and can focus on writing code. Of course the code still runs on a server, but everything that comes with it is handled by Cloud Functions.
Pay for what you use
If you’ve read our previous blog post on docker & containers, you’ve read that containers are small units of computing power with minimal overhead. With Cloud Functions you should think in functions instead of applications, the resources needed to run one function are of course much smaller than for an application, so the overhead here is even smaller!
Runtime & autoscaling
Currently you can only write Cloud Functions in javascript as the only supported runtime is NodeJS, but other languages will follow. Cloud functions will also scale automatically, independently from each other, with no configuration needed to make this work. Each time a cloud function is called you will only be billed for the time it took for the function to run, rounded to the nearest 100ms.
In the real world
As mentioned before, Cloud Functions are triggered on certain events, such as uploading files to Cloud Storage or plain HTTP calls, which opens up the possibility of writing WebHooks.
There are dozens of things you can do with Cloud Functions: Want to notify owners of Cloud Storage buckets every time someone uploads/overwrites a new file? Write the logic, tick off the Cloud Storage trigger, deploy it and off you go. With HTTP triggers you can respond to events originating from services such as Github, so you could for example perform some logic every time a push happens to a certain repository. As mentioned before you could also write a (microservices) API with Cloud Functions since they are such a good fit to this strategy.
To summarise: Cloud Functions are small, independent functions that will automatically scale, run in a serverless environment and have minimal overhead.
Want to find out more about Cloud Functions? Head over to the official page or watch the talk at Next that I followed.
Written by: Robin Hellemans
This post belongs to a series of blogs in response to Google’s yearly conference in San Francisco, March 8-10th. Stay tuned for more.