← All blogs
Design write-up · dbt

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.

TL;DRdbt's built-in freshness stops at the source, and extending it model by model doesn't survive a 10,000-model project. So I designed a post-run macro pipeline that checks every mart deliverable's entire upstream lineage from the graph instead. SLAs (service level agreements: each source's maximum allowed data age) are resolved from folder paths instead of tags, mid-chain staleness is caught with a dedicated 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:

  1. 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.
  2. 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.
  3. 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.
  4. 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

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.

The check still walks each deliverable's full upstream DAG all the way back to source. Scope limits which models get evaluated, not how far back each evaluation looks.

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.

source
staging-load anchor
chain node
view, never checked
deliverable
fresh
problem upstream
0
STEP 0 · SELECTION

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.

1
STEP 1 · COLLECT UPSTREAM

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.

2
STEP 2 · RESOLVE SLA

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.

3
STEP 3 · CHECK & WRITE

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

sources
150.9%
staging
1,00657.7%
raw vault
52229.9%
biz vault
17810.2%
marts
231.3%
daily · 149

checked > 48h

weekly · 65

checked > 8 days

monthly · 72

checked > 1 month + 1d

disabled · 165

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:

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:

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

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}
The tag on a model (e.g. 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.

FolderPeriodThreshold
dailydaydata older than 48h
weeklyweekdata older than 8 days
monthlymonthdata older than 1 month + 1 day
_inactive / _undefined / refdisabledno 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:

ConditionVerdict
Never rannever_loaded
Last run status ≠ successlast_run_failed
Hours since the loaded file's date > error_after_hoursstale
Otherwisefresh; 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:

  1. Exception (model-name or tag match in freshness_exceptions): skip evaluation, but pass its own last run through as fresh if it has one, so children downstream can still compare against it.
  2. 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.
  3. 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
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_failed in FAILED_STAGING_SOURCES.
  • Last run succeeded: no failure recorded, and it's seeded as a real fresh signal so Phase 2 can still check chain nodes downstream of it.
  • Never ran: silent. That's expected for a folder with no SLA.
If a model's only staging-load ancestors are all config-excluded, 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.

ColumnMeaning
MODEL_NAMEThe mart deliverable checked
CHECK_RUN_IDdbt's invocation_id for this run
CHECKED_ATUTC timestamp the check itself ran
STATUSok everything upstream fresh, or fail something stale or missing
FRESHNESS_EXPECTEDHuman-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_SOURCESJSON array of staging-load anchors that failed Phase 1, each {source, expected, issue, last_loaded?, hours_ago?}
FAILED_CHAIN_SOURCESJSON 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
SwitchEffect
DBT_SKIP_FRESHNESS_CHECK=trueSkips 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.
Written from a freshness system I designed and run in production on a large dbt + Snowflake project. Model names and the example DAG labels are invented; the topology, the verdict logic, and every number are real.