<?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=State_store</id>
	<title>State store - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=State_store"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=State_store&amp;action=history"/>
	<updated>2026-12-06T00:13:41Z</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=State_store&amp;diff=207&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=State_store&amp;diff=207&amp;oldid=prev"/>
		<updated>2026-11-25T00:53:00Z</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            = State store&lt;br /&gt;
| also_known_as   = State store provider&lt;br /&gt;
| field           = [[Stream processing]]&lt;br /&gt;
| key_parts       = Versioned key-value store per operator and partition, state store provider class, checkpointed files, maintenance task&lt;br /&gt;
| implementations = [[Structured Streaming]]: &amp;lt;code&amp;gt;HDFSBackedStateStoreProvider&amp;lt;/code&amp;gt; (default) and &amp;lt;code&amp;gt;RocksDBStateStoreProvider&amp;lt;/code&amp;gt;&lt;br /&gt;
| related         = [[RocksDB state store]], [[Streaming checkpoint]], [[Stateful stream processing]], [[Watermark]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the Spark 4.3.0 Structured Streaming programming guide (State Store section) and miscellaneous notes, &amp;lt;code&amp;gt;SQLConf.scala&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;HDFSBackedStateStoreProvider.scala&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;RocksDBFileManager.scala&amp;lt;/code&amp;gt; at tag v4.3.0 of apache/spark, the state data source guide, SPARK-45511, the Databricks RocksDB state store page, and the Apache Flink 2.3 &amp;quot;State Backends&amp;quot; page}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]] [[Structured Streaming]], a &amp;#039;&amp;#039;&amp;#039;state store&amp;#039;&amp;#039;&amp;#039; is the versioned key-value store in which stateful operators keep the data they carry from one micro-batch to the next, such as running aggregates, deduplication keys, buffered join rows and user state. Each stateful operator has one state store per shuffle partition, running on an executor, and every batch produces a new version that is saved to the [[streaming checkpoint]] so the state survives failures.&amp;lt;ref name=&amp;quot;ss-store&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#state-store |title=Structured Streaming: State Store (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Spark ships two implementations, the HDFS-backed state store and the [[RocksDB state store]], and the choice between them mostly decides how much state a query can hold without memory problems.&lt;br /&gt;
&lt;br /&gt;
== Which operators use the state store? ==&lt;br /&gt;
Streaming aggregations, streaming deduplication with &amp;lt;code&amp;gt;dropDuplicates&amp;lt;/code&amp;gt;, stream-stream joins and the arbitrary stateful operators (&amp;lt;code&amp;gt;mapGroupsWithState&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;flatMapGroupsWithState&amp;lt;/code&amp;gt; and [[transformWithState]]) all keep state in the state store.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt; Stateless operations, including [[stream-static join]]s, do not.&amp;lt;ref name=&amp;quot;ss-join&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#stream-static-joins |title=Structured Streaming: Stream-static Joins (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; See [[Stateful stream processing]].&lt;br /&gt;
&lt;br /&gt;
== How does the state store work? ==&lt;br /&gt;
A state store is a versioned key-value store with reads and writes. Updates are applied in sets, transactionally, and each set increments the store&amp;#039;s version; a retried task can therefore re-run its updates against the correct earlier version.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt; The version of a store matches the batch id of the query.&lt;br /&gt;
&lt;br /&gt;
The state store provider is set with &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.providerClass&amp;lt;/code&amp;gt;. Its default is &amp;lt;code&amp;gt;org.apache.spark.sql.execution.streaming.state.HDFSBackedStateStoreProvider&amp;lt;/code&amp;gt;, and it cannot be changed between restarts from the same checkpoint location.&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 (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;misc&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/additional-information.html |title=Structured Streaming: Miscellaneous Notes (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Users can also write their own provider by extending the &amp;lt;code&amp;gt;StateStoreProvider&amp;lt;/code&amp;gt; interface.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
State is partitioned by hashing the grouping key, which is why &amp;lt;code&amp;gt;spark.sql.shuffle.partitions&amp;lt;/code&amp;gt; cannot change for a query that already has a checkpoint.&amp;lt;ref name=&amp;quot;misc&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Spark tries to run each state store on the same executor in every batch, using the preferred-location feature of RDDs, because loading a store on a new executor means reading its checkpointed files. The preference is not a guarantee; raising &amp;lt;code&amp;gt;spark.locality.wait&amp;lt;/code&amp;gt; makes it more likely to hold. A background maintenance task, run every &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.maintenanceInterval&amp;lt;/code&amp;gt; (default 60 seconds), runs background maintenance in every loaded provider and unloads providers that are no longer active on an executor.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== HDFS-backed vs RocksDB state store ==&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;HDFS-backed state store&amp;#039;&amp;#039;&amp;#039; keeps all of its data in an in-memory map in the executor JVM and saves it to files in an HDFS-compatible file system.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt; Each batch writes a &amp;lt;code&amp;gt;&amp;#039;&amp;#039;version&amp;#039;&amp;#039;.delta&amp;lt;/code&amp;gt; file with that batch&amp;#039;s changes, and Spark consolidates deltas into a &amp;lt;code&amp;gt;&amp;#039;&amp;#039;version&amp;#039;&amp;#039;.snapshot&amp;lt;/code&amp;gt; file after &amp;lt;code&amp;gt;spark.sql.streaming.stateStore.minDeltasForSnapshot&amp;lt;/code&amp;gt; (default 10) delta files.&amp;lt;ref name=&amp;quot;hdfs&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/HDFSBackedStateStoreProvider.scala |title=HDFSBackedStateStoreProvider.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;RocksDB state store&amp;#039;&amp;#039;&amp;#039;, added in Spark 3.2, keeps state in RocksDB in native memory and on local disk instead of the JVM heap, and uploads its files to the checkpoint location. The Spark guide recommends it for queries with millions of keys in state, where the HDFS-backed store causes long JVM garbage collection pauses and uneven micro-batch times.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt; It is the only provider that supports [[transformWithState]]. See [[RocksDB state store]].&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! !! HDFS-backed state store !! RocksDB state store&lt;br /&gt;
|-&lt;br /&gt;
! Provider class&lt;br /&gt;
| &amp;lt;code&amp;gt;HDFSBackedStateStoreProvider&amp;lt;/code&amp;gt; (default in Apache Spark)&amp;lt;ref name=&amp;quot;sqlconf&amp;quot; /&amp;gt;&lt;br /&gt;
| &amp;lt;code&amp;gt;RocksDBStateStoreProvider&amp;lt;/code&amp;gt;&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Where live state is held&lt;br /&gt;
| In-memory map on the executor JVM heap&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
| RocksDB, in native memory and on local disk&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! Checkpoint files&lt;br /&gt;
| &amp;lt;code&amp;gt;.delta&amp;lt;/code&amp;gt; per batch, &amp;lt;code&amp;gt;.snapshot&amp;lt;/code&amp;gt; after consolidation&amp;lt;ref name=&amp;quot;hdfs&amp;quot; /&amp;gt;&lt;br /&gt;
| A &amp;lt;code&amp;gt;&amp;#039;&amp;#039;version&amp;#039;&amp;#039;.zip&amp;lt;/code&amp;gt; per version plus shared SST files; optionally changelog files&amp;lt;ref name=&amp;quot;rocksfm&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/core/src/main/scala/org/apache/spark/sql/execution/streaming/state/RocksDBFileManager.scala |title=RocksDBFileManager.scala (Apache Spark v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! State size limit in practice&lt;br /&gt;
| Executor heap; large state causes GC pauses&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
| Local disk and the configured memory bound&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
! transformWithState&lt;br /&gt;
| Not supported&lt;br /&gt;
| Supported&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
On Databricks, RocksDB is the default state store provider in Databricks Runtime 17.3 LTS and above.&amp;lt;ref name=&amp;quot;db-rocks&amp;quot;&amp;gt;{{Cite web |url=https://docs.databricks.com/aws/en/structured-streaming/rocksdb-state-store |title=Configure RocksDB state store on Databricks |publisher=Databricks |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== How big does state get? ==&lt;br /&gt;
State size is driven by the number of distinct keys each operator keeps and how long it keeps them. A [[watermark]] bounds it for windowed aggregations, deduplication and stream-stream joins; without one, aggregation and deduplication state grows for as long as new keys arrive.&amp;lt;ref name=&amp;quot;ss-dedup&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#streaming-deduplication |title=Structured Streaming: Streaming Deduplication (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Each operator reports state metrics in the query progress, including the number of rows in state (&amp;lt;code&amp;gt;numTotalStateRows&amp;lt;/code&amp;gt;), updated and removed rows.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;#039;&amp;#039;&amp;#039;state data source&amp;#039;&amp;#039;&amp;#039; reads the state of a checkpoint as a batch DataFrame, which helps to inspect state size and contents. It is experimental and, as of Spark 4.0, read-only.&amp;lt;ref name=&amp;quot;ss-store&amp;quot; /&amp;gt;&amp;lt;ref name=&amp;quot;jira45511&amp;quot;&amp;gt;{{Cite web |url=https://issues.apache.org/jira/browse/SPARK-45511 |title=SPARK-45511: SPIP: State Data Source - Reader |publisher=Apache Software Foundation JIRA |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
spark.conf.set(&lt;br /&gt;
    &amp;quot;spark.sql.streaming.stateStore.providerClass&amp;quot;,&lt;br /&gt;
    &amp;quot;org.apache.spark.sql.execution.streaming.state.RocksDBStateStoreProvider&amp;quot;,&lt;br /&gt;
)  # set before the query first starts; fixed for its checkpoint&lt;br /&gt;
&lt;br /&gt;
state = spark.read.format(&amp;quot;statestore&amp;quot;).load(&amp;quot;/checkpoints/page_counts&amp;quot;)&lt;br /&gt;
state.groupBy(&amp;quot;partition_id&amp;quot;).count().show()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Comparison with Flink state backends ==&lt;br /&gt;
[[Apache Flink]] calls the same component a &amp;#039;&amp;#039;&amp;#039;state backend&amp;#039;&amp;#039;&amp;#039;. Without other configuration it uses the &amp;lt;code&amp;gt;HashMapStateBackend&amp;lt;/code&amp;gt;, which holds state as objects on the Java heap, much like Spark&amp;#039;s HDFS-backed store. The &amp;lt;code&amp;gt;EmbeddedRocksDBStateBackend&amp;lt;/code&amp;gt; keeps state as serialized bytes in RocksDB and is the only Flink backend that offers incremental checkpoints; the &amp;lt;code&amp;gt;ForStStateBackend&amp;lt;/code&amp;gt; is experimental.&amp;lt;ref name=&amp;quot;flink-sb&amp;quot;&amp;gt;{{Cite web |url=https://nightlies.apache.org/flink/flink-docs-release-2.3/docs/ops/state/state_backends/ |title=State Backends (Apache Flink 2.3) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[RocksDB state store]]&lt;br /&gt;
* [[Stateful stream processing]]&lt;br /&gt;
* [[Streaming checkpoint]]&lt;br /&gt;
* [[transformWithState]]&lt;br /&gt;
* [[Watermark]]&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;br /&gt;
[[Category:Pipelines and orchestration]]&lt;/div&gt;</summary>
		<author><name>Open Lakehouse Wiki sync</name></author>
	</entry>
</feed>