CASE STUDIES LIST/ HOME
← Case #03#04 / 25Case #05 →
CASE STUDY #04Phase 1: Foundations & IngestionCLASSIFICATION: ACTUAL

Why I Stopped Re-Processing Millions of Rows Every Night

Incremental Extraction Architecture with High-Watermark State Management

PythonPostgreSQLAzure ADLSSQL

1. The Problem

Nightly ETL job performed full `SELECT *` table scans over 20M historical records. Pipeline execution time reached 45 minutes and ballooned cloud egress costs.

2. What I Initially Thought

"I assumed re-processing full tables was necessary to catch updated or edited rows. But 98% of historical rows never change after creation."

3. What I Learned

Incremental extractions track a high-watermark column (`updated_at`). By storing the timestamp of the last processed record, extractions scan only rows modified since the last run.

High-Watermark TrackingIncremental vs Full LoadIdempotent WatermarksWrite-Ahead Log Filtering

4. What I Built

Watermark state persistence module in PostgreSQL storing last extracted timestamp per pipeline, filtering source tables with `WHERE updated_at > last_watermark`.

SELECT * FROM tasks 
WHERE updated_at > :last_watermark 
ORDER BY updated_at ASC 
LIMIT :batch_size;

5. The Experiment

BEFORE

Full table extraction scanning 20 million rows every night. Execution duration: 45 minutes.

CHANGE APPLIED

Implemented incremental extraction querying only records updated after high-watermark timestamp.

AFTER RESULT

Execution time reduced from 45 minutes to 35 seconds per batch; scanned row volume cut by 99.2%.

6. What Went Wrong

Encountered late-arriving data race conditions when source transactions committed with timestamps earlier than the watermark execution window.

7. Engineering Decision & Trade-offs

Added a 5-minute overlap lookback window (`last_watermark - INTERVAL '5 minutes'`) to guarantee late-committing transactions are captured.

8. What I Would Do Differently in Production

Ensure source tables have a composite index on `(updated_at, id)` to prevent full table scans during incremental `WHERE updated_at > ?` filter queries.

Questions I Can Now Answer Confidently in an Interview:

  • How do you implement incremental ETL using high-watermarks?
  • How do you handle late-arriving data or out-of-order transaction commits in incremental extractions?
  • Why is ordering by watermark timestamp critical when fetching incremental batches?

Expected / Verified Evidence

•SQL query benchmark comparison (Full vs Incremental)
•High-watermark tracking table execution logs
•Pipeline runtime duration metrics graph
BACK TO ALL CASE STUDIESNEXT: CASE #05 (Beyond GROUP BY: How Window Functions Saved Me From 5-Way Self-Joins)