+1 (726) 227-3027

Incremental Loads in Talend: High-Water Marks, Late-Arriving Data, and Safe Reruns

Full table reloads work until the table gets big. Then the nightly window shrinks, source DBAs complain, and someone proposes "just load what changed." That sounds simple, but most incremental loads we get called in to fix share the same flaws: the watermark lives in a context file, late rows are silently missed, and a failed run leaves the job in an unknown state. This tutorial walks through a pattern that avoids those problems using standard Talend components.

When to use a watermark (and when not to)

A high-water mark works when the source has a reliable, monotonically increasing column such as updated_at or a sequence ID. If the source has hard deletes, or updated_at is not maintained by every writer, use log-based change data capture instead (see our CDC with Talend post).

Step 1: Keep the watermark in a control table

Do not store the watermark in a context file or a local file on the job server. Engines get replaced, containers restart, and files vanish. Use a small table in the target database:

CREATE TABLE etl_control (
  job_name       VARCHAR(100) PRIMARY KEY,
  last_watermark TIMESTAMP    NOT NULL,
  last_run_id    VARCHAR(64),
  last_status    VARCHAR(20),
  updated_at     TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

Seed it with an early date for the first run so the initial load is just a very large incremental load.

Step 2: Read the watermark at job start

  1. Add a tDBInput that selects last_watermark for this job name.
  2. Send it to a tSetGlobalVar (or tJavaRow) to store it as globalMap value lower_bound.
  3. Capture the upper bound once, at start: new Date() minus a small safety delay, stored as upper_bound. Using a fixed upper bound stops rows committed mid-run from being half-seen.

Step 3: Query with a lookback window

Late-arriving data is the usual cause of silent gaps. A transaction that started before your upper bound may commit after it, carrying an earlier updated_at. Subtract a lookback window from the lower bound:

SELECT * FROM orders
WHERE updated_at >  TIMESTAMP '" + lowerBoundMinusLookback + "'
  AND updated_at <= TIMESTAMP '" + upperBound + "'

A lookback of 15 minutes to a few hours is common; pick it from how long your longest source transaction runs. The lookback means you will re-read some rows, which is fine only if the load is idempotent.

Step 4: Make the load idempotent

Load into a staging table, then MERGE (or update-then-insert) into the target on the business key. Re-reading rows then changes nothing. Truncate staging at the start of each run, not the end, so you can inspect it after a failure. For database-specific merge patterns see our posts on PostgreSQL and SQL Server.

Step 5: Advance the watermark only on success

Update etl_control with upper_bound in a final subjob connected by OnSubjobOk from the merge. Never advance it in a tPostjob, which runs even when the job failed. If the merge fails, the watermark stays put and the next run covers the same range.

Put the staging load, merge, and watermark update inside one transaction where the database allows it (tDBConnection with shared connection and tDBCommit at the end). Where it does not, the idempotent merge still protects you.

Step 6: Handle deletes and clock issues

  • Hard deletes are invisible to a watermark. Either ask the source team for soft-delete flags, run a periodic key-only reconciliation, or move to CDC.
  • Clock skew: take timestamps from the source database, not the Talend server. SELECT CURRENT_TIMESTAMP on the source for the upper bound avoids mismatches between machines.
  • Time zones: store the watermark in UTC and convert explicitly.
  • Equal timestamps: use > with a lookback, or a composite watermark of timestamp plus ID, so rows sharing the boundary timestamp are not skipped.

Step 7: Add reconciliation checks

After each run, log source count versus target count for the window, and weekly compare a checksum or row count for the full table. Write results to your logging tables so alerts can fire on drift. Our error handling and observability post covers the logging side.

Failure checklist

  • Job fails mid-merge: watermark unchanged, rerun is safe.
  • Job runs twice concurrently: add a lock row or scheduler-level concurrency limit, otherwise two runs may race on the watermark.
  • Source backfill rewrites old updated_at values: expect a large window; consider a manual watermark reset.
  • Need to reprocess a date range: set last_watermark back by hand and rerun; idempotency makes this safe.

Summary

Persist the watermark in the database, fix the upper bound at start, subtract a lookback window, merge idempotently, and advance the mark only after success. These five habits remove most incremental-load incidents we see.

If you have a fragile set of incremental jobs or are planning a move to Qlik Talend Cloud, contact ETL Advisors and we can review the design with you.