Home / Databricks on Azure

Databricks on AzureRunbookAdvanced

Sev1: a deleted or reset streaming checkpoint made a Databricks stream reprocess everything and duplicate production data

A stream restarted on an empty checkpoint and re-ingested old files or Delta versions into production. Stop it, size the damage with Delta history, restore or de-duplicate, and restart from the right position.

Deepak Bhardwaj6 min read

Applies toAzure Databricks Structured Streaming and Auto Loader on Databricks Runtime 13.3 LTS and later, Delta Lake sinks, ADLS Gen2 checkpoints

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 checkpointLocation in 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 can RESTORE back if the repair is wrong. Do not run VACUUM on 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 RESTORE or REPLACE WHERE, which is not an append. They fail with an "update detected" error. Use skipChangeCommits or 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 queryId across restarts.

Prevent it next time

  • Treat checkpoints as production state: keep them in a dedicated container with blob soft delete, a CanNotDelete lock on the account and no broad write access.
  • Derive checkpointLocation from 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 foreachBatch and MERGE on the business key, or use txnAppId/txnVersion for 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 StreamingQueryListener or job duration alerts.