Course contentsShow
← Databases & SQL
Lesson 1789 of 1,95317. Analytics and Data PipelinesFree lesson

Designing Incremental Data Loads

Identify changed data using watermarks to minimize resource consumption during processing.

In this lesson, you will learn how to optimize data pipelines by using watermarks to process only the data that has changed since the last successful execution.

The Problem: Full Loads vs. Incremental Loads

In a data warehouse environment, performing a full load (copying the entire source table every time) is highly inefficient as datasets grow. It consumes excessive network bandwidth, increases CPU load on the source database, and significantly delays pipeline completion. Instead, we use Incremental Data Loads.

Identifying Changes with Watermarks

A "watermark" is a metadata marker—usually a high-water mark—that tracks the last point in time or the last ID processed by your pipeline. By recording the maximum value of a tracking column (like updated_at or row_version) in a persistent control table, you can filter your extraction query to only pull records created or modified after that specific point.

Consider a source table orders. Instead of SELECT * FROM orders, your incremental pipeline executes:

-- Retrieve the stored watermark from your metadata store
-- Assume last_processed_at = '2023-10-27 10:00:00'

SELECT * 
FROM orders 
WHERE updated_at > '2023-10-27 10:00:00'
ORDER BY updated_at ASC;

Implementing the Pattern

  1. Fetch: Query the source for records greater than the last_processed_at value.
  2. Transform: Apply your business logic to these specific records.
  3. Load: Insert the transformed data into the target staging table.
  4. Update: Upon a successful commit, update the last_processed_at in your control table to the MAX(updated_at) value of the data just processed.

Handling Challenges

Using watermarks requires careful handling of "in-flight" data. If a transaction is occurring on the source while your query runs, a standard timestamp comparison might miss records that were being committed simultaneously. For highly active systems, it is best practice to include a small buffer or "overlap" window (e.g., subtracting a few seconds from the watermark) to ensure no records are skipped, combined with an idempotent design to handle any resulting duplicate records.

Key Takeaway: Watermarking minimizes resource consumption by treating data as a delta, extracting only the specific records modified since the previous successful execution.