CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-5-QUESTIONS practice question 3 of 25

44 of 55. A data engineer is working on a real-time analytics pipeline using Spark Structured Streaming. They want the system to process incoming data in micro-batches at a fixed interval of 5 seconds. Which code snippet fulfills this requirement?

Full set: 135 questions
Answer options
A:

A. query = df.writeStream \ .outputMode("append") \ .trigger(processingTime="5 seconds") \ .start()

Correct answer
B:

B. query = df.writeStream \ .outputMode("append") \ .trigger(continuous="5 seconds") \ .start()

C:

C. query = df.writeStream \ .outputMode("append") \ .trigger(once=True) \ .start()

D:

D. query = df.writeStream \ .outputMode("append") \ .start()

Correct Answer:
A. A. query = df.writeStream \ .outputMode("append") \ .trigger(processingTime="5 seconds") \ .start()
Explanation

The trigger(processingTime="5 seconds") configuration explicitly sets up a micro-batch processing model where the Spark engine initiates a new batch at a fixed interval. This means the query will check for new data and start processing it every 5 seconds, regardless of whether the previous batch has finished. This directly fulfills the requirement for a real-time analytics pipeline that processes data in micro-batches at a fixed 5-second interval.

Why Incorrect

B. trigger(continuous="5 seconds") enables continuous processing, a low-latency mode, not the requested fixed-interval micro-batch model. The interval here is for checkpointing, not batching.
C. trigger(once=True) processes only a single batch of all available data and then stops the query, which is not suitable for a continuous, real-time pipeline.
D. The default trigger (no trigger specified) starts a new micro-batch immediately after the previous one completes. This does not guarantee a fixed interval; the timing depends on processing duration.

References

1. Apache Spark 3.5.0 Documentation

Structured Streaming Programming Guide

Section: Triggers.

"If you specify a processing time trigger

Spark will check for new data when the previous processing has completed. If new data is available

Spark will start a new processing. If no new data is available

Spark will sleep until the processing time is reached

and then check for new data again." This describes the behavior of Trigger.ProcessingTime("5 seconds")

confirming option A. The documentation also explicitly contrasts this with the default behavior (option D)

Trigger.Once() (option C)

and Trigger.Continuous() (option B).

2. Databricks Documentation

Structured Streaming

"Configure Structured Streaming trigger intervals".

Under the heading "Fixed interval micro-batches

" the documentation states: "You can configure structured streaming queries to run with a fixed batch interval using processingTime. If you do not specify a processingTime trigger

queries run using the default micro-batch setting...". This directly validates that processingTime is the correct parameter for achieving a fixed interval.

Question breakdown

Tests
Configure Structured Streaming triggers
Difficulty
Easy

Key idea: trigger(processingTime="5 seconds") runs micro-batches on a fixed 5-second schedule.

How to reach the answer

  1. The deciding clues are 'micro-batches' and 'fixed interval of 5 seconds'.
  2. processingTime is the trigger type that schedules micro-batches at a fixed interval.
  3. continuous is a different, non-micro-batch execution mode, and its interval is a checkpoint interval.
  4. once=True runs a single batch and stops, and leaving out the trigger starts each batch as soon as the previous one finishes.

Each option

  • ACorrect. A processingTime trigger launches micro-batches every 5 seconds, or right away if the previous batch overran the interval.
  • BIncorrect. A continuous trigger switches to continuous processing mode, and its 5-second value controls checkpointing rather than batch timing.
  • CIncorrect. trigger(once=True) processes the available data in one batch and then terminates the query.
  • DIncorrect. With no trigger set, micro-batches run back to back with no fixed interval.

Common trap: Option B also contains "5 seconds", so it looks equivalent, but the continuous trigger is not micro-batch execution and the interval means something different.

In practice: Fixed processingTime intervals are used to control cost and batch sizes for sinks such as Delta tables. availableNow is the usual choice for scheduled incremental runs.

Remember: Use processingTime for fixed-interval micro-batches, continuous for low-latency non-batch mode, and once or availableNow for one-off runs.

Drafted with AI assistance and checked against the answer key.

Keep practicing

Take the free CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-5-QUESTIONS practice test

Ten exam-style questions with answers and explanations, plus the exam facts and study guides.

Start the free practice test

More questions

Other CERTIFIED-ASSOCIATE-DEVELOPER-FOR-APACHE-SPARK-3-5-QUESTIONS practice questions

Scroll to Top