Skip to the page

Orchestration and dbt · mid

dbt incremental models and snapshots

An incremental model needs a key and a lookback window or it loses and repeats rows. Snapshots record history but only what they see at run time.

The notes

What you must know

  • Incremental: the first run builds the whole table, later runs process rows that pass the is_incremental() filter.
  • Without unique_key, changed rows are inserted, not updated, so a payment moving from PENDING to SUCCESS gets a second row. Use unique_key with the merge or delete+insert strategy.
  • A strict high-water mark (updated_at greater than the max) misses rows that commit late with an older updated_at. Use a lookback window, for example where updated_at >= (max - interval 3 hours).
  • Reprocessing the window is safe because the merge is idempotent. The cost is reading the window again.
  • The microbatch strategy (dbt 1.9 and later): event_time, batch_size, begin and lookback. Each batch is idempotent, dbt retry reruns only failed batches, and --event-time-start and --event-time-end backfill a range.
  • Source deletes are invisible to incremental models. Use a soft-delete flag, a snapshot or CDC. on_schema_change decides what happens when columns change.
  • Snapshots without a reliable updated_at: use strategy check with check_cols listing the columns that matter, not all. A volatile column such as last_seen_at makes a new version every run.
  • A snapshot records state at run time: two changes in one day look like one. Deletes: hard_deletes invalidate or new_record (dbt 1.9 and later); the default ignores them.
  • Snapshots cannot be rebuilt: lose the table and the history is gone. Keep them in their own schema. Alternatives: log-based CDC, or a cheap daily full extract kept in bronze.

The red pen

Common traps: mistake → fix

  • Mistake: Add unique_key and keep the strict greater-than filter

    Fix: late rows are still missed.

  • Mistake: Full refresh on every run

    Fix: it removes the point of incremental.

  • Mistake: Snapshots catch every change

    Fix: they catch the state at each run only.

Easy to hard

Questions interviewers ask, easy to hard

  1. This incremental model loses late payments and repeats others. What is wrong?
  2. What is the microbatch strategy?
  3. How would you snapshot a table with no updated_at?
  4. What do snapshots lose compared with CDC?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview