Google Cloud

Dataflow / Apache Beam Guide: Unified Streaming and Batch Pipelines on GCP

2026-05-24
NicheeLab Editorial Team

Dataflow is Google Cloud's serverless data-processing service that runs pipelines written with the Apache Beam SDK as a managed workload. Its signature feature is the Unified model: the same code handles streaming and batch. It's the de facto standard for Pub/Sub to BigQuery ETL.

Apache Beam Unified Model

  • PCollection: Distributed dataset (shared by Streaming and Batch)
  • PTransform: Transformations (Map, Filter, GroupBy, etc.)
  • Pipeline: A chain of PTransforms
  • Runner: Execution engine (Dataflow / Spark / Flink / Direct)

Window / Trigger / Watermark

Window TypeUse Case
Fixed (Tumbling)Fixed intervals (e.g., aggregate every 1 minute)
SlidingOverlapping (5-minute windows every 1 minute)
SessionClosed on inactivity (e.g., user behavior)
GlobalNo window (batch-oriented)
  • Watermark: Beam estimates the boundary 'no data older than this will arrive'
  • Trigger: AfterWatermark / AfterProcessingTime / AfterCount
  • Late Data: How to handle data arriving after the Watermark (drop or re-aggregate)

Dataflow vs Dataflow Prime

  • Dataflow: Standard tier; Worker type is set manually
  • Dataflow Prime: Vertical Autoscaling (auto-tuned CPU/memory), Right-fitting (per-stage optimization), and built-in Streaming Engine

Key Features

  • Autoscaling: Automatic worker-count adjustment (especially effective for bursty streaming workloads)
  • Streaming Engine: Offloads state management to Dataflow, keeping workers lightweight
  • Dataflow Shuffle: Managed shuffle (especially effective for large batch jobs)
  • FlexRS: Uses Spot VMs for 40% cost savings (batch only)
  • Templates: Pre-built templates plus Flex Templates for customization
  • Notebooks integration: Develop directly from Vertex AI Workbench

Typical Pipeline: Pub/Sub to BigQuery

# Python Apache Beam
import apache_beam as beam
from apache_beam.options.pipeline_options import PipelineOptions, StandardOptions

options = PipelineOptions(streaming=True)

with beam.Pipeline(options=options) as p:
  (p
   | "Read from Pub/Sub" >> beam.io.ReadFromPubSub(topic='projects/PROJECT/topics/events')
   | "Parse JSON" >> beam.Map(lambda msg: json.loads(msg))
   | "Window" >> beam.WindowInto(beam.window.FixedWindows(60))
   | "Group by user" >> beam.GroupByKey()
   | "Write to BQ" >> beam.io.WriteToBigQuery(
       'PROJECT:dataset.events',
       schema='user_id:STRING,count:INTEGER,window_start:TIMESTAMP',
       write_disposition=beam.io.BigQueryDisposition.WRITE_APPEND)
  )

Pricing

ItemPrice (us-central1)
vCPU$0.069/h (Batch) / $0.075/h (Streaming)
Memory$0.0046/GB/h
Shuffle$0.011/GB (Batch) / $0.018/GB (Streaming Engine)
FlexRS (Spot)40% discount

Comparison with Other Tools

ItemDataflowDataproc (Spark)AWS Kinesis Data Analytics
ModelBeam (Unified)Spark / HadoopFlink
ServerlessHas Serverless mode
OSS compatibility○ (Beam OSS)◎ (Spark/Hadoop)○ (Flink)
PricingWorker timeCluster timeKPU time

Typical Use Cases

  • Real-time aggregation of IoT telemetry
  • Web logs to BigQuery streaming ETL
  • CDC (Datastream to Dataflow to BQ)
  • Fraud detection (Pub/Sub to Dataflow ML to alerts)
  • Audio/video pipelines (GCS to Dataflow to ML)

How are Dataflow and Apache Beam related?

Apache Beam is an open-source unified programming model, and Dataflow is Google's managed version of its Runner (execution engine). The same Beam code can also run on Spark or Flink.

