CertLumen

Databricks Data Engineer Professional · Section 1 · 23% of the exam

Choose between Spark Structured Streaming and Apache Spark™ Declarative Pipelines for scalable ETL given operational constraints.

One of the objectives of the Databricks Certified Data Engineer Professional exam, in the section “Developing Code for Data Processing using Python and SQL”. Here is what it covers, the points to remember and a question to try.

What it covers

Reason precisely about stateful streaming: how watermarks bound state, what each output mode emits, how foreachBatch and checkpoints give fault-tolerant, effectively exactly-once results, which query changes a checkpoint survives, and when hand-written Structured Streaming is a better fit than Lakeflow Spark Declarative Pipelines.

Points to remember

  • Watermark = max event time seen minus the delay; data within the delay is always processed, later data may be dropped; state older than the watermark is evicted.
  • Multiple watermarks: default policy min (slowest stream wins); max is lower latency but can drop data.
  • Append (default) emits final rows only, delayed by the watermark; update emits changed rows; complete rewrites everything and never drops state.
  • Delta sinks support append and complete, not update; use foreachBatch + MERGE for upserts.
  • foreachBatch(batch_df, batch_id) is at-least-once; make it idempotent with txnAppId + txnVersion or a sequenced MERGE.

Try a question

IoT devices send heartbeats. For each device, the business needs a state machine that raises an alert when no heartbeat arrives for 10 minutes, with per-device timers and custom state that expires after a day. The team writes Python and already orchestrates with Lakeflow Jobs. Which approach fits best?

  1. AA pipeline materialized view that groups heartbeats by device and filters for gaps longer than 10 minutes
  2. BStructured Streaming with transformWithStateInPandas timers and TTL, run as a Lakeflow Jobs task
  3. CAn AUTO CDC flow keyed by device that sequences events by heartbeat_ts
  4. DA streaming table with a 10-minute watermark and dropDuplicatesWithinWatermark
Show the answer

B. Custom per-key state with timers that fire when no data arrives is arbitrary stateful processing. transformWithState / transformWithStateInPandas (DBR 16.2+) provides value, list and map state, processing-time or event-time timers and TTL, and Databricks recommends it over the legacy group-state operators. This is a case for Structured Streaming rather than declarative datasets.

Written for practice in the style of the exam: never a question from the real exam.

In the course

The lesson Stateful Structured Streaming and Choosing It over Declarative Pipelines teaches this objective (about 60 minutes), and 13 practice questions test it. The course has lessons, exam-style questions, timed practice exams and an AI tutor for every objective, and a pass prediction that tells you when you're ready to book.

More in this section

← Previous objective · All 45 objectives · Next objective →