Özer Cem KELAHMETKELAHMET
Articles · Pipelines and orchestration

dbt incremental models explained: merge, delete+insert, microbatch and safe backfills

Incremental models are how dbt keeps big tables cheap to rebuild. This guide runs every main strategy on dbt Core 1.12 with DuckDB, shows the SQL dbt actually generates, and explains how late data and backfills break naive filters.

Download Markdown
At a glance
Reading time
16 min
Sections
9
Code examples
9
Tables
5
Sources
9
Published
23 Nov 2026
In 30 seconds
What changed
dbt Core 1.12.0 is published
Why it matters
Incremental models trade simplicity for cost.
What to do
Inventory your incremental models

Most dbt projects start with every model materialized as a table. Each run drops the table and rebuilds it from scratch. That is simple and always correct, but the cost grows with the size of the history, not with the size of the change. A fact table with two billion rows that gains five million rows a day is rebuilt in full every night to absorb 0.25% new data.

Incremental models fix this. On the first run dbt builds the table normally. On later runs it selects only new or changed rows and folds them into the existing table. The catch is that "only new rows" is a filter you write, and a wrong filter silently loses data. This article walks through the strategies dbt offers, shows the SQL dbt generates for each one, and demonstrates the two failure modes that bite most teams: late-arriving rows and unsafe backfills. Every example below was run on dbt Core 1.12.7 with the dbt-duckdb 1.11.1 adapter and DuckDB 2.0.1.

If you are new to dbt itself, the dbt tool page covers the basics. Incremental models usually feed the silver and gold layers described in the medallion architecture article.

What happened

dbt Core 1.12.0 is published (16 July 2026)

The 1.12 minor release of dbt Core was published to PyPI on 16 July 2026, and dbt Labs announced it as generally available on its blog. The upgrade guide for 1.12 lists the behaviour changes to check before moving a project. Incremental materializations, is_incremental() and the microbatch strategy work the same way described here.

dbt-duckdb 1.11.1 ships merge and microbatch support for DuckDB (26 October 2026)

The dbt-duckdb adapter version 1.11.1 was published on 26 October 2026. Its source registers append and delete+insert as base strategies, and adds merge and microbatch when the connected DuckDB is version 1.4 or newer, because DuckDB gained a native MERGE INTO statement in that line. The adapter's microbatch macro is written as a delete and insert over each batch's time range, and it refuses a unique_key on microbatch models with an explicit error.

dbt Core 1.12.7 patch release (12 November 2026)

The latest patch, 1.12.7, was published on 12 November 2026. That is the version used for the runs in this article. DuckDB 2.0.1, used as the local warehouse, followed on 20 November 2026.

How an incremental model works

An incremental model is a normal select with two additions: a config block that says how to apply new rows, and a Jinja block that narrows the select on later runs.

-- models/orders_merge.sql
{{ config(
    materialized='incremental',
    unique_key='order_id',
    incremental_strategy='merge'
) }}

select order_id, status, amount, updated_at
from {{ ref('raw_orders') }}

{% if is_incremental() %}
where updated_at > (select max(updated_at) from {{ this }})
{% endif %}

is_incremental() returns true only when four things hold: the target relation already exists, it is a table (not a view), the model is configured as incremental, and the run is not a --full-refresh. On the first run the where clause disappears, so dbt builds the full table. On every later run the clause appears, and {{ this }} resolves to the existing table, so the query reads only rows newer than the newest row already loaded.

dbt then does two steps. First it writes the narrowed result to a temporary relation. Second it applies that relation to the target with the strategy you chose. Think of it like updating a paper ledger: the first step is writing today's receipts on a separate sheet; the second is deciding whether to staple the sheet to the back (append), cross out old lines and rewrite them (delete+insert), or edit lines in place (merge).

The strategies side by side

The table summarises what each strategy does and what it needs. Not every adapter supports every strategy; check the adapter's documentation before you pick one.

Table 1. The strategies side by side
Strategy What it does Needs unique_key Handles updates Typical use
append Inserts every new row No No, creates duplicates Immutable event logs
delete+insert Deletes target rows whose key appears in the batch, then inserts the batch Yes Yes Warehouses without efficient MERGE, or large key sets
merge One MERGE statement: update on match, insert otherwise Yes Yes Mutable entities such as orders or customers
insert_overwrite Replaces whole partitions touched by the batch No (uses partitions) Yes, at partition level BigQuery and Spark tables partitioned by date
microbatch Splits the run into time batches and replaces each batch's time range No Yes, at time-range level Large time-series facts with backfills

Running the strategies on the same data

