Articles · Data engineering · · 8 min read
Warehouse Cost Attribution in Snowflake and Fabric
Compute bills arrive as one number. Building a cost fact at run grain, choosing an allocation rule, and catching drift while the total stays flat.
By Matthieu de La Mettrie · Founder, Skopura
The invoice arrives as one number. Every question you actually care about — who should pay, what to fix first, whether last quarter’s tuning worked — depends on a reconstruction that nobody hands you. Platform owners end up building that reconstruction twice: once badly, in a spreadsheet, under pressure from finance; and once properly, as a modelled fact table that sits alongside everything else in the warehouse.
This is about the second build.
What question is cost attribution actually answering?
There are three, and conflating them is the first failure.
The first is allocation: which cost centre carries this spend. That question is political, it has a deadline, and it tolerates approximation. The second is optimisation: which workload has the worst ratio of compute consumed to value delivered. That question is engineering, it has no deadline, and approximation ruins it. The third is drift detection: has the cost of doing a fixed unit of work changed. That one is the reason to instrument at all, and it is the one most attribution projects never reach, because they stop once finance is satisfied.
A model built only for allocation will answer the other two badly. Allocation wants totals per team per month. Optimisation wants cost per run with enough metadata to join to the thing that ran. Drift wants a stable denominator — rows landed, models built, refreshes completed — held constant across periods. Build for the finest of the three and the coarser ones fall out as aggregations. Build for the coarsest and you will rebuild.
Why does the bill resist attribution in the first place?
Because the meter and the work are not the same shape. Whether the meter is a Snowflake virtual warehouse, a Databricks cluster, or a Fabric capacity, compute is billed against a resource that is shared, sometimes idle, and sometimes concurrent.
Concurrency is the hard part. When several jobs share a warehouse, wall-clock time attributed per query double-counts, and credit-seconds split evenly across concurrent queries punish the small ones. Idle time belongs to nobody in particular — it is the cost of keeping a resource warm so somebody else’s interactive query returns quickly. Auto-suspend thresholds, pool sizing and minimum billing increments all generate spend that no individual query caused.
The decomposition matters because each layer needs a different rule, and because the residual should stay visible. Forcing every cent into a team bucket produces a number that is defensible in a meeting and useless in a design review. Keep the residual as a line item and watch its size — a growing residual is itself a signal that tagging discipline is slipping.
What grain should the cost fact use?
One row per execution: query, job run, pipeline activity, dataset refresh. That is the only grain at which the platform’s own telemetry and your orchestration metadata can be joined without guessing.
From there the dimensions are the ones you already have, or should: domain, owning team, environment, workload class (batch transformation, serving, interactive, ML training), and the logical artefact — the dbt model, the notebook, the semantic model. Treat it like any other mart. Conform the dimensions to the ones used elsewhere so a cost figure can sit next to a volume figure without a translation step.
The join key is the problem. Platform query history gives you a session, a user, a warehouse and a duration. It does not give you “the nightly sales transformation”. You have to inject that, either through query tags and session parameters set by the orchestrator, or through comment headers that the engine preserves in its history views.
-- staging: one row per execution, enriched with orchestration context
with executions as (
select
query_id,
session_id,
warehouse_name,
start_time,
execution_time_ms,
credits_used_cloud_services,
-- tags injected by the orchestrator at session start
try_parse_json(query_tag) as run_context
from {{ source('platform', 'query_history') }}
where start_time >= {{ lookback_window() }}
),
attributed as (
select
e.query_id,
e.start_time::date as run_date,
e.warehouse_name,
coalesce(r.domain, 'unattributed') as domain,
coalesce(r.team, 'unattributed') as owning_team,
coalesce(r.workload, 'interactive') as workload_class,
r.artefact_name,
e.execution_time_ms
from executions e
left join {{ ref('dim_run_context') }} r
on r.run_id = e.run_context:run_id::string
)
select * from attributedThe allocation of warehouse-level credits down to the execution row is a separate step, and it should be an explicit, named rule — proportional to execution time within a billing interval, say — rather than something buried in a window function. Write the rule down. Someone will challenge it, and the right answer to the challenge is “here is the rule, here is what changes if we pick the other one”, not a rebuild.
How much compute isolation is worth buying?
Separating workloads onto their own warehouses, clusters or capacities is the brute-force path to attribution: if a team has its own meter, the meter is the answer. It also multiplies idle time, warm-up cost and reserved headroom, because each pool carries its own floor.
The useful split is usually by workload class rather than by team, because workload class is what drives sizing. Batch transformation wants a large pool for a short window. Interactive serving wants a small pool that stays warm. ML training wants something else again. Isolating those three gives you most of the attribution benefit and a sizing policy you can defend; isolating fourteen teams gives you fourteen idle floors and a tuning backlog.
What does drift look like when the total is flat?
This is the case the monthly spreadsheet cannot see. Volume grows, efficiency degrades, and the two cancel. The invoice looks stable, and then a data source doubles and the platform falls over a cliff that has been forming for months.
Drift detection needs a denominator. Cost per model build. Cost per million rows landed in bronze. Cost per semantic model refresh. Pick denominators that are stable in meaning even when the business grows, and track the ratio rather than the total. A transformation whose cost per row is climbing is telling you something — a join that lost its pruning, an incremental model quietly doing full refreshes because the merge predicate stopped matching, a table that needs maintenance.
The same instrumentation catches the opposite error: a team that halved its spend by halving its freshness. Cost per unit of work going down is not automatically a win, which is why the cost mart should sit next to the freshness and volume marts rather than in a finance-only corner.
Showback or chargeback?
| Showback | Chargeback | |
|---|---|---|
| What it asks of teams | Awareness and justification | Budget ownership and trade-offs |
| Tolerance for residual cost | High — residual can stay visible | Low — someone must carry every line |
| Typical failure | Reports read, nothing changes | Energy spent disputing the allocation rule |
| Pressure on tagging quality | Gentle | Immediate and unforgiving |
| Effect on shared platform work | Stays funded centrally | Gets pushed into someone's budget or starved |
Showback first is the safer sequence, not because chargeback is wrong but because chargeback without trustworthy tagging converts an engineering problem into a dispute. The moment money moves, every team acquires a strong interest in the allocation rule, and you will spend the next quarter defending a methodology rather than fixing the workloads it exposed.
What should happen when a spike lands?
Treat as a change-management question — tie the spike to the release and decide whether the new cost is acceptable, not whether it was a mistake.
The branch that matters most is the second. Teams reach for the largest query because it is easy to find and satisfying to optimise. The largest query is usually large for a reason and has been large for a long time. The query whose unit cost is growing fastest is the one with a defect, and it is invisible unless you have been recording the denominator.
What does good look like after a quarter?
A run-grain cost fact refreshed on the same schedule as the rest of the warehouse. An explicit allocation rule, written down, with the residual left visible. Compute pools split by workload class rather than org chart. Two or three unit-cost metrics with enough history to show a trend. And a triage path that starts with “did the ratio move” rather than “who is the biggest spender”.
None of it is glamorous, and none of it shows up in a demo. It is the layer that decides whether the next platform conversation is about capability or about the bill.
cost-attribution · data-platform-engineering · snowflake · microsoft-fabric
Share on LinkedIn ↗Work with Skopura
Facing this bottleneck in your own estate?
Skopura builds production-grade lakehouse pipelines, evaluation harnesses, and provides fractional data leadership. Thirty-minute call, no deck.