What if your data was outdated and you didn't even know it?
Why Source freshness checks in dbt? - Purpose & Use Cases
Start learning this pattern below
Jump into concepts and practice - no test required
Imagine you run a small online store and update your sales data every day by copying files manually into your system.
Before making business decisions, you have to check if the data you copied is actually the latest.
You open files, check timestamps, and ask your team if the data is fresh.
This manual checking is slow and easy to forget.
You might use old data by mistake, leading to wrong decisions like ordering too much or too little stock.
It's also hard to track when data updates fail or delay.
Source freshness checks automatically verify if your data is up-to-date.
They run simple tests that tell you if the data arrived on time or if it's stale.
This saves time, reduces errors, and gives you confidence in your reports.
Check file date manually before loading data
dbt source freshness --select my_source
It lets you trust your data pipelines and focus on insights, not on hunting for data problems.
A marketing team uses source freshness checks to ensure daily campaign data is updated before running performance reports.
If data is late, they get alerts and avoid making decisions on incomplete information.
Manual data freshness checks are slow and risky.
Source freshness checks automate this process and catch issues early.
This leads to more reliable data and better business decisions.
Practice
Solution
Step 1: Understand the role of freshness checks
Freshness checks monitor the age of data in source tables to ensure it is up-to-date.Step 2: Compare options to the purpose
Only To track how recent the data in your source tables is describes tracking data recency, which matches the purpose of freshness checks.Final Answer:
To track how recent the data in your source tables is -> Option AQuick Check:
Freshness checks = track data recency [OK]
- Confusing freshness checks with table creation
- Thinking freshness checks optimize queries
- Assuming freshness checks schedule runs
Solution
Step 1: Recall correct YAML syntax for freshness
dbt expects warn_after and error_after as objects with count and period keys.Step 2: Match options to syntax
freshness: warn_after: {count: 1, period: day} error_after: {count: 2, period: day} correctly uses {count: X, period: day} format; others use incorrect formats or swap thresholds.Final Answer:
freshness: warn_after: {count: 1, period: day} error_after: {count: 2, period: day} -> Option BQuick Check:
Use count and period keys in YAML freshness [OK]
- Using strings instead of objects for thresholds
- Swapping warn_after and error_after values
- Missing count or period keys
{"status": "", "max_loaded_at": "2024-04-20T00:00:00Z"}Solution
Step 1: Calculate data age from last loaded timestamp
If today is 2024-04-23, data is 3 days old (2024-04-23 - 2024-04-20).Step 2: Compare data age to thresholds
3 days > error_after (2 days), so status is error.Final Answer:
error -> Option AQuick Check:
Data age > error_after = error status [OK]
- Confusing warn_after and error_after thresholds
- Assuming status is warn for data older than error_after
- Ignoring current date when calculating age
sources:
- name: my_source
freshness:
warn_after: {count: 1, period: day}
error_after: {count: 2, period: days}
What is the likely cause of the error?Solution
Step 1: Check period values in freshness YAML
dbt expects period values as singular strings like 'day', not plural 'days'.Step 2: Identify error cause
Using 'days' causes a validation error; changing to 'day' fixes it.Final Answer:
The period value 'days' should be singular 'day' -> Option DQuick Check:
Period values must be singular like 'day' [OK]
- Using plural period names
- Swapping warn_after and error_after
- Adding unnecessary quotes around numbers
Solution
Step 1: Identify correct period and count values
Period should be singular 'hour', counts are numbers without quotes.Step 2: Check warn_after and error_after order
warn_after must be less than error_after; 2 < 4 is correct.Step 3: Validate options
freshness: warn_after: {count: 2, period: hour} error_after: {count: 4, period: hour} matches correct syntax and logic; A uses strings for counts, B uses plural 'hours', D swaps thresholds.Final Answer:
freshness: warn_after: {count: 2, period: hour} error_after: {count: 4, period: hour} -> Option CQuick Check:
Use singular period and correct threshold order [OK]
- Using plural period names like 'hours'
- Putting counts as strings instead of numbers
- Swapping warn_after and error_after values