To see the differences, I built three models over the same source: orders_append, orders_di (delete+insert) and orders_merge. The source starts with three orders.

Table 2. Running the strategies on the same data
order_id status amount updated_at
1 placed 40.00 2026-11-20 09:00
2 placed 25.00 2026-11-20 10:00
3 placed 60.00 2026-11-21 08:00

The first dbt run builds all three tables in full. Then the source changes: order 2 ships at 2026-11-22 07:00 and order 4 arrives at 2026-11-22 09:30. The second run selects only rows with updated_at after 2026-11-21 08:00, which is two rows: the new version of order 2, and order 4.

Here is what each table holds after run two:

Table 3. Running the strategies on the same data
Model Rows Order 2
orders_append 5 Two rows: placed and shipped
orders_di 4 One row: shipped
orders_merge 4 One row: shipped

Append doubled order 2, because append never looks at keys. That is correct for an event log, where "order 2 was placed" and "order 2 shipped" are both facts, and wrong for an entity table.

The SQL dbt generated

The compiled files in target/run/ show exactly what reached the database. For the merge model, dbt-duckdb produced:

MERGE INTO "shop"."main"."orders_merge" AS DBT_INTERNAL_DEST
USING "orders_merge__dbt_tmp..." AS DBT_INTERNAL_SOURCE
ON (DBT_INTERNAL_SOURCE.order_id = DBT_INTERNAL_DEST.order_id)
WHEN MATCHED THEN UPDATE BY NAME
WHEN NOT MATCHED THEN INSERT BY NAME

For delete+insert it produced two statements:

delete from "shop"."main"."orders_di"
where (order_id) in (select (order_id) from "orders_di__dbt_tmp...");

insert into "shop"."main"."orders_di" ("order_id", "status", "amount", "updated_at")
(select "order_id", "status", "amount", "updated_at" from "orders_di__dbt_tmp...");

Both reach the same end state here. The difference is cost and atomicity on your warehouse. A MERGE is one statement that the engine can plan as a single join. Delete+insert is two passes; on some engines it is cheaper for very large batches because a bulk delete plus a bulk insert avoids row-by-row update work. Read the compiled SQL for your adapter before you decide; it is the fastest way to learn what a strategy really costs.

Late data: the bug in max(updated_at)

The filter updated_at > max(updated_at) assumes rows arrive in timestamp order. Real sources do not behave like that. A mobile app syncs a day late, a CDC connector replays after an outage, or an upstream job backfills a partition.

To test it, I added order 5 with updated_at 2026-11-21 23:00, after the target already held a row stamped 2026-11-22 09:30. The next run selected nothing for order 5, because 23:00 on the 21st is not greater than 09:30 on the 22nd. The run reported success, and the table still had four orders. Nothing failed; the row was simply skipped, and it would stay skipped until a full refresh.

The common fix is a lookback window. Instead of starting from the maximum, start a fixed period before it and let the merge absorb the overlap:

{% if is_incremental() %}
where updated_at > (select max(updated_at) - interval 3 day from {{ this }})
{% endif %}

With that change the next run picked up order 5 and the table held five orders. Rows already loaded inside the window are matched on order_id and rewritten with identical values, so the overlap is harmless. This only works with a key-aware strategy. With append, a lookback window creates duplicates on every run.

How long should the window be? Measure it. Compute the lag between event time and load time for a month of data and choose a window that covers the 99.9th percentile, then add a scheduled full refresh (weekly or monthly) as a safety net for anything older.

What the window costs

Lookback is not free, because every run rereads the window. A worked example:

  • The source holds 2,000,000,000 rows and gains 5,000,000 a day.
  • A full rebuild scans 2,000,000,000 rows.
  • A one-day incremental run scans about 5,000,000 rows, 0.25% of the full scan, if the source is partitioned or clustered on updated_at so the filter can prune.
  • A three-day lookback rescans about 15,000,000 to 20,000,000 rows (the window plus today), still about 1% of a full rebuild.

The pruning condition matters more than the window size. If the source is not organised by updated_at, the filter cannot skip files, and the "incremental" run still scans the whole source. The Parquet internals article explains how min and max statistics make that skipping possible.

Microbatch: incremental runs as a series of time batches

The microbatch strategy, added in dbt Core 1.9, changes the model of incremental processing. Instead of you writing an is_incremental() filter, you declare a time column and a batch size, and dbt runs the model once per time slice.

-- models/daily_events.sql
{{ config(
    materialized='incremental',
    incremental_strategy='microbatch',
    event_time='event_ts',
    batch_size='day',
    begin='2026-11-18',
    lookback=1
) }}

