Hi @gowri_databrick,
Welcome to the world of Structured Streaming!
Think of a checkpoint as a bookmark for your streaming pipeline. It's a directory on durable storage (such as S3, ADLS, or GCS) where Spark Structured Streaming saves your query's progress after each micro-batch. Specifically, it records:
- Offsets... which records from the source have already been processed.
- Commits... which micro-batches have been successfully written to the sink.
- State... for stateful operations like aggregations or deduplication, the intermediate computation state is saved here too.
- Metadata.... the unique query ID and configuration details.
You enable it by setting the checkpointLocation option on your writeStream:
(df.writeStream
.option("checkpointLocation", "/Volumes/catalog/schema/volume/checkpoint")
.toTable("catalog.schema.target_table")
)
Say you have a pipeline reading customer transactions from Kafka and writing them to a Delta Lake table. The pipeline has processed transactions 1 through 10,000 and the checkpoint has recorded that progress. Now the cluster crashes.
When the pipeline restarts, Spark reads the checkpoint and sees: "I already committed everything up to offset 10,000." It picks up right at 10,001... no data is lost, and no transaction gets processed twice. Without a checkpoint, the pipeline would have no memory of what it already did. It would either start from the beginning (duplicating everything) or skip ahead and lose data.
The checkpoint is what gives Structured Streaming its
exactly-once processing guarantee. Combined with an idempotent sink like Delta Lake, it ensures every record is processed once and only once, even through failures. This is critical for pipelines where duplicates or missing records have real business consequences, like financial transactions, inventory updates, or customer event tracking.
A few things worth keeping in mind as you build:
- Every streaming query needs its own unique checkpoint location. Never share a checkpoint between two different queries.
- Deleting or changing the checkpoint directory resets the query, so it starts fresh from the beginning.
- Certain changes to your query logic (like modifying stateful operations) are not compatible with an existing checkpoint and require starting with a new one. The Structured Streaming checkpoints docs cover exactly which changes are safe and which are not.
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.
Regards,
Ashwin | Delivery Solution Architect @ Databricks
Helping you build and scale the Data Intelligence Platform.
***Opinions are my own***