5. Recover, reconcile, reload, replay: semantics and mechanisms
5. Recover, reconcile, reload, replay: semantics and mechanisms
Date: 2026-10-26
Status
Accepted
Problem
The brief says the solution must "recover, reconcile or reload data when required" and asks how the architecture handles "failures, retries, duplicate data, partial processing, missed changes and recovery/reprocessing". Those words hide four different operations, and a design that supports one does not automatically support the others. The architect raised the same ambiguity: is this historical replay, or idempotency?
Brainstormed interpretations, all of which turn out to be needed:
| Term | Meaning adopted | Trigger | Touches the source? |
|---|---|---|---|
| Recover | Resume a run after a failure from the last committed position, without duplicates | API 5xx mid-page, capacity throttling, deployment | Yes, from the checkpoint |
| Reload | Re-extract a bounded window or object from the source, because the source changed its answer or an extraction was wrong | Google Ads restatement; Salesforce bulk job failure; a reconciliation discrepancy; a bug in an adapter | Yes, bounded window |
| Replay | Rebuild Silver and Gold from Bronze with new logic, without calling any source | Transformation bug; schema change; new Gold measure | No |
| Reconcile | Measure whether the lake matches the source (and whether Gold matches Silver), and turn discrepancies into targeted reloads | Scheduled daily; after any incident | Yes, counts only |
| Idempotency | The property that makes all of the above safe: any run for a window can be executed twice with the same result | Every run | — |
Event streams complicate this: Salesforce replay expires after 72 hours and HubSpot webhooks cannot be replayed at all, so reload of a window can only ever come from the polling path.
Decision
We will implement the following mechanisms, all of them, and name them in the run ledger.
Idempotency (the foundation)
- Every run has a
run_id(unique per attempt) and a deterministicwindow_key={source}/{object}/{window_start}/{window_end}with UTC timestamps inyyyy-MM-ddTHH:mm:ss.fffZand a half-open interval, so every adapter keys the same window identically (WP0b finding C21). Arun_idfixes its windows and split plan at first start; a rerun with the samerun_idreads them from the ledger and overwrites the same page files; only a newrun_idrecomputes from the watermark (finding C23). A run covers at mostmax_windows_per_runwindows ofwindow_size_minutesand advances the watermark after each landed window, so a catch-up is several short runs; a gap longer thanhistorical_threshold_daysis a historical load through the list endpoints (finding C18). A HubSpot window markedtruncated(offset mode only) fails its run and leaves the watermark; only Google Adschange_eventwindows are halved and rerun, by the adapter inside the same run, down tomin_window_seconds, each level costing one extra operation; a window that still truncates at that floor fails the run with the watermark unchanged (findings C26, C28, C36; brief §9). Watermarks are kept per(source, object, partition), the partition being the customer for multi-account sources (finding C34). - Bronze dedupes on
(source, object, record_id, source_version, payload_hash); a re-extracted identical row is a no-op, a changed row is a new version. - Silver current-state tables MERGE on business key and keep the row
with the highest
source_version(SystemModstamp,hs_lastmodifieddate, or report date plus entity key for ads). SCD2 tables close and open rows bysource_version, so replaying the same version twice changes nothing. - Gold facts are rebuilt per date with a
replaceWhereon the date column inside monthly partitions, never by row-level merge, so a rebuilt day replaces the old one exactly. The one exception isbusiness_event, inserted-if-absent on a deterministicevent_id, so a re-run adds nothing. - Outbound events carry an
event_idderived from event type, subject key, source version and rule version, so a re-run or replay produces the same id; consumers deduplicate on it (ADR 7). - Exactly-once is not attempted anywhere; at-least-once plus idempotent sinks is the contract.
Recover
- Cursors (page token, replay id,
aftercursor, lastsegments.date) are committed by the adapter to its state store (Azure Table Storage, which a Function can write; a notebook mirrors it into the control schema) after each successfully landed page. A restarted run resumes from the cursor; a watermark is advanced only when the whole window has landed. - Retries: full-jitter exponential backoff on 429 and 5xx (cap 8 s, 5
attempts per request), honouring
Retry-After; a per-source daily budget (requests) tracked in the ledger so retries cannot exhaust the API allocation; a circuit breaker per caller whose state is persisted in the adapter state across requests and runs, tripping on 10 or more 429s in a rolling minute (a per-request count can never reach a threshold above the attempt count, finding C13); alert. - Partial processing is visible: the ledger records rows read, rows
written, pages completed, and status per window; a window is either
landedor not.
Reload
- A reload is a run with an explicit window and
mode = reload; it uses the polling path even for sources that have push. It appends to Bronze (new versions, provenance saysreload) and lets Silver MERGE resolve the state. - Standing reloads: Google Ads trailing 30 days daily and trailing 90 days weekly; Salesforce and HubSpot deletion sweeps daily.
- Horizon: Salesforce and HubSpot can be reloaded for their full history; Google Ads reports can be reloaded back to account creation; CDC and webhooks cannot be reloaded at all, which is why they are never the truth.
Replay
- Silver and Gold jobs accept
(object, window)parameters and read only Bronze or Silver. A full replay of Gold is a loop over date partitions. Delta time travel (30-day VACUUM retention on Gold, ADR 2) lets a replay be compared with the previous state before publishing. - Change Data Feed on Silver records what a replay changed row by row;
Gold facts are compared by time travel, because a rebuilt day appears
whole in any feed. Replay does not re-emit business events: their ids
are deterministic, so already-published events are no-ops. A restated
closed day emits only
metrics.restated.
Reconcile
- Daily, per object, per source-modified-day for the trailing 35 days:
source count (SOQL
COUNT(), HubSpot searchtotal, Google AdsSUM(metrics)by date) versus Silver count. Weekly: sample hash comparison of N records per object. Results land incontrol.reconciliation_resultwith a verdict and an action (ok,reload_scheduled,investigate). Discrepancies above a per-object tolerance schedule a targeted reload automatically; below tolerance they are reported. - Intra-lake: row counts and key sums Bronze → Silver → Gold per run; Gold spend per day versus Silver; dimension coverage (no orphan keys).
- The reconciliation history is the auditable evidence of completeness.
Considered Options
| Option | Summary | Pros | Cons |
|---|---|---|---|
| ✅ All four operations, idempotent sinks, control ledger | As above | Each failure mode in the brief maps to a named mechanism; auditable | More control tables and jobs to build |
| Treat CDC and webhooks as truth, reload by full re-pull | Event streams drive Silver; recovery = full reload | Fewer moving parts | A silent gap is undetectable until someone notices; full reload burns allocation. Rejected. |
| Nightly full reload of everything | Idempotent by construction | No watermarks or cursors | API allocation grows with data; no intraday freshness. Kept only for Google Ads entity snapshots. |
| Exactly-once pipelines | Transactional outbox across stores | Theoretically clean | Not achievable across three SaaS APIs, OneLake and a message bus; the cost is complexity with no gain. Rejected in favour of idempotent sinks. |
Consequences
Positive:
- "Reconcile or reload" becomes a button with a window parameter, not an incident.
- Replay is free of API cost, which encourages fixing logic properly.
Negative / Trade-offs:
- Bronze holds multiple versions of the same record; storage grows with change rate (cheap) and Silver MERGE must be correct.
- Reconciliation itself consumes API requests; the budget is part of the daily allocation plan.
Risks: | Risk ID | Description | Impact (E/H/M/L) | Mitigation | |---------|-------------|------------------|------------| | R1 | Source count semantics differ from lake semantics (time zones, soft deletes) | M | Reconcile on source-modified-day in UTC; include deleted flag in both counts; tolerance per object | | R2 | A reload of a large window exhausts the daily API allocation | M | Reload scheduler spreads windows across days; budget check before scheduling | | R3 | Replay changes Gold figures that were already reported | M | Time travel comparison; business events for restated partitions; freeze policy for closed months on request |
Related
- Related ADRs: 2, 3, 7
- Related requirements: Reliability and recovery; Data integrity; Historical and incremental data
- Related documents: control tables, sequence: reload
- Principles: DP-01, DP-03, DP-04, DP-05, AP-04
- TOGAF phase: C (Data)
- Decision maker(s): Lead Architect, Data lead
- Stakeholders: Marketing Operations, Finance, internal audit