CertSafari
    Databricks Certified Data Engineer Professional - October 9 onwards· Lessons

    Domain 1 · Lesson 8/45

    Structured Streaming vs Spark Declarative Pipelines for ETL

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

    13 min read
    1.92% of exam
    10 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Explain why Lakeflow pipelines and hand-written Structured Streaming share an engine but differ in who owns checkpoints, retries, orchestration and dependency ordering
    • Pick hand-written Structured Streaming when a workload needs fine-grained procedural control or already exists as imperative streaming code
    • Pick a declarative pipeline when streaming tables, AUTO CDC and expectations cover the workload, so managed operations outweigh flexibility

    Key concept

    Operational ownership — Structured Streaming and Spark Declarative Pipelines run the same streaming engine. What separates them is who owns checkpoints, retries, orchestration and dependency ordering: you, in a hand-written job, or the pipeline engine, in a declarative pipeline.

    1.One streaming engine, two ways to operate it

    Choosing between Spark Structured Streaming and Apache Spark Declarative Pipelines is not a choice between engines. Lakeflow pipelines are built on Spark Declarative Pipelines (SDP), and their streaming tables run on Structured Streaming. A hand-written spark.readStream.load() / spark.writeStream.start() job and a pipeline streaming table process data incrementally in the same way. So a question that asks which one 'scales better' or 'streams faster' is usually looking for a different answer: who operates the stream.

    In the two models, the work falls in different places. With Structured Streaming you write procedural code: you decide the order of operations, where each query keeps its checkpoint, how the job is scheduled and what happens when it fails. With a pipeline you declare the tables and the queries that produce them, and the engine does the rest. The Lakeflow Declarative Pipelines (Apache Spark Declarative Pipelines) model covers how to author those declarations. This lesson is about the operational work they let you skip.

    Databricks' default is the declarative side. For most ETL workloads it recommends Lakeflow pipelines and keeps Spark notebooks and jobs for complex transformation logic that you want to express directly in Spark. That default holds until an operational constraint, such as needing control the pipeline doesn't give you, outweighs what the pipeline handles for you.

    Checkpoint 1 of 8· Check yourself

    A team is starting a new incremental ETL workload made of filters and joins. It has no special control requirements. Which approach does Databricks recommend, and why?

    Sources12

    2.The operational work a pipeline takes off your hands

    The strongest argument for a declarative pipeline is the list of jobs you no longer do yourself. A pipeline analyses the dependencies between its streaming tables, materialized views and sinks, and then orders and parallelises their execution. Checkpointing and retries are automatic, so after a failure the pipeline resumes from the last processed offset instead of starting over. Even scaling behaves differently. Classic compute autoscaling has trouble shrinking clusters under streaming workloads, and Databricks recommends pipelines with enhanced autoscaling for streaming instead. State rebalancing is also on by default for every streaming workload in a pipeline.

    A production Structured Streaming job has to provide all of this by hand. The checklist is concrete. Run on jobs compute, never all-purpose compute. Schedule the job in Continuous mode. Leave autoscaling off. Configure automatic restart on failure, which some features such as schema evolution require. Give each query its own checkpoint directory in durable cloud storage. Remove display and count calls from the notebook. Each item is an operational decision that someone has to make, review and maintain.

    Who owns each operational concern
    ConcernHand-written Structured StreamingLakeflow pipeline
    CheckpointsYou give each query its own checkpoint directory in durable cloud storageManaged by the pipeline, which resumes from the last processed offset
    Orchestration and dependency orderYou schedule streams as Lakeflow Jobs; with the continuous trigger you cannot set dependencies between tasksThe pipeline infers the dependency graph and orders execution
    RetriesYou configure streaming jobs to automatically restart on failureAutomatic
    Compute scalingJobs compute; don't enable autoscalingServerless pipelines manage and automatically scale compute resources

    Dependency ordering matters most once a pipeline has several layers. Suppose a bronze ingest feeds a silver cleanse, which feeds two gold aggregates. As separate Structured Streaming jobs, that is four checkpoints, four schedules and a wiring problem: a continuous job's tasks cannot declare dependencies on each other. As a pipeline, it is four dataset definitions. An update analyses the source files, builds the dependency graph and updates each dataset in dependency order.

    Checkpoint 2 of 8· Match them up

    You run streaming ETL as hand-written Structured Streaming jobs instead of a Lakeflow pipeline. Match each operational concern to what you now have to handle yourself.

    Tap a term, then the definition that fits it.

    Sources3456

    3.When hand-written Structured Streaming is the right call

    Structured Streaming wins when the workload needs control that a declarative definition cannot express. The procedural model is the right fit in three situations. First, when you need fine-grained control over execution logic. Second, when the business rules are too complex to express declaratively. Third, when performance depends on manual tuning. Legacy systems and existing imperative scripts also fall on the procedural side, because rewriting working code into declarations is itself a cost.

    A hand-rolled state machine is the clearest example. Picture an IoT job that tracks state per device across micro-batches with mapGroupsWithState, handles its own timeouts, and raises an alert only when the state machine reaches one particular transition. You decide every step of that logic: when state changes, when it expires, what gets emitted. That is the procedural model. The job belongs in a standalone Structured Streaming application, scheduled as a Lakeflow Job. AUTO CDC is the wrong tool here, because it applies inserts, updates and deletes to a table; it does not run your state machine. A nightly materialized view is also wrong, because it turns a streaming alert into a batch job that fires a day late. Lakeflow pipelines can run arbitrary stateful logic in Python through the transformWithState operator, but only if you rewrite the code for that operator. Existing mapGroupsWithState code with manual timeouts is not dropped into a pipeline as it is.

    Custom sinks need more care. Pipelines have a ForEachBatch sink for targets that don't support streaming writes natively, but the pipeline doesn't track what that sink writes. After a full refresh, cleaning up and resetting the downstream data is your job. Plain foreachBatch has a second catch. It gives at-least-once guarantees, not exactly-once, so the write it performs must be idempotent. How foreachBatch and checkpoints recover state is covered under stateful processing semantics.

    Checkpoint 3 of 8· Check yourself

    An existing IoT job tracks per-device state across micro-batches with mapGroupsWithState. It handles its own timeouts and raises an alert only on one specific state transition. Where should this workload run?

    Checkpoint 4 of 8· Check yourself

    Your hand-written stream uses foreachBatch to MERGE each micro-batch into a target that doesn't support streaming writes. What does that MERGE need?

    Checkpoint 5 of 8· Exam question

    A team ingests a continuous stream of IoT sensor events and must track custom per-device state across micro-batches using mapGroupsWithState, including manual timeout handling and arbitrary logic that only emits an alert when a hand-rolled state machine reaches a specific transition. They are deciding whether to implement this inside a Lakeflow Declarative Pipeline flow or as a standalone Structured Streaming job. Which approach should they choose, and why?

    Sources7896

    4.Where the declarative side wins: streaming tables, AUTO CDC and expectations

    For append-only sources, a streaming table already does what a hand-written stream would do. Files arriving through Auto Loader and events on a message bus both land in a streaming table, which checkpoints its progress. A restart therefore neither reprocesses nor drops data, and each record is processed incrementally exactly once. A clickstream that needs sub-minute freshness and never revisits old records is this case. A materialized view would be the wrong target, because a full recompute scales with your whole history, not with the rate of new data. The general rules for choosing between them are in streaming tables versus materialized views.

    Change feeds are where hand-written code costs the most. The usual procedural approach is a foreachBatch MERGE, and MERGE INTO can give wrong results when records arrive out of sequence unless you also write logic to reorder them. The AUTO CDC API handles that ordering for you. You name the keys that identify a record and a sequence column for ordering, then choose SCD Type 1 or Type 2. In Python, stored_as_scd_type=2 makes the pipeline keep the full history with no hand-written merge. The keys are still required: AUTO CDC doesn't work out row identity for you. The syntax is covered under AUTO CDC and SCD types.

    Change-feed processing: hand-written MERGE versus AUTO CDC
    RequirementforeachBatch MERGE in Structured StreamingAUTO CDC flow in a pipeline
    Row identityYour MERGE conditionKEYS ( keys )
    Out-of-order recordsMERGE INTO can produce incorrect results without custom reordering logicSEQUENCE BY orderByColumn
    HistoryHand-written SCD logicSTORED AS { SCD TYPE 1 | SCD TYPE 2 | BITEMPORAL }
    DeletesHand-written branch in the mergeAPPLY AS DELETE WHEN condition

    Data quality is the third built-in feature. Expectations check incoming records against rules and apply the row-level action you define, so bad change records can be dropped or quarantined before they reach the SCD table, with no extra orchestration code (data quality expectations). None of this reaches past the pipeline, though. AUTO CDC doesn't make calls to an external REST API exactly-once, and it doesn't build a star schema for you. Idempotent consumers and dimensional modelling remain your work.

    Checkpoint 6 of 8· Check yourself

    Clickstream events land through Auto Loader. They need sub-minute freshness, and old records are never updated after they arrive. Which pipeline target fits, and why?

    Checkpoint 7 of 8· Exam question

    A team ingests clickstream events that arrive continuously through Auto Loader and must be queryable downstream with sub-minute freshness. Each event should be processed incrementally and exactly once, and there is no need to revisit or recompute records that already landed. Which Lakeflow Declarative Pipeline dataset type should they define for this ingestion layer, and why?

    Checkpoint 8 of 8· Exam question

    A team receives a raw change feed (inserts, updates, deletes) from an upstream OLTP database through Auto Loader and must materialize a Type 2 slowly changing dimension with full history, while minimizing hand-written merge logic and out-of-order handling. They are choosing between the AUTO CDC API inside a Lakeflow Declarative Pipeline and a custom foreachBatch MERGE written in Structured Streaming. Which of the following are valid reasons to prefer the Lakeflow Declarative Pipeline approach? (Select all that apply)(Select 3)

    0 of 3 selected

    Sources410

    Sources

    (10)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “The underlying engine of Lakeflow pipelines (Apache Spark and Structured Streaming) has a unified architecture for batch and streaming processing”
      ↩︎ One streaming engine, two ways to operate it
    2. 2.
      “You declare the tables and transformations, and the pipeline engine manages dependencies, incremental processing, and orchestration.”
      ↩︎ One streaming engine, two ways to operate it
      “Complex transformation logic that you want to express directly in Spark.”
      ↩︎ One streaming engine, two ways to operate it
      “Databricks recommends Lakeflow pipelines, built on Apache Spark™ Declarative Pipelines (SDP), for most ETL workloads.”
      ↩︎ Checkpoint
    3. 3.
      “it analyzes the dependencies between these objects and orchestrates their order of execution and parallelization automatically.”
      ↩︎ The operational work a pipeline takes off your hands
    4. 4.
      “Checkpointing and retries are automatic, so a pipeline resumes from the last processed offset rather than reprocessing everything.”
      ↩︎ The operational work a pipeline takes off your hands
      “ingest into a streaming table, which checkpoints its progress so a restart neither reprocesses nor drops data.”
      ↩︎ Where the declarative side wins: streaming tables, AUTO CDC and expectations
      “Expectations apply the row-level action you define.”
      ↩︎ Where the declarative side wins: streaming tables, AUTO CDC and expectations
      “Because Lakeflow pipelines handle orchestration, checkpointing, retries, and incremental processing, your work at each stage is mostly a design decision rather than implementation.”
      ↩︎ Key concept
      “incremental processing scales with the rate of new data while a full recompute scales with your entire history.”
      ↩︎ Exam trap 2
      “incremental processing scales with the rate of new data while a full recompute scales with your entire history”
      ↩︎ Checkpoint
    5. 5.
      “Databricks recommends using Spark Declarative Pipelines on Lakeflow with enhanced autoscaling for streaming workloads.”
      ↩︎ The operational work a pipeline takes off your hands
    6. 6.
      “Don't run Structured Streaming workloads using all-purpose compute. Always schedule streams as Lakeflow Jobs using jobs compute.”
      ↩︎ The operational work a pipeline takes off your hands
      “When you configure a job using the continuous trigger, you cannot set dependencies between tasks.”
      ↩︎ The operational work a pipeline takes off your hands
      “Some operations like foreachBatch provide at-least-once rather than exactly-once guarantees.”
      ↩︎ When hand-written Structured Streaming is the right call
      “Some operations like foreachBatch provide at-least-once rather than exactly-once guarantees.”
      ↩︎ Exam trap 1
      “Some operations like foreachBatch provide at-least-once rather than exactly-once guarantees. For these operations, make sure that your processing pipeline is idempotent.”
      ↩︎ Checkpoint
    7. 7.
      “Transformations involve complex business rules that are difficult to express declaratively.”
      ↩︎ When hand-written Structured Streaming is the right call
      “Legacy systems or existing imperative scripts.”
      ↩︎ When hand-written Structured Streaming is the right call
    8. 8.
      “Use the transformWithState operator within Lakeflow pipelines to implement arbitrary stateful logic in your streaming pipelines using Python.”
      ↩︎ When hand-written Structured Streaming is the right call
    9. 9.
      “Limited housekeeping: The pipeline does not track what data is written from a ForEachBatch sink, so cannot clean up that data.”
      ↩︎ When hand-written Structured Streaming is the right call
    10. 10.
      “MERGE INTO can produce incorrect results because of out-of-sequence records or requires complex logic to re-order records.”
      ↩︎ Where the declarative side wins: streaming tables, AUTO CDC and expectations
      “AUTO CDC simplifies CDC by automatically handling out-of-order records.”
      ↩︎ Where the declarative side wins: streaming tables, AUTO CDC and expectations
      “You specify keys to identify records, a sequence column for ordering”
      ↩︎ Exam trap 3

    Continue to part 2 of 2

    Streaming trigger modes: availableNow, processingTime and continuous

    Spotted a mistake, or was something unclear? Tell us.