ETL vs ELT — Data Engineering

ETL and ELT are the same three steps, Extract, Transform, Load, in a different order. ETL cleans data before it enters the warehouse, so the warehouse only…

In the previous lesson, the sales table was built from a raw copy, raw_order_lines, already sitting in the warehouse. That's one way. The other is to clean the data on the way, so it arrives in the warehouse already tidy. The two ways are called ETL and ELT: two orders for the same three steps, Extract (take data from the source), Transform (clean and shape it), Load (put it in the warehouse). The only difference is where and when the transform happens. It's like buying vegetables. You can wash and cut them at the market, so only ready-to-cook pieces go into your fridge, and the peels and stalks stay behind. Or you bring everything home whole, it goes into the fridge as it is, and you cut it in your kitchen when you cook. Tomorrow you want a different dish, and the whole ingredients are still there. The first way is ETL, the second is ELT. The market is the data source, the fridge is the warehouse, the kitchen is the warehouse's engine.

The same three steps

Bookshop's pipeline from the previous lesson, split into steps:

Step What it means At Bookshop
Extract reading data from the source a SELECT of one day's orders from the app's MySQL
Transform cleaning and organising drop doubled lines, a NULL city becomes Unknown, price from the catalogue, work out week
Load writing to the target table an INSERT into the warehouse

Pipelines usually run per day: every night, one daily load picks up yesterday's orders. In the Lab, the source and the warehouse sit in one SQLite so they can run together. In real life they are separate databases, and a script moves the query's result from one to the other.

ETL: clean first, then in

In ETL, the transform happens before the data reaches the warehouse. The warehouse only receives clean results. The daily load for 1 October:

INSERT INTO sales
SELECT DISTINCT oi.order_id, oi.book_id,
       date(o.created_at) AS order_date,
       date(o.created_at, 'weekday 0', '-6 days') AS week,
       COALESCE(c.city, 'Unknown') AS city,
       b.title AS title,
       oi.qty,
       b.price AS price
FROM order_items oi
JOIN orders o ON o.id = oi.order_id
JOIN customers c ON c.id = o.customer_id
JOIN books b ON b.id = oi.book_id
WHERE date(o.created_at) = '2026-10-01';

In real life, ETL's transform is often written in Python (pandas, two lessons from now) and runs on its own server. The idea is the same: the warehouse never sees the raw data.

ELT: in raw, cleaned in the warehouse

In ELT, extract and load run first, as is. The transform happens inside the warehouse, with SQL:

-- 1. Extract + Load: copy the 1 October lines unchanged
INSERT INTO raw_order_lines
SELECT oi.id, o.id, o.created_at, c.name, c.city, b.id, b.title, oi.qty, oi.price
FROM order_items oi
JOIN orders o ON o.id = oi.order_id
JOIN customers c ON c.id = o.customer_id
JOIN books b ON b.id = oi.book_id
WHERE date(o.created_at) = '2026-10-01';

-- 2. Transform: rebuild sales from every raw line
DROP TABLE IF EXISTS sales;
CREATE TABLE sales AS
SELECT DISTINCT r.order_id, r.book_id,
       date(r.created_at) AS order_date,
       date(r.created_at, 'weekday 0', '-6 days') AS week,
       COALESCE(r.city, 'Unknown') AS city,
       r.title AS title,
       r.qty,
       b.price AS price
FROM raw_order_lines r
JOIN books b ON b.id = r.book_id;

Where the cleaning happens

ETL ELT
The transform runs before the warehouse: a query on the source, or a Python script inside the warehouse, with SQL
What the warehouse keeps clean results only the raw data, plus clean tables built from it
The cleaning rule turns out wrong extract again from the source, if the data is still there rerun the transform SQL on raw
You need a column that was dropped impossible: it was never loaded still in raw
Common tools Python scripts, Informatica, Talend Airbyte or Fivetran for E and L, dbt for T

Why ELT won

Warehouses used to be expensive and slow, so data was tidied on another server first to keep what went in as small as possible. Cloud warehouses such as BigQuery and Snowflake changed the sums: storage is cheap, and compute (the processing power) can be scaled up for one heavy query and switched off again. So it's cheaper to load everything raw and clean it with SQL there. A bonus: analysts know SQL too, and the raw data can be reprocessed at any time. That's why ELT fits better when the target warehouse has a lot of compute.

ETL is still used when:

Many teams use a mix: drop sensitive columns on the way, load the rest raw, and clean it in the warehouse.

An idempotent load

Idempotent means running it once or many times gives the same end result (you met the term in the API Idempotency lesson). A daily load will be run again at some point: it fails halfway, the server restarts, or someone presses "run" twice.

The ETL load above is just INSERT INTO sales SELECT .... Say it fails halfway one night, so it's run again. After two runs, how many books does This Earth of Mankind have in London for the week of 28 September: 2, 4 or 6? Guess first, then look at what SQLite gives:

Loaded once Loaded twice
1 October rows in sales 2 4
This Earth of Mankind, London, week of 28 September 2 4
The Rainbow Troops, London, week of 28 September 3 3

The answer is 4. This Earth of Mankind overtakes The Rainbow Troops again, the same wrong answer as in the previous lesson, this time caused by the pipeline itself. The warehouse doesn't refuse it: BigQuery and Snowflake don't enforce primary keys, so twin rows slip in silently.

The most common way to make it idempotent: delete the part you're about to fill, then fill it. That part is called a partition, here one date:

BEGIN;
DELETE FROM sales WHERE order_date = '2026-10-01';
INSERT INTO sales
SELECT DISTINCT oi.order_id, oi.book_id,
       date(o.created_at) AS order_date,
       date(o.created_at, 'weekday 0', '-6 days') AS week,
       COALESCE(c.city, 'Unknown') AS city,
       b.title AS title,
       oi.qty,
       b.price AS price
FROM order_items oi
JOIN orders o ON o.id = oi.order_id
JOIN customers c ON c.id = o.customer_id
JOIN books b ON b.id = oi.book_id
WHERE date(o.created_at) = '2026-10-01';
COMMIT;

The second way: upsert, write it if it isn't there, change it if it is, based on a key. In SQLite and PostgreSQL that's INSERT ... ON CONFLICT (order_id, book_id) DO UPDATE SET ..., in MySQL INSERT ... ON DUPLICATE KEY UPDATE, in BigQuery and Snowflake MERGE. In ELT, the load into raw must be idempotent too: rerun without the DELETE, raw_order_lines becomes 22 rows. The answer in sales happens to stay right because DISTINCT drops twin rows, but raw no longer matches the source.

⚠️ Why can a load that succeeds still be wrong?

TL;DR: ETL and ELT are the same three steps, Extract, Transform, Load, in a different order. ETL cleans data before it enters the warehouse, so the warehouse only keeps clean results. ELT loads raw data into raw tables, then cleans it with SQL inside the warehouse; it's the main pattern now because cloud warehouse compute is cheap and scalable, and the raw data can be reprocessed. ETL is still used for sensitive data that must not enter the warehouse. A load must be idempotent: a plain INSERT run again turns 1 October into 4 rows and This Earth of Mankind into 4; a DELETE per date then INSERT in one transaction (or an upsert) keeps it at 2 rows however many times it runs.

⚡ Three steps, two orders

Meaning: ETL and ELT are both Extract, Transform, Load. ETL cleans the data before it enters the warehouse, so the warehouse only keeps clean results. ELT loads the raw data into a raw table first, then cleans it with SQL inside the warehouse.

⚡ ELT: in raw first

Write:

-- 1. Extract + Load: copy the 1 October lines unchanged
INSERT INTO raw_order_lines
SELECT oi.id, o.id, o.created_at, c.name, c.city, b.id, b.title, oi.qty, oi.price
FROM order_items oi
JOIN orders o ON o.id = oi.order_id
JOIN customers c ON c.id = o.customer_id
JOIN books b ON b.id = oi.book_id
WHERE date(o.created_at) = '2026-10-01';

Meaning: No DISTINCT, no COALESCE: the lines go into raw as they are. The cleaning happens later, with SQL in the warehouse. If the rules change tomorrow, just rerun it, because the raw data is still there.

⚡ Why ELT won

Meaning: On cloud warehouses such as BigQuery and Snowflake, storage is cheap and compute can be scaled up. So ELT fits when the target warehouse has a lot of compute. ETL is still used for sensitive data that must not enter the warehouse.

⚡ An idempotent load

Guess first: a load that's just INSERT runs twice. How many books does This Earth of Mankind have in London for the week of 28 September: 2, 4 or 6?

It's 4. The 1 October rows are doubled, and This Earth of Mankind overtakes The Rainbow Troops again, without an error.

Meaning: First DELETE FROM sales WHERE order_date = '2026-10-01', then INSERT, wrapped in BEGIN and COMMIT as one transaction. However many times it runs, 1 October stays at 2 rows.

What you will learn