By the end of this lesson, you’ll know how to:

  • Understand what snapshots are and why they matter

  • Track historical changes in e-commerce data (customers, orders, products, payments)

  • Configure and run snapshots using dbt (dbt snapshot)

  • Choose the right strategy (timestamp vs check)

  • Query both current and historical records

  • Apply best practices to keep snapshots reliable and efficient

What are Snapshos ?

In dbt, a snapshot is a way to capture and track changes to a table over time.
Instead of only seeing the latest values, snapshots store historical versions of records, making it possible to analyze how data has evolved (for example, customer status changes, product price updates, or order state transitions).

Example: 

The snapshot below shows how a customer’s status is tracked over time. At first, customer 101 was active. When the status changed to inactive on Aug 20, dbt closed the old record and created a new one—keeping both the history and the current state.

-- Initial record
customer_id   status    updated_at     dbt_valid_from   dbt_valid_to
101           active    2023-06-15     2023-06-15       null

-- After status change
101           active    2023-06-15     2023-06-15       2023-08-20
101           inactive  2023-08-20     2023-08-20       null

Snapshot Strategies

dbt supports two main strategies to detect changes:

  • Relies on an updated_at column

  • Best when the source reliably tracks update times

  • Compares specific column values for changes

  • Useful when no timestamp is available

Steps to creaate Snapshot

Before creating snapshots, ensure you have:

  • A schema in your warehouse for snapshots (e.g., snapshots/)

  • A reliable updated_at column in your source data

  • A snapshots/ directory in your dbt project

How Snapshots Work

When you run dbt snapshot:

  1. dbt creates the snapshot table if it doesn’t exist

  2. For existing tables, it compares rows against the last snapshot

  3. If a change is detected:

    • The previous record is closed (dbt_valid_to is set)

    • A new record is added as current (dbt_valid_to = null)

  4. New records are inserted

Metadata Columns (added automatically)

  • dbt_valid_from → When this version became valid

  • dbt_valid_to → When it stopped being valid (null if current)

  • dbt_updated_at → When snapshot ran

  • dbt_scd_id → Unique version identifier