Symptoms
- Row counts in a silver or gold table jumped by a whole day, week or the entire history in one run.
- Business reports show doubled totals; key-based checks find many duplicate keys.
- The job run that caused it looks normal, just much longer, with a very large first micro-batch.
- Someone deleted, renamed or "cleaned up" the checkpoint folder, changed the
checkpointLocationin code, or redeployed with a new path per environment.
Structured Streaming keeps "what have I already processed" only in the checkpoint. The Delta sink's exactly-once guarantee is tied to the query ID stored there. A new checkpoint is a new query: nothing stops it from writing the same data again.
What a new checkpoint does, by source
| Source | Behaviour on an empty checkpoint | Result |
|---|---|---|
Auto Loader (cloudFiles) | Lists the input path and processes every existing file (includeExistingFiles defaults to true) | Full re-ingest, duplicates |
| Delta table as source | Reads the current snapshot of the table, then new commits, unless startingVersion or startingTimestamp is set | Full re-ingest, duplicates |
| Kafka / Event Hubs Kafka endpoint | Uses startingOffsets (streaming default is latest) | Usually a data gap, not duplicates; with earliest, replays all retained events |
Kafka sources are the opposite problem: if the stream started at latest, events produced while it was down are skipped. Check which case you have before you fix anything.
Step 1: stop the stream (5 minutes)
Stop it before it writes more. For a job, cancel the active run and pause the schedule or continuous trigger:
databricks jobs list-runs --job-id 123456 --active-only -o json | jq '.[].run_id'
databricks jobs cancel-run 987654321
If the job is continuous, pause it in the UI (Pause) or set continuous.pause_status to PAUSED with databricks jobs update. Tell downstream owners to hold their refreshes; every downstream stream that reads this table is now copying the duplicates.
Step 2: find the commits written by the new query
Each streaming write records the query ID and epoch in the Delta history. The new checkpoint has a new queryId:
from pyspark.sql import functions as F
h = spark.sql("DESCRIBE HISTORY prod.silver.orders")
(h.filter(F.col("operation") == "STREAMING UPDATE")
.select("version", "timestamp",
F.col("operationParameters.queryId").alias("query_id"),
F.col("operationParameters.epochId").alias("epoch"),
F.col("operationMetrics.numOutputRows").alias("rows"))
.orderBy(F.desc("version"))
.show(50, truncate=False))
Look for the version where query_id changes and epoch restarts at 0. That version is the first bad commit; the version just before it is your last good version. Note whether any other writers (MERGE, batch jobs, deletes) committed after it.
Confirm the duplicates with the table's business key:
SELECT order_id, count(*) AS copies
FROM prod.silver.orders
GROUP BY order_id
HAVING count(*) > 1
ORDER BY copies DESC
LIMIT 20;
Step 3: get the old checkpoint back if you can
If the checkpoint was deleted and the storage account has blob soft delete enabled, you may be able to restore it. That is the cleanest recovery because the stream resumes exactly where it stopped.
az storage fs list-deleted-path --account-name stlakeprod -f checkpoints \
--path-prefix orders_silver --auth-mode login -o table
az storage fs undelete-path --account-name stlakeprod -f checkpoints \
--deleted-path-name orders_silver --deletion-id <deletion-id> --auth-mode login
If the old folder still exists (the code simply pointed at a new path), you don't need to undelete anything. Point the code back at it.
Warning
Do not restart the stream on the old checkpoint until the table is back to the last good version (step 4). The old checkpoint does not know about the rows the new query wrote.
Step 4: repair the table
Pick one option per table.
Option A: RESTORE (only the stream writes to the table)
RESTORE TABLE prod.silver.orders TO VERSION AS OF 4812;
Fast and exact. It also removes legitimate rows written after version 4812, which is fine if only this stream writes and you are about to replay from the old checkpoint.
Option B: de-duplicate in place (other writers committed after the incident)
Rewrite only the affected range from a de-duplicated copy of itself. Choose a column (ingest date, partition) that bounds the damage:
INSERT INTO prod.silver.orders
REPLACE WHERE ingest_date >= '2026-11-01'
SELECT * FROM prod.silver.orders
WHERE ingest_date >= '2026-11-01'
QUALIFY row_number() OVER (PARTITION BY order_id ORDER BY _ingested_at) = 1;
Check the counts before and after, and run the key check from step 2 again.
Caution
Both options rewrite production data. Record the current version first (
DESCRIBE HISTORY ... LIMIT 1) so you canRESTOREback if the repair is wrong. Do not runVACUUMon the table until the incident is closed.
Step 5: restart from the right position
| Situation | Restart with |
|---|---|
| Old checkpoint restored or still present, table restored to last good version | The old checkpoint, unchanged code path |
| Old checkpoint gone, Delta source | New checkpoint plus startingVersion = first source version not yet processed |
| Old checkpoint gone, Auto Loader | New checkpoint plus modifiedAfter (or includeExistingFiles = false if every existing file is already loaded) |
| Old checkpoint gone, Kafka | New checkpoint plus startingOffsets JSON per partition, or startingTimestamp |
Example for a Delta source:
(spark.readStream
.option("startingVersion", 15233)
.table("prod.bronze.orders")
.writeStream
.option("checkpointLocation", "abfss://checkpoints@stlakeprod.dfs.core.windows.net/orders_silver_v2")
.toTable("prod.silver.orders"))
startingVersion and startingTimestamp are read only when a checkpoint is new; on later restarts the checkpoint wins.
Step 6: repair downstream
- Downstream streams that read the table now see a
RESTOREorREPLACE WHERE, which is not an append. They fail with an "update detected" error. UseskipChangeCommitsor a controlled restart; see streaming source detected an update. - Materialized views and gold tables built during the incident need a refresh; aggregates computed from duplicated rows will not fix themselves.
- Tell report owners which time window was wrong and when it was fixed.
Confirm
- Duplicate-key query returns no rows.
- Row counts match the source for the incident window.
- The stream processes new data with small micro-batches and the same
queryIdacross restarts.
Prevent it next time
- Treat checkpoints as production state: keep them in a dedicated container with blob soft delete, a
CanNotDeletelock on the account and no broad write access. - Derive
checkpointLocationfrom the table name in code, never from a per-deploy variable, and fail fast if the path is empty on a job that has run before. - Make the sink idempotent: write with
foreachBatchandMERGEon the business key, or usetxnAppId/txnVersionfor batch-style writes, so a replay cannot create duplicates. - Add a data quality check (duplicate keys, row count against source) that pauses the job when it fails.
- Alert when a first micro-batch processes far more rows than normal, for example with a
StreamingQueryListeneror job duration alerts.
Get the weekly HubDatAI email
One email a week with everything new: posts, learning sessions and videos. Free, no spam, unsubscribe in one click. What you get