Start here
Loading is the step where you write finished rows into a table in the warehouse. A warehouse is a database built for analysis.
Recap: the raw layer keeps data as it arrived. The curated layer holds the clean tables that people query. A load writes into a curated table.
How you write matters, because a job often runs twice. A scheduler (a tool that starts jobs on time) runs a failed job again. This is called a retry.
A person may also run a job again to fix a bug.
One order tells the story in this chapter. On day 1, order 105 is pending and has no amount yet.
On a later day it is paid, for 22.00. We made up that amount for this example.
Here is the warehouse table orders after the first load.
| order_id | status | amount | order_date |
|---|---|---|---|
| 101 | paid | 40.00 | 2026-01-03 |
| 102 | paid | 25.00 | 2026-01-10 |
| 103 | refunded | 60.00 | 2026-01-11 |
| 104 | paid | 15.50 | 2026-01-15 |
| 105 | pending | NULL | 2026-01-20 |
Order 106 does not exist yet. It arrives on day 2. Each pattern below starts from this table.
New rows first go into a staging table. A staging table is a holding table for rows that are not yet in the final table. In the examples, it is called orders_staging.
The next sections show six ways to write from staging into orders.
- Append: add the new rows at the end.
- Full refresh: empty the table, then load everything.
- Replace one day: delete one day of rows, then load that day again.
- Upsert: update a row if the same order_id is already there; add it if not.
- Soft delete: mark a row as deleted, but keep it.
- Atomic swap: build a new table, then switch to it.
For each one, ask two questions. What does the table look like after the load? What happens if the same load runs again?
