Interview's MateData Engineer
Interview's Mate

Data Engineer

SQL · Spark · Lakehouse · Streaming

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Data Engineer topics
Lesson 109/ 160
06. Data Transformation (dbt) & Workflow Orchestration

Built-in & Custom Data Tests, Sources & Freshness Checks

Declare source freshness and generic/custom tests so bad data fails the build loudly.

IntermediateTests · Sources · Freshness3 quiz questions
Practice Generative AI Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Database/schema/table and owner. Next, stable loaded_at field and thresholds. Finally, severity, stored failures, and owner route.

Think of it like…

Source freshness is the receiving dock's clock, tests are inspection gauges, and severity is the difference between quarantine at the gate and a note left for tomorrow.

Where you’ve seen it

sources.yml sets freshness: {warn_after: {count: 30, unit: minute}, error_after: {count: 2, unit: hour}} and tests: [unique, not_null, relationships]; dbt source freshness exits on the SLO breach.

Words you’ll hear

Tests
Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries.
Sources
First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata.
Freshness
A source timestamp compared with current time under warning/error intervals to detect missing producer loads.
Operational boundary
A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish. Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.

Visual diagram

Loading interactive diagram

Theory & deep dive

Tests: the working mechanism

dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules.

Database/schema/table and owner. Stable loaded_at field and thresholds, then standard and domain-specific tests; this exposes the state governed by Freshness.

Built-in & Custom Data Tests, Sources & Freshness Checks in one concrete design

sources.yml sets freshness: {warn_after: {count: 30, unit: minute}, error_after: {count: 2, unit: hour}} and tests: [unique, not_null, relationships]; dbt source freshness exits on the SLO breach.

Key takeaway: dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules

Built-in & Custom Data Tests, Sources & Freshness Checks: failure mode and production response

A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.

Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage. Track Warn/error delay as "freshness thresholds relative to consumer SLO", and make Test selectivity visible to the dataset owner.

Key takeaway: Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.

How it works, step by step

Step 1 of 4
Tests

1. Declare source

Database/schema/table and owner. dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules.

database/schema/table and owner
Key numbers at this step
Warn/error delay
freshness thresholds relative to consumer SLO
Sources
First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata.

When to use it & trade-offs

What it is

dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules. sources.yml sets freshness: {warn_after: {count: 30, unit: minute}, error_after: {count: 2, unit: hour}} and tests: [unique, not_null, relationships]; dbt source freshness exits on the SLO breach.

Why it matters: A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish. Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.

When to reach for it

  • Declare source freshness and generic/custom tests so bad data fails the build loudly.
  • Choose Tests because it provides this capability: Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries.
  • Keep evidence for Warn/error delay at "freshness thresholds relative to consumer SLO" so the last production stage-Gate and diagnose - severity, stored failures, and owner route-remains testable.

When to avoid or be careful

  • A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
  • Do not conflate Sources with Tests. The second concept contributes different behavior: First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata.
  • Release only after this guardrail is in place: Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.

Tests / Sources / Freshness - roles, limits, and operating cost

Tests
Best for: Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries.

Strengths: Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries. dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules.

Watch out: A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.

Sources
Best for: First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata.

Strengths: First-class raw table nodes with descriptions, lineage, owners, and optional freshness metadata. In this workflow it supports: Assert contract - standard and domain-specific tests.

Watch out: The operating cost is real: failing rows bounded and explainable.

Freshness
Best for: A source timestamp compared with current time under warning/error intervals to detect missing producer loads.

Strengths: A source timestamp compared with current time under warning/error intervals to detect missing producer loads. Its output can be checked with Failure retention.

Watch out: Operating guardrail: Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.

Interview signals & numbers to know

When this topic comes up

  • “Where is the failure boundary for Tests, and how would Warn/error delay reveal it?”
  • “Why is Sources distinct from this behavior: a source timestamp compared with current time under warning/error intervals to detect missing producer loads?”
  • Production clue: A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
  • Design probe: Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.

Benchmarks & rules of thumb

Warn/error delay -
freshness thresholds relative to consumer SLO
Test selectivity -
failing rows bounded and explainable
Failure retention -
store or expose results for owner debugging

Common mistakes & follow-ups

Common interview mistakes

  • A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
  • Reporting success from a job exit code without checking Warn/error delay and Test selectivity.
  • Treating this example as complete without replay, rollback, or access boundaries: sources.yml sets freshness: {warn_after: {count: 30, unit: minute}, error_after: {count: 2, unit: hour}} and tests: [unique, not_null, relationships]; dbt source freshness exits on the SLO breach.

Likely interviewer follow-ups

  • How would you prove this contract instead of only checking that the command ran: Parameterized assertions such as unique/not_null/relationships packaged in dbt YAML and compiled as model queries.
  • What does the recovery plan do when this occurs? A freshness threshold on a source field that updates on every warehouse read is meaningless, expensive full-table tests can gate every tiny model, and warning-only failures can allow a known broken KPI to publish.
  • When is Tests insufficient for Test selectivity, and what does adding Sources cost in Warn/error delay?
Interview tip: Lead with the data path and failure boundary: dbt source declarations document raw nodes and freshness queries, generic tests assert constraints such as not null/unique/relationships, and singular/custom SQL tests encode domain rules. Then make the answer operational: Set loaded_at_field to the true producer/ingest timestamp, classify tests as blocking or warn by contract, store failures for diagnosis, and select critical tests in production while preserving broader CI coverage.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Built-in & Custom Data Tests, Sources & Freshness Checks with data engineer interview Q&A and hands-on practice.

Open Data Engineer Q&A →Machine Learning Q&A
Previous topic
Implementing SCD Type 2 with dbt Snapshots
Next topic
dbt Documentation, Lineage Graphs (DAG) & Exposures