Data Pipelines on GCP: Pub/Sub, Dataflow, Dataproc, Cloud Composer, Data Fusion and Choosing the Right Tool
Batch and Streaming
| Batch | Streaming | |
|---|---|---|
| Data | Collected and processed in chunks (hourly, nightly) | Processed event by event as it arrives |
| Latency | Minutes to hours | Seconds |
| Example | Nightly sales report | Fraud alert on a card swipe |
Pub/Sub: Messaging
- A global, serverless messaging service that decouples producers and consumers
- Topic receives messages. Subscriptions deliver them. Each subscription gets its own copy (fan-out)
- Pull (the app asks), push (Pub/Sub calls an HTTPS endpoint), BigQuery and Cloud Storage subscriptions (write directly, no code)
- At-least-once delivery by default, optional exactly-once and ordering keys, dead-letter topics, message retention up to 31 days with replay
- Scales to millions of messages per second
bash
gcloud pubsub topics create orders
gcloud pubsub subscriptions create orders-bq --topic=orders --bigquery-table=my-proj:sales.orders_stream --use-table-schema
gcloud pubsub subscriptions create orders-worker --topic=orders --ack-deadline=30 --dead-letter-topic=orders-dlq --max-delivery-attempts=5
gcloud pubsub topics publish orders --message='{"orderId": 42, "amount": 499}'
gcloud pubsub subscriptions pull orders-worker --auto-ack --limit=5
Dataflow
- Fully managed service for Apache Beam pipelines, for batch and streaming with the same code
- Autoscaling, exactly-once processing, windowing and watermarks for late data
- Ready templates (for example Pub/Sub to BigQuery, Cloud Storage text to BigQuery) need no code
bash
gcloud dataflow jobs run orders-to-bq --gcs-location=gs://dataflow-templates-asia-south1/latest/PubSub_Subscription_to_BigQuery \
--region=asia-south1 --parameters=inputSubscription=projects/my-proj/subscriptions/orders-worker,outputTableSpec=my-proj:sales.orders_stream
python
import apache_beam as beam
with beam.Pipeline() as p:
(p | "Read" >> beam.io.ReadFromText("gs://acme-reports-482/words.txt")
| "Split" >> beam.FlatMap(lambda line: line.split())
| "Pair" >> beam.Map(lambda w: (w, 1))
| "Count" >> beam.CombinePerKey(sum)
| "Write" >> beam.io.WriteToText("gs://acme-reports-482/out/counts"))
Dataproc
- Managed Spark, Hadoop, Hive, Flink clusters that start in about 90 seconds
- Best to migrate existing Hadoop/Spark jobs with few changes
- Use ephemeral clusters (create, run job, delete) and preemptible/Spot workers to save money, or Dataproc Serverless for no cluster
bash
gcloud dataproc clusters create etl --region=asia-south1 --num-workers=2 --image-version=2.2-debian12
gcloud dataproc jobs submit pyspark gs://acme-code/job.py --cluster=etl --region=asia-south1
gcloud dataproc clusters delete etl --region=asia-south1 --quiet
Orchestration: Cloud Composer
- Managed Apache Airflow to schedule and chain tasks as DAGs (what runs first, retries, alerts)
- Use it when a pipeline has many steps across services (load, transform, check, notify)
- Lighter options: Workflows, Cloud Scheduler, Cloud Run jobs
python
from airflow import DAG
from airflow.providers.google.cloud.operators.bigquery import BigQueryInsertJobOperator
from datetime import datetime
with DAG("daily_sales", start_date=datetime(2026, 11, 1), schedule="0 2 * * *", catchup=False) as dag:
BigQueryInsertJobOperator(task_id="build_summary", configuration={"query": {"query": "CALL sales.build_daily_summary()", "useLegacySql": False}})
Other Tools
| Tool | What it is |
|---|---|
| Cloud Data Fusion | Visual, drag-and-drop ETL (based on CDAP) |
| Datastream | Serverless change data capture from MySQL, PostgreSQL, Oracle into BigQuery or Cloud Storage |
| Dataform / BigQuery pipelines | SQL-based transformations in BigQuery (ELT) |
| Dataplex | Data governance, quality, lineage and catalog across lakes and warehouses |
| Looker / Looker Studio | BI and dashboards |
Reference Architecture: Streaming Analytics
text
Apps / IoT ─► Pub/Sub ─► Dataflow (clean, window, enrich) ─► BigQuery ─► Looker dashboards
└─► raw copy to Cloud Storage (data lake)
Cloud Composer schedules nightly Dataproc or BigQuery jobs; Dataplex governs data
Choosing
| Need | Choose |
|---|---|
| Ingest and fan out events | Pub/Sub |
| Stream or batch transform with managed scaling | Dataflow |
| Run existing Spark/Hadoop code | Dataproc |
| Schedule many dependent tasks | Cloud Composer or Workflows |
| No-code ETL | Data Fusion |
| Replicate database changes | Datastream |
| SQL transformations inside the warehouse | BigQuery / Dataform |
Practice
- Create a topic with a BigQuery subscription and publish three messages
- Run a Dataflow template from Pub/Sub to BigQuery
- Describe a nightly batch pipeline and a streaming pipeline for the same shop
- Pick tools for a company with many Spark jobs on-premises
Conclusion
Pub/Sub ingests events, Dataflow processes batch and streaming, Dataproc runs Spark and Hadoop, Composer orchestrates and BigQuery stores analytics. Choose by whether you are moving existing code, building new pipelines or scheduling.
Quick Summary: batch vs streaming; Pub/Sub; Dataflow; Dataproc; Composer; other; architecture; choosing.

