<?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=Checkpointing_(Spark)</id>
	<title>Checkpointing (Spark) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://openlakehouse.io/w/index.php?action=history&amp;feed=atom&amp;title=Checkpointing_(Spark)"/>
	<link rel="alternate" type="text/html" href="https://openlakehouse.io/w/index.php?title=Checkpointing_(Spark)&amp;action=history"/>
	<updated>2026-12-06T00:08:14Z</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=Checkpointing_(Spark)&amp;diff=132&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=Checkpointing_(Spark)&amp;diff=132&amp;oldid=prev"/>
		<updated>2026-11-25T00:52:37Z</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            = Checkpointing (Spark)&lt;br /&gt;
| also_known_as   = Lineage checkpoint, streaming checkpoint&lt;br /&gt;
| field           = Distributed data processing&lt;br /&gt;
| key_parts       = RDD and DataFrame checkpoints, local checkpoints, checkpoint directory, Structured Streaming &amp;lt;code&amp;gt;checkpointLocation&amp;lt;/code&amp;gt;&lt;br /&gt;
| implementations = [[Apache Spark]]&lt;br /&gt;
| related         = [[Caching and persistence]], [[Structured Streaming]], [[Exactly-once semantics]], [[RDD]], [[Delta Lake]]&lt;br /&gt;
}}&lt;br /&gt;
{{Verified|2026-11-23|the v4.3.0 tag of apache/spark (core RDD.scala, sql/api Dataset.scala, python/pyspark/sql/dataframe.py, docs/configuration.md, docs/streaming/apis-on-dataframes-and-datasets.md) and the Delta Lake protocol at tag v4.4.1}}&lt;br /&gt;
&lt;br /&gt;
In [[Apache Spark]], &amp;#039;&amp;#039;&amp;#039;checkpointing&amp;#039;&amp;#039;&amp;#039; is saving data or query progress to storage so that later work can start from the saved copy instead of recomputing it, and the word names two different features. &amp;#039;&amp;#039;&amp;#039;Lineage checkpointing&amp;#039;&amp;#039;&amp;#039; saves the data of an [[RDD]] or DataFrame to storage and cuts its lineage or query plan, so that later work starts from the saved data instead of recomputing everything. &amp;#039;&amp;#039;&amp;#039;Streaming checkpoints&amp;#039;&amp;#039;&amp;#039; are the progress and state that a [[Structured Streaming]] query writes to its &amp;lt;code&amp;gt;checkpointLocation&amp;lt;/code&amp;gt; so it can restart where it stopped.&amp;lt;ref name=&amp;quot;rdd&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/core/src/main/scala/org/apache/spark/rdd/RDD.scala |title=RDD.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&amp;lt;ref name=&amp;quot;ss&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming/apis-on-dataframes-and-datasets.html#recovering-from-failures-with-checkpointing |title=Structured Streaming: Recovering from Failures with Checkpointing (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; The two share a name but not a purpose, a format, or an API. This page is a short guide to which is which.&lt;br /&gt;
&lt;br /&gt;
== Kinds of checkpoint ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Kind !! API !! What it saves !! Why&lt;br /&gt;
|-&lt;br /&gt;
| RDD checkpoint&lt;br /&gt;
| &amp;lt;code&amp;gt;sc.setCheckpointDir(dir)&amp;lt;/code&amp;gt;, then &amp;lt;code&amp;gt;rdd.checkpoint()&amp;lt;/code&amp;gt;&lt;br /&gt;
| The RDD&amp;#039;s partitions, in the checkpoint directory; references to parent RDDs are removed&amp;lt;ref name=&amp;quot;rdd&amp;quot; /&amp;gt;&lt;br /&gt;
| Cut long lineage, for example in iterative algorithms&lt;br /&gt;
|-&lt;br /&gt;
| RDD local checkpoint&lt;br /&gt;
| &amp;lt;code&amp;gt;rdd.localCheckpoint()&amp;lt;/code&amp;gt;&lt;br /&gt;
| The RDD&amp;#039;s partitions in executor storage, through the caching layer&amp;lt;ref name=&amp;quot;rdd&amp;quot; /&amp;gt;&lt;br /&gt;
| Cut lineage without the cost of a reliable file system; not fault tolerant&lt;br /&gt;
|-&lt;br /&gt;
| DataFrame checkpoint&lt;br /&gt;
| &amp;lt;code&amp;gt;df.checkpoint(eager=True)&amp;lt;/code&amp;gt;&lt;br /&gt;
| The DataFrame&amp;#039;s data in the checkpoint directory; the logical plan is truncated&amp;lt;ref name=&amp;quot;dataset&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/sql/api/src/main/scala/org/apache/spark/sql/Dataset.scala |title=Dataset.scala (v4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Stop a query plan from growing in loops&lt;br /&gt;
|-&lt;br /&gt;
| DataFrame local checkpoint&lt;br /&gt;
| &amp;lt;code&amp;gt;df.localCheckpoint(eager=True)&amp;lt;/code&amp;gt;&lt;br /&gt;
| The data in executor storage&amp;lt;ref name=&amp;quot;dataset&amp;quot; /&amp;gt;&lt;br /&gt;
| Faster, but executor loss can fail the job&lt;br /&gt;
|-&lt;br /&gt;
| Structured Streaming checkpoint&lt;br /&gt;
| &amp;lt;code&amp;gt;.option(&amp;quot;checkpointLocation&amp;quot;, path)&amp;lt;/code&amp;gt; on &amp;lt;code&amp;gt;writeStream&amp;lt;/code&amp;gt;&lt;br /&gt;
| Offsets processed in each trigger, and running state such as aggregates&amp;lt;ref name=&amp;quot;ss&amp;quot; /&amp;gt;&lt;br /&gt;
| Restart a query after failure or shutdown&lt;br /&gt;
|-&lt;br /&gt;
| [[Spark Streaming (DStreams)|DStreams]] checkpoint&lt;br /&gt;
| &amp;lt;code&amp;gt;StreamingContext.checkpoint(dir)&amp;lt;/code&amp;gt;&lt;br /&gt;
| Metadata defining the computation, and generated RDDs saved to reliable storage&amp;lt;ref name=&amp;quot;dstreams&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/streaming-programming-guide.html#checkpointing |title=Spark Streaming Programming Guide: Checkpointing (Spark 4.3.0) |publisher=Apache Software Foundation |access-date=2026-11-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
| Recovery for the DStreams API, deprecated since Spark 3.4.0&amp;lt;ref name=&amp;quot;spark42075&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-23}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Lineage checkpointing (RDD and DataFrame) ==&lt;br /&gt;
An RDD checkpoint is lazy. &amp;lt;code&amp;gt;rdd.checkpoint()&amp;lt;/code&amp;gt; only marks the RDD, and the data is written at the end of the first action on it. The Spark source recommends persisting the RDD first, because writing the checkpoint otherwise recomputes it.&amp;lt;ref name=&amp;quot;rdd&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A DataFrame checkpoint is eager by default: &amp;lt;code&amp;gt;df.checkpoint()&amp;lt;/code&amp;gt; runs a job right away and returns a new DataFrame whose plan starts from the saved data.&amp;lt;ref name=&amp;quot;dataset&amp;quot; /&amp;gt; With &amp;lt;code&amp;gt;eager=False&amp;lt;/code&amp;gt;, the saved data may differ from what the job used if the plan is non-deterministic and tasks are retried, so the Spark docs recommend &amp;lt;code&amp;gt;eager=True&amp;lt;/code&amp;gt; for a deterministic snapshot.&amp;lt;ref name=&amp;quot;dataset&amp;quot; /&amp;gt; DataFrame checkpointing has been in the Dataset API since Spark 2.1.0 and works with [[Spark Connect]] since Spark 4.0.0.&amp;lt;ref name=&amp;quot;pydf&amp;quot;&amp;gt;{{Cite web |url=https://github.com/apache/spark/blob/v4.3.0/python/pyspark/sql/dataframe.py |title=dataframe.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 checkpoint directory comes from &amp;lt;code&amp;gt;SparkContext.setCheckpointDir&amp;lt;/code&amp;gt; or, since Spark 4.0.0, the &amp;lt;code&amp;gt;spark.checkpoint.dir&amp;lt;/code&amp;gt; configuration. Spark does not delete checkpoint files when the checkpointed data goes out of scope unless &amp;lt;code&amp;gt;spark.cleaner.referenceTracking.cleanCheckpoints&amp;lt;/code&amp;gt; (default false) is set.&amp;lt;ref name=&amp;quot;config&amp;quot;&amp;gt;{{Cite web |url=https://spark.apache.org/docs/4.3.0/configuration.html |title=Spark Configuration (Spark 4.3.0) |publisher=Apache Software Foundation |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.checkpoint.dir is set when the session starts, for example&lt;br /&gt;
#   --conf spark.checkpoint.dir=s3a://bucket/checkpoints&lt;br /&gt;
&lt;br /&gt;
df = spark.read.table(&amp;quot;main.ml.features&amp;quot;)&lt;br /&gt;
for i in range(20):&lt;br /&gt;
    df = update_step(df)          # user function; each step adds to the plan&lt;br /&gt;
    if i % 5 == 4:&lt;br /&gt;
        df = df.checkpoint()      # cut the plan every five iterations&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Local checkpoints are faster because they skip the reliable file system, but executor loss makes the data unreachable and can fail the job. The Spark source warns that local checkpointing is not safe with [[dynamic allocation]], which removes executors together with their cached blocks.&amp;lt;ref name=&amp;quot;rdd&amp;quot; /&amp;gt; Lineage checkpointing is also different from [[Caching and persistence|caching]], which keeps lineage and recomputes lost partitions.&lt;br /&gt;
&lt;br /&gt;
== Streaming checkpoints ==&lt;br /&gt;
A Structured Streaming query with a &amp;lt;code&amp;gt;checkpointLocation&amp;lt;/code&amp;gt; saves its progress (the range of offsets processed in each trigger) and its running state to that path, using checkpoints and write-ahead logs. On restart with the same location, the query continues where it left off. The location has to be a path in an HDFS-compatible file system.&amp;lt;ref name=&amp;quot;ss&amp;quot; /&amp;gt; Streaming checkpoints are needed for the end-to-end guarantees described in [[Exactly-once semantics]].&lt;br /&gt;
&lt;br /&gt;
A streaming checkpoint is tied to one query. Deleting it, or pointing a changed query at it, changes what the query reprocesses; the Structured Streaming guide&amp;#039;s section &amp;quot;Recovery Semantics after Changes in a Streaming Query&amp;quot; lists which changes are allowed between restarts.&amp;lt;ref name=&amp;quot;ss&amp;quot; /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Delta Lake checkpoints ==&lt;br /&gt;
[[Delta Lake]] uses the word for a third thing: a &amp;#039;&amp;#039;&amp;#039;checkpoint&amp;#039;&amp;#039;&amp;#039; in the Delta transaction log is a Parquet file that summarizes the table&amp;#039;s state at a version, so readers can rebuild a snapshot without replaying every JSON commit, and old log entries can be cleaned up.&amp;lt;ref name=&amp;quot;delta&amp;quot;&amp;gt;{{Cite web |url=https://github.com/delta-io/delta/blob/v4.4.1/PROTOCOL.md#checkpoints |title=Delta Transaction Log Protocol: Checkpoints (v4.4.1) |publisher=Delta Lake (Linux Foundation) |access-date=2026-11-23}}&amp;lt;/ref&amp;gt; Delta checkpoints are written by the table format, not by Spark&amp;#039;s checkpoint APIs.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* [[Caching and persistence]]&lt;br /&gt;
* [[Structured Streaming]]&lt;br /&gt;
* [[Exactly-once semantics]]&lt;br /&gt;
* [[RDD]]&lt;br /&gt;
* [[Delta Lake]]&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>