Skip to content
Bronze 5 min read · Config 1 practice problem ↓

Materializations

The same model SELECT can become a view, a table, an incremental table or an ephemeral snippet. That choice, the materialization, decides cost and speed. This lesson shows what each one does and when to pick it.

Pipelines in production · dbt · Bronze · Building models, lesson 3 of 4

Read first: ref() and the DAG (skip if you know it)

In plain words first

A recipe can be served as a fresh dish cooked on every order (a view), a batch cooked once and kept in the fridge (a table), a batch topped up each day with only the new portions (incremental), or a sauce folded straight into another dish (ephemeral). Same recipe, different way of serving it.

Same SELECT, different DDL

The materialization decides what dbt does with a modelmodel: A SELECT statement in a .sql file. dbt runs it and saves the result in the warehouse as a table or view named after the file. Learn more →'s SELECT. The model code does not change; only the wrapping does.

MaterializationWhat dbt runsQuery costBuild cost
view (default)create or replace view x as (select ...)Runs the SELECT every time someone queries itAlmost none
tablecreate or replace table x as (select ...)Reads stored rows: fastRecomputes everything every run
incrementalFirst run: create table. Later runs: insert or merge only new rowsFastOnly the new data
ephemeralNothing. The SELECT is inlined as a CTE into the models that ref itPaid by each childNone
materialized_viewcreate materialized view; the warehousewarehouse: A database built for analytics on large tables, like Snowflake, BigQuery, Databricks or Redshift. dbt runs its SQL there. Learn more → refreshes itFastRefresh managed by the warehouse

Configuring it

dbt · models/marts/fct_invoices.sql
{{ config(materialized='table', tags=['finance']) }}

select ...
YAML · models/marts/_marts__models.yml
models:
  - name: fct_invoices
    config:
      materialized: table

Or for a whole folder with +materialized in dbt_project.yml. The config in the model file wins over YAML, which wins over the project file.

Choosing

  1. 1
    Start with a view. Staging modelsstaging model: The first layer of models: one per source table, renaming and casting columns, with no joins or business logic. Learn more → are thin and read rarely on their own, so views cost nothing to build and are never stale.
  2. 2
    Make it a table when people or BI tools query it, or when many models read it: computing once beats computing on every read.
  3. 3
    Make it incremental when rebuilding the table takes too long or costs too much, typically large event or fact tables. It adds complexity (see Incremental modelsincremental model: A model that, after its first build, only processes new or changed rows and merges them into the existing table. Learn more →), so it is not the default.
  4. 4
    Use ephemeral for small helper steps you do not want in the warehouse. Not for anything you want to query or debug directly.
Why this matters: A chain of views is cheap to build but expensive to read: a dashboard on a view of a view of a view runs all three queries on every refresh. Tables on the marts layer break that chain.

Ephemeral, inlined

dbt · models/marts/fct_invoices.sql
select * from {{ ref('int_invoice_charges') }}   -- an ephemeral model

Compiles to

with __dbt__cte__int_invoice_charges as (
    select invoice_id, sum(amount) as charged from analytics.dbt_alice.stg_charges group by 1
)
select * from __dbt__cte__int_invoice_charges

Because an ephemeral model never exists in the warehouse, you cannot query it while debugging, and if five models ref it, its SQL runs five times. Keep ephemeral models small.

Materialized views

Supported on Snowflake (dynamic tables), BigQuery, Databricks, Redshift and Postgres. dbt creates the object; the warehouse keeps it up to date. Useful for near-real-time marts with simple SQL. The limits come from the platform: some SQL is not allowed in materialized views, refresh costs are paid even when nobody reads, and dbt cannot run custom logic per refresh as it can with incremental models.

How a table rebuild stays safe

On warehouses without atomic create or replace, dbt builds the new table under a temporary name, then renames: the old version stays readable until the swap, and a failed build leaves the old table untouched. Readers never see a half-built table.

Common mistakes

  • Making everything a table — Every run rebuilds every table. Staging as views is usually enough.
  • Long chains of views under dashboards — Every dashboard query recomputes the whole chain.
  • Big ephemeral models referenced many times — Their SQL is inlined and executed once per child.

Key takeaways

  • A materialization only changes the DDL around the same SELECT.
  • Views cost nothing to build but recompute on read; tables are the reverse.
  • Incremental models trade simplicity for build time on large tables.
  • Ephemeral models are inlined as CTEs and cannot be queried directly.

Interview prep

THE QUESTION

"When would you choose a view, a table or an incremental model in dbt?"

View by default for light models such as staging: no build cost, always current, but the query runs on every read. Table for marts that are read often or feed many models: computed once per run. Incremental when a table is too large or slow to rebuild each run: only new or changed rows are processed, at the cost of more logic and edge cases (late data, schema changes, full refreshes). Ephemeral for small helper logic that should not exist in the warehouse.

Avoid: "always use tables because they are faster". Tables rebuild fully each run; views and incremental models exist for good reasons.

Follow-ups · answer out loud, then open

Follow-up"What exactly is an ephemeral model?"
A model that is never built: its SQL is inlined as a CTE into each model that refs it. It keeps helper logic out of the warehouse but cannot be queried directly, and runs once per child.
Scenario"A dashboard on a dbt mart is slow, and the mart is a view over three other views. What do you change?"
Materialize the mart (and possibly a heavy intermediate) as a table, so the dashboard reads stored rows instead of recomputing the chain on every refresh. If rebuilds then take too long, make it incremental.
Trap"A materialized view is the same as an incremental model."
The warehouse refreshes a materialized view on its own terms, with SQL restrictions and continuous refresh cost; an incremental model runs your logic when dbt runs, with full control over the filter and the merge.

Check yourself

3 questions

What is the default materialization in dbt?

Show the answer

view. Models are views unless configured otherwise.

An ephemeral model is referenced by four models. How many times does its SQL run during dbt run?

Show the answer

Four times, once inlined in each child. It is inlined as a CTE into each model that refs it.

A 3 TB plays table takes two hours to rebuild nightly. Which materialization fits?

Show the answer

incremental. Process only new plays each run.

Practise this

Problems that use this, graded on hidden tests

Keep going

Up next · Building models · lesson 4 of 4 · 5 min read
Data tests
unique, not_null, accepted_values and relationships, singular tests, and how a test fails: it returns rows.

Related lessons

Previous: ref() and the DAG

Primary sources: Materializations