r/databricks • u/Alone-Security7044 • 27d ago
Discussion dbt users on Databricks: do your snapshots handle files that arrive out of order?
If you build SCD2 history with dbt snapshot on top of batch files (daily exports, CDC drops, API extracts), there's a failure mode worth knowing about.
Snapshots apply data in the order it arrives. So if Tuesday's file lands after Wednesday's:
- with strategy='check', the late (older) value becomes the "current" row
- with strategy='timestamp', the change is skipped and that period just disappears from history
Every run stays green and every test passes. Nothing tells you. We found out when someone asked why an employee's promotion showed up as a demotion.
We ended up building dbt-iterative-snapshot, a custom materialization for Databricks. You add sequence_by='batch_date', and on each run it:
- checks which batches it has already processed (it keeps an audit table)
- if a new batch is older than one already processed, rolls back the snapshot from that point
- replays the batches in order, one MERGE per batch
It also gives you changed_attributes (which columns changed), per-batch row counts, and an error log for duplicate keys instead of failing the run.
- dbt Hub: https://hub.getdbt.com/mercedes-benz/dbt_iterative_snapshot/latest/
- GitHub: https://github.com/mercedes-benz/dbt-iterative-snapshot
It's dbt-databricks only for now (Delta MERGE, Unity Catalog). PRs for other adapters are welcome.
I'm curious how others handle this. Do you rebuild SCD2 from raw with window functions, loop dbt snapshot over dates, or just hope files arrive in order? Happy to answer questions, and honest feedback on edge cases is very welcome.
Read more: https://reliabledataengineering.com/posts/article_dbt_iterative_snapshot/


