yesterday
Hi everyone,
Iโm learning about Structured Streaming in Databricks and came across checkpoints.
I understand that checkpoints are used to keep track of the progress of a streaming query, but Iโd like to understand their purpose more clearly.
For example, if a streaming pipeline is processing customer transactions and the pipeline stops unexpectedly, how does the checkpoint help the pipeline continue processing from where it stopped?
What is the main purpose of checkpoints, and why are they important in a real-time data pipeline?
Thanks!
yesterday
Hi @gowri_databrick,
Welcome to the world of Structured Streaming!
(df.writeStream
.option("checkpointLocation", "/Volumes/catalog/schema/volume/checkpoint")
.toTable("catalog.schema.target_table")
)If you are just getting started, the Run your first Structured Streaming workload tutorial walks through a complete example with checkpointing. For production pipelines, also check out Production considerations for Structured Streaming, which covers how to configure automatic restarts so your pipeline recovers from failures without manual intervention.
If this answer resolves your question, could you mark it as โAccept as Solutionโ? That helps other users quickly find the correct fix.
yesterday
Checkpoints in Structured Streaming serve as the ledger and recovery mechanism for streaming queries. It tracks which data has been processed and successfully written, enabling exactly once processing guarantees. A checkpoint contains several key components: offsets (which records to process), commits (which batches completed successfully) and metadata about the stream. When your customer transactions pipeline processes data, Spark writes the offset before starting a batch and writes the commit after the batch completes. This two-phase approach ensures that if the pipeline crashes mid-batch, Spark knows precisely where to resume.
When an unexpected failure occurs, the checkpoint enables automatic recovery without data loss or duplication. Upon restart, Spark reads the checkpoint and discovers the last committed offset. If a batch started but didn't complete (offset exists but no matching commit), Spark automatically reprocesses that batch. For your transactions example, if the pipeline crashes while processing transactions 1000-1500, the checkpoint shows offset 1000 was started but never committed. On restart, Spark reprocesses from transaction 1000 onward ensuring no transactions are lost or duplicated. This fault tolerance is critical in pipelines where stopping to manually determine restart positions would cause data gaps and operational overhead.
12 hours ago
Yes, checkpoints are basically how Structured Streaming remembers where it got to.
For example, imagine a streaming pipeline processing customer transactions:
Source โ Structured Streaming โ Delta table
Suppose the pipeline has processed transactions up to transaction 10,000, and then the cluster suddenly stops.
The checkpoint stores the progress information, so when the pipeline starts again, it can understand what has already been processed and continue from the appropriate point rather than starting from the beginning.
So, in simple terms:
Checkpoint = the streaming pipeline's saved progress
This is important because in a real-time pipeline, we don't want to lose data or process the same data unnecessarily every time there is a restart or failure.
One important point is that the checkpoint location should be persistent and stable. It shouldn't be stored somewhere that gets deleted when the cluster restarts.
A simple example would be:
10,000 transactions processed โ pipeline fails โ restart โ checkpoint helps resume from the saved progress
That's why checkpoints are an important part of reliable Structured Streaming pipelines.
10 hours ago
Hey @gowri_databrick ,
Think of the checkpoint as a bookmark for your stream.
As your query runs, it writes down two things: which data it has already read from the source, and the state it has built up so far, like running counts or aggregations.
So with your transactions example, say the stream has processed everything up to file 500 and then the cluster dies. When you restart, Spark reads the checkpoint, sees that it got through file 500, and picks up at 501. No gap, and nothing gets processed twice. Without a checkpoint it would either start over from scratch or start from now and silently lose everything in between.
That is really the whole point: exactly once processing across restarts. Streams do not run forever without interruption. Clusters restart, jobs get redeployed, code gets updated. The checkpoint is what makes those interruptions boring instead of a data quality incident.
Two practical things worth knowing. Each streaming query needs its own checkpoint location, because sharing one between two queries will break them. And do not delete the checkpoint directory when a stream misbehaves. It is tempting, but it wipes the bookmark, so you will either reprocess everything or lose data.