๐ค Data Loading & Change Data Capture (CDC)
๐ฅ Data Loading
If extraction is mining the ore, and transformation is refining it into steel, loading is delivering the finished steel to the warehouse so people can start building with it.
Data Loading is the final step in the pipeline โ moving processed, ready-to-use data into the Data Warehouse or Lakehouse.
๐๏ธ Types of Data Loading
How often and how fast you load data depends on what the business needs.
| Load Type | What It Does | Speed | Best For |
|---|---|---|---|
| Batch Loading | Loads data in large chunks at scheduled intervals (e.g., nightly) | Slow (hours) | Historical reporting, daily dashboards, end-of-day reconciliation |
| Micro-Batching | Loads data in small chunks frequently (e.g., every 5-15 mins) | Medium (minutes) | Near real-time analytics, intra-day reporting |
| Real-time / Streaming | Loads data continuously as soon as it is generated | Fast (milliseconds) | Fraud detection, live recommendations, monitoring |
Real-time loading is expensive and complex. Don't use it unless the business actually needs to make sub-second decisions. For 90% of BI dashboards, daily or hourly batch loading is perfectly fine.
๐ Change Data Capture (CDC)
CDC is a modern approach to incremental loading. Instead of querying a table to see what changed, CDC listens directly to the source database's transaction log (e.g., the binlog in MySQL or WAL in PostgreSQL).
How CDC Works:
- An UPDATE happens in the source database.
- The database writes this change to its internal log.
- The CDC tool (like Debezium) reads the log instantly.
- The change is streamed into the Data Warehouse.
Why CDC is powerful:
- Zero impact on the source database (no heavy
SELECTqueries) - Instant updates (enables real-time replication)
- Captures every single change (even if a row is updated 5 times in a minute, CDC catches all 5; normal incremental loading would only catch the final state).
๐ง Key Loading Concepts
1๏ธโฃ Data Freshness (Latency)
How up-to-date is the data in the warehouse?
- If a pipeline runs every night at 2 AM, the data freshness during the day is up to 24 hours old.
- If a business asks for "real-time data", they are actually asking for very low latency (high freshness).
2๏ธโฃ Scheduling & Orchestration
Data doesn't load itself. You need a tool to trigger the extraction, wait for the transformation, and execute the load.
- Tools used: Apache Airflow, Dagster, Prefect, or cloud-native schedulers.
- Dependency Graphs: Jobs are run as a DAG (Directed Acyclic Graph). For example, Load Customers must finish before Load Sales can begin.
3๏ธโฃ Incremental vs Full Load
We covered this in Extraction, but it applies to Loading too.
- Full Load: Wipe the target table clean (Truncate) and insert everything from scratch. Used for small dimension tables (e.g., a list of 50 states).
- Incremental Load: Only insert new rows or update changed rows. Used for massive fact tables (e.g., millions of daily transactions).
๐ ๏ธ Handling Updates During Load (SCD)
When incrementally loading data, what happens if a customer's address changes? You have to decide how to load that change into the DW. This is called Slowly Changing Dimensions (SCD).
| Strategy | How it handles the change | Result |
|---|---|---|
| SCD Type 1 | Overwrite the old value | You lose history (only know current address) |
| SCD Type 2 | Add a new row with a new timestamp | You keep full history (know when they moved) |
| SCD Type 3 | Add a new column (previous_address) | You keep limited history (only previous and current) |
We will cover SCDs in much greater detail in the Dimensional Modeling chapters, but it's important to know that loading logic dictates how history is tracked.
๐งช Practice Drill
// Try answering these:
// Q1. A retail manager checks a dashboard every morning to see yesterday's total sales. What type of loading strategy is most appropriate for this?
// Q2. What is the primary advantage of CDC over traditional incremental loading using timestamp columns?
// Q3. An analyst runs a query at 3 PM. The ETL pipeline runs once a day at midnight. What is the data freshness (latency) of the results?
// Q4. A company needs to trigger a Python script, wait for it to finish, and then trigger 5 SQL queries in Snowflake. What kind of tool do they need for this?
// Q5. Match the scenario to the correct SCD Type:
// | Scenario | SCD Type |
// | -------------------------------------------------------------------------------------------------- | -------- |
// | A customer corrects a typo in their name. The old name doesn't matter. | ? |
// | A customer moves to a new city. We need to track sales in both their old and new cities over time. | ? |
๐ก Click for Solutions
A1. Batch Loading (running nightly is sufficient since they only look at it in the morning).
A2. CDC reads directly from the database's transaction log, which has zero impact on database query performance and captures every single intermediate change, not just the final state.
A3. 15 hours. The data is as fresh as the last successful load (midnight).
A4. An Orchestration Tool or Scheduler (like Apache Airflow).
A5.
| Scenario | SCD Type |
|---|---|
| A customer corrects a typo in their name. The old name doesn't matter. | SCD Type 1 (Overwrite) |
| A customer moves to a new city. We need tracking over time. | SCD Type 2 (History / New Row) |
โ Previous Topic | Next Topic โ Next Topic