Bird
Raised Fist0
dbtdata~20 mins

Environment management (dev, staging, prod) in dbt - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Environment Mastery in dbt
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Purpose of Different Environments in dbt

Why do data teams use separate environments like dev, staging, and prod in dbt projects?

ATo allow multiple users to edit the same model simultaneously without conflicts
BTo run the same models multiple times for faster results
CTo isolate development work, test changes safely, and deploy stable models to production
DTo store different versions of data in separate databases permanently
Attempts:
2 left
💡 Hint

Think about how changes are tested before affecting real data.

❓ Predict Output
intermediate
1:30remaining
dbt Profile Target Output

Given this profiles.yml snippet, what is the active target when running dbt run --target staging?

my_project:
  target: dev
  outputs:
    dev:
      type: snowflake
      database: dev_db
    staging:
      type: snowflake
      database: staging_db
    prod:
      type: snowflake
      database: prod_db
AThe database used will be <code>staging_db</code>
BThe database used will be <code>dev_db</code>
CThe database used will be <code>prod_db</code>
Ddbt will raise an error because <code>target</code> is set to <code>dev</code> in the profile
Attempts:
2 left
💡 Hint

The --target flag overrides the default target in the profile.

❓ data_output
advanced
2:00remaining
Effect of Environment Variable in dbt Model

Consider this dbt model SQL snippet that uses an environment variable to filter data:

select * from raw.sales
where region = '{{ env_var('REGION', 'all') }}'

If you run dbt run with REGION set to north, what will be the output?

AAll rows because default <code>all</code> is used
BRows where <code>region</code> equals <code>north</code>
CNo rows because <code>region</code> is filtered by a missing variable
DSyntax error due to incorrect use of <code>env_var</code>
Attempts:
2 left
💡 Hint

Check how env_var uses the environment variable if set.

🔧 Debug
advanced
2:00remaining
Debugging Environment-Specific Model Failures

A model runs fine in dev but fails in prod with a missing table error. What is the most likely cause?

AThe <code>prod</code> environment has incorrect Python dependencies
BThe model SQL syntax is invalid only in <code>prod</code>
CThe <code>dev</code> environment has a different dbt version causing the error
DThe <code>prod</code> environment is missing a required source table or schema
Attempts:
2 left
💡 Hint

Think about differences in data availability between environments.

🚀 Application
expert
2:30remaining
Configuring dbt for Multiple Environments

You want to configure dbt to use different schemas for dev, staging, and prod environments automatically. Which dbt_project.yml snippet correctly sets the schema based on the active target?

A
models:
  my_project:
    +schema: '{{ target.name }}_schema'
B
models:
  my_project:
    +schema: '{{ target.schema }}'
C
models:
  my_project:
    +schema: 'prod_schema' if target.name == 'prod' else 'dev_schema'
D
models:
  my_project:
    +schema: 'schema_{{ env_var('DB_ENV') }}'
Attempts:
2 left
💡 Hint

Use the target variable to dynamically set schema names.

Practice

(1/5)
1. What is the main purpose of having separate environments like dev, staging, and prod in dbt?
easy
A. To run multiple dbt projects at the same time
B. To safely develop and test changes before applying them to production
C. To store different versions of dbt itself
D. To backup data automatically

Solution

  1. Step 1: Understand environment roles

    Development (dev) is for building and testing changes. Staging is for final testing. Production (prod) is the live environment.
  2. Step 2: Purpose of separation

    This separation prevents untested changes from affecting live data and users.
  3. Final Answer:

    To safely develop and test changes before applying them to production -> Option B
  4. Quick Check:

    Environment separation = safe testing before production [OK]
Hint: Think: Why not test directly in production? [OK]
Common Mistakes:
  • Confusing environment roles
  • Thinking environments store dbt versions
  • Assuming environments backup data automatically
2. Which command correctly runs dbt models in the staging environment?
easy
A. dbt run --profile staging
B. dbt run --env staging
C. dbt run --target staging
D. dbt run --environment staging

Solution

  1. Step 1: Identify the correct flag for environment selection

    dbt uses the --target flag to specify which environment to run against.
  2. Step 2: Match the flag with the environment name

    Using --target staging runs models in the staging environment.
  3. Final Answer:

    dbt run --target staging -> Option C
  4. Quick Check:

    Use --target to switch environments [OK]
Hint: Remember: --target selects environment in dbt commands [OK]
Common Mistakes:
  • Using --env or --environment instead of --target
  • Confusing --profile with environment selection
  • Omitting the flag and running default environment
3. Given the following profiles.yml snippet, what database will dbt connect to when running with --target prod?
my_project:
  outputs:
    dev:
      type: postgres
      host: dev-db.example.com
      dbname: dev_db
    prod:
      type: postgres
      host: prod-db.example.com
      dbname: prod_db
  target: dev
medium
A. prod_db on prod-db.example.com
B. dev_db on dev-db.example.com
C. dev_db on prod-db.example.com
D. prod_db on dev-db.example.com

Solution

  1. Step 1: Understand the --target flag effect

    Running with --target prod tells dbt to use the prod output configuration.
  2. Step 2: Identify prod output details

    The prod output connects to prod-db.example.com and database prod_db.
  3. Final Answer:

    prod_db on prod-db.example.com -> Option A
  4. Quick Check:

    --target prod uses prod output config [OK]
Hint: Match --target value to profiles.yml output key [OK]
Common Mistakes:
  • Ignoring --target and using default target
  • Mixing host and dbname from different environments
  • Assuming target in profiles.yml overrides command line
4. You run dbt run --target staging but get a connection error. The profiles.yml has a typo in the staging host key as hst instead of host. What is the best fix?
medium
A. Run dbt clean before running again
B. Change the command to dbt run --target hst
C. Remove the staging environment from profiles.yml
D. Correct the typo from hst to host in profiles.yml

Solution

  1. Step 1: Identify cause of connection error

    A typo in the key hst means dbt cannot find the host to connect to.
  2. Step 2: Fix the typo in profiles.yml

    Changing hst to host corrects the connection details.
  3. Final Answer:

    Correct the typo from hst to host in profiles.yml -> Option D
  4. Quick Check:

    Fix config typos to resolve connection errors [OK]
Hint: Check spelling of keys in profiles.yml for connection issues [OK]
Common Mistakes:
  • Changing command flags instead of fixing config
  • Deleting environment instead of fixing it
  • Running unrelated dbt commands
5. You want to test a new model in your dev environment without affecting staging or prod. Which approach is best to manage this safely?
hard
A. Create a separate dev target in profiles.yml and run with --target dev
B. Run the model directly in prod and rollback if needed
C. Delete the staging environment temporarily
D. Run all models in dev and prod simultaneously

Solution

  1. Step 1: Understand environment isolation

    Using a separate dev target isolates testing from staging and production.
  2. Step 2: Use --target dev to run safely

    Running with --target dev ensures changes only affect the dev environment.
  3. Final Answer:

    Create a separate dev target in profiles.yml and run with --target dev -> Option A
  4. Quick Check:

    Use dev target for safe isolated testing [OK]
Hint: Always test in dev environment using --target dev [OK]
Common Mistakes:
  • Testing directly in production
  • Removing staging environment
  • Running multiple environments at once
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard