End to end serverless data pipeline on Google Cloud

Jose Valdebenito
Nov 5, 2019 · 7 min read


We created an e2e serverless data pipeline using a scheduled service that gets data from OpenWeatherMap and stores it into BigQuery. The data can be explored directly on BigQuery or Data Studio.

Well, it’s known the importance of data for large to small organizations. Gartner says that by 2022, 90% of corporate strategies will consider . Besides, the concept of serverless is becoming one of the golden rocks of modern computing. Indeed, -let me paraphrase Dylan Stamat, CEO of Iron.io- one of the most important reasons why companies are moving to serverless concerns to the fact of its nature of cost and use optimization (they want to spend less and do more!).

Motivating your hearth

Regarding the title of this short-to-read article/tutorial, you are here maybe because:

  1. you love working with new technologies related to data,
  2. it is just your job to work with it,
  3. or perhaps you are part of a secret society that believes in the power of the Datum God.

Whatever the option, we mind data. A similar jargon could be used to talk about serverless. Furthermore, they both combined form , who have excellent dev skills and don’t want to worry about managing and operating servers (see: AWS talking about serverless).

Photo by jesse orrico on Unsplash

What will you read here?

Keeping in mind your time, let’s get to the point. This article is a how-to reading in which we are going to build a serverless data pipeline that regularly obtains data from an API/service and loads it into an analytics engine to be explored by business users or data scientists.

Our tech stack is conformed by some serverless services of :

  • Cloud Function: Our code will obtain data from an API/service and will load it into , being subscribed to our execution topic of
  • Cloud Pub/Sub: Our executiontopic that will trigger our .
  • Cloud Scheduler: This service will allow us to schedule the execution of our , invoking the Cloud Pub/Sub trigger.
  • BigQuery: The data obtained by the will be loaded here. It is our analytics engine, allowing us making simple or complex queries and data processes.
  • Data Studio: Our reporting tool for the analyst or data explorer, It will consume data from . Although It is not part of GCP (and is a SaaS app), I love it !

Along with GCP, the role of API/service will be covered by the current weather API by. I chose it because of its free plan, also is one of the most popular APIs on that thing called The Internet. Moreover, I decided , as the geographic point to get data from this API. However, you have to consider that this is just an exemplification; you may need an according-to-your-job service to gather data.

The next image outlines our reference architecture.

Serverless data pipeline reference architecture

Hands-on (ur ♥️)

This section will empower your data engineer’s tool belt.

Pre-requisites for a good travel

Before, you will need this as pre-requisite:

  1. A GCP project with a linked billing account. Don’t worry about this; if you specify a gentle frequency of execution, the entire pipeline will .
  2. Installed and initialized the Google Cloud SDK.
  3. An App Engine app activated in your project. Why?
  4. Enabled the Cloud Functions, Cloud Scheduler, and APP Engine APIs.
  5. An API key from OpenWeatherMap.
  6. Unix based command line interpreter. Remember that
Photo by Jakob Owens on Unsplash

Step 1: Clone the repo

You have to clone the repo that contains the function code. Also, you can pass to salute!

cd gcp-serverless-data-pipeline

Step 2: Setting up environmental variables

I follow -and take- the specialization courses of GCP on , that bring me to the world of excelling the use of while working with the command-line tools of the GCP SDK. Hence, let’s set some variable:

: Your project ID, you can find it on the GCP Console. Example:

# Take care of the id
A good name for a project

: This is the topic name for Pub/Sub. I set something like:


: This is the job name to be executed on Cloud Scheduler. I set something like:


: This is the name of the function on index.js; in this particular scenario, the name is loadDataIntoBigQuery, so…


: This is the frequency of execution, be gentle here. For instance, you can set it as:

 SCHEDULE_TIME="every 1 hour"

You can read more about this in the docs of Cloud Scheduler.

: Sign up on OpenWeather, and generate an API key here. The key takes some time to be ready to use. Meanwhile, you can try to call the API through Insomnia (Debug APIs like a human, not a robot).


: This is the BigQuery dataset name. I set something like:


: This is the BigQuery table name. I set something like (very repetitive):


Step 3: Activate the GCP project

Activating the project helps to execute the next commands more quickly:

 config set project $PROJECT_ID
Project creation ss

Step 4: Create the Cloud Pub/Sub topic

Let’s create a Pub/Sub topic called TOPIC_NAME:

 pubsub topics create $TOPIC_NAME
Pub/Sub topic creation ss

Step 5: Create the Cloud Scheduler job

This command will create a Cloud Scheduler job, named as JOB_NAME, that is going to send a message through the Pub/Sub TOPIC_NAME every SCHEDULE_TIME (frequency).

 scheduler jobs create pubsub $JOB_NAME --schedule="$SCHEDULE_TIME" --topic=$TOPIC_NAME --message-body="execute"
Cloud Scheduler job creation ss

Step 6: Create the BigQuery dataset and table

Dataset creation ss

Step 7: Create the BigQuery table

The BQ_TABLE will contain our data:

Table creation ss

Step 8: Deploy the Kraken! Sorry… our function

Finally! The glue of our pipeline, our function, you can read the next code as:

“Ok, Google, deploy the function called FUNCTION_NAME that will be triggered by the topic TOPIC_NAME and don’t forget to set up some env variables for this lovely service.”

 functions deploy $FUNCTION_NAME --trigger-topic $TOPIC_NAME --runtime nodejs10 --set-env-vars OPEN_WEATHER_MAP_API_KEY=$OPEN_WEATHER_MAP_API_KEY,BQ_DATASET=$BQ_DATASET,BQ_TABLE=$BQ_TABLE

Our service is running in a bold and robust way

Function execution

There are some crucial parts to name on the function code:

We will use the temporary space of Cloud Functions as our launch zone. A more scalable approach could use Cloud Storage as a middle space for the data.

We are setting variables containing our env variables passed in the deployment command.

We are appending data into BigQuery in JSON format.

You have todelete the temporary space files. “Files that you write consume memory available… and sometimes persist between invocations. Failing to delete these files explicitly may eventually lead to an out-of-memory error”

What now?

Photo by William Krause on Unsplash

How to end this pipeline as a real ?

This particular stage depends totally on the data or insights you want to obtain. Felipe Hoffa illustrates different use cases and ideas using BigQuery; you can read his articles on Medium!

Query your table

Two options (clearly more).

First, remember the env variables? They are still util. If you run the next command, a query will be executed to count all the records on your table. If you complete the steps above correctly, you will see at least one entry.

 query --nouse_legacy_sql "SELECT COUNT(*) FROM $BQ_DATASET.$BQ_TABLE"
Query to BQ ss

Second, BigQuery on the GCP Console is also an enjoyable manner to explore and analyze your data.

Data Studio, the grand finale

Day to day, Google’s technological ecosystem proliferates. This project is a small -but concise- proof of how completed could be an end to end data solution built into this ecosystem.

I built a report on Data Studio and was a great and fast experience. Look it, just 20–30 minutes of learning by doing, and is connected directly to BigQuery! A big

Data Studio visualization

What’s next?

What about making the deployment process with fewer commands? The next article will be shorter (promise), with a similar focus, however, smarter, with .

Who inspired this article

Further readings

Entel Ocean

Abrimos infinitos caminos usando la tecnología y aceleramos la transformación de tu negocio.

Jose Valdebenito

Written by

Loving tech | Architecting with love | Software artisan

Entel Ocean

Abrimos infinitos caminos usando la tecnología y aceleramos la transformación de tu negocio.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade