dbt - Analytics Engineering Certification Study Guide

    7: Leveraging the dbt state

    This chapter walks through the state surface that closes the production workflow loop: the structure and contents of the `manifest.json` artifact, the `dbt retry` command and its restart semantics, and the composition of state and result selectors that powers slim CI and defer-to-prod. The treatment focuses on the diff algorithm dbt uses to decide which nodes are modified, the precise rules `dbt retry` follows when resuming a failed run, and the selector compositions that keep CI builds inside their budget without rebuilding the world.

    Learning Objectives

    By the end of this chapter, you will be able to:

    • Explain what the manifest.json artifact contains, when each part of the artifact is produced, and how the state comparison algorithm uses it to compute state:modified and its subselectors.
    • Run dbt retry against a failed run, predict which nodes will re-execute, and recognize the cases where retry is invalidated and a fresh dbt build is required.
    • Compose state:modified+, result:error+, result:fail+, and result:skipped+ selectors with the --defer and --state flags to build slim CI Jobs, slim retry workflows, and defer-to-prod developer environments.

    Executive Summary

    • The manifest.json artifact is dbt's pre-execution graph snapshot; the diff between a development manifest and a comparison manifest is the only input to the state:modified family of selectors. Every selector trick in slim CI starts there.
    • dbt retry consults run_results.json and resumes from the failed and skipped nodes of the immediately previous invocation in the same target/ directory. The retry contract is strict: change the project, change the manifest, and the retry is forfeit.
    • The slim CI pattern is a composition, not a single command. state:modified+ --defer --state path/to/prod-manifest rebuilds only what changed and references untouched upstream relations from the production schema. Replacing state:modified+ with result:error+ converts the same flag set into a targeted retry of a failed deploy.

    Assumptions

    • The terms manifest.json artifact, state:modified+ selector, defer, slim CI, dbt retry, and result:error+ selector are taken as defined in earlier chapters. This chapter goes deeper into the mechanics rather than reintroducing them.
    • All examples assume dbt 1.11 against a cloud warehouse (Snowflake, BigQuery, Databricks, Redshift, or Postgres). Adapter-specific behaviors are called out inline.
    • Project paths follow the convention analytics/ for the project root, target/ for the active build directory, and ci_state/ for a comparison manifest fetched from a production artifact store.

    Sections in this chapter

    1. Free
    2. Free with account
    3. Free with account
    4. Free with account