Table of Contents

What is an ETL pipeline?

Before we dive into building pipelines with GCP Dataflow and Apache Beam, let’s understand what an ETL pipeline actually is. ETL, which stands for Extract, Transform, Load, serves as the backbone for data-driven decisions in modern enterprises. Initially devised for combining data from multiple systems into a single repository, ETL processes have evolved to meet the demands of today’s cloud-centric world.

GCP Dataflow, ETL pipeline, Apache Beam, Tutorial, Setup

How ETL Works

  • Extraction: Retrieve data from various sources like online databases, on-premises systems, or SaaS applications.
  • Transformation: Clean and format the extracted data for uniformity.
  • Loading: Insert the transformed data into the target data store or database.

What is an ETL pipeline used for?

Here are a few mot common uses of ETL pipelines for business that process large amounts of data.

Data Warehousing: One of the most common applications of ETL is to populate data warehouses. Here, data from disparate sources is unified for collective analysis, helping businesses to make informed decisions.

Machine Learning and Artificial Intelligence: ETL pipelines can move data into centralized locations, where machine learning algorithms can learn and make predictions or classifications based on that data.

Cloud Migration: As companies transition from on-premises solutions to cloud storage, ETL pipelines play a critical role in moving and optimizing data for cloud migration.

When it comes to building ETL pipelines, Google Cloud Platform (GCP) offers a trio of robust services: Cloud Data Fusion, Dataflow, and Dataproc. In this article, however, we’re honing in on Google’s Dataflow service and its seamless integration with Apache Beam.

What is GCP Dataflow?

Google Cloud Platform (GCP) introduces Dataflow as a robust, serverless solution engineered to cater to your Extract-Transform-Load (ETL) needs. This fully managed data processing service excels at executing both batch and streaming data pipelines.

With its intrinsic compatibility with Apache Beam, Dataflow offers a unified approach to data ingestion, transformation, and egress, letting you construct complex pipelines that scale with your business needs.

How Does GCP Dataflow Architecture Work?

Dataflow adopts an architecture designed around the concept of pipelines. These pipelines consist of a series of stages that handle everything from ingestion to transformation and eventual storage.

Upon initiating a Dataflow job, Google takes the reins by allocating a pool of worker VMs. These virtual machines operate in concert to execute the pipeline, dynamically distributing workloads to ensure efficient, parallel data processing.

GCP Dataflow, ETL pipeline, Apache Beam, Tutorial, Setup
  1. Pub/Sub: Serves as the ingestion layer, collecting data from various external systems.
  2. Dataflow: Reads this data, possibly transforming or aggregating it, and then writes it to BigQuery.
  3. BigQuery: Acts as your data warehouse, storing the transformed data.
  4. Looker: Looker studio Provides real-time Business Intelligence insights from BigQuery.

In simpler scenarios, Dataflow templates can be used to execute pre-defined pipelines. For more complex needs, starting with the Apache Beam SDK is recommended.

Batch vs Stream Processing Jobs in Dataflow

Dataflow gives you the flexibility to choose between two types of processing jobs: Batch and Stream.

  • Batch Jobs: Ideal for scenarios where data is available in finite sets and doesn’t require real-time processing. For instance, if you have a file that needs to be processed once a day, a batch job would suffice.
  • Stream Jobs: Tailored for real-time data analytics, stream jobs continuously monitor for data (say, in a GCS Bucket) and process it as it arrives. This is particularly useful for time-sensitive applications like real-time analytics or IoT sensor data processing.

What is Apache Beam?

Apache Beam is a versatile, open-source programming model designed to simplify the complex task of large-scale data processing. Evolving from various Apache projects, it allows you to focus on formulating your data processing logic while it takes care of the operational challenges.

How Apache Beam Works with GCP Dataflow

\When you choose Dataflow as your runner, it translates the Apache Beam pipeline into an API format that’s compatible with its own backend for distributed data processing. The seamless integration between Apache Beam and Dataflow offers a managed, scalable, and cost-effective solution for constructing complex ETL workflows.

GCP Dataflow, ETL pipeline, Apache Beam, Tutorial, Setup

Key Features of Apache Beam

  1. Multi-language Support: Apache Beam currently supports Java, Python, and Go SDKs, offering flexibility in the choice of language for building pipelines.
  2. Multiple Runners: Besides GCP Dataflow, it can work with several other runners like Apache Flink, Apache Nemo, and Apache Spark, providing you with the flexibility to switch distributed processing backends without having to rewrite your code.
  3. Extensive Input Options: The model can take input from multiple sources, whether it be from a batch data source or a real-time streaming source, offering a wide range of data processing possibilities.

Building an ETL pipeline with Apache Beam and GCP Cloud Dataflow


Before diving into the hands-on tutorial for building an Apache Beam Pipeline with GCP Dataflow, it’s imperative to set the stage with a proper environment and required dependencies. These prerequisites serve the purpose of smoothening your learning curve, ensuring you can focus solely on building and optimizing your Dataflow pipeline.

Install the Apache Beam SDK

First and foremost, you’ll need to install the Apache Beam SDK. This SDK is an open-source programming model that allows you to define data pipelines. With Apache Beam, you can choose Dataflow as a runner to execute your pipeline.

