0
0
dbtdata~10 mins

Source freshness checks in dbt - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - Source freshness checks
Define source in dbt project
Configure freshness criteria
Run dbt source freshness command
dbt queries source metadata
Compare source timestamps to criteria
Report freshness status
Take action if stale or warn
END
This flow shows how dbt checks source data freshness by defining sources, setting freshness rules, running checks, and reporting results.
Execution Sample
dbt
sources:
  - name: my_source
    tables:
      - name: users
        freshness:
          warn_after: {count: 12, period: hour}
          error_after: {count: 24, period: hour}
This YAML config defines a source table with freshness thresholds for warnings and errors.
Execution Table
StepActionSource TimestampCurrent TimeAge (hours)Check ResultMessage
1Start freshness check-2024-06-01 12:00-PendingStarting check for source 'users'
2Query source metadata2024-06-01 01:302024-06-01 12:0010.5Within thresholdSource data is fresh
3Compare to warn_after (12h)10.5 < 12N/ATrueNo warningNo freshness warning needed
4Compare to error_after (24h)10.5 < 24N/ATrueNo errorNo freshness error needed
5Finish check---SuccessSource freshness check passed
💡 Source timestamp age 10.5 hours is less than warn_after 12 hours, so freshness is good.
Variable Tracker
VariableStartAfter Step 2After Step 3After Step 4Final
source_timestamp-2024-06-01 01:302024-06-01 01:302024-06-01 01:302024-06-01 01:30
current_time2024-06-01 12:002024-06-01 12:002024-06-01 12:002024-06-01 12:002024-06-01 12:00
age_hours-10.510.510.510.5
check_resultPendingWithin thresholdNo warningNo errorSuccess
Key Moments - 2 Insights
Why does dbt compare the source timestamp age to both warn_after and error_after?
dbt uses warn_after to trigger a warning if data is getting old, and error_after to fail the check if data is too stale. This two-level check helps catch issues early (see execution_table rows 3 and 4).
What happens if the source timestamp is missing or null?
If the timestamp is missing, dbt cannot calculate freshness age, so the check usually fails or warns. This is important because freshness depends on having a valid timestamp (not shown in this trace but common in practice).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the age in hours of the source data at step 2?
A12
B24
C10.5
D1.5
💡 Hint
Check the 'Age (hours)' column at step 2 in the execution_table.
At which step does dbt decide that no freshness warning is needed?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Look for the 'Check Result' and 'Message' columns mentioning warnings in the execution_table.
If the source timestamp was 13 hours old instead of 10.5, what would change in the execution table?
AStep 5 would say freshness check failed
BStep 3 would show a warning triggered
CStep 4 would show an error triggered
DNo changes, still passes
💡 Hint
Compare age_hours to warn_after threshold in execution_table rows 3 and 4.
Concept Snapshot
Source freshness checks in dbt:
- Define sources and tables in YAML
- Set freshness thresholds: warn_after and error_after
- Run 'dbt source freshness' to check timestamps
- Compare source data age to thresholds
- Report status: fresh, warning, or error
- Helps monitor data timeliness automatically
Full Transcript
Source freshness checks in dbt help ensure your data is up-to-date. You define your source tables and set freshness rules like warn_after and error_after in your dbt project YAML. When you run the freshness check, dbt queries the source metadata to get the latest timestamp. It calculates how old the data is by comparing the source timestamp to the current time. Then it compares this age to your thresholds. If the data is younger than warn_after, it passes with no warnings. If it is older than warn_after but younger than error_after, dbt issues a warning. If it is older than error_after, it triggers an error. This process helps catch stale data early and keeps your analytics reliable.