Running a Data Incident and Reprocessing Safely
Handle a data incident from first alert to closed review: declare it and assign roles, contain the damage by flagging the affected data, tell consumers what is wrong in a message they can act on, correct the data with an audited, repeatable reprocess, and write a blameless review whose findings change the system. Run the containment and the reprocessing on a small DuckDB mart.
Contentsand lesson path
On this page
- Why it matters
- Declare the incident and assign roles
- Contain the damage first
- Inform consumers
- Correct the data with a safe reprocess
- Write a blameless review
- Check your understanding
- Apply it
- Review prompt
Lessons of Pipeline Observability & Cost
- Signals for Data: Freshness, Volume, Schema, Distribution Concept · 20 min
- Lab: Instrumented Runs and a Freshness Dashboard Lab · 30 min
- Worked Example: Tracing a Wrong Number to Its Source Worked example · 25 min
- Running a Data Incident and Reprocessing Safely Concept · 20 min
- Lab: Cost Attribution and a Measured Cost Cut Lab · 30 min
- Check: Operations Scenario Review Knowledge check · 8 questions
What you will learn
- Handle a data incident end to end: contain it, inform consumers, correct or backfill the data, and write a blameless review.
01. Why it matters
Lesson 3 found the cause of a wrong number. In real life, the cause is often found while the wrong number is still being used: a dashboard is open in a meeting, an export is about to send data to the accounting system, or a model retrains overnight. A data incident is any event where data that people rely on is wrong, late or missing in a way that affects their work. Handling one well is less about clever debugging and more about doing things in the right order.
The order is: contain the damage, inform the people affected, correct the data, then review what happened. Teams under pressure tend to skip straight to debugging and fixing, while consumers keep reading bad numbers and nobody knows what is going on. A clear process also lowers stress: everyone knows what happens next and who decides.
This lesson walks through one incident: a new loader appended orders a second time, so two days in a published mart show double revenue. You will contain it and reprocess it with DuckDB, and write the messages and the review around it. The code runs in the poc-lab folder from lesson 1 with its .venv (DuckDB 1.5.6).
02. Declare the incident and assign roles
An incident starts when someone says so. If a check fails or a consumer reports a problem that affects published data, declare an incident: open a channel or ticket with an id (here INC-42), write one line about what is known, and set a severity. Base severity on impact on consumers, not on how interesting the bug is: wrong numbers in a regulatory report or a customer-facing product rank higher than a delay in an internal dashboard.
Then give people roles, even if the team is small:
- The incident lead coordinates, decides and keeps the timeline. They do not need to be the person debugging.
- The communications role keeps consumers informed, so the people fixing are not interrupted.
- One or more responders investigate and fix.
Write down times as you go: when the alert fired, when the incident was declared, what was tried. The alert log and run metadata from lesson 2 already give you the first entries.
03. Contain the damage first
Containment stops the bad data from spreading or being used, before you know the full cause. Typical options are: pause the job that writes the data, so it does not make things worse; stop publishing, for example by hiding the affected dates in the views that consumers read; or roll back the table to the last good version, if your table format keeps versions (Delta Lake and Apache Iceberg do, with time travel). Keep the evidence: do not delete bad rows before you have counted them.
Set up the example mart. A buggy deploy loaded 9 and 10 November twice, and the dashboard reads the view orders_published.
"""Create incident.duckdb: raw orders for 8-10 Nov and an orders_mart that a buggy
deploy loaded twice for 9 and 10 Nov (an append that was retried)."""
import duckdb
con = duckdb.connect("incident.duckdb")
con.execute("""
CREATE OR REPLACE TABLE raw_orders AS
SELECT 1000 + i AS order_id, DATE '2026-11-08' + (i % 3)::INT AS day,
round(10 + (i * 37 % 900) / 10, 2)::DECIMAL(8, 2) AS amount
FROM range(150) t(i);
-- The order system's own daily totals, sent with each extract. Here they are
-- computed from the raw data; in real life they come from the source system.
CREATE OR REPLACE TABLE source_control AS
SELECT day, count(*) AS orders, sum(amount) AS revenue FROM raw_orders GROUP BY day;
CREATE OR REPLACE TABLE orders_mart AS SELECT * FROM raw_orders;
-- The bug: the new loader appends instead of replacing, and it was retried.
INSERT INTO orders_mart SELECT * FROM raw_orders WHERE day >= '2026-11-09';
CREATE OR REPLACE TABLE data_status (day DATE, status VARCHAR, incident VARCHAR);
-- What the dashboard reads: days flagged as suspect are hidden, not shown wrong.
CREATE OR REPLACE VIEW orders_published AS
SELECT * FROM orders_mart
WHERE day NOT IN (SELECT day FROM data_status WHERE status = 'suspect');
""")
print(con.sql("""SELECT day, count(*) AS mart_rows, count(DISTINCT order_id) AS orders,
sum(amount) AS revenue FROM orders_mart GROUP BY day ORDER BY day""")).venv/bin/python incident_setup.py┌────────────┬───────────┬────────┬───────────────┐
│ day │ mart_rows │ orders │ revenue │
│ date │ int64 │ int64 │ decimal(38,2) │
├────────────┼───────────┼────────┼───────────────┤
│ 2026-11-08 │ 50 │ 50 │ 2757.50 │
│ 2026-11-09 │ 100 │ 50 │ 5345.00 │
│ 2026-11-10 │ 100 │ 50 │ 5175.00 │
└────────────┴───────────┴────────┴───────────────┘The mart holds 100 rows for each bad day but only 50 distinct orders, so revenue is doubled. Pause the loader in the orchestrator first. Then flag the two days as suspect in a status table that the published view reads. Consumers now see no data for those days instead of wrong data, and a dashboard can show "under review" for them.
"""Containment: flag the affected days as suspect, so consumers stop using them."""
import duckdb
con = duckdb.connect("incident.duckdb")
con.execute("""INSERT INTO data_status VALUES ('2026-11-09', 'suspect', 'INC-42'),
('2026-11-10', 'suspect', 'INC-42')""")
print(con.sql("SELECT day, count(*) AS rows FROM orders_published GROUP BY day")).venv/bin/python contain.py┌────────────┬───────┐
│ day │ rows │
│ date │ int64 │
├────────────┼───────┤
│ 2026-11-08 │ 50 │
└────────────┴───────┘Hiding is not free: some consumers may need a number, even an approximate one. That is why the next step is a message that says what to do in the meantime.
04. Inform consumers
Consumers need to decide what to do with their own work: delay a report, rerun a model later, warn their customers. Give them what they need for that decision, in plain words, as soon as the incident is contained, and again at the times you promise. A good update states what is wrong in terms of their data, exactly which tables and dates are affected (and which are not), what they should do now, and when the next update will come. Send it through the channel they watch, and list every owner found by the downstream lineage walk from lesson 3.
[INC-42] Duplicate orders in orders_mart (update 1, 10:40 UTC)
Status: contained. The loader is paused; a fix is being tested.
What is wrong: orders for 9 and 10 Nov were loaded twice, so revenue
for those two days is about double the real value.
Affected: orders_mart, orders_published and the daily revenue dashboard,
dates 2026-11-09 and 2026-11-10 only. Other dates are correct.
What to do now: do not use revenue for those dates. Dashboards show
them as "under review". Hold any export that includes them.
Next update: 12:00 UTC, or earlier if corrected data is published.
Contact: #inc-42. Incident lead: data platform on-call.Note what the message leaves out: the technical details of the bug, guesses about the cause, and blame. Those belong in the review. A message sent early with "we don't know yet, next update at 12:00" is far more useful than a perfect explanation sent after the fix.
05. Correct the data with a safe reprocess
Reprocessing (or a backfill) rebuilds data for a range of dates. It is the most dangerous step, because it writes to the same tables consumers read, often under time pressure. Three rules keep it safe.
First, make it idempotent: running it twice must give the same result as running it once. Replacing whole days (delete, then insert, in one transaction) has that property; appending does not, and appending is exactly the bug here. If someone re-ran the buggy loader to "fix" the problem, it would add the day's orders yet again.
Second, use write-audit-publish: write the rebuilt data to a staging table, audit it, and publish only if every audit passes. A failed audit leaves the published table exactly as it was. The audits must be able to fail, so compare with something the rebuild did not produce. Here that is source_control, the daily order count and revenue that the order system reports with each extract (the setup script computes it from the raw data; in real life the source sends it). The script first runs the same audits on the damaged mart, to show that they catch this bug.
Third, limit the scope to what lineage says is affected, and rebuild downstream tables in dependency order, as in lesson 3. Reprocessing a year of data when two days are wrong costs compute and money, and widens the risk.
"""Write-audit-publish: audit the damaged days, rebuild them in a staging table,
audit the rebuild against the order system's control totals, and publish only if
every audit passes."""
import duckdb
con = duckdb.connect("incident.duckdb")
con.execute("CREATE OR REPLACE TEMP TABLE affected AS "
"SELECT unnest(['2026-11-09', '2026-11-10']::DATE[]) AS day")
AUDITS = {
"no duplicate order ids": """SELECT count(*) = count(DISTINCT order_id)
FROM {t} WHERE day IN (SELECT day FROM affected)""",
"every affected day present": """SELECT count(DISTINCT day) = 2
FROM {t} WHERE day IN (SELECT day FROM affected)""",
"orders and revenue match control totals": """SELECT count(*) = 0 FROM (
SELECT day, count(*) AS orders, sum(amount) AS revenue FROM {t}
WHERE day IN (SELECT day FROM affected) GROUP BY day) AS t
JOIN source_control AS c USING (day)
WHERE t.orders <> c.orders OR t.revenue <> c.revenue""",
}
def audit(table):
results = {name: con.execute(sql.format(t=table)).fetchone()[0]
for name, sql in AUDITS.items()}
for name, ok in results.items():
print(f"audit {table}: {name}: {'pass' if ok else 'FAIL'}")
return all(results.values())
audit("orders_mart") # the damage
con.execute("""CREATE OR REPLACE TABLE orders_staging AS -- 1. write
SELECT DISTINCT * FROM raw_orders WHERE day IN (SELECT day FROM affected)""")
if not audit("orders_staging"): # 2. audit
raise SystemExit("not published: orders_mart is unchanged")
con.execute("BEGIN") # 3. publish
con.execute("DELETE FROM orders_mart WHERE day IN (SELECT day FROM affected)")
con.execute("INSERT INTO orders_mart SELECT * FROM orders_staging")
con.execute("UPDATE data_status SET status = 'corrected' WHERE incident = 'INC-42'")
con.execute("COMMIT")
print(con.sql("""SELECT day, count(*) AS rows, sum(amount) AS revenue
FROM orders_published GROUP BY day ORDER BY day""")).venv/bin/python reprocess.py
.venv/bin/python reprocess.py | head -n 6audit orders_mart: no duplicate order ids: FAIL
audit orders_mart: every affected day present: pass
audit orders_mart: orders and revenue match control totals: FAIL
audit orders_staging: no duplicate order ids: pass
audit orders_staging: every affected day present: pass
audit orders_staging: orders and revenue match control totals: pass
┌────────────┬───────┬───────────────┐
│ day │ rows │ revenue │
│ date │ int64 │ decimal(38,2) │
├────────────┼───────┼───────────────┤
│ 2026-11-08 │ 50 │ 2757.50 │
│ 2026-11-09 │ 50 │ 2672.50 │
│ 2026-11-10 │ 50 │ 2587.50 │
└────────────┴───────┴───────────────┘
audit orders_mart: no duplicate order ids: pass
audit orders_mart: every affected day present: pass
audit orders_mart: orders and revenue match control totals: pass
audit orders_staging: no duplicate order ids: pass
audit orders_staging: every affected day present: pass
audit orders_staging: orders and revenue match control totals: passOn the damaged mart, two audits fail: duplicate order ids, and totals that do not match the source. The staging copy passes all three, so it was published; the two days now show 50 orders each, and the status changed from suspect to corrected, so the view shows them again. The second run, cut to its audit lines, finds a healthy mart and publishes the same result: the reprocess is safe to repeat. Before closing, send a final update to consumers saying the data is corrected, from when, and what they need to rerun on their side.
06. Write a blameless review
After the incident, write a short review while memories are fresh. Blameless means it describes what the system allowed, not who made a mistake. People act on the information and tools they have; if a reasonable person could make the same change, the system needs to change. Naming and blaming teaches everyone to hide problems, which makes the next incident longer.
A useful review has a timeline (from the alert log, run metadata and the incident channel), the impact (which data, dates and consumers, for how long), the contributing factors, what went well, and action items. Write contributing factors as conditions: "the loader had no check that rejects duplicate order ids", "the published view had no way to hide a date until this incident", "reruns appended instead of replacing a day". Each action item has an owner and a due date, for example "add a unique-key audit to the loader, owner: data platform, due 24 Nov". Close the incident only when the data is corrected, consumers have been told, and every action item has an owner.
07. Check your understanding
08. Apply it
For the skill practice, write the incident timeline and fix for the late file and the schema change you simulated in lesson 2. Use the alert log and run metadata for the times. Include the first consumer update you would have sent, the containment step you would use in your platform (pause, hide or roll back), a reprocess that is idempotent and audited, and a short blameless review with at least two contributing factors and owned action items.
09. Review prompt
Without looking back, explain: what makes an event a data incident; the four stages in order and why containment comes first; the roles of incident lead and communications; three ways to contain bad data; what a consumer update must contain; why a reprocess must be idempotent, and how write-audit-publish protects consumers; and what makes a review blameless.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.