Your dbt run succeeded. Was it built on fresh data?
dbt ships with a freshness check, and on a small project it's fine. At enterprise scale it answers the wrong question. I needed to know, after every run, whether each deliverable was built on data that actually arrived, through lineages of up to 1,744 upstream nodes. This is the story of that check: why the built-in one falls short, what I needed instead, and how it works. I built it to catch late sources. Late sources turned out to be the rare failure. Model names below are invented; the DAG shapes and every number are from the real system.
not_rerun_since_upstream verdict, and failures cascade-skip so
each problem is reported once, at its source. The largest DAG observed had
1,744 upstream nodes; the check walks all of them as a multi-step
graph traversal and touches the database with exactly
one monitoring query.dbt source freshness is not built for enterprise scale
A mart deliverable can build successfully while still being built on stale data. Its staging load may not have run today, or it ran right on schedule and loaded a file that was itself a month old. Or a model in the middle of the vault may never have re-run after its own parent last rebuilt, so it is quietly serving last week's logic on last week's rows. dbt's run success or failure says nothing about any of these.
dbt does ship a tool for part of this: dbt source freshness.
It runs a max(loaded_at) per source table and compares the
result against warn/error thresholds. On a small project, that's enough. On an
enterprise project it breaks down in four ways:
- It stops at the source, and pushing it deeper doesn't scale. Between a source and a mart there can be more than a thousand models, and any one of them can silently skip its schedule while the freshness report stays green: a fresh source proves nothing about the chain. You can bolt per-model freshness checks onto the chain, and I looked at that path properly, but then every model needs its own threshold and config entry, which is unmaintainable across a project of over 10,000 models.
- It answers per source, not per deliverable. The question stakeholders actually ask is "can I trust this mart today?" Mapping hundreds of green and red sources onto that answer is left entirely to you.
- It's a separate run. Freshness gets checked on its own schedule, detached from the models you just built. What needs checking is the lineage of exactly what shipped in this invocation.
- Config and cost scale badly. Every source needs a reliable timestamp column and its own YAML block, and every check is its own query. At the scale below (451 load anchors under a single deliverable) that's hundreds of queries to answer the wrong question.
The chain's freshness has to come from the graph, not from more config. So I stopped trying to bend the built-in check and designed the one I actually needed.
The check I actually needed
- Runs automatically at
on-run-endfor consumer-level runs: whenever a deliverable is built, its check happens. - Gives a verdict per deliverable actually built in that invocation, not per source.
- Walks each deliverable's full upstream DAG back to source, catching stale sources and never-rerun mid-chain models alike, with zero per-model config: chain verdicts come from the graph.
- Needs no per-source setup either. Nobody writes a YAML entry per source: a load model gets its SLA by sitting in the right folder (
daily/,weekly/,monthly/), and one small config file defines what those folders mean, once. - Judges staging on the loaded file's date, not the run time: a load can run on schedule and still deliver a month-old file.
- Does the heavy lifting as graph traversal over the manifest (selection, breadth-first collection, SLA resolution, verdicts in dependency order) and touches the database with one monitoring query, no matter how deep the lineage.
- Writes one row per deliverable to
LOG.FRESHNESS_CHECK_RESULTS, naming the exact failing nodes, and joins into the team's overall logging view: freshness sits next to run history and everything else we track about a model, in one place.
The rest of this post is how that's done.
Scope
Freshness is checked only for models tagged as mart deliverables, and only for the ones dbt actually executed in this invocation. Any other selected model is ignored; its upstream freshness doesn't matter to a deliverable that didn't depend on it this run.
How it works: the pipeline on a real DAG shape
on-run-end:
- "{{ check_upstream_freshness(results) }}"
check_upstream_freshness() is the orchestrator. For each
selected deliverable it runs its own isolated Step 1 + Step 2, then hands
everything to one shared Step 3. The four diagrams below freeze the check at each
step, on a representative slice of a real deliverable's sub-DAG.
Selection
fsh_step0_resolve_selection(results)Reads the on-run-end results list and returns the unique ids of every model node dbt actually executed this invocation, exact regardless of the --select/--selector syntax used. This run rebuilt mart_fact_premiums. Freshness only checks mart deliverables, and this is one. Nothing upstream has been explored yet, so only the deliverable itself is drawn below.
Collect upstream
fsh_step1_collect_upstream(selected_ids)A breadth-first search (BFS) walk of the model's full upstream DAG back to source, enqueue-deduped so each node is visited exactly once. Nodes split into staging-load anchors (blue) and chain nodes (violet); views (grey) are recognized but never checked. Real total for this deliverable: 1,744 upstream nodes. The diagram shows a representative slice, with the animated dashes walking backward toward source, matching the direction of this BFS.
Resolve SLA
fsh_step2_resolve_config(step1_result, freshness_tree)Each anchor gets its SLA from its folder path, not its tag: daily means 48h, weekly means 8 days, monthly means 1 month + 1 day, shown as the badge now revealed above each anchor. No source is configured individually; putting the model in the folder is the configuration. Anchors under inactive/undefined/ref folders are disabled and skipped (no badge). Stage views are always skipped too, revealed here with their own "view · skipped" badge. A view has no load time of its own; it just recomputes live.
Check & write
fsh_step3_run_checks(per_model, exceptions_list)One shared monitoring query gets the last run per model, then every node's verdict flows forward toward the deliverable (dashes now animate left to right). Two separate problems reach the same red verdict here. The daily anchor's last loaded file is 73h old, past its 48h SLA, so it's stale at the source. Separately, the weekly anchor is perfectly fresh, but bv_premiums_monthly never re-ran after its own immediate parent sat_contract_policy last rebuilt (not_rerun_since_upstream). Either way, any node downstream of a problem turns red; the deliverable inherits both.
Real-world scale, for context
Full upstream of one mart deliverable · 1,744 nodes by layer
checked > 48h
checked > 8 days
checked > 1 month + 1d
inactive / undefined / ref
286 checked · 165 skipped by config. SLA comes from the folder path, not the tag.
What it found
Three patterns, in order of how often they actually fired:
- Mid-chain models months stale. Models that had not re-run since
their parents last changed, some for months, while every run log showed green.
This is what
not_rerun_since_upstreamexists for, and it was the most common real failure. - Cadence mismatches hiding in the middle. Chains where the load and the deliverable were both daily, but a model in between was weekly. Nothing was broken; the design itself capped the chain at its slowest link, and the check made that visible for the first time.
- Plain stale sources. The case I built it for. Real, but the rarest of the three.
Performance shape
The naive version of this check would run one freshness query per upstream node. At real project scale (largest single-model DAG observed: 1,744 upstream nodes; see Real-world scale above) that doesn't scale. To be clear, this check is not "one simple query" either: it is a four-step traversal with BFS collection, config resolution, and verdicts in topological order. The design just ensures all of that work runs against the manifest in memory, so the database only gets asked once:
- Step 1/2 collection is pure Jinja graph traversal; no queries.
- Step 3 issues exactly one monitoring query per invocation, covering the union of every selected model's checked + chain + skipped node names, then does all comparison logic in Jinja against the cached result set.
- One batched
INSERT ... SELECT ... UNION ALL ...writes all result rows, not one INSERT per model. Snowflake's multi-rowVALUESclause rejects function calls likePARSE_JSON, so rows are unioned asSELECTs instead.
Each selected model gets its own Step 1 + Step 2 call; there is no shared BFS state across models. A stale source that happens to sit in one model's DAG can never affect another model's verdict, even if both models are built in the same invocation.
What I learned
- Most real failures were mid-chain, not at the source. I built this to catch late sources; what it actually caught was models that never re-ran after their parents changed, while every log showed green.
- A run timestamp is not a data timestamp. A check that trusts run times is checking your scheduler, not your data.
- Convention scales; configuration rots. Folder placement is the whole setup. 10,000 hand-written thresholds would start rotting the day they were written.
- A check only changes behavior if it is too cheap to skip. Checks that cost something get scheduled, scheduled checks get skipped, skipped checks get forgotten.
- A red flag has to name the culprit. A report that says "something is wrong somewhere" trains people to close it, not to investigate it.
The sharp edges, for anyone building this
Everything above is the design. The exact rules and switches live below, folded away so the story stays short.
Staging folders & SLA config
The staging load layer is organized by refresh cadence:
daily/, weekly/,
monthly/, plus _inactive/
and _undefined/:
load/pas/ ├── daily/ stg_pas_policy · stg_pas_party ├── weekly/ stg_pas_claim └── monthly/ stg_pas_coverage
upstream_freshness_config.yml mirrors that same
folder structure and is walked leaf to parent to project-default, each
level's keys overwriting the parent's
(fsh_resolve_path_config):
# models/sources/upstream_freshness_config.yml analytics_dbt: error_after: {count: 1, period: day} # project default error_buffer_hours: 24 staging: load: daily: {error_after: {count: 1, period: day}} weekly: {error_after: {count: 1, period: week}} monthly: {error_after: {count: 1, period: month}} _inactive: {enabled: false} _undefined: {enabled: false} ref: {enabled: false}
staging_load_pas_daily)
drives job scheduling only. Freshness config is
resolved from node.fqn, the folder path, not
from tags. A model tagged one frequency but sitting in a different
frequency's folder would get the folder's SLA.
error_after converts to hours via
fsh_period_to_hours() (month/quarter/year are
calendar-aware: actual days in the current UTC period). The final
threshold is error_after_hours = frequency_hours + error_buffer_hours.
A daily anchor is stale once its data is
more than 24h (frequency) + 24h (buffer) = 48h old,
measured on the loaded file's date, not the run time.
There is no warn tier; a source is either fresh or stale.
| Folder | Period | Threshold |
|---|---|---|
| daily | day | data older than 48h |
| weekly | week | data older than 8 days |
| monthly | month | data older than 1 month + 1 day |
| _inactive / _undefined / ref | disabled | no SLA; success-only check |
The exact verdict logic (views, Phase 1, Phase 2)
Views are never checked
A view has no load time of its own; it recomputes live from its
parents at query time, so it can never meaningfully be "stale". Step 1
walks straight through any view parent to find the nearest non-view
ancestor (immediate_check_parents); Step 3
never queries or evaluates view_nodes at all.
Phase 1: staging check (staging-load anchors)
One detail here matters more than it looks: the staleness comparison uses the
loaded file's date, not the run timestamp. A load job can succeed
right on schedule while the file it ingested is a month old, and judging by run
time would call that fresh. For each checked_nodes entry:
| Condition | Verdict |
|---|---|
| Never ran | never_loaded |
Last run status ≠ success | last_run_failed |
Hours since the loaded file's date > error_after_hours | stale |
| Otherwise | fresh; timestamp kept for Phase 2 |
skipped_nodes get the lighter check described in the section above instead.
Phase 2: chain check (everything between staging and the deliverable)
Every chain_nodes entry is checked against its
immediate_check_parents, not just the root
anchor, so a stale node hiding in the middle of a long chain (behind
an otherwise-fresh anchor) is still caught. Resolved in dependency
order (Kahn's algorithm, a topological sort) so a node's verdict always
exists before anything checks against it.
For each chain node, once its immediate parents are resolved:
- Exception (model-name or tag match in
freshness_exceptions): skip evaluation, but pass its own last run through asfreshif it has one, so children downstream can still compare against it. - Every resolved immediate parent is stale or failed: cascade-skip. Not independently evaluated; the failure was already reported at its source, and this node's own children will cascade-skip too.
- Otherwise (no parent resolved yet, or at least one resolved parent is fresh): evaluate this node's own last run:
- Never ran:
never_run - Last run status ≠
success:last_run_failed - Ran fine, but its own last-build timestamp predates a fresh parent's:
not_rerun_since_upstream(the anchor is fine, but this node never rebuilt after its parent last changed) - Otherwise:
fresh
- Never ran:
enabled: false is not the same as "not checked"
Disabling a folder does not turn off checking entirely;
it removes the SLA window. The node moves from
checked_nodes into skipped_nodes,
and Step 3 still runs one check on it:
- Last run failed: flagged
excluded_but_failedinFAILED_STAGING_SOURCES. - Last run succeeded: no failure recorded, and it's seeded as a real
freshsignal so Phase 2 can still check chain nodes downstream of it. - Never ran: silent. That's expected for a folder with no SLA.
FRESHNESS_EXPECTED is written as
'no SLA (success-only)' rather than left
NULL. That keeps it distinguishable from a
model that has no staging-load ancestor at all.
The results table
One row per selected and run deliverable per invocation. The table joins into the overall logging view, so freshness shows up next to run history and the rest of a model's operational story instead of living in its own silo.
| Column | Meaning |
|---|---|
| MODEL_NAME | The mart deliverable checked |
| CHECK_RUN_ID | dbt's invocation_id for this run |
| CHECKED_AT | UTC timestamp the check itself ran |
| STATUS | ok everything upstream fresh, or fail something stale or missing |
| FRESHNESS_EXPECTED | Human-readable label for the tightest (most frequent) SLA among this model's checked anchors, e.g. every day, every 2 weeks. 'no SLA (success-only)' if the model's only staging-load ancestors are config-excluded. |
| FAILED_STAGING_SOURCES | JSON array of staging-load anchors that failed Phase 1, each {source, expected, issue, last_loaded?, hours_ago?} |
| FAILED_CHAIN_SOURCES | JSON array of chain models that failed Phase 2, each {model, issue, stale_relative_to?} |
STATUS = 'fail' whenever either array is
non-empty. The two arrays are kept separate deliberately: staging
failures and chain failures are different failure domains, and mixing
them into one combined list would hide which side actually broke.
Bypass & global switches
| Switch | Effect |
|---|---|
| DBT_SKIP_FRESHNESS_CHECK=true | Skips the entire check. Emergency use only; pair with an incident ticket. |
| skip_targets: [local_dev] | Skips the entire check for listed dbt targets, evaluated before any queries run. |