Design a late-arriving data strategy
Orders can arrive up to 7 days late and finance locks reports after 48 hours. Design the pipeline that keeps both honest.
Scenario
NorthBridge Retail ingests store orders from 400 franchise locations. Stores with flaky connectivity upload on reconnect, so ~2% of orders arrive between 1 and 7 days late. Finance publishes daily revenue at T+1 and locks the numbers at T+2 for reconciliation. The BI team currently reloads the whole month nightly, which takes 6 hours and still disagrees with finance.
Task
Design the data flow. Your answer should cover:
- How bronze/silver/gold each handle a late order.
- How you reprocess only affected days, not the whole month.
- What happens when a late order lands for a day finance has already locked.
- Which metrics/monitoring make lateness visible instead of surprising.
Constraints
- Azure + Databricks + Delta Lake stack.
- Gold daily revenue must be reproducible for auditors (what did we report, and what is true now?).
- The 6-hour full reload must go away.
Hints
Hint 1
Separate two timelines: when the order happened (event time) and when you received it (ingestion time). Every layer should keep both.
Hint 2
If silver records _ingest_date, "which event days got new data since the last gold run?" is a cheap SELECT DISTINCT order_date WHERE _ingest_date > last_run. That set drives targeted gold rebuilds.
Hint 3
A locked report and a correct number can coexist: snapshot the published figure (as-reported) and keep gold current (as-is). The difference becomes an explicit restatement row, not a silent change.
Solution
Show solution
Reference design
- Bronze — append-only, never rejected for lateness. Every row carries
order_ts(event time) and_ingest_ts. - Silver — MERGE by
order_id, pruned by event date (late window = 7 days, from measured lateness, with a slow path for stragglers beyond it). Keeps_ingest_date. - Affected-day detection — after each silver batch:
SELECT DISTINCT order_date
FROM silver.orders
WHERE _ingest_date = current_date();- Gold — rebuild only those days with partition overwrite (
replaceWhere). A 7-day tail rebuild takes minutes, not 6 hours. - Locking —
gold.revenue_reportedis an immutable snapshot written once at T+2 (as-reported).gold.revenue_currentstays live. Arestatementsview diffs them; material differences page the finance data lead instead of silently rewriting history. Delta time travel is the audit backstop, but the explicit snapshot is what auditors sign. - Monitoring — lateness histogram (
_ingest_ts - order_ts) per store; alert when p99 lateness grows or when a late order exceeds the 7-day window (those route to a manual adjustment queue).
Why not just reload everything?
Full reloads hide the problem: they make every number quietly unstable and cost 6 hours a night. Targeted rebuilds plus explicit restatement make lateness a managed business event.
Alternative approaches
- Structured Streaming with watermarking handles in-window lateness naturally; the locked-report/restatement layer is still needed — watermarks don't solve reporting policy.
Follow-up questions
- A store's clock was wrong by 3 days for a month. Which part of your design catches it?
- Finance wants the lock moved to T+1. What breaks first, and what do you renegotiate?
Learn the concept
Keep going
Delta Lake MERGE without the full-table rewrite
Why MERGE quietly rewrites far more data than it changes, and the three fixes that keep it fast: prune the target, deduplicate the source, compact after.
Build an SCD Type 2 with MERGE
Apply a day's customer address changes to a dimension table, closing old versions and inserting new ones, in a single MERGE.
ADF: tumbling window triggers are not schedule triggers
Tumbling windows are stateful — they backfill, retry per window and expose window start/end. Schedule triggers just fire and forget.