Skip to content
Visual explainer 3h to learn 5 steps

Choose Dataflow, managed Spark or Cloud Composer pipelines

Pick Dataflow, Managed Service for Apache Spark (formerly Dataproc) or Cloud Composer for a batch and a streaming scenario and design for schema change and idempotent sinks.

By Invicly Tech, , in Google Cloud Engineering and Services. About 9 minutes to read.

Topic 20 of 32

In short

Google Cloud has several ways to move and transform data. Dataflow runs Apache Beam pipelines for batch and streaming, Managed Service for Apache Spark (formerly Dataproc) runs Spark and Hadoop jobs, and Cloud Composer schedules and orders jobs. Pick by workload, not by habit.

Explained simply

A data pipeline moves data from where it is made to where it is used, and changes it on the way. Google Cloud has a few services for this. They overlap, so it helps to know what each is best at.

Dataflow runs pipelines written with Apache Beam. The same Beam code can process a file once (batch) or an endless stream of messages from Pub/Sub. Dataflow starts and stops the workers for you.

Managed Service for Apache Spark, formerly called Dataproc, runs Spark and Hadoop jobs on clusters. It is a good fit when you already have Spark code or need that ecosystem. It is more hands-on than Dataflow because you think about clusters.

Cloud Composer is managed Apache Airflow. It does not crunch data itself. It runs a workflow that says: load the file, then start the transform, then run a BigQuery query, then tell me if anything failed.

Whatever you choose, plan for two things. Data will change shape, and messages will sometimes arrive twice. Handle both and your pipeline stays calm instead of waking you at night.

Press Play on a diagram to walk through it one step at a time.

CompareWhich service for which job
Dataflow
  • Apache Beam code
  • Batch and streaming
  • Fully managed workers
  • Good with Pub/Sub and BigQuery
Managed Spark
  • Spark and Hadoop jobs
  • Reuse existing Spark code
  • You choose cluster shape
  • Good for migrations
Cloud Composer
  • Managed Apache Airflow
  • Runs DAGs on a schedule
  • Orders and retries tasks
  • Calls other services; not a processor
LayersWho does what in a data platform
  1. 1
    Cloud Composer

    Schedules and orders the work

  2. 2
    Dataflow or managed Spark

    Does the transform

  3. 3
    Pub/Sub or Cloud Storage

    Supplies the input

  4. 4
    BigQuery

    Stores the result

In depth

Dataflow for batch and streaming

A Beam pipeline reads from a source, applies transforms and writes to a sink. In batch the input is bounded, like files in Cloud Storage. In streaming it is unbounded, like a Pub/Sub subscription. Streaming pipelines group events into time windows, and a watermark tracks how late data may arrive. Dataflow autoscales workers. Streaming jobs keep running and are billed while they run, so cancel test jobs. You can launch from a template without writing code.

  • Bounded input is batch; unbounded is streaming
  • Windows group events by time
  • Late data is handled with watermarks and triggers
  • Cancel or drain streaming test jobs to stop charges
FlowA streaming pipeline
  1. 1
    Pub/Sub subscription
  2. 2
    Parse and validate
  3. 3
    Window by minute
  4. 4
    Aggregate
  5. 5
    Write to BigQuery
  6. 6
    Bad records to dead-letter table

Choosing between the three

Start from the work, not the tool. New streaming or batch transforms with no Spark history suit Dataflow. A migration of existing Spark jobs suits managed Spark. Simple jobs that only need SQL can often run as scheduled BigQuery queries, with no extra service. When many steps must run in order across services, add Composer. Composer environments run all the time and have a base cost, so a single small job rarely justifies one.

  • SQL only: scheduled BigQuery queries
  • Beam code or streaming: Dataflow
  • Existing Spark: managed Spark
  • Many ordered steps: Composer on top

Schema change and duplicate writes

Producers add fields over time. Prefer additive changes: new nullable fields that old readers can ignore. Validate each record and send failures to a dead-letter table with the error, so one bad row does not stop the job. For duplicates, assume at-least-once delivery. Give every record a stable id and write with MERGE or by deduplicating on that id. That makes the sink idempotent: running the same input twice leaves the same result.

  • Add nullable fields; avoid renames and type changes
  • Dead-letter bad records with the reason
  • Use a unique id per record
  • MERGE or dedupe at the sink

Learn it in 5 short steps

