nerdexam
Google

PROFESSIONAL-DATA-ENGINEER · Question #251

You are analyzing the price of a company's stock. Every 5 seconds, you need to compute a moving average of the past 30 seconds' worth of data. You are reading data from Pub/Sub and using DataFlow to…

The correct answer is D. Use a sliding window with a duration of 30 seconds and a period of 5 seconds. Option D correctly matches both requirements: a 30-second duration captures the full lookback window needed for the moving average, and a 5-second period controls how often a new window is emitted - this is precisely what a sliding window is designed for, producing overlapping…

Submitted by thandi_sa· Mar 30, 2026Designing data processing systems

Question

You are analyzing the price of a company's stock. Every 5 seconds, you need to compute a moving average of the past 30 seconds' worth of data. You are reading data from Pub/Sub and using DataFlow to conduct the analysis. How should you set up your windowed pipeline?

Options

  • AUse a fixed window with a duration of 5 seconds. Emit results by setting the following trigger:
  • BUse a fixed window with a duration of 30 seconds. Emit results by setting the following trigger:
  • CUse a sliding window with a duration of 5 seconds. Emit results by setting the following trigger:
  • DUse a sliding window with a duration of 30 seconds and a period of 5 seconds.

How the community answered

(45 responses)
  • A
    11% (5)
  • B
    2% (1)
  • C
    4% (2)
  • D
    82% (37)

Explanation

Option D correctly matches both requirements: a 30-second duration captures the full lookback window needed for the moving average, and a 5-second period controls how often a new window is emitted - this is precisely what a sliding window is designed for, producing overlapping windows that advance at a fixed interval.

Why the distractors fail:

  • A uses a 5-second fixed window, capturing only 5 seconds of data - far too short for a 30-second average, and fixed windows don't overlap.
  • B uses a 30-second fixed window with the right duration but wrong frequency - fixed windows are non-overlapping, so results would only emit every 30 seconds, not every 5.
  • C uses a sliding window but with only a 5-second duration, capturing the wrong amount of data; the slide interval is irrelevant if the window itself is too narrow.

Memory tip: Match the terms directly to the formula - "moving average of X seconds, every Y seconds" = sliding window with duration=X, period=Y. If you ever see "moving average" or "rolling window" in an exam question, reach for a sliding window first, then map duration to the lookback and period to the emission frequency.

Topics

#Dataflow#Apache Beam#Windowing#Streaming Analytics

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-DATA-ENGINEER Practice