<?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=Spark_Streaming_(DStreams)</id>
	<title>Spark Streaming (DStreams) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Spark_Streaming_(DStreams)"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_Streaming_(DStreams)&amp;action=history"/>
	<updated>2026-12-06T00:08:13Z</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=Spark_Streaming_(DStreams)&amp;diff=76&amp;oldid=prev</id>
		<title>Open Lakehouse Wiki sync: Sync from open-lakehouse/wiki@9783fe6</title>
		<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Spark_Streaming_(DStreams)&amp;diff=76&amp;oldid=prev"/>
		<updated>2026-11-22T21:29:56Z</updated>

		<summary type="html">&lt;p&gt;Sync from open-lakehouse/wiki@9783fe6&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            = Spark Streaming (DStreams)&lt;br /&gt;
| also_known_as   = Spark Streaming, DStream API, discretized streams&lt;br /&gt;
| field           = Stream processing&lt;br /&gt;
| introduced      = Apache Spark 0.7.0 (alpha)&lt;br /&gt;
| key_parts       = &amp;lt;code&amp;gt;StreamingContext&amp;lt;/code&amp;gt;, DStream, receivers, batch interval, checkpointing&lt;br /&gt;
| implementations = [[Apache Spark]] (&amp;lt;code&amp;gt;streaming&amp;lt;/code&amp;gt; module)&lt;br /&gt;
| related         = [[Structured Streaming]], [[Stream processing]], [[Apache Spark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-22|the v4.3.0 tag of apache/spark (streaming module source, PySpark StreamingContext, streaming programming guide), the Spark 0.7.0 and 3.4.0 release notes and SPARK-42075}}&lt;br /&gt;
{{Status|deprecated |since=Apache Spark 3.4.0 |replacement=[[Structured Streaming]] |note=Still included in Spark 4.3.0; the documentation calls it a legacy project that receives no further updates. |ref=&amp;lt;ref name=&amp;quot;jira&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-42075 |title=SPARK-42075: Deprecate DStream API |publisher=Apache Software Foundation JIRA |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;r340&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-3-4-0.html |title=Spark Release 3.4.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Spark Streaming&amp;#039;&amp;#039;&amp;#039;, also called the &amp;#039;&amp;#039;&amp;#039;DStream API&amp;#039;&amp;#039;&amp;#039;, is the original stream processing library of [[Apache Spark]], in which a live data stream is divided into small batches and represented as a &amp;#039;&amp;#039;&amp;#039;discretized stream&amp;#039;&amp;#039;&amp;#039; (DStream): a continuous series of RDDs, each holding the data received in one time interval.&amp;lt;ref name=&amp;quot;guide&amp;quot;&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; The API has been deprecated since Spark 3.4.0. Spark&amp;#039;s documentation calls it the previous generation of Spark&amp;#039;s streaming engine and directs all new streaming applications to [[Structured Streaming]].&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Status ==&lt;br /&gt;
The DStream API was deprecated in Apache Spark 3.4.0 under SPARK-42075, &amp;quot;Deprecate DStream API&amp;quot;, and the 3.4.0 release notes list the deprecation.&amp;lt;ref name=&amp;quot;jira&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;r340&amp;quot; /&amp;gt; At the v4.3.0 tag the deprecation is still in place:&lt;br /&gt;
&lt;br /&gt;
* The Scala &amp;lt;code&amp;gt;StreamingContext&amp;lt;/code&amp;gt; and the Java &amp;lt;code&amp;gt;JavaStreamingContext&amp;lt;/code&amp;gt; carry &amp;lt;code&amp;gt;@deprecated(&amp;quot;DStream is deprecated. Migrate to Structured Streaming.&amp;quot;, &amp;quot;Spark 3.4.0&amp;quot;)&amp;lt;/code&amp;gt;.&amp;lt;ref name=&amp;quot;scala&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/streaming/src/main/scala/org/apache/spark/streaming/StreamingContext.scala |title=StreamingContext.scala at v4.3.0 |publisher=GitHub |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* The PySpark &amp;lt;code&amp;gt;StreamingContext&amp;lt;/code&amp;gt; constructor issues a &amp;lt;code&amp;gt;FutureWarning&amp;lt;/code&amp;gt;: &amp;quot;DStream is deprecated as of Spark 3.4.0. Migrate to Structured Streaming.&amp;quot; Its docstring adds that there are no longer updates to DStream and that it is a legacy project.&amp;lt;ref name=&amp;quot;py&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/streaming/context.py |title=pyspark/streaming/context.py at v4.3.0 |publisher=GitHub |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
* The Spark 4.3.0 programming guide opens with a note that Spark Streaming &amp;quot;is the previous generation of Spark&amp;#039;s streaming engine&amp;quot;, that &amp;quot;there are no longer updates to Spark Streaming and it&amp;#039;s a legacy project&amp;quot;, and that users should use Structured Streaming.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The API has not been removed. The &amp;lt;code&amp;gt;streaming&amp;lt;/code&amp;gt; module and its programming guide are still part of Spark 4.3.0, and the guide still documents the Kafka and Kinesis integrations.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt; No Spark release up to 4.3.0 announces a removal date.&lt;br /&gt;
&lt;br /&gt;
== Programming model ==&lt;br /&gt;
A Spark Streaming application creates a &amp;lt;code&amp;gt;StreamingContext&amp;lt;/code&amp;gt; with a &amp;#039;&amp;#039;&amp;#039;batch interval&amp;#039;&amp;#039;&amp;#039;, such as one second. &amp;#039;&amp;#039;&amp;#039;Input DStreams&amp;#039;&amp;#039;&amp;#039; receive data from a source; every input DStream except file streams is associated with a &amp;#039;&amp;#039;&amp;#039;receiver&amp;#039;&amp;#039;&amp;#039;, which receives the data and stores it in Spark&amp;#039;s memory for processing. Basic sources include sockets and file systems, and advanced sources such as Kafka and Kinesis come from separate artifacts (&amp;lt;code&amp;gt;spark-streaming-kafka-0-10&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;spark-streaming-kinesis-asl&amp;lt;/code&amp;gt;).&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Each operation on a DStream becomes an operation on the RDDs underneath it. The API offers RDD-style transformations (&amp;lt;code&amp;gt;map&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;flatMap&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;reduceByKey&amp;lt;/code&amp;gt;), window operations such as &amp;lt;code&amp;gt;reduceByKeyAndWindow&amp;lt;/code&amp;gt;, stateful &amp;lt;code&amp;gt;updateStateByKey&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;transform&amp;lt;/code&amp;gt; for arbitrary RDD-to-RDD functions, and output operations such as &amp;lt;code&amp;gt;foreachRDD&amp;lt;/code&amp;gt;. Stateful transformations, such as &amp;lt;code&amp;gt;updateStateByKey&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;reduceByKeyAndWindow&amp;lt;/code&amp;gt; with an inverse function, require a checkpoint directory.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt; The window length and sliding interval of a window operation must be multiples of the batch interval.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The following PySpark example, adapted from the programming guide, counts words in one-second batches from a socket. On Spark 4.3 it runs but prints the deprecation warning.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;py&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from pyspark import SparkContext&lt;br /&gt;
from pyspark.streaming import StreamingContext&lt;br /&gt;
&lt;br /&gt;
sc = SparkContext(&amp;quot;local[2]&amp;quot;, &amp;quot;NetworkWordCount&amp;quot;)&lt;br /&gt;
ssc = StreamingContext(sc, 1)  # 1-second batches; emits a FutureWarning&lt;br /&gt;
&lt;br /&gt;
lines = ssc.socketTextStream(&amp;quot;localhost&amp;quot;, 9999)&lt;br /&gt;
counts = (lines.flatMap(lambda line: line.split(&amp;quot; &amp;quot;))&lt;br /&gt;
               .map(lambda word: (word, 1))&lt;br /&gt;
               .reduceByKey(lambda a, b: a + b))&lt;br /&gt;
counts.pprint()&lt;br /&gt;
&lt;br /&gt;
ssc.start()&lt;br /&gt;
ssc.awaitTermination()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
DStreams are built on RDDs and the &amp;lt;code&amp;gt;SparkContext&amp;lt;/code&amp;gt;, which the Spark Connect documentation lists as unsupported, so DStream applications cannot run through a [[Spark Connect]] client.&amp;lt;ref name=&amp;quot;connect&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/spark-connect-overview.html |title=Spark Connect Overview (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== History ==&lt;br /&gt;
Spark Streaming first appeared as an alpha in Spark 0.7.0, which described it as an extension adding near-real-time processing, with transformations such as &amp;lt;code&amp;gt;map&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;filter&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;reduce&amp;lt;/code&amp;gt; and sliding windows.&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/releases/spark-release-0-7-0.html |title=Spark Release 0.7.0 |publisher=Apache Software Foundation |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; Structured Streaming, built on the Spark SQL engine, arrived as an experimental API in Spark 2.0.0.&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; The Spark 4.3 documentation recommends it for all new streaming applications and pipelines.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Migration to Structured Streaming ==&lt;br /&gt;
{{Main|Structured Streaming}}&lt;br /&gt;
There is no automatic converter. Migration means rewriting the job against the DataFrame API. The table maps DStream concepts to their usual Structured Streaming counterparts in Spark 4.3.&amp;lt;ref name=&amp;quot;guide&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;ssapis&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;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! DStream API !! Structured Streaming&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;StreamingContext&amp;lt;/code&amp;gt; with a batch interval || &amp;lt;code&amp;gt;SparkSession&amp;lt;/code&amp;gt;; &amp;lt;code&amp;gt;spark.readStream&amp;lt;/code&amp;gt; to read, &amp;lt;code&amp;gt;writeStream&amp;lt;/code&amp;gt; with a processing-time trigger to set the micro-batch interval&lt;br /&gt;
|-&lt;br /&gt;
| DStream (series of RDDs) || Streaming DataFrame or Dataset (an unbounded table)&lt;br /&gt;
|-&lt;br /&gt;
| RDD transformations (&amp;lt;code&amp;gt;map&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;reduceByKey&amp;lt;/code&amp;gt;) || DataFrame operations (&amp;lt;code&amp;gt;select&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;groupBy&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;agg&amp;lt;/code&amp;gt;) or SQL&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;window&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;reduceByKeyAndWindow&amp;lt;/code&amp;gt; (multiples of the batch interval) || &amp;lt;code&amp;gt;groupBy(window(...))&amp;lt;/code&amp;gt; on an event-time column, with a [[watermark]] for late data&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;updateStateByKey&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;mapWithState&amp;lt;/code&amp;gt; (Scala and Java)&amp;lt;ref&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/streaming/src/main/scala/org/apache/spark/streaming/dstream/PairDStreamFunctions.scala |title=PairDStreamFunctions.scala at v4.3.0 |publisher=GitHub |access-date=2026-11-22}}&amp;lt;/ref&amp;gt; || Built-in stateful aggregations, or &amp;lt;code&amp;gt;transformWithState&amp;lt;/code&amp;gt; (Spark 4.0 and later) for arbitrary state&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;
| &amp;lt;code&amp;gt;foreachRDD&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;foreachBatch&amp;lt;/code&amp;gt; or a built-in sink&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ssc.checkpoint(dir)&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;checkpointLocation&amp;lt;/code&amp;gt; option on each query&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;spark-streaming-kafka-0-10&amp;lt;/code&amp;gt; || Kafka source and sink in &amp;lt;code&amp;gt;spark-sql-kafka-0-10&amp;lt;/code&amp;gt;&amp;lt;ref&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/structured-streaming-kafka-integration.html |title=Structured Streaming + Kafka Integration 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;
&lt;br /&gt;
The word count above becomes the following query, taken from the Structured Streaming quick example.&amp;lt;ref name=&amp;quot;ssstart&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; One semantic difference matters: the DStream version prints counts for each batch, while this query keeps a running count over all data received, because the result table is cumulative and is written in complete mode.&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 explode, split&lt;br /&gt;
&lt;br /&gt;
spark = SparkSession.builder.appName(&amp;quot;StructuredNetworkWordCount&amp;quot;).getOrCreate()&lt;br /&gt;
&lt;br /&gt;
lines = (spark.readStream.format(&amp;quot;socket&amp;quot;)&lt;br /&gt;
         .option(&amp;quot;host&amp;quot;, &amp;quot;localhost&amp;quot;).option(&amp;quot;port&amp;quot;, 9999).load())&lt;br /&gt;
words = lines.select(explode(split(lines.value, &amp;quot; &amp;quot;)).alias(&amp;quot;word&amp;quot;))&lt;br /&gt;
counts = words.groupBy(&amp;quot;word&amp;quot;).count()&lt;br /&gt;
&lt;br /&gt;
query = counts.writeStream.outputMode(&amp;quot;complete&amp;quot;).format(&amp;quot;console&amp;quot;).start()&lt;br /&gt;
query.awaitTermination()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Unlike DStreams, Structured Streaming queries run on the optimized Spark SQL engine and provide end-to-end [[exactly-once semantics]] through checkpointing and write-ahead logs.&amp;lt;ref name=&amp;quot;ssindex&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; Most of the Structured Streaming API, including &amp;lt;code&amp;gt;DataStreamReader&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;DataStreamWriter&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;StreamingQuery&amp;lt;/code&amp;gt;, is supported in [[Spark Connect]].&amp;lt;ref name=&amp;quot;connect&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Stream processing]]&lt;br /&gt;
* [[Watermark]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[GraphX]]&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:Apache Spark]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>