Skip to content
mentoor

Topic 1 of 5 · 5 min read

ETL versus ELT with SQL models

Goal: Lay out a source-to-report flow as staging, intermediate and mart models and say which steps run incrementally.

ETL transforms data before it reaches the warehouse; ELT loads the raw data first and transforms it inside the warehouse with SQL. Most modern stacks use ELT, and the transformations live as versioned SQL models.

Check yourself · 1 of 3

What belongs in a staging model in an ELT project?

Choose one answer

Why it matters

Warehouses such as BigQuery, Snowflake, Redshift and Postgres are fast enough to do the heavy joins themselves. Loading raw data first means you keep the original rows, so a wrong transformation can be fixed and replayed without going back to the source system. Tools like dbt turn each transformation into a select statement in a file, with tests, docs and a dependency graph. An assistant can draft these models quickly, so you need to know what a good layout looks like.

How to lay it out

  1. Raw (sources). Tables as loaded. Never edit them.
  2. Staging. One model per source table. Rename columns, cast types, trim strings, nothing else. No joins.
  3. Intermediate. Joins and business logic that several reports share, such as orders joined to payments.
  4. Marts. Wide, report-ready tables named for the business: fct_orders, dim_customers. Dashboards read only from here.
  5. Incremental where needed. A small table can be rebuilt in full on every run. A large events table should add only new rows, filtered by a timestamp and merged on a unique key so a late-arriving update replaces the old row rather than duplicating it.

Choose ETL when data must be cleaned or masked before it may land at all, for example removing card numbers, or when the target cannot run heavy SQL.

Before and after

An assistant is asked for a revenue report and writes one 120-line query joining five raw tables, with currency conversion and test-account filtering mixed in. It works once and nobody can reuse a piece of it.

The fixed layout:

  • stg_orders, stg_payments, stg_customers: rename and cast.
  • int_orders_with_payments: the shared join.
  • fct_revenue_daily: the mart, built incrementally on order_date.

Now a currency bug is fixed in one place, and the test-account filter exists once.

What goes wrong

  • Business logic in staging. The filter hides rows other models need, and nobody finds it.
  • Incremental without a unique key. Each run appends again, so rows duplicate when a source row is updated.
  • A mart that reads raw tables. Two reports then disagree because each re-implements the join.
  • Never doing a full refresh. Incremental logic drifts from the truth. Schedule a periodic full rebuild or a reconciliation.

Examples

One long query split into layers

A 200-line revenue query is split into three staging models, one intermediate join and one mart. The mart is fct_revenue_daily. A change to the refund rule now edits only the intermediate model, and every dashboard picks it up on the next run.

Why the incremental table doubled its rows

{{ config(materialized='incremental') }}
select * from {{ ref('stg_events') }}
{% if is_incremental() %}
where event_time > (select max(event_time) from {{ this }})
{% endif %}

There is no unique_key, so an event corrected after its first load is inserted again. Adding unique_key='event_id' makes the run replace it. A look-back window (reprocess the last few days) also catches late rows.

Key points

  • ELT loads raw data first and transforms it in the warehouse; ETL transforms before loading and suits masking or limited targets.
  • Staging models rename and cast one source table each, with no joins or business rules.
  • Marts are the only layer dashboards read, so every report shares one definition of a metric.
  • An incremental model needs a filter for new rows and a unique key so updated rows replace old ones.
  • Keep raw data unedited so a wrong transformation can be rebuilt without touching the source system.

Common mistakes

  • Putting joins and business filters in staging models.
  • Letting an assistant produce one giant query because it runs.
  • Building incremental models with no unique key or no way to catch late rows.
  • Pointing a dashboard at intermediate or raw tables.

Check yourself · 2 of 3

An incremental model loads only new rows by timestamp, but a source row can be corrected after it was first loaded. What do you add so the correction is not duplicated?

Choose one answer

Check yourself · 3 of 3

When is ETL, transforming before load, the better choice than ELT?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic