The Data Lifecycle, ETL vs ELT and Ingestion Choices
Follow data from the system that creates it to the report that uses it, run the same small job as ETL and as ELT to see what each keeps, design raw, staging and modelled layers, and choose an ingestion approach and cadence for a source.
Contentsand lesson path
On this page
- Why it matters
- The lifecycle and its sources
- ETL and ELT: where the transformation runs
- Designing the layers for a source
- Choosing how to ingest
- Check your understanding
- Apply it
- Review prompt
Lessons of ETL/ELT Pipeline Design
- The Data Lifecycle, ETL vs ELT and Ingestion Choices Concept · 25 min
- Lab: A Python Extractor That Survives Flaky APIs Lab · 30 min
- Bulk Loading Without Row-by-Row Inserts Worked example · 20 min
- Incremental Loads with Watermarks and Lookbacks Worked example · 25 min
- Lab: Idempotent Writes and a Safe Backfill Lab · 30 min
- Check: Is This Pipeline Safe to Re-run? Knowledge check · 10 questions
What you will learn
- Compare ETL and ELT and design a pipeline with raw landing, staging and modeled layers for a given source and freshness requirement.
- Choose an ingestion approach for a source (custom extractor, open-source connector framework such as dlt or Airbyte, managed connector service, file drop on object storage, or event collector) and a batch, streaming or hybrid cadence, justified by freshness, volume, schema drift and maintenance cost.
Prerequisites: Data Handling, SQL Fundamentals
01. Why it matters
Most data problems that reach a dashboard started much earlier: a record that was never extracted, a rule applied before anyone could check it, or a source that changed shape without warning. A data engineer designs the path between the systems that create data and the people who use it, so that the path is reliable, cheap enough and easy to repair. This lesson gives you the vocabulary for that path and two decisions you will make for every new source: in which order to extract, load and transform, and which way to bring the data in.
02. The lifecycle and its sources
A common way to describe the work is the data engineering lifecycle, five stages that every dataset passes through:
- Generation: an application, device or person creates the data. You usually do not own this system.
- Ingestion: you move the data out of the source and into your platform.
- Storage: you keep it somewhere durable, such as object storage, a warehouse or a database.
- Transformation: you clean, combine and reshape it into tables that answer questions.
- Serving: dashboards, analysts, machine learning models and other applications read the result.
Ingestion is where most of the surprises are, because the source decides what is possible. An operational database can be queried, or its change log can be read; when it is busy, extract from a read replica so the application does not slow down. A SaaS API returns pages of JSON and limits how fast you may ask. A partner may only send files, such as a CSV every night. Servers write logs, and apps and devices emit events, small records such as "button clicked", often thousands per second. Each kind needs a different ingestion approach, which is the last section of this lesson.
03. ETL and ELT: where the transformation runs
In ETL (extract, transform, load), a program transforms the data on its way in and loads only the finished result. In ELT (extract, load, transform), you load the records as they arrived and transform them afterwards, with SQL, inside the warehouse or lakehouse. ETL was the norm when warehouse storage and compute were expensive; ELT became common once cloud warehouses made it cheap to keep raw data and run SQL over it.
The difference matters most when something goes wrong. The file below holds five order records from an API. Order 2 appears twice because it was refunded later, and order 3 has an amount written with a comma, 12,50.
{"id":1,"amount":"40.00","ccy":"EUR","status":"paid","ts":"2026-11-02T08:10:00Z"}
{"id":2,"amount":"15.50","ccy":"GBP","status":"paid","ts":"2026-11-02T08:40:00Z"}
{"id":3,"amount":"12,50","ccy":"EUR","status":"paid","ts":"2026-11-02T09:05:00Z"}
{"id":2,"amount":"15.50","ccy":"GBP","status":"refunded","ts":"2026-11-02T11:00:00Z"}
{"id":4,"amount":"99.00","ccy":"EUR","status":"paid","ts":"2026-11-02T12:30:00Z"}To run the examples, create a virtual environment and pip install "duckdb==1.5.6". The ETL version keeps the newest version of each order, converts the amount to euros, drops rows it cannot parse, and loads only paid orders.
"""ETL: transform in Python, load only the result."""
import json
import duckdb
RATES = {"EUR": 1.0, "GBP": 1.15} # to EUR, a fixed rate for the example
latest = {}
for line in open("raw_orders.jsonl"): # in real ETL this is an API response
r = json.loads(line)
if r["id"] not in latest or r["ts"] > latest[r["id"]]["ts"]:
latest[r["id"]] = r # keep the newest version of each order
clean = []
for r in latest.values():
try:
amount = float(r["amount"])
except ValueError:
continue # bad row dropped before loading
if r["status"] == "paid":
clean.append((r["id"], round(amount * RATES[r["ccy"]], 2)))
con = duckdb.connect("etl.duckdb")
con.execute("CREATE OR REPLACE TABLE paid_orders (id INT, amount_eur DECIMAL(10,2))")
con.executemany("INSERT INTO paid_orders VALUES (?, ?)", clean)
print(con.sql("SELECT count(*) AS orders, sum(amount_eur) AS revenue_eur"
" FROM paid_orders"))┌────────┬───────────────┐
│ orders │ revenue_eur │
│ int64 │ decimal(38,2) │
├────────┼───────────────┤
│ 2 │ 139.00 │
└────────┴───────────────┘The ELT version loads all five records unchanged into raw_orders, with a _loaded_at column that records when they arrived. It reads the amount as text, so a badly formatted amount cannot fail the load. A staging view then renames columns, converts types with TRY_CAST (which gives NULL instead of an error) and keeps the newest version of each order. A model view, fct_paid_orders, answers the business question.
"""ELT: load the raw records as they are, then transform with SQL in the database."""
import duckdb
con = duckdb.connect("elt.duckdb")
# 1. Raw landing: every record, unchanged, plus when it was loaded.
con.execute("""
CREATE OR REPLACE TABLE raw_orders AS
SELECT *, TIMESTAMPTZ '2026-11-02 13:00:00+00' AS _loaded_at
FROM read_json('raw_orders.jsonl', columns = {
id: 'INT', amount: 'VARCHAR', ccy: 'VARCHAR',
status: 'VARCHAR', ts: 'TIMESTAMPTZ'})""")
# 2. Staging: typed, standard names, latest version of each order.
con.execute("""
CREATE OR REPLACE VIEW stg_orders AS
SELECT id AS order_id, TRY_CAST(amount AS DECIMAL(10,2)) AS amount,
ccy AS currency, status, ts AS updated_at
FROM raw_orders
QUALIFY row_number() OVER (PARTITION BY id ORDER BY ts DESC) = 1""")
# 3. Model: the business question.
con.execute("""
CREATE OR REPLACE VIEW fct_paid_orders AS
SELECT order_id,
round(amount * CASE currency WHEN 'GBP' THEN 1.15 ELSE 1.0 END, 2)
AS amount_eur
FROM stg_orders WHERE status = 'paid'""")
print(con.sql("SELECT count(*) AS orders, sum(amount_eur) AS revenue_eur"
" FROM fct_paid_orders"))
print(con.sql("SELECT order_id, amount FROM stg_orders WHERE amount IS NULL"))┌────────┬───────────────┐
│ orders │ revenue_eur │
│ int64 │ decimal(38,2) │
├────────┼───────────────┤
│ 3 │ 139.00 │
└────────┴───────────────┘
┌──────────┬───────────────┐
│ order_id │ amount │
│ int32 │ decimal(10,2) │
├──────────┼───────────────┤
│ 3 │ NULL │
└──────────┴───────────────┘Both versions report €139.00, but ETL silently lost order 3, while ELT counts it and shows its amount as NULL, which a simple test can catch. When you learn that 12,50 means 12.50, the ELT fix is a new staging view; the model rebuilds from the raw table, and the source is not asked again.
"""The source fixes nothing, but we learn that "12,50" means 12.50. Rebuild from raw."""
import duckdb
con = duckdb.connect("elt.duckdb")
con.execute("""
CREATE OR REPLACE VIEW stg_orders AS
SELECT id AS order_id,
TRY_CAST(replace(amount, ',', '.') AS DECIMAL(10,2)) AS amount,
ccy AS currency, status, ts AS updated_at
FROM raw_orders
QUALIFY row_number() OVER (PARTITION BY id ORDER BY ts DESC) = 1""")
print(con.sql("SELECT count(*) AS orders, sum(amount_eur) AS revenue_eur"
" FROM fct_paid_orders"))┌────────┬───────────────┐
│ orders │ revenue_eur │
│ int64 │ decimal(38,2) │
├────────┼───────────────┤
│ 3 │ 151.50 │
└────────┴───────────────┘In the ETL version the raw record was never stored, so the only fix is to extract it again, and many APIs keep only recent history. That is the main argument for ELT. ETL still has a place: when data must not be stored at all, such as card numbers that must be masked before they reach the warehouse, or when a heavy transformation is cheaper outside it.
04. Designing the layers for a source
The ELT example already had the three layers that most pipelines use:
- Raw landing: records exactly as the source sent them, append-only, with load metadata such as
_loaded_atand the source file name. It is your evidence and your replay log. - Staging: one cleaned table or view per source table: standard names, proper types, one row per key. No business rules yet.
- Modelled: facts, dimensions and marts that join staging tables and apply business definitions, such as "revenue counts only paid orders".
The freshness requirement, how old the data may be when someone reads it, decides how often the layers run. If finance reads a report at 07:00 about yesterday, one nightly run is enough. If support agents need orders from the last five minutes, ingestion must run every few minutes or continuously, and the staging and model steps must keep up. Write the requirement down for each source before you choose tools; it is the number every later choice is measured against.
05. Choosing how to ingest
There are five common ways to bring a source in:
- A custom extractor: your own code, like the one in the next lab. Full control, but you maintain pagination, retries, schema changes and secrets for ever.
- An open-source connector framework such as dlt or Airbyte: ready-made connectors and helpers for state, pagination and schema changes, run on your own infrastructure.
- A managed connector service: a vendor runs and maintains the connectors for a fee, usually priced by the rows or volume moved.
- A file drop: the source writes files to object storage, and an event or a schedule starts the load.
- An event collector: an HTTP endpoint or SDK that receives events from apps and devices and writes them to a queue or to storage.
Judge them with four questions. How fresh must the data be? How much is there? How often does its shape change (schema drift)? And who will maintain the code in a year? A popular SaaS product with a well-kept connector rarely justifies custom code. An internal API that nobody else uses has no connector, so you write one. A source that can only produce files gets a file drop.
The cadence is a separate choice. Batch ingestion moves data on a schedule, such as hourly or nightly; it is simple and cheap. Streaming moves each event within seconds, through a queue such as Kafka; it costs more to build and run, so use it only where someone acts on data that fresh. A hybrid design streams the events that need speed and batch-loads the same data for everything else.
06. Check your understanding
07. Apply it
The skill practice ends with a one-page ingestion decision. Start it now for two sources: a SaaS tool that has an off-the-shelf connector, and a partner that drops a file every night. For each, write the freshness requirement, the expected volume, how often the shape changes, and who will maintain the pipeline. Then choose custom code, a connector framework or a managed service, and a batch, streaming or hybrid cadence, and name the raw, staging and modelled tables you will create.
08. Review prompt
Without looking back, name the five stages of the lifecycle and five kinds of source. Explain the difference between ETL and ELT and give one reason to prefer each. Describe what belongs in raw, staging and modelled layers. Finally, list the five ingestion approaches and the four questions you use to choose between them.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
10 questions · about 8 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.