The full answer
Structured Streaming is Spark's current streaming engine. It treats a stream as a table that keeps growing, lets you write the same DataFrame or SQL query you would write for batch data, and runs it incrementally, updating results as new data arrives with exactly-once guarantees. DStreams, the older API, represented a stream as a sequence of RDDs and is now a legacy project.
The model
Each new record is a new row appended to an unbounded input table. Your query defines a result table; on each trigger, Spark processes only the new rows, updates any state, and writes changes to the sink according to the output mode (append, update or complete).
from pyspark.sql import functions as F
orders = (spark.readStream.format("delta").table("bronze.orders"))
revenue = (orders
.withWatermark("order_ts", "30 minutes")
.groupBy(F.window("order_ts", "5 minutes"), "country")
.agg(F.sum("amount").alias("revenue")))
(revenue.writeStream
.outputMode("append")
.option("checkpointLocation", "/chk/revenue_5min")
.trigger(processingTime="1 minute")
.toTable("gold.revenue_5min"))
Differences from DStreams
| DStreams (legacy) | Structured Streaming | |
|---|---|---|
| Abstraction | Sequence of RDDs | Unbounded DataFrame or table |
| API | RDD-style functions, separate from batch code | Same DataFrame and SQL API as batch |
| Optimisation | None | Catalyst optimizer and Tungsten, like batch |
| Time | Processing time (arrival); event time is hard | Event-time windows and watermarks for late data |
| Exactly-once | Developer's responsibility | Built in, with replayable sources, checkpoints and idempotent or transactional sinks |
| State | updateStateByKey, mapWithState | Managed state for aggregations, joins and deduplication; transformWithState for custom logic; RocksDB state store for large state |
| Triggers | Fixed batch interval | Micro-batches as fast as possible, fixed intervals, availableNow (process what's there, then stop), experimental continuous mode |
| Sources and sinks | Receivers and custom code | Kafka, files, Delta and other tables, rate source; foreachBatch for any batch sink |
| Status | No more updates | Actively developed |
Why it matters in practice
- One codebase for batch and streaming logic.
- Correct results with late data, through watermarks.
- Fault tolerance and exactly-once writes without hand-written bookkeeping.
- Incremental pipelines can run continuously or on a schedule with
availableNow, the basis of most lakehouse ingestion today (including Databricks Auto Loader and Lakeflow declarative pipelines).
Limitations to mention
- Some operations aren't supported on streams, such as most sorting outside aggregations, and some outer joins need watermarks.
- Micro-batch latency is typically from a few hundred milliseconds to seconds; very low latency needs special modes or a different engine.
- State must be sized and monitored; unbounded state grows forever without watermarks.
Last updated 16 October 2026
Sources