
dbt (data build tool)
Build a dbt incremental model with a stable composite key and compare a late-event replay with a fresh build.
- Existing aggregate
- Subscription A has 150 units on November 14.
- Late event
- Rebuild the affected day to 170 units using all relevant events.
- Compare
- Replay and compare the result against a clean test build.
A subscription-day model feeds the renewal dashboard. A usage row arrives late and changes the total for an existing day. In dbt, a bounded lookback can recalculate that day, and the model’s unique key can replace the prior row.
Use an incremental key that reflects the published row
Configure the model as incremental and choose a supported adapter strategy that uses unique_key. For the example, the grain is one row per subscription and service date. Set both as the key and ensure neither is null. Recompute complete totals for the affected keys in the lookback window. An incremental model that sees only the newest event can replace the prior aggregate with a partial total.
Subscription A has 150 units on November 14. A late event adds 20. Recalculate the entire affected subscription-day to 170, then run the same input again. Configure data tests on the key components and a uniqueness check at the full composite grain. A dbt key setting specifies how incremental rows are matched. The data tests check whether your assumption is true.
Verify the replay and the full build
| Run | Expected result | Check |
|---|---|---|
| Incremental run includes November 14. | The existing subscription-day becomes 170 units. | Compare the complete underlying event set and destination total. |
| Replay identical input. | One row for that key, still 170 units. | Run the grain and null-key tests. |
| Rebuild the same sample in a test target. | The rebuilt model and incremental model agree for the example period. | Compare both by key and report differences before release. |
Document how to backfill records older than the normal lookback. The object and data model guide explains how to define the row before deciding what should be unique.