Note: If you were using the Dataflow SDK, be aware that it has been deprecated, and the Dataflow service now fully supports official Apache Beam SDK releases.

For Java Users

The latest released version of Apache Beam SDK for Java is 2.50.0. The source code for Apache Beam can be found on Github. Add the following dependencies to your pom.xml:


Initialize Google Cloud Environment

1. Google Cloud CLI

Before running any GCP-based project, you need to install the Google Cloud CLI and initialize it by running the gcloud init command

2. Project Setup

Create or select a Google Cloud Project:

gcloud projects create PROJECT_ID
gcloud config set project PROJECT_ID
  • Ensure that billing is enabled for your project.

3. Enable Required APIs

Run the following command to enable the Dataflow, Datastore, Compute Engine, Storage Transfer, and other necessary APIs:

gcloud services enable dataflow compute_component logging storage_component storage_api bigquery pubsub

4. Authentication

Authenticate your Google account:

gcloud auth application-default login

5. Set IAM Roles

Grant necessary roles to your Google Account:

gcloud projects add-iam-policy-binding PROJECT_ID --member="user:EMAIL_ADDRESS" --role=ROLE

Create a Google Cloud Storage Bucket

Create a bucket with the standard storage class and set its location to the United States.

gsutil mb -c STANDARD -l US gs://BUCKET_NAME

Grant roles to your Compute Engine default service account.

Run the following command once for each of the following IAM roles: roles/dataflow.adminroles/dataflow.worker, and roles/storage.objectAdmin.

gcloud projects add-iam-policy-binding PROJECT_ID --member="" --role=SERVICE_ACCOUNT_ROLE

Copy the following, as you need them in a later section:

  • Your Cloud Storage bucket name.
  • Your Google Cloud project ID.

Run the pipeline on the Dataflow service

To deploy the pipeline, in your shell or terminal, build and run the WordCount pipeline on the Dataflow service from your word-count-beam directory:

mvn -Pdataflow-runner compile exec:java \
    -Dexec.mainClass=org.apache.beam.examples.WordCount \
    -Dexec.args="--project=PROJECT_ID \
    --gcpTempLocation=gs://BUCKET_NAME/temp/ \
    --output=gs://BUCKET_NAME/output \
    --runner=DataflowRunner \

View your results

  1. In the Google Cloud console, go to the Dataflow Jobs page. The Jobs page shows the details of all the available jobs, including the status. The wordcount job’s Status is Running at first, and then updates to Succeeded
GCP Dataflow, ETL pipeline, Apache Beam, Tutorial, Setup

2. In the Google Cloud console, go to the Cloud Storage Browser page. The Browser page displays the list of all the storage buckets in your project.

GCP Dataflow, ETL pipeline, Apache Beam, Tutorial, Setup, Cloud Storage Browser

3. Click the storage bucket that you created. The Bucket details page shows the output files and staging files that your Dataflow job created.

GCP Dataflow, ETL pipeline, Apache Beam, Tutorial, Setup, Bucket

FAQs and Also Asked

This FAQ section aims to address some common questions and misconceptions, along with providing troubleshooting tips.

Is Apache Beam only for Big Data?

While Apache Beam is particularly beneficial for big data applications, it’s flexible enough to be useful for small to medium data sets as well.

Do I need to know Java to work with Apache Beam?

Although Java is one of the languages supported by Apache Beam, it also has SDKs for Python and Go, allowing you to build pipelines in those languages as well.

Is Dataflow expensive?

The cost of using Dataflow varies depending on the complexity and scale of your data processing tasks. Google Cloud Platform offers various pricing options to suit different requirements.

My Dataflow job is stuck. What should I do?

Check the job logs for any errors. Ensure that your pipeline isn’t trying to read from an empty or non-existent data source. Verify quotas and limits in your Google Cloud Console.

Why am I getting OutOfMemoryError in Apache Beam?

This could happen when your pipeline is trying to process a data set larger than the allocated memory. Consider partitioning your data or increasing the memory allocated to your pipeline.

My pipeline is too slow. How can I optimize it?

Optimizing your pipeline often involves tweaking its parallelism settings, adjusting window sizes, or even restructuring the pipeline to avoid performance bottlenecks.


From understanding the basic architecture to dispelling common misconceptions and tackling technical glitches, we’ve covered a broad spectrum of topics. Our aim has been to provide you a comprehensive guide that not only answers your pressing questions but also prepares you to troubleshoot issues with confidence.

The beauty of Apache Beam lies in its flexibility and interoperability, while GCP Dataflow offers the scalability and management ease that most businesses desire. Together, they form a potent combination that can handle both batch and real-time data processing requirements.

A Special Note on Cloud Costs

If you’re grappling with rising cloud costs month-over-month and can’t pinpoint why, it might be time to consider a more holistic approach. Economize offers a free demo that can help you understand how to cut your cloud costs by up to 30% in less than 5 minutes. Take the free demo today and see the difference that expertise can make.

Thank you for reading, and we wish you success in your data processing endeavors!

Adarsh Rai

Adarsh Rai, author and growth specialist at Economize. He holds a FinOps Certified Practitioner License (FOCP), and has a passion for explaining complex topics to a rapt audience.

Related Articles