select event_id, user_id, event_ts
from {{ ref('raw_events') }}

The upstream model also declares event_time='event_ts' in its config. That lets dbt filter the ref() automatically for each batch. There is no is_incremental() block at all.

The four settings mean:

Table 4. Microbatch: incremental runs as a series of time batches
Setting Meaning
event_time The column that places each row in time
batch_size hour, day, month or year (the four values in dbt Core's BatchSize type)
begin The earliest time to build on a first run or full refresh
lookback How many batches before the current one to reprocess on a normal run

What one batch looks like

The first run built five daily batches, 18 to 22 November. Each batch compiled to a filtered read of the upstream model:

select event_id, user_id, event_ts
from (select * from "shop"."main"."raw_events"
      where event_ts >= '2026-11-22 00:00:00+00:00'
        and event_ts <  '2026-11-23 00:00:00+00:00')

and was applied with a delete and insert over the same half-open range:

delete from "shop"."main"."daily_events"
where event_ts >= '2026-11-22 00:00:00+00:00'
  and event_ts <  '2026-11-23 00:00:00+00:00';

insert into "shop"."main"."daily_events" ("event_id", "user_id", "event_ts")
select "event_id", "user_id", "event_ts"
from "daily_events__dbt_tmp_..."
where event_ts >= '2026-11-22 00:00:00+00:00'
  and event_ts <  '2026-11-23 00:00:00+00:00';

The half-open range (>= start, < end) matters. Every row lands in exactly one batch, so batches never overlap and never leave gaps.

A normal run on 23 November, with lookback=1, processed two batches: 22 November (the lookback) and 23 November (the current day). A row for the 22nd that arrived late is therefore picked up automatically on the next day's run.

Backfills become a command, not a code change

To reprocess a range, pass explicit bounds:

dbt run -s daily_events --event-time-start 2026-11-20 --event-time-end 2026-11-21

I appended a late event for 20 November at 23:30 and ran that command. dbt ran exactly one batch, for the 20th, and the day's count went from three rows to four. The other days were untouched and nothing was duplicated, because the batch first deletes its own time range. That property, replaying a slice gives the same result as running it once, is idempotency, and it is what makes backfills safe.

Each batch is its own unit of work. If one batch fails, the others still commit, and dbt retry reruns only the failed batches; dbt Core's retry task contains explicit handling for previously failed microbatch batches. Batches can also run in parallel where the adapter allows it, controlled by the optional concurrent_batches config.

Choosing a strategy

Table 5. Choosing a strategy
Situation Recommended approach Why
Append-only events, no updates, no late data append with a strict filter Cheapest; no key lookups
Entities that change (orders, accounts) merge with unique_key and a lookback window Upserts by key; the window absorbs late rows
Very large key sets where MERGE is slow delete+insert Two bulk statements can beat a row-level merge
Date-partitioned tables on BigQuery or Spark insert_overwrite Replaces whole partitions, no key join
Time-series facts that need regular backfills microbatch Built-in batching, lookback, retries and range backfills
Small tables (under a few million rows) Plain table Simplicity beats savings

Two rules hold across all of them. First, incremental logic must be idempotent: running the same window twice must produce the same table. Second, every incremental model needs a way back to truth. That is dbt run --full-refresh for the model, which drops and rebuilds it, or a microbatch backfill from begin.

What it means in practice

Incremental models trade simplicity for cost. The saving is real: in the worked example a lookback run reads about 1% of what a full rebuild reads. The risk is equally real: a filter that drops late rows does not error, it just produces a table that is slightly wrong forever.

Microbatch removes most of the hand-written risk for time-series data. You no longer write max() filters, backfills are a CLI flag, and failures are isolated per batch. It is not a fit for entity tables where a row's identity is a key rather than a time, and in dbt-duckdb it explicitly rejects unique_key, because each batch replaces a time range rather than upserting keys. If one order can appear in several days of source data, a microbatch model keyed on event time will keep several rows for it, which may or may not be what you want.

For orchestration, incremental models change what a "rerun" means. An orchestrator such as Apache Airflow or Dagster that retries a failed nightly job must be able to pass the same time window again, or the retry will process a different slice than the failed run. Microbatch with explicit --event-time-start and --event-time-end gives you that handle. Upstream, sources fed by change data capture are the classic case for merge with a lookback, because CDC replays are exactly the late, out-of-order updates the window exists to catch.

What to do now

  1. Inventory your incremental models. List every model with materialized='incremental' and note its strategy, its filter and whether it has a unique_key.
  2. Find append models that see updates. Run a uniqueness check on the natural key of each append model; any duplicates mean the strategy is wrong for that table.
  3. Measure arrival lag. For each source, compute the difference between event time and load time and take the 99.9th percentile. Use it to size lookback windows.
  4. Add lookback to max-based filters. Replace > max(updated_at) with > max(updated_at) - interval N day on merge and delete+insert models.
  5. Read the compiled SQL. Open target/run/ after a run and check the statement your adapter really issues, then look at its query profile.
  6. Check pruning. Confirm the source is partitioned or clustered on the filter column so incremental runs skip old files.
  7. Move time-series facts to microbatch. Start with one large fact table, set begin, batch_size and lookback, and test a one-day backfill.
  8. Schedule a full refresh. Pick a quiet window, weekly or monthly, to rebuild incremental models from scratch and compare row counts with the incremental version.
  9. Add tests after each run. Run unique and not_null tests on keys with dbt build so a broken increment fails the job instead of shipping.

Risks and open questions

A successful run can still be wrong. Skipped late rows do not produce errors. Only tests, reconciliations or full-refresh comparisons reveal them.

Schema changes need an explicit policy. The on_schema_change config accepts ignore (the default), fail, append_new_columns and sync_all_columns. With ignore, a new source column is silently left out of the incremental table until the next full refresh.

Adapter behaviour differs. The same strategy name can compile to different SQL on different warehouses, and support for merge, insert_overwrite and microbatch varies by adapter and version. dbt-duckdb, for example, enables merge and microbatch only on DuckDB 1.4 or newer.

Time zones shift batch boundaries. Microbatch ranges in the compiled SQL are UTC timestamps. If event_ts is stored in local time, a "day" batch will not line up with a local calendar day.

Full refreshes of huge tables are expensive. A safety-net rebuild of a multi-billion-row table can cost more than months of incremental runs; plan it like a backfill, in slices.

Watch next: how microbatch support evolves across adapters and across dbt's engines, how orchestrators expose batch-level status and retries, and whether teams standardise on event-time batching for most large facts.

Frequently asked questions

What does is_incremental() check?

It returns true when the target relation already exists as a table and the run is not a full refresh. On the first run, or with --full-refresh, it returns false, so the whole query runs without the incremental filter. Code inside the block is therefore only used on later runs.

Do I need a unique_key?

For append, no. For merge and delete+insert, yes, because the key is how dbt matches incoming rows to existing ones. Without a key those strategies cannot update rows, and you can end up with duplicates.

How is microbatch different from insert_overwrite?

Both replace a slice of the table rather than matching keys. Insert_overwrite replaces whole physical partitions touched by the batch, while microbatch replaces time ranges defined by event_time and batch_size, and runs one query per batch with built-in lookback, retries and range backfills.

How do I backfill a microbatch model?

Run it with --event-time-start and --event-time-end. dbt runs one batch per period in that range, deletes each range in the target and reinserts it, so rerunning a range does not create duplicates. Days outside the range are untouched.

When should a model stay a plain table?

When the full rebuild is cheap enough, typically small or medium tables where the run finishes in seconds. A table rebuild is always correct and has no filter to get wrong, so only move to incremental when cost or runtime makes it worth the added risk.

Summary

dbt incremental models read only new or changed rows and fold them into an existing table, using append, delete+insert, merge, insert_overwrite or microbatch. Running each strategy on dbt Core 1.12.7 with DuckDB shows the trade-offs clearly: append duplicates updated rows, merge and delete+insert upsert by key, and a naive max(updated_at) filter silently skips late data until you add a lookback window. Microbatch moves the time logic into dbt itself, running one idempotent delete-and-insert per time batch, which makes lookback, retries and backfills routine. Pick the strategy that matches how your data changes, keep every increment idempotent, and keep a full refresh as the path back to truth.

Sources

Cite this article

Kelahmet, Ö. C. (2026, November 23). dbt incremental models explained: merge, delete+insert, microbatch and safe backfills. Özer Cem KELAHMET. https://www.ozercemkelahmet.com/articles/dbt-incremental-models-microbatch-backfills

BibTeX
@online{kelahmet2026incremental,
  author = {Kelahmet, {\"O}zer Cem},
  title  = {{dbt incremental models explained: merge, delete+insert, microbatch and safe backfills}},
  year   = {2026},
  month  = {nov},
  url    = {https://www.ozercemkelahmet.com/articles/dbt-incremental-models-microbatch-backfills}
}
Version historyfirst version
  1. Published

Factual corrections are listed here with what changed. Wording and formatting edits are not listed.

Last updated Nov 23, 2026
Type to search.
    ↑↓ navigate↵ open