<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Structured_Streaming</id>
	<title>Structured Streaming - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Structured_Streaming"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Structured_Streaming&amp;action=history"/>
	<updated>2026-12-06T00:07:28Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.11</generator>
	<entry>
		<id>https://openlakehouse.io/w/index.php?title=Structured_Streaming&amp;diff=51&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@355a38d</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Structured_Streaming&amp;diff=51&amp;oldid=prev"/>
		<updated>2026-11-22T18:53:22Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@355a38d&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox software&lt;br /&gt;
| name                = Structured Streaming&lt;br /&gt;
| developer           = [[Apache Software Foundation]] ([[Apache Spark]] project)&lt;br /&gt;
| initial_release     = Spark 2.0.0 (2016-07-26, experimental)&lt;br /&gt;
| latest_release      = Spark 4.3.0&lt;br /&gt;
| latest_release_date = 2026-10-30&lt;br /&gt;
| written_in          = Scala, Java, Python&lt;br /&gt;
| type                = Stream processing engine&lt;br /&gt;
| license             = Apache License 2.0&lt;br /&gt;
| website             = [https://spark.apache.org/docs/latest/streaming/index.html Programming guide]&lt;br /&gt;
| repo                = [https://github.com/apache/spark github.com/apache/spark]&lt;br /&gt;
| related             = [[Spark Declarative Pipelines]], [[Apache Spark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-22|the Spark 4.3.0 Structured Streaming guides (overview, APIs, Real-time Mode, transformWithState) and the Spark 2.0.0, 2.2.0, 4.0.0, 4.1.0 and 4.3.0 release notes}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Structured Streaming&amp;#039;&amp;#039;&amp;#039; is the stream processing engine of [[Apache Spark]], built on the Spark SQL engine, in which a streaming computation is written with the same DataFrame and Dataset operations as a batch computation on static data.&amp;lt;ref name=&amp;quot;overview&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/index.html |title=Structured Streaming Programming Guide (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Spark runs the query incrementally as new data arrives and keeps the result up to date. Through checkpointing and write-ahead logs, Structured Streaming provides end-to-end exactly-once guarantees with sources and sinks that support them.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Programming model ==&lt;br /&gt;
Structured Streaming treats a live data stream as a table that grows as new rows arrive. A streaming query is a query on that input table, and its output is a result table that Spark updates each time it processes new data.&amp;lt;ref name=&amp;quot;start&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/getting-started.html |title=Structured Streaming: Getting Started (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;output mode&amp;#039;&amp;#039;&amp;#039; says what part of the result table is written to the sink after each update:&amp;lt;ref name=&amp;quot;start&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Append&amp;#039;&amp;#039;&amp;#039;: only rows added since the last trigger. It applies to queries whose existing result rows never change.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Complete&amp;#039;&amp;#039;&amp;#039;: the entire result table.&lt;br /&gt;
* &amp;#039;&amp;#039;&amp;#039;Update&amp;#039;&amp;#039;&amp;#039;: only rows that changed since the last trigger (available since Spark 2.1.1). Without aggregations it behaves like append mode.&lt;br /&gt;
&lt;br /&gt;
Streaming queries can aggregate over event-time windows, including tumbling, sliding and session windows. A &amp;#039;&amp;#039;&amp;#039;watermark&amp;#039;&amp;#039;&amp;#039; tells Spark how late data may arrive, so that it can finalize old windows and drop their state. Structured Streaming also supports stream-static joins, stream-stream joins and deduplication.&amp;lt;ref name=&amp;quot;apis&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html |title=Structured Streaming: APIs on DataFrames and Datasets (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following PySpark example counts rows from the built-in &amp;lt;code&amp;gt;rate&amp;lt;/code&amp;gt; test source in 30-second event-time windows and prints finished windows to the console. It runs on Spark 4.3.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark.sql import SparkSession&lt;br /&gt;
from pyspark.sql.functions import window&lt;br /&gt;
&lt;br /&gt;
spark = SparkSession.builder.appName(&amp;quot;rate-counts&amp;quot;).getOrCreate()&lt;br /&gt;
&lt;br /&gt;
events = spark.readStream.format(&amp;quot;rate&amp;quot;).option(&amp;quot;rowsPerSecond&amp;quot;, 10).load()&lt;br /&gt;
&lt;br /&gt;
counts = (&lt;br /&gt;
    events.withWatermark(&amp;quot;timestamp&amp;quot;, &amp;quot;1 minute&amp;quot;)&lt;br /&gt;
    .groupBy(window(&amp;quot;timestamp&amp;quot;, &amp;quot;30 seconds&amp;quot;))&lt;br /&gt;
    .count()&lt;br /&gt;
)&lt;br /&gt;
&lt;br /&gt;
query = (&lt;br /&gt;
    counts.writeStream.outputMode(&amp;quot;append&amp;quot;)&lt;br /&gt;
    .format(&amp;quot;console&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;/tmp/rate-counts-checkpoint&amp;quot;)&lt;br /&gt;
    .start()&lt;br /&gt;
)&lt;br /&gt;
query.awaitTermination()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Sources, sinks and state ==&lt;br /&gt;
Built-in sources include files, Apache Kafka, a socket source for testing and rate sources that generate test data.&amp;lt;ref name=&amp;quot;apis&amp;quot; /&amp;gt; Built-in sinks include files, Kafka, &amp;lt;code&amp;gt;foreach&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;foreachBatch&amp;lt;/code&amp;gt;, and console and memory sinks for debugging.&amp;lt;ref name=&amp;quot;apis&amp;quot; /&amp;gt; Connectors for [[open table format]]s such as [[Apache Iceberg]] and [[Delta Lake]] let their tables serve as streaming sources and sinks.&amp;lt;ref&amp;gt;{{Cite web |url=https://iceberg.apache.org/docs/latest/spark-structured-streaming/ |title=Spark Structured Streaming |publisher=Apache Iceberg |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://docs.delta.io/delta-streaming/ |title=Table streaming reads and writes |publisher=Delta Lake |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stateful operators such as aggregations, joins and deduplication keep state between batches in a &amp;#039;&amp;#039;&amp;#039;state store&amp;#039;&amp;#039;&amp;#039;. Since Spark 3.2, Spark includes a RocksDB-based state store provider that keeps state in native memory and on local disk instead of the JVM heap.&amp;lt;ref name=&amp;quot;apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt;, available since Spark 4.0, is the operator for arbitrary stateful processing. It replaces the older &amp;lt;code&amp;gt;mapGroupsWithState&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt; APIs in Scala and &amp;lt;code&amp;gt;applyInPandasWithState&amp;lt;/code&amp;gt; in Python, and adds features such as timers and time-to-live (TTL) eviction of state. It is available in Scala, Java and Python.&amp;lt;ref name=&amp;quot;tws&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/structured-streaming-transform-with-state.html |title=Structured Streaming: transformWithState (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Execution modes and triggers ==&lt;br /&gt;
By default, Structured Streaming runs a query as a series of small batch jobs (&amp;#039;&amp;#039;&amp;#039;micro-batches&amp;#039;&amp;#039;&amp;#039;), with end-to-end latencies as low as about 100 milliseconds.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt; The &amp;#039;&amp;#039;&amp;#039;trigger&amp;#039;&amp;#039;&amp;#039; controls timing:&amp;lt;ref name=&amp;quot;apis&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Trigger !! Behaviour&lt;br /&gt;
|-&lt;br /&gt;
| Unspecified (default) || Starts the next micro-batch as soon as the previous one finishes.&lt;br /&gt;
|-&lt;br /&gt;
| Fixed interval (&amp;lt;code&amp;gt;processingTime&amp;lt;/code&amp;gt;) || Starts micro-batches at a set interval; skips a batch when there is no new data.&lt;br /&gt;
|-&lt;br /&gt;
| Available-now (&amp;lt;code&amp;gt;availableNow&amp;lt;/code&amp;gt;) || Processes all data available at start, possibly in several micro-batches, then stops.&lt;br /&gt;
|-&lt;br /&gt;
| One-time || Processes available data in one micro-batch, then stops. Deprecated in favour of available-now.&lt;br /&gt;
|-&lt;br /&gt;
| Continuous || Experimental low-latency mode, added in Spark 2.3, with at-least-once guarantees.&amp;lt;ref name=&amp;quot;overview&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| Real-time || Real-time Mode, added in Spark 4.1.0 (see below).&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Real-time Mode&amp;#039;&amp;#039;&amp;#039; runs long-lived tasks, one per input partition, that process records as they arrive instead of waiting for a batch boundary. The Spark documentation states that this lowers end-to-end latency from the micro-batch floor to roughly the time needed to process and send one record. The trigger&amp;#039;s duration (default 5 minutes) then mainly sets how often the query checkpoints.&amp;lt;ref name=&amp;quot;rtm&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/real-time-mode.html |title=Real-time Mode (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Spark 4.1.0 supported stateless queries in this mode.&amp;lt;ref name=&amp;quot;r410&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4.1.0.html |title=Spark Release 4.1.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Spark 4.3.0 added streaming aggregation, &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt; and the Scala and Java &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt; operator, using a pipelined shuffle; stream-stream joins and &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt; are not yet supported in this mode.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r430&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-3-0.html |title=Spark Release 4.3.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; In PySpark, the mode is enabled with &amp;lt;code&amp;gt;.trigger(realTime=&amp;quot;5 minutes&amp;quot;)&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
Spark 2.0.0 shipped the first, experimental release of Structured Streaming as a higher-level streaming API on Spark SQL and the Catalyst optimizer.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-2-0-0.html |title=Spark Release 2.0.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Spark 2.2.0 removed the experimental label and declared the APIs generally available (SPARK-20844).&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-2-2-0.html |title=Spark Release 2.2.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Spark 4.0.0 added the Arbitrary State API v2 (&amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt;) and a State Data Source for reading state when debugging.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-0-0.html |title=Spark Release 4.0.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Real-time Mode followed in 4.1.0 (SPARK-53736) and gained stateful queries in 4.3.0.&amp;lt;ref name=&amp;quot;r410&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r430&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The older Spark Streaming API, based on discretized streams (DStreams), is described in the Spark 4.3 documentation as the previous generation of Spark&amp;#039;s streaming engine; it receives no further updates, and the documentation directs new work to Structured Streaming.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming-programming-guide.html |title=Spark Streaming Programming Guide (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Use in an open lakehouse ==&lt;br /&gt;
In an [[open lakehouse]], Structured Streaming typically ingests events from a message bus into bronze tables and keeps downstream tables current. [[Spark Declarative Pipelines]] builds on it: SDP streaming tables are filled by Structured Streaming flows, and SDP can read from any source that &amp;lt;code&amp;gt;spark.readStream&amp;lt;/code&amp;gt; supports.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/declarative-pipelines-programming-guide.html |title=Spark Declarative Pipelines Programming Guide (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Apache Spark]]&lt;br /&gt;
* [[Spark Declarative Pipelines]]&lt;br /&gt;
* [[Medallion architecture]]&lt;br /&gt;
* [[Delta Lake]]&lt;br /&gt;
* [[Apache Iceberg]]&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&amp;lt;references /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{{Navbox open lakehouse}}&lt;br /&gt;
&lt;br /&gt;
[[Category:Pipelines and orchestration]]&lt;br /&gt;
[[Category:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>