About 35m each. Track them with a timer in your plan.

  1. 1
    Run a batch pipeline on Dataflow~35m
  2. 2
    Process a stream from Pub/Sub~35m
  3. 3
    Know when managed Spark fits~35m
  4. 4
    Orchestrate with Cloud Composer~35m
  5. 5
    Handle schema change and duplicate writes~35m

Key points

  • Dataflow runs Beam pipelines. One pipeline can be bounded (batch) or unbounded (a stream from Pub/Sub).
  • Managed Spark fits teams that already have Spark code or need libraries from the Spark and Hadoop ecosystem.
  • Cloud Composer does not process data itself. It runs workflows (DAGs) that start Dataflow, Spark, BigQuery or other jobs in order.
  • Schema changes will happen. Add nullable fields, validate input, and send bad records to a dead-letter table instead of failing the whole job.
  • Streams and retries can deliver a record twice. Make sinks idempotent, for example by merging on a unique key.

Key terms

Tap a card to flip it. 0/5 known

Examples

Run a batch pipeline on Dataflow, then clean up

Prerequisites: Dataflow, Compute Engine and Cloud Storage APIs enabled, billing on, and a bucket for temp files. Use Google's public WordCount template so there is no code to write. Expected evidence: the job reaches the Succeeded state in the Dataflow console and output files appear in your bucket. Cleanup: delete the output files and the bucket. Dataflow uses paid workers, so a short batch job costs a small amount.

bash
gcloud dataflow jobs run wordcount-demo \
  --gcs-location=gs://dataflow-templates/latest/Word_Count \
  --region=us-central1 \
  --parameters=inputFile=gs://dataflow-samples/shakespeare/kinglear.txt,output=gs://example-bucket/out/wc
gcloud dataflow jobs list --region=us-central1
gcloud storage ls gs://example-bucket/out/
# cleanup
gcloud storage rm -r gs://example-bucket/out/

Make a BigQuery sink idempotent with MERGE

A stream retried a message, so the staging table holds the same order twice. Deduplicate staging by order_id, then merge into the final table. Run it twice: the final table is the same both times. Expected evidence: the row count of the final table does not grow on the second run. This uses synthetic tables you create yourself.

sql
MERGE shop_demo.orders_final AS t
USING (
  SELECT * EXCEPT(rn) FROM (
    SELECT *, ROW_NUMBER() OVER (
      PARTITION BY order_id ORDER BY received_at DESC) AS rn
    FROM shop_demo.orders_staging)
  WHERE rn = 1) AS s
ON t.order_id = s.order_id
WHEN MATCHED THEN UPDATE SET total = s.total
WHEN NOT MATCHED THEN
  INSERT (order_id, total) VALUES (s.order_id, s.total);

Quick reference

  • Dataflow runs Apache Beam; one model for batch and streaming
  • Managed Service for Apache Spark (formerly Dataproc) suits existing Spark code
  • Cloud Composer is managed Airflow; it orders tasks, not heavy data
  • Scheduled BigQuery queries are enough for SQL-only transforms
  • Assume at-least-once delivery; dedupe on a unique id
  • Add nullable fields; avoid renaming or retyping columns
  • Route bad records to a dead-letter table
  • Cancel or drain test streaming jobs to stop charges

Common mistakes

  • Using Composer to move large data through its own workers. It should trigger other services, not do the heavy work.
  • Appending streaming rows with no unique key, then finding duplicates after a retry.
  • Failing the whole pipeline on one malformed record instead of routing it to a dead-letter table.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1A team has 200 existing Spark jobs to move to Google Cloud. What fits best?

Question 2

2What does Cloud Composer mainly provide?

Question 3

3A stream retries and inserts the same order twice. What is the best fix?

Question 4

4Which schema change is safest for old readers?

Question 5

5What is a bounded data source?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Name the best service for each: (a) nightly SQL summary, (b) live clickstream, (c) 200 Spark jobs.

  2. Exercise 2medium

    Write the stages of a pipeline that reads JSON from Pub/Sub and handles bad records safely.

  3. Exercise 3hard

    Design a daily workflow in Composer: load a file, transform, check row count, notify on failure.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

Is Dataproc gone?
The service is now called Managed Service for Apache Spark, formerly Dataproc. Check the current docs for exact product names and commands.
Do I need Composer for one job?
Usually not. A scheduled query or Cloud Scheduler plus a service is simpler. Use Composer when many ordered steps need retries and monitoring.
Can Dataflow guarantee no duplicates?
Dataflow gives strong processing guarantees inside the pipeline, but sources and sinks can still repeat data. Design the sink to be idempotent.

Go deeper

ShareXLinkedInWhatsApp