What is the difference between Streaming and Batch?

Streaming pulls data continuously from Pub/Sub, while Batch reads once from GCS or BigQuery. The same Beam pipeline handles both (the Unified model).

What are Window, Trigger, and Watermark?

Window groups data over a time range, Trigger decides when to emit results, and Watermark defines the boundary for late data. These are the three core concepts of streaming processing.

What is Dataflow Prime?

An enhanced version of Dataflow with Vertical Autoscaling (automatic resource tuning), Right-fitting, and improved shuffle. Especially effective for complex pipelines.

How is Dataflow priced?

You pay for Worker time (vCPU + memory + storage) plus Shuffle data and Streaming Engine data. Streaming runs around the clock and gets expensive, so the Autoscaler is essential for keeping costs down.

How does it compare to Apache Spark?

Spark is a processing engine, while Beam is a programming model plus a Runner abstraction. Dataflow's strength is serverless management; Spark on Dataproc's strength is OSS compatibility.

What are Dataflow Templates?

Pre-built templates from Google (Pub/Sub to BQ, GCS to BQ, and more). You can run them from the UI without writing code, and Flex Templates let you customize them.

How do I debug and monitor Dataflow jobs?

Use the Dataflow UI graph view, Worker Metrics, Cloud Profiler integration, and Dataflow Insights for automatic diagnostics.

Related Articles: Data Processing

Pub/Sub 完全ガイド|料金・Push vs Pull・Ordering Key・Kafka 比較 (GCP)

Google Cloud Pub/Sub の全機能解説。Push vs Pull、Ordering Key、Exactly-once、Dead Letter、Schema Registry、Pub/Sub Lite、AWS SNS/SQS / Kafka 比較、料金体系を網羅。

GCP Professional Cloud Developer (PCD) 完全ガイド|Cloud Run・GKE・CI/CD・APM

Google Cloud Professional Cloud Developer の試験範囲、Cloud Run / GKE / Cloud Build / Cloud Trace、AWS DVA / Azure AZ-204 比較、学習ロードマップを徹底解説。

App Engine 完全ガイド|Standard vs Flexible・料金・Cloud Run 比較 (GCP)

Google App Engine の Standard と Flexible の違い、料金、Traffic Splitting、Cron、Cloud Run / Cloud Functions との使い分け、AWS Elastic Beanstalk / Azure App Service 比較を徹底解説。

BigQuery 入門|サーバレス DWH の全機能・料金・他クラウド比較

Google Cloud BigQuery の基礎から実装まで。サーバレスアーキテクチャ、料金モデル (オンデマンド / Editions)、BigQuery ML、Pub/Sub 連携、Snowflake / Redshift / Synapse との比較を解説。

Google Cloud and Apache Beam are trademarks of their respective owners. For the latest information, see the official Dataflow docs.

Check what you learned with practice questions

Practice with certification-focused question sets

Visit the GCP exam prep page
Author

NicheeLab Editorial Team

NicheeLab editorial team focused on data engineering and cloud certification learning. Content is structured around practical study needs and official exam domains.


Related articles
Google Cloud

Google Cloud Certification Roadmap (2026)

Choose your GCP certification path — Foundational, Associate...

Google Cloud

CDL Cloud Digital Leader: Complete Exam Guide (2026)

Pass the Cloud Digital Leader exam — cloud business value, G...

Google Cloud

GAIL Generative AI Leader: Complete Exam Guide (2026)

Pass the Generative AI Leader exam — Gemini, Vertex AI, Work...

Google Cloud

Vertex AI Fundamentals for GCP Certs (2026)

Vertex AI basics every cert candidate needs — Workbench, Pip...

Google Cloud

Associate Cloud Engineer (ACE): Complete Guide (2026)

Pass the Associate Cloud Engineer exam — Console, gcloud, pr...

Browse all Google Cloud articles (103)
© 2026 NicheeLab All rights reserved.