A Lakeflow Jobs job gets built to bring data in for analytics or ML. It works fine in testing and passes review. Then it goes to production. The first month's Databricks compute cost comes in well above what anyone estimated.
If you spend time on Databricks communities, you've seen some version of this story. The causes people name are almost always the same four:
- Full reloads where CDC should be
- No plan for schema evolution
- Jobs that run far more often than the data changes
- Clusters sized for the worst day of the year
What This Post Covers and What Ran Where
This post covers a dbt project that a Lakeflow Jobs job runs on Databricks. Here, pipeline means that dbt project. It does not mean Lakeflow Declarative Pipelines. Most posts on Databricks compute cost stop at the list above. I wanted to know how many of these causes you can catch before the job ships.
Here is what ran where:
- The PR review demo ran locally on a DuckDB copy of dbt Labs'
jaffle_shopsample project. Nothing in it ran on Databricks. - The review step needs no warehouse connection, though
dbt compilemay. - The cost queries read Databricks system tables. You run them in your own workspace.
Two of the four causes leave a trace in the code. A PR review catches the first one and part of the second. The other two show up only in usage data.
Databricks Compute Cost Is Data per Run Times Runs Times Compute Size
A scheduled job's Databricks compute cost is three factors multiplied together. The first factor is the data each run processes. The second is how often it runs. The third is the size of the compute it runs on.
A test run measures only the first factor, once, on a sample. That is why it tells you so little about the bill. Databricks bills DBUs per second of use. Classic clusters bill while they run, whether busy or idle. So anything that adds runs or stretches a run's duration shows up directly on the invoice.
Each of the four causes inflates at least one of those factors of Databricks compute cost. Cause 2 inflates two. The diagram below maps each cause to the factors it inflates and to the setting that usually causes it.
The four causes, the factor each one inflates, and the settings that usually produce them.
Teams make the first two decisions in files that a pull request touches. They make the last two in a job scheduler and a cluster policy. Both are often set in the UI and never committed. None of the four is a Databricks defect. They are design decisions, and you can review a decision made in code like any other code.
Job Spend Lands in Three Billing Buckets
A Lakeflow Jobs run with a dbt task bills to up to three places. The dbt CLI runs on job compute. Databricks recommends serverless compute for jobs or a single-node classic cluster for it. The SQL that dbt generates runs on a SQL warehouse that you pick in the task. The task lists serverless and pro warehouses.
Where one dbt job's spend lands, and the billing_origin_product value for each place.
This split matters for every query below. Job compute shows up as JOBS in system.billing.usage. Warehouse spend shows up as SQL. A query that reads only JOBS misses the warehouse part of your Databricks compute cost. Start with one query that shows how many DBUs each billing product used over the last 30 days:
SELECT billing_origin_product,
ROUND(SUM(usage_quantity), 1) AS dbus_30d
FROM system.billing.usage
WHERE usage_unit = 'DBU'
AND usage_date >= CURRENT_DATE() - INTERVAL 30 DAYS
GROUP BY billing_origin_product
ORDER BY dbus_30d DESC;
If SQL is large next to JOBS, your dbt spend sits on a warehouse. The queries later in this post cover both buckets.
Full Reloads Pay for Every Row on Every Run
Let's start with the most common one. A full reload reprocesses every row on every run. That includes rows that haven't changed since yesterday. So the cost of each run tracks the size of the table instead of the size of the change. Suppose a fact table holds a few years of orders and gains a day's worth each night. A full reload pays for all those years every single night.
A full reload reads the whole table every night. An incremental model reads only the new day.
The quickest place to check is your dbt_project.yml. In jaffle_shop, every model outside staging/ is built as a table:
models:
jaffle_shop:
+materialized: table
staging:
+materialized: view
For a sample project with a few hundred rows, that's fine. In production, the same two lines rebuild every mart from scratch on every run. On Databricks, each rebuild runs as SQL on the job's warehouse, so it bills to the SQL bucket. Nobody chose that for any specific model.
A dbt Incremental Model Without is_incremental() Still Reads Everything
The subtler version shows up after someone has already tried to fix it. Someone switches a model to a dbt incremental model with materialized='incremental'. The PR title says "make orders incremental," and it looks done.
But dbt only filters rows inside an {% if is_incremental() %} block. That macro returns true only when all three of these hold:
- The model already exists as a table.
- The run isn't a
--full-refresh. - The model is set to incremental.
Without the block, every run still selects the entire source and then merges it into the target. You end up paying for a full reload plus a merge.
You can check for this by hand. The following command lists incremental models that never call is_incremental():
grep -rlE --null "materialized *= *['\"]incremental['\"]" models | xargs -0 grep -L "is_incremental()"
On my test branch, it printed models/orders.sql. After I added the filter, it printed nothing. The command has two blind spots. It only finds configs set inside a model's config() block, so an incremental materialization set in YAML slips past it. And a model that mentions is_incremental() only in a comment counts as guarded.
When Incremental or CDC Costs More Than a Full Reload
Before you convert everything, there are two cases where the fix can cost more than the problem.
The first is the merge itself. dbt-databricks uses the merge strategy by default. With a unique_key set, a merge has to match every incoming row against the target. Without a partition or cluster key the merge can prune by, each incremental run can still read most of the target table. One thread on the dbt Community Forum reports an incremental run scanning more data than a full rebuild. The replies assume BigQuery. On Databricks, open the query profile to see how much of the target a merge reads.
The second is Databricks CDC ingestion. Lakeflow Connect's database connectors capture changes through an ingestion gateway. The gateway runs on classic compute, continuously. That lets it read change logs before the source truncates them. Take a small database that changes a few hundred rows a day. That means a cluster running around the clock for very little work. Mariusz Kujawski works through the numbers.
So the rule I use is this: a dbt incremental model or Databricks CDC pays off when three things hold. The table is large. The daily change is a small fraction of it. The target is laid out so the merge can prune. For small dimension tables and quiet sources, a scheduled full reload is often the cheaper and simpler choice. The decision tree below walks through the same three questions in order.
When converting a model to incremental pays off, and when a full reload is still the better choice.
Schema Changes Cause Retries, Silent Drops, and Full Rebuilds
The second cause is harder to spot because it looks like a reliability problem. Someone may add, rename, or retype an upstream column. An incremental model can then react in two ways, and both cost compute. It can fail. A failing job that retries pays for the partial work every time. Or it can ignore the change until someone downstream notices and asks for a rebuild.
dbt controls this with the on_schema_change config on incremental models. The table below shows the four options. The part that matters for your bill is that none of them backfill old rows. dbt's docs recommend a manual update or a --full-refresh to fill them in. So even a well-configured model can still owe you one full rebuild per upstream change.
| Option | What dbt does | What it costs you |
|---|---|---|
ignore (the default) | Never adds the new column | The run succeeds and the new column is dropped without a warning |
append_new_columns | Adds new columns and keeps columns that are missing from the new data | Old rows stay empty until you backfill them |
sync_all_columns | Adds new columns and removes missing ones, including data type changes | Old rows stay empty until you backfill them |
fail | Stops the run when the source and target schemas diverge | The run fails, and each retry bills compute |
On Databricks there's one more caveat. dbt-databricks 1.11 and up requires Databricks Runtime 12.2 LTS or later for every incremental model. The reason is that it fixes column-order bugs under sync_all_columns.
Most discussions I've read treat schema drift as a correctness problem. My conclusion is that it's a cost problem too. The fix is almost always a full reprocess, and Databricks bills the failed runs before it as well. The query below lists repaired or retried runs. A failed run nobody repaired will not appear. To see the retries you're already paying for, the jobs system table docs include this query:
WITH repaired_runs AS (
SELECT workspace_id, job_id, run_id, COUNT(*) - 1 AS retries_count
FROM system.lakeflow.job_run_timeline
WHERE result_state IS NOT NULL
GROUP BY ALL
HAVING retries_count > 0
)
SELECT * FROM repaired_runs
ORDER BY retries_count DESC
LIMIT 10;
Which option should you pick? I'd use fail plus an alert for models that consumers depend on. It stops the run before a shape change spreads. Set max_retries to 0 on that task. A schema failure repeats on every retry. Each retry also bills compute. append_new_columns is fine for wide, append-mostly tables where NULL in old rows is acceptable. Either way, set it per model, because a model left at ignore drops new columns without telling anyone.
A PR Review Catches Full Reloads and Part of Schema Changes
Now that we know what the first two causes look like in code, let's see how much of this a tool can catch before merge. I used Altimate Code, the CLI I work on. I chose it because it has a deterministic dbt review. That review runs locally and needs no warehouse connection for the review itself, though dbt compile may. Everything below was run with altimate-code v0.9.4 and dbt-core 1.12.5 against a copy of jaffle_shop_duckdb.
Can Static Analysis Catch Expensive SQL Before It Runs?
It can, but only partly. A SQL linter reads query text, so it catches patterns like SELECT *. But the materialization config decides a full reload. A linter never reads that config. Run against the raw model file, it found nothing, even though the file contains select * from {{ ref('raw_orders') }}:
$ altimate check models/staging/stg_orders.sql --checks lint
Found 1 SQL file(s) to check with [lint]
Checked 1 file(s) with [lint]
0 finding(s): 0 error(s), 0 warning(s), 0 info
PASS
Completed in 6ms
The Jinja hides the query from the linter. Pointed at the output of dbt compile instead, the same check fires two warnings:
$ altimate check target/compiled/jaffle_shop/models/staging/stg_orders.sql --checks lint
WARNING target/compiled/jaffle_shop/models/staging/stg_orders.sql:2 [select_star]: SELECT * is used — consider listing columns explicitly
WARNING target/compiled/jaffle_shop/models/staging/stg_orders.sql [select-without-limit]: SELECT without LIMIT may return unbounded results
2 finding(s): 0 error(s), 2 warning(s), 0 info
Completed in 7ms
Neither warning says anything about reloads or schema changes. So a file-level lint pass is the wrong layer for these two causes. One gotcha I hit: a single altimate check call on two files failed the second one with No native handler for altimate_core.lint. That happened on this version, so run files one at a time. Version 0.9.6 and later check both files in one call without the error.
Review the Change Instead of the File
The altimate review command works on a git diff plus the compiled dbt project, which is where the materialization is actually set. I made a branch with the change a PR would describe as "make orders incremental," adding this line to the top of models/orders.sql with no is_incremental() filter:
{{ config(materialized='incremental', unique_key='order_id') }}
Then I compiled the project and ran the review against main. The --no-ai flag turns off the advisory LLM reviewer. So everything that follows came from the deterministic rules, with no model calls and no warehouse:
dbt compile
altimate review --no-ai --base main --head HEAD
Here is the full output from that run, with the finding that matters highlighted:
altimate review --no-ai on the branch that makes orders incremental without a filter.
The run took about three seconds. It raised one warning, orders: refactor could not be proven equivalent, plus four suggestions. The incremental no guard finding is cause number one, caught at the moment someone believes they've fixed it. The unique key note tells you to plan the full refresh this change will need.
Next, I added the filter the way the dbt docs show it:
select * from final
{% if is_incremental() %}
where order_date > (select max(order_date) from {{ this }})
{% endif %}
The incremental no guard finding went away. A new suggestion took its place: max() subquery boundary can defeat partition pruning. Its message names where that happens. On BigQuery and on Snowflake external tables, the optimizer can't prune partitions from a dynamic subquery. So each run scans everything. The rule doesn't make that claim for Delta tables. So on Databricks I'd read it as a prompt to open the query profile and check how many files the incremental run actually read. The strict > in that filter also skips rows that arrive late with a date at or before the current maximum. So pick a filter column that matches how your source changes.
I have two practical notes from running this. After switching branches, the review warned that the manifest "appears stale" until I re-ran dbt compile. So compile before every review. And both runs returned a COMMENT verdict. In a GitHub Action with --mode gate, the findings reach the reviewer without blocking the merge. That mode fails only on REQUEST_CHANGES.
What the Review Doesn't Catch
Schema evolution is only half visible. On a third branch, I renamed status to order_status in stg_orders and updated the downstream model. The diagram below shows what the review saw.
The test branch: a rename in stg_orders reaches the incremental orders model and customers.
- It flagged
high downstream fan-out (2 models)underlineage_breakage. - It counted 2 downstream models and 15 tests.
- It asked me to verify that no columns were removed or renamed.
- It didn't say anything about
on_schema_changeon the incremental model downstream.
The review tells you where a schema change will land. The plan for handling it is still yours to make.
The output also confused me in one place. Every run printed a banner saying no dbt manifest was available, even with --manifest target/manifest.json passed explicitly, while the footer printed a manifest hash. I'd treat that banner with some suspicion for now.
Schedules and Cluster Sizes Only Show up in Usage Data
A review reads one diff once, while a schedule or a sizing problem only shows up across many runs. For the last two causes you need usage data, and Databricks system tables have it. The queries below cover job compute and SQL warehouses.
Schedules That Run More Often Than the Data Needs
This one usually gets described as serverless SQL being expensive, and I don't think that's the right way to look at it. Serverless is cheap for work that runs rarely and expensive for work that runs constantly. What costs money is a schedule set for near real-time freshness. People reading the table would often be fine with an update every few hours. Every run pays for compute whether or not new data arrived.
The following query covers job compute. It compares how often each job ran over the last 30 days with the DBUs it used, from system.lakeflow.job_run_timeline and system.billing.usage. A job running dozens of times a day against a source that updates twice a day is the pattern to look for:
WITH runs AS (
SELECT workspace_id, job_id, COUNT(DISTINCT run_id) AS runs_30d
FROM system.lakeflow.job_run_timeline
WHERE period_start_time > CURRENT_TIMESTAMP() - INTERVAL 30 DAYS
GROUP BY ALL
),
usage AS (
SELECT workspace_id, usage_metadata.job_id AS job_id, SUM(usage_quantity) AS dbus_30d
FROM system.billing.usage
WHERE billing_origin_product = 'JOBS'
AND usage_date >= CURRENT_DATE() - INTERVAL 30 DAYS
GROUP BY ALL
)
SELECT r.job_id,
r.runs_30d,
ROUND(r.runs_30d / 30, 1) AS runs_per_day,
ROUND(u.dbus_30d, 1) AS dbus_30d,
ROUND(u.dbus_30d / r.runs_30d, 2) AS dbus_per_run
FROM runs r
JOIN usage u USING (workspace_id, job_id)
ORDER BY u.dbus_30d DESC
LIMIT 20;
One caveat from the docs: Databricks populates usage_metadata.job_id only for jobs on job compute or serverless compute. So a job running on an all-purpose cluster won't show up here, and neither will a job with no billable usage. That's a cost problem of its own, which our six-lever post covers. For the pricing side of serverless versus classic, see Databricks Serverless vs Classic Compute.
SQL Warehouse Spend Needs Its Own Queries
The query above reads JOBS usage only. Databricks' job cost docs say jobs that run on SQL warehouses are not billed as jobs. If your dbt task sends its SQL to a warehouse, most of that spend sits under SQL instead. This query lists DBUs per SQL warehouse for the last 30 days:
WITH wh AS (
SELECT warehouse_id, warehouse_name, warehouse_type
FROM system.compute.warehouses
QUALIFY ROW_NUMBER() OVER (PARTITION BY warehouse_id ORDER BY change_time DESC) = 1
)
SELECT u.usage_metadata.warehouse_id AS warehouse_id,
wh.warehouse_name,
wh.warehouse_type,
ROUND(SUM(u.usage_quantity), 1) AS dbus_30d
FROM system.billing.usage u
LEFT JOIN wh ON wh.warehouse_id = u.usage_metadata.warehouse_id
WHERE u.billing_origin_product = 'SQL'
AND u.usage_metadata.warehouse_id IS NOT NULL
AND u.usage_unit = 'DBU'
AND u.usage_date >= CURRENT_DATE() - INTERVAL 30 DAYS
GROUP BY ALL
ORDER BY dbus_30d DESC;
Billing data includes corrections, so sum the rows instead of counting them. To turn DBUs into dollars, join to system.billing.list_prices. The docs show the join.
Statements that run inside a job task carry a job_info struct in query history. This query counts them per job and warehouse:
SELECT query_source.job_info.job_id AS job_id,
compute.warehouse_id AS warehouse_id,
COUNT(*) AS statements,
SUM(total_task_duration_ms) AS task_ms,
COUNT(DISTINCT query_source.job_info.job_task_run_id) AS task_runs
FROM system.query.history
WHERE query_source.job_info.job_id IS NOT NULL
AND compute.type = 'WAREHOUSE'
AND start_time >= CURRENT_TIMESTAMP() - INTERVAL 30 DAYS
GROUP BY ALL
ORDER BY task_ms DESC;
The Databricks docs don't name dbt tasks in that struct, so check that your dbt statements show a job_id. If they don't, dbt adds a JSON comment that starts with /* {"app": "dbt" to each statement. You can filter statement_text on it. Only account admins and members of databricks_pii_access see statement text.
Warehouse DBUs bill per warehouse, not per job. A shared warehouse mixes every job and user, so a job's cost there is an estimate. One honest proxy is a job's share of total_task_duration_ms on that warehouse, multiplied by the warehouse DBUs. Idle time and auto-stop time get spread the same way. A dedicated warehouse per job makes the DBUs equal the job's cost.
Clusters Sized for the Worst Day
Teams usually pick a cluster size from a small, medium, or large template, just in case. They can't know what a job needs until it has run. Few teams go back to check afterwards.
system.compute.node_timeline records CPU and memory use per node. So you can see how much of each cluster a job actually used over the last two weeks. Each run on job compute gets its own cluster_id. The driver node sits near idle on most runs, so the query keeps worker nodes only. That makes each row one cluster run. The query does not name the job. It also covers classic compute only:
SELECT cluster_id,
ROUND(AVG(cpu_user_percent + cpu_system_percent), 1) AS avg_cpu_pct,
ROUND(MAX(cpu_user_percent + cpu_system_percent), 1) AS peak_cpu_pct,
ROUND(AVG(mem_used_percent), 1) AS avg_mem_pct
FROM system.compute.node_timeline
WHERE start_time >= CURRENT_TIMESTAMP() - INTERVAL 14 DAYS
AND driver = false
GROUP BY ALL
ORDER BY avg_cpu_pct ASC
LIMIT 20;
As a rule of thumb, look at fleets that average 15% CPU with a peak under 50% over two weeks. They are good candidates for fewer workers or a smaller instance. Check avg_mem_pct first to confirm that a smaller instance has enough memory. Keep one distinction in mind, though. A pipeline that starts a separate cluster for every task pays startup time on each one. The fix there is sharing one job cluster across the tasks. For why right-sizing and autoscaling don't add up the way you'd expect, see Right-sizing a Databricks cluster isn't the same fix as autoscaling.
For SQL warehouses, read the settings instead. This query lists each warehouse's size, cluster range and auto-stop time:
WITH latest AS (
SELECT *,
ROW_NUMBER() OVER (PARTITION BY workspace_id, warehouse_id ORDER BY change_time DESC) AS rn
FROM system.compute.warehouses
QUALIFY rn = 1
)
SELECT warehouse_name, warehouse_type, warehouse_size,
min_clusters, max_clusters, auto_stop_minutes
FROM latest
WHERE delete_time IS NULL
ORDER BY warehouse_name;
A large warehouse with a long auto_stop_minutes for a job that runs once a night is a candidate to shrink. Treat it as a prompt to look closer, as you would with the cluster numbers.
Altimate Covers the PR and the Usage Data
The two halves of this post map to two Altimate tools:
- Altimate Code reviews the dbt change in the PR. It covers cause 1 and part of cause 2, as the review demo above shows.
- Altimate for Databricks reads your system tables and splits Databricks spend by team, then by workspace, SKU, product, and user. It shows job compute and SQL warehouse spend side by side, so a JOBS-only query no longer hides the warehouse.
Two gaps remain. Shared all-purpose compute and untagged serverless usage still lack per-job attribution. Altimate reports how big those two gaps are. It does not close them. Our chargeback post covers both gaps. Our cluster cost post covers the cloud VM cost that sits outside the DBU bill.
Two Causes Belong in the PR and Two in a Monthly Check
The timeline below puts each check at the point in a job's life where it can first catch its cause.
Two checks belong in the pull request, and the other two need a few weeks of production runs.
The table collects the same checks into one list for your next job review.
| Cause | Visible in a PR? | What catches it | When to look |
|---|---|---|---|
| 1. Full reloads instead of CDC | Yes | the +materialized config, an is_incremental() grep, or a review that flags incremental no guard | every PR that adds or changes a model |
| 2. No schema-evolution plan | In part | on_schema_change set per model, and a lineage check that shows the blast radius | every PR that touches a staging model or a source |
| 3. Schedules more frequent than the data needs | Often not | run frequency against DBUs, for both JOBS and SQL usage | monthly, and whenever a new schedule ships |
| 4. Clusters sized for peak load | Often not | CPU and memory in system.compute.node_timeline, and warehouse settings in system.compute.warehouses | a few weeks after a job goes to production |
Put Two Checks in Your PR Template and Two on a Calendar
Put full reloads and schema changes in your PR checklist. That can be a grep, a reviewer who knows to look for is_incremental() and on_schema_change, or a review tool that flags them. Put schedules and cluster sizes on a calendar. Look monthly at run frequency and node CPU and memory use. Look once more a few weeks after any new pipeline goes to production. To try the review part on your own project, the dbt PR Review docs walk through the setup.
Frequently Asked Questions
What Drives Databricks Compute Cost for a Scheduled Job?
A scheduled job's Databricks compute cost is three factors multiplied together. The first factor is the data each run processes. The second is how often it runs. The third is the size of the compute it runs on. A test run measures only the first factor, once, on a sample.
Where Does a dbt Job's Cost Show Up in System Tables?
A Lakeflow Jobs run with a dbt task bills to up to three places. The dbt CLI runs on job compute and bills as JOBS. The SQL that dbt generates runs on a SQL warehouse and bills as SQL. Any all-purpose cluster the job uses bills as ALL_PURPOSE.
Why Does a dbt Incremental Model Still Read Everything?
dbt only filters rows inside an {% if is_incremental() %} block. Without the block, every run still selects the entire source and then merges it into the target. You end up paying for a full reload plus a merge.
Which Databricks Compute Cost Causes Can a PR Review Catch?
A PR review can catch full reloads, such as an incremental model with no is_incremental() guard. It sees schema changes only in part. Schedules and cluster sizes are often set outside the repo, so they show up in usage data instead.
How Do You Find Over-Eager Schedules and Oversized Clusters?
Use Databricks system tables. Compare run frequency against DBUs with system.lakeflow.job_run_timeline and system.billing.usage. Check CPU and memory per node in system.compute.node_timeline, and warehouse settings in system.compute.warehouses, a few weeks after a job goes to production.
