<?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=Real-time_mode_(Structured_Streaming)</id>
	<title>Real-time mode (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=Real-time_mode_(Structured_Streaming)"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Real-time_mode_(Structured_Streaming)&amp;action=history"/>
	<updated>2026-12-06T00:25:20Z</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=Real-time_mode_(Structured_Streaming)&amp;diff=171&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@7c9abaa</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Real-time_mode_(Structured_Streaming)&amp;diff=171&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:48Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@7c9abaa&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Infobox concept&lt;br /&gt;
| name            = Real-time mode&lt;br /&gt;
| also_known_as   = Real-time Mode (RTM), real-time trigger&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| introduced      = Apache Spark 4.1.0 (2025)&lt;br /&gt;
| key_parts       = Real-time trigger, long-running tasks, pipelined shuffle, checkpoint interval, update output mode&lt;br /&gt;
| implementations = [[Structured Streaming]] in [[Apache Spark]] 4.1.0 and later&lt;br /&gt;
| related         = [[Trigger (Structured Streaming)]], [[Structured Streaming]], [[transformWithState]], [[Exactly-once semantics]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|docs/streaming/real-time-mode.md and Trigger.java at tag v4.3.0, Trigger.java at v4.1.0 and v4.2.0, python/pyspark/sql/streaming/readwriter.py at v4.1.0 and v4.3.0, SQLConf.scala at v4.3.0, the Spark 4.1.0, 4.2.0 and 4.3.0 release notes, and SPARK-53736, SPARK-53737, SPARK-54660 and SPARK-57281}}&lt;br /&gt;
{{Status|active |since=Apache Spark 4.1.0 |note=The &amp;lt;code&amp;gt;Trigger.RealTime&amp;lt;/code&amp;gt; methods carried the &amp;lt;code&amp;gt;@Experimental&amp;lt;/code&amp;gt; annotation in Spark 4.1.0; SPARK-57281, listed in the Spark 4.3.0 release notes, removed it, and the Spark 4.3.0 documentation does not label Real-time mode experimental. |ref=&amp;lt;ref name=&amp;quot;jira57281&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-57281 |title=SPARK-57281: Remove @Experimental annotation from Real-time Mode trigger APIs |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], &amp;#039;&amp;#039;&amp;#039;real-time mode&amp;#039;&amp;#039;&amp;#039; (Real-time Mode, RTM) is a streaming execution mode that runs long-lived tasks which process and emit each record as it arrives, instead of running a new short job for every micro-batch, to reach millisecond-scale end-to-end latency with the same DataFrame APIs and exactly-once processing guarantees.&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-23}}&amp;lt;/ref&amp;gt; It was introduced in Spark 4.1.0 for stateless Scala queries and is enabled with a real-time [[Trigger (Structured Streaming)|trigger]] on the streaming write.&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-23}}&amp;lt;/ref&amp;gt; Spark 4.3.0 added a first set of stateful operations: deduplication, streaming aggregation and the Scala and Java [[transformWithState]] API.&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-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What is real-time mode? ==&lt;br /&gt;
Real-time mode is an alternative to the default micro-batch engine of Structured Streaming. The Spark 4.3.0 documentation describes it as aimed at operational workloads that must react to data as soon as it arrives, and gives fraud detection, real-time alerting and live personalization as examples.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt; The query code is the same as for a micro-batch query; only the trigger changes.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Real-time mode is not the same as continuous processing, the older low-latency mode started with &amp;lt;code&amp;gt;Trigger.Continuous&amp;lt;/code&amp;gt;. The documentation calls continuous processing experimental and legacy, notes that it supports only map-like operations with at-least-once guarantees, and recommends real-time mode for new low-latency workloads.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How does real-time mode work? ==&lt;br /&gt;
In micro-batch execution, the driver plans each batch and launches a fresh set of short tasks, and that fixed per-batch overhead sets a latency floor of about 100 milliseconds. Real-time mode instead launches one long-running task per input partition for the duration of a long batch, so records flow from source through transformations to sink without waiting for a batch boundary. The documentation puts the resulting latency at roughly the time to process and ship one record, often a few milliseconds.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In real-time mode the trigger duration is mainly a &amp;#039;&amp;#039;&amp;#039;checkpoint interval&amp;#039;&amp;#039;&amp;#039;, not a latency target. With the default duration of 5 minutes, results can still be emitted within milliseconds; the duration controls how often the query commits progress and starts the next batch. Batch-scoped work, such as advancing the [[watermark]] and firing processing-time timers on idle partitions, can wait for the boundary.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt; A shorter duration gives finer-grained recovery but adds more commit gaps, which can raise tail latency.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Stateful operators need records grouped by key, which normally requires a [[shuffle]] whose producer stage finishes before the consumer stage starts. Because a real-time task never finishes its batch, Spark 4.3.0 runs these shuffles as a &amp;#039;&amp;#039;&amp;#039;pipelined shuffle&amp;#039;&amp;#039;&amp;#039;: producer and consumer stages are scheduled at the same time, and shuffle data is streamed over the network record by record rather than written to files. This is enabled automatically.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt; The Spark 4.3.0 release notes describe stateful real-time queries as reaching end-to-end latency on the order of 100 milliseconds.&amp;lt;ref name=&amp;quot;r430&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How is real-time mode enabled? ==&lt;br /&gt;
Real-time mode is enabled by setting a real-time trigger. In Scala and Java the trigger is &amp;lt;code&amp;gt;Trigger.RealTime()&amp;lt;/code&amp;gt;, with forms that take a duration string, milliseconds, a value and &amp;lt;code&amp;gt;TimeUnit&amp;lt;/code&amp;gt;, or a Scala &amp;lt;code&amp;gt;Duration&amp;lt;/code&amp;gt;; with no argument the duration is 5 minutes.&amp;lt;ref name=&amp;quot;trig430&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/java/org/apache/spark/sql/streaming/Trigger.java |title=sql/api/src/main/java/org/apache/spark/sql/streaming/Trigger.java (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; In PySpark the trigger is the &amp;lt;code&amp;gt;realTime&amp;lt;/code&amp;gt; keyword of &amp;lt;code&amp;gt;DataStreamWriter.trigger()&amp;lt;/code&amp;gt;, and a duration string is required.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt; The PySpark keyword was added in Spark 4.2.0 (SPARK-54660); it is not in the 4.1.0 PySpark API.&amp;lt;ref name=&amp;quot;r420&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-4-2-0.html |title=Spark Release 4.2.0 |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.1.0/python/pyspark/sql/streaming/readwriter.py |title=python/pyspark/sql/streaming/readwriter.py (v4.1.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The [[Spark Connect]] Python client also accepts &amp;lt;code&amp;gt;realTime&amp;lt;/code&amp;gt; at v4.3.0.&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/connect/streaming/readwriter.py |title=python/pyspark/sql/connect/streaming/readwriter.py (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following PySpark query (Spark 4.2.0 or later) reads a Kafka topic, drops duplicate keys and writes to another Kafka topic in real-time mode. Deduplication needs Spark 4.3.0.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
query = (&lt;br /&gt;
    spark.readStream.format(&amp;quot;kafka&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;kafka.bootstrap.servers&amp;quot;, &amp;quot;host1:9092&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;subscribe&amp;quot;, &amp;quot;input-topic&amp;quot;)&lt;br /&gt;
    .load()&lt;br /&gt;
    .selectExpr(&amp;quot;CAST(key AS STRING) AS key&amp;quot;, &amp;quot;CAST(value AS STRING) AS value&amp;quot;)&lt;br /&gt;
    .dropDuplicates([&amp;quot;key&amp;quot;])&lt;br /&gt;
    .writeStream.format(&amp;quot;kafka&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;kafka.bootstrap.servers&amp;quot;, &amp;quot;host1:9092&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;topic&amp;quot;, &amp;quot;output-topic&amp;quot;)&lt;br /&gt;
    .option(&amp;quot;checkpointLocation&amp;quot;, &amp;quot;/tmp/checkpoints/rtm-dedup&amp;quot;)&lt;br /&gt;
    .outputMode(&amp;quot;update&amp;quot;)&lt;br /&gt;
    .trigger(realTime=&amp;quot;5 minutes&amp;quot;)&lt;br /&gt;
    .start()&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What are the requirements and limits? ==&lt;br /&gt;
A real-time query is checked when it starts. The Spark 4.3.0 documentation lists these requirements:&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
* The output mode must be &amp;lt;code&amp;gt;update&amp;lt;/code&amp;gt;; other modes fail with &amp;lt;code&amp;gt;STREAMING_REAL_TIME_MODE.OUTPUT_MODE_NOT_SUPPORTED&amp;lt;/code&amp;gt;.&lt;br /&gt;
* A &amp;lt;code&amp;gt;checkpointLocation&amp;lt;/code&amp;gt; is required.&lt;br /&gt;
* The trigger duration must be at least &amp;lt;code&amp;gt;spark.sql.streaming.realTimeMode.minBatchDuration&amp;lt;/code&amp;gt;, which defaults to 5000 milliseconds; month-based intervals are not accepted.&lt;br /&gt;
* Stateful queries do not support asynchronous progress tracking.&lt;br /&gt;
&lt;br /&gt;
Operators and sinks are checked against an allowlist before the query starts, controlled by &amp;lt;code&amp;gt;spark.sql.streaming.realTimeMode.allowlistCheck&amp;lt;/code&amp;gt; (default &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;). Both settings were added in Spark 4.1.0.&amp;lt;ref name=&amp;quot;sqlconf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/catalyst/src/main/scala/org/apache/spark/sql/internal/SQLConf.scala |title=SQLConf.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For stateful real-time queries, Spark 4.3.0 applies soft defaults at query start: the RocksDB [[state store]] provider, state store checkpoint format version 2, and RocksDB changelog checkpointing. Format version 1 is rejected unless &amp;lt;code&amp;gt;spark.sql.streaming.realTimeMode.dangerouslyAllowCheckpointV1.enabled&amp;lt;/code&amp;gt; is set to &amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt;, which the documentation describes as unsafe for stateful queries.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Which sources, sinks and operations are supported? ===&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Area !! Supported in Spark 4.3.0 !! Not supported&lt;br /&gt;
|-&lt;br /&gt;
| Sources || Kafka || Other sources, including the built-in &amp;lt;code&amp;gt;rate&amp;lt;/code&amp;gt; source&lt;br /&gt;
|-&lt;br /&gt;
| Sinks || Kafka, &amp;lt;code&amp;gt;foreach&amp;lt;/code&amp;gt; (&amp;lt;code&amp;gt;ForeachWriter&amp;lt;/code&amp;gt;), console, memory || &amp;lt;code&amp;gt;foreachBatch&amp;lt;/code&amp;gt; and other sinks&lt;br /&gt;
|-&lt;br /&gt;
| Stateless operations (since 4.1.0) || Projections, filters, UDFs, &amp;lt;code&amp;gt;explode&amp;lt;/code&amp;gt;, unions of distinct sources, stream-static joins with a broadcast static side || Unions that read the same source twice&lt;br /&gt;
|-&lt;br /&gt;
| Stateful operations (since 4.3.0) || &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt;, streaming aggregation including windowed aggregation, Scala and Java &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;withWatermark&amp;lt;/code&amp;gt; || Stream-stream joins, &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt;, session windows, &amp;lt;code&amp;gt;dropDuplicatesWithinWatermark&amp;lt;/code&amp;gt;, PySpark &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;transformWithStateInPandas&amp;lt;/code&amp;gt;, range partitioning&lt;br /&gt;
|}&lt;br /&gt;
All rows are from the Spark 4.3.0 Real-time Mode documentation.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== What delivery guarantees does real-time mode give? ==&lt;br /&gt;
Real-time mode gives the same exactly-once processing guarantee as the micro-batch engine: each input record affects engine-managed state once, across failures and restarts. End-to-end delivery depends on the sink. Offsets are committed at the end of each batch, after records have reached the sink, so a failure can cause records to be written again; the built-in Kafka sink is at-least-once, and Spark does not yet ship an exactly-once sink for real-time mode.&amp;lt;ref name=&amp;quot;rtm&amp;quot; /&amp;gt; See [[Exactly-once semantics]].&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
Real-time mode was developed under the umbrella issue SPARK-53736, &amp;quot;Real-time Mode in Structured Streaming (Scala stateless support)&amp;quot;, created on 27 September 2025, with fix version 4.1.0; SPARK-53737 added the trigger.&amp;lt;ref name=&amp;quot;jira53736&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-53736 |title=SPARK-53736: Real-time Mode in Structured Streaming (Scala stateless support) |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-53737 |title=SPARK-53737: Add Real-time Mode trigger |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The Spark 4.1.0 release notes call it the first official support for Structured Streaming queries in real-time mode.&amp;lt;ref name=&amp;quot;r410&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Spark release !! Real-time mode change&lt;br /&gt;
|-&lt;br /&gt;
| 4.1.0 || Real-time trigger and stateless Scala and Java queries; &amp;lt;code&amp;gt;Trigger.RealTime&amp;lt;/code&amp;gt; marked &amp;lt;code&amp;gt;@Experimental&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;r410&amp;quot; /&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.1.0/sql/api/src/main/java/org/apache/spark/sql/streaming/Trigger.java |title=sql/api/src/main/java/org/apache/spark/sql/streaming/Trigger.java (v4.1.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.2.0 || PySpark &amp;lt;code&amp;gt;realTime&amp;lt;/code&amp;gt; trigger keyword (SPARK-54660)&amp;lt;ref name=&amp;quot;r420&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| 4.3.0 || Stateful queries on pipelined shuffles (SPARK-58508, SPARK-58635, SPARK-57228); async progress tracking (SPARK-58131); &amp;lt;code&amp;gt;@Experimental&amp;lt;/code&amp;gt; removed (SPARK-57281)&amp;lt;ref name=&amp;quot;r430&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira57281&amp;quot; /&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Trigger (Structured Streaming)]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[transformWithState]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[Stream processing]]&lt;br /&gt;
* [[Streaming lakehouse]]&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:Concepts]]&lt;br /&gt;
[[Category:Glossary terms]]&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>