Dataflow and Apache Beam
Professional Data Engineer · Lesson 8 of 23 · 55:01
YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗
Learning with these videos? Subscribe for new courses and exam-style questions.
Subscribe on YouTube (opens in a new tab)In this lesson
Prepare for the Google Cloud Professional Data Engineer exam, on the official exam guide. In this lesson: Apache Beam and Dataflow, fixed, sliding, and session windows, event time, watermarks, allowed lateness, and late data, triggers, and processing guarantees. Includes three original practice questions, with Cymbal Mobility, a fictional ride-hailing and scooter company, as the example.
Study notes
The text of this lesson, to read at your own pace. Information as of November 2026.
Late events, right numbers
Cymbal Mobility wants the number of rides per city every five minutes, a running average of scooter speed, and each rider's app sessions. Phones lose signal in tunnels, and send their events minutes late. The numbers must still be right.
Beam and Dataflow
Apache Beam is an open source model for batch and streaming pipelines, and Dataflow is the managed service that runs them. A pipeline reads a PCollection, a data set that can be bounded, like files, or unbounded, like a stream, and applies transforms to it. ParDo processes each element, to parse, clean, or filter it, GroupByKey and Combine aggregate, and side inputs bring in small reference data, like the list of cities. The same code can run in batch or streaming, and Dataflow manages the workers, scales them automatically, and retries failures. Cleansing happens here too: invalid elements go to a separate output, a dead-letter pattern, instead of failing the job.
Windows
In a stream, aggregations need windows. Fixed windows cut time into equal intervals that do not overlap, like the rides per city every five minutes. Sliding windows overlap: a one-hour window that starts every five minutes gives a running average. Session windows are per key, and close after a quiet gap, like a rider's app session that ends after ten minutes without events. And the single global window, the default, suits batch data; in a stream, it needs a trigger to produce results.
Watermarks and late data
Each event has an event time, when it happened, and a processing time, when the pipeline sees it, and events do not always arrive in order. The watermark is the pipeline's estimate of when all the data for a window has arrived. Once the watermark passes the end of a window, an event that belongs to it is late data. By default, late data is dropped, but an allowed lateness keeps the window open for late events, for example for two hours. Take the event time from the data itself, not from the arrival time, so a late event still counts in the right window.
Triggers and guarantees
Triggers decide when a window emits its results. The default trigger fires when the watermark passes the end of the window, then again for each late event that is allowed. Early triggers give speculative results, for example every minute, before the window closes, and the accumulation mode decides whether each new result includes earlier events, or only the new ones. In Dataflow, batch pipelines always process exactly once, and streaming pipelines do too by default, with no repeats in the results. When some repeats are acceptable, at-least-once mode lowers cost and latency.
Recap
Let's recap. Beam pipelines apply transforms to PCollections, bounded or unbounded, and Dataflow runs them, with autoscaling and retries. Fixed windows do not overlap, sliding windows do, session windows close after a gap for each key, and the global window is the default. The watermark gives an estimate of when a window is complete, and allowed lateness keeps it open for late events, which are otherwise dropped. Triggers decide when results are emitted, and the accumulation mode decides whether results include earlier events. And Dataflow processes exactly once by default, with at-least-once mode when repeats are acceptable.
Quick checks for this lesson
The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.
The fraud team wants, for each rider, the events of each app session, and a session ends when the app sends nothing for ten minutes. Which window fits?
- Fixed windows of ten minutes
- Sliding windows of ten minutes, every minute
- Session windows with a ten-minute gap
- The single global window
Show the answer
Session windows with a ten-minute gap
Session windows are per key, and a new window starts after a gap of ten minutes without events. “Fixed windows of ten minutes” would cut sessions at fixed times, so one session could fall into two windows. “Sliding windows of ten minutes, every minute” would put each event in several overlapping windows. And “The single global window” would keep everything in one window, with no sessions at all.
Trips recorded in tunnels reach the pipeline up to forty minutes late, and they are dropped from the five-minute counts. What should the data engineer change?
- Switch to processing-time timestamps
- Set an allowed lateness of about an hour
- Use shorter, one-minute windows
- Turn on exactly-once delivery in Pub/Sub
Show the answer
Set an allowed lateness of about an hour
An allowed lateness of about an hour keeps each window open for those late events, so they update the counts. “Switch to processing-time timestamps” would count each trip at its arrival time, in the wrong window. “Use shorter, one-minute windows” would only make windows shorter, and the events would still be late. And “Turn on exactly-once delivery in Pub/Sub” only prevents repeats, and does nothing for late events.
The city dashboard shows hourly ride counts, but operations wants an updated count every minute during the hour, including all of the hour’s rides so far. What should the data engineer configure?
- Fixed windows of one minute
- An early trigger every minute, in discarding mode
- At-least-once streaming mode
- An early trigger every minute, in accumulating mode
Show the answer
An early trigger every minute, in accumulating mode
An early trigger fires every minute, and accumulating mode makes each result include all the rides so far in the hour. “Fixed windows of one minute” would count each minute on its own, never the whole hour. “An early trigger every minute, in discarding mode” would fire every minute, but each result would only hold the new rides. And “At-least-once streaming mode” only changes how repeats are handled.