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);maxis 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+MERGEfor upserts. foreachBatch(batch_df, batch_id)is at-least-once; make it idempotent withtxnAppId+txnVersionor 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?
- AA pipeline materialized view that groups heartbeats by device and filters for gaps longer than 10 minutes
- BStructured Streaming with
transformWithStateInPandastimers and TTL, run as a Lakeflow Jobs task - CAn AUTO CDC flow keyed by device that sequences events by
heartbeat_ts - 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
- Implement scalable Python project structures for Declarative Automation Bundles (formerly Databricks Asset Bundles / DABs) to support modular development and CI/CD integration.
- Apply troubleshooting techniques to dependency conflicts and installation failures for external libraries (PyPI, local wheels, source archives) across serverless, pipeline, and bundle-deployed environments.
- Develop User-Defined Functions (UDFs) using Pandas, Python, and SQL, including Unity Catalog functions for the given constraints.
- Create production-ready data pipelines for streaming data using Lakeflow Pipelines and Auto Loader.
- Create and automate ETL workloads using Lakeflow Jobs via the UI, API, and CLI.
- Choose between a streaming table and a materialized view for a given latency, cost, and refresh requirement.
- Implement CDC pipelines using AUTO CDC APIs (formerly APPLY CHANGES) in Lakeflow Pipelines, including SCD Type 1 and Type 2 via stored_as_scd_type.
- Create Lakeflow Jobs that use control-flow operators such as If/Else conditions and For Each loops.
- Choose appropriate compute and configuration for environments and dependencies — including serverless compute (serverless environments, dependency management, performance mode), high-memory notebook tasks, and auto-optimization settings (e.g., disallowing retries).
- Develop unit and integration tests using assertDataFrameEqual, assertSchemaEqual, DataFrame.transform, and testing frameworks to ensure code correctness.
- Apply Structured Streaming stateful-processing semantics, including watermarks, output modes, foreachBatch, and checkpoints for fault-tolerant exactly-once state recovery.