TECHNOLOGIESTieInn Technologies

Dataflow and Apache Beam

GCP · 13 questions

Short notes

Key idea

Dataflow is Google's managed runner for Apache Beam pipelines. You write one pipeline in Python or Java that works for batch or streaming; Dataflow starts and scales the workers for you.

Syntax

import apache_beam as beam
with beam.Pipeline(options=opts) as p:
    (p | beam.io.ReadFromText("gs://raw/orders/*.csv")
       | beam.Map(parse)
       | beam.Filter(lambda r: r["amount"] > 0)
       | beam.io.WriteToBigQuery("proj:sales.orders"))
  • PCollection: a dataset in the pipeline; PTransform: a step (Map, Filter, GroupByKey, CombinePerKey).
  • Streaming: windows (fixed, sliding, session), watermarks and triggers for late data.
  • Google-provided templates for common jobs (Pub/Sub → BigQuery).

Example

A streaming job reads orders from Pub/Sub, groups them into 1-minute fixed windows, sums revenue per city and writes to BigQuery: a live dashboard with no servers.

Traps

  • Late data: without allowed lateness it's dropped; set a policy.
  • Hot keys (one city with most events) slow GroupByKey; use combiners.
  • Streaming jobs run, and bill, until you stop them.
  • For simple batch SQL work, BigQuery alone is cheaper and easier.

Want the full lesson with step-by-step examples, a project and a certificate? GCP course, ₹120 →

Questions

5 free questions
5 questions

    Dataflow and Apache Beam

  1. Question 1easy

    What is the relationship between Apache Beam and Dataflow?

  2. Dataflow and Apache Beam

  3. Question 2medium

    Why do streaming pipelines need windows to compute "revenue per city"?

  4. Dataflow and Apache Beam

  5. Question 3hard

    A phone loses network and sends an order event placed at 10:00:50 at 10:03:00. With 1-minute event-time windows and 5 minutes allowed lateness, which window counts it?

  6. Dataflow and Apache Beam

  7. Question 4medium

    You need a nightly job that aggregates yesterday's orders already in BigQuery. What's simplest?

  8. Dataflow and Apache Beam

  9. Question 5medium

    You want to group a user's clicks into visits that end after 30 minutes of inactivity. Which window?

8 more questions on this topic, with hints, and tests

Sign up free for 21 days of every question and test.