Introducing Google Cloud Functions: deploying serverless microservices

Google Cloud Functions

Google Cloud Functions are the new guys in town and they come fully packed with great features such as:

  • Serverless Architecture
  • Triggered Based Behaviour
  • Optimized runtimes for Node.js 6, Node.js 8, and Python3
  • Automatic Scaling
  • Pay Only for Function Executions

They provide a seamless plug-n-play behaviour, whereby you simply ship and deploy functions within various projects, monitoring the usage of computing resources such as memory, CPU, disk space, as well as metrics such as Number of Invocations.

One common use case would be integrating a cloud function with cloud storage. The function executes when a new blob is uploaded to a cloud storage bucket due to an event: been emited. There are four standard events emitted by cloud storage operations, namely: finalize, delete, archive, metadataUpdate.

To deploy a simple cloud function, lets first write a hello world function using Python and save it to a file named under a folder called hello-world-gcf. The code is as follows:

def hello_world(request):
   print("Hello World")

You can deploy this function to Google Cloud by first initializing and configuring your gcloud environment using the gcloud CLI. Run the following commands:

$ gcloud init
// Configure your gcloud following the instructions
$ gcloud functions deploy hello_world --runtime python37 --trigger-http

This would provision a cloud function to be ran within a Python3 runtime and return a httpsTrigger URL of the form:


Now test the function with trigger URL by visiting it in your browser or  retrieve the URL if you missed it using:

$ gcloud functions describe hello_world

To monitor the cloud functions, view the logs and analyse the chart metrics to analyze its behaviour and operational state.

Cloud functions should be used as much as possible to replace various microservices that do not require customizable containers used in GAE flexible and Kubernetes deployments. They offer a constrained enviroment and should be painstakingly analyzed before beginning development and deployment.

Author: daltonwhyte

A technocrat who believes in a smart future, that will be proliferated with systems that allow us to focus on the bigger picture.

Leave a Reply

Your email address will not be published. Required fields are marked *