2 weeks ago
This article focuses mainly on cost management which has become ever more important with advent of fast-pace AI. A rise in total spend tells a platform administrator that something changed, but not necessarily which workload caused it or what action to take.
A useful cost-governance model needs to answer four questions:
Databricks provides complementary capabilities that address different parts of this problem. Governed tags and serverless usage policies help establish attribution. System tables provide the data for cost analysis. AI/BI dashboards and SQL alerts help surface problems. Compute policies and Unity AI Gateway controls can constrain certain configurations and AI traffic.
This article explains how to connect these capabilities into a practical operating model, including a reusable SQL pattern for analyzing costs by user, team, and asset.
Please note that, in Databricks, cost tracking is mainly dependent on the tags. If tags are standard, consistent and widely used then it makes the cost analysis way easier.
Governed Tags
The problem
Suppose a workspace contains workloads belonging to engineering, analytics, and machine learning teams. The billing data shows the consumption, but the available metadata does not consistently identify the owning team or project.
To create further solution on cost, we need a consistent way of identifying or marking each consumption area. For eg: Team name, environment, project name etc.
How governed tags help
Databricks governed tags provide centrally managed tag definitions and permitted values for supported objects. They help establish a consistent vocabulary across the platform. The biggest issue solved by Governed tags is that it helps us maintain the tag consistency.
Issue Faced in project: Teams were mandated to put a tag, "Env", across the workloads. However, within teams also, engineers ended up using different version of same value. For eg: "Prod" was used as "prod", "PROD", "Production", "production", "main" etc. This made it harder for us to track all the versions of tag values for cost tracking.
Once this standard is in place, billing data in system.billing.usage can be used to aggregate consumption by the tags recorded with each usage record.
Recommendation:
Centrally control the creation, modification and deletion of Governed tags to reduce the inconsistencies and improve standardization.
Serverless Budget policies
In shared environments, multiple teams may use supported serverless workloads within the same workspace. Also, every time a user might not put tags around the workloads. Thus, we might end up getting alot of cost as "untagged". To control this, SBP can be used.
How SBP Works:
- Admin creates a serverless budget policies with fixed values of various tags.
- User/Teams are given USE access on the SBP
- Whenever a user deploys a workload or use notebooks for experimentation, SBP automatically is applied to workload. This means tags are automatically applied on workload
- Cost dashboard can easily capture the cost based on tags.
Cost observability with AI/BI dashboards
Once the billing data contains useful attribution, the next step is to make it operationally useful.
Databricks system tables provide the foundation for this analysis. In particular:
These tables can feed an AI/BI dashboard that helps platform administrators move from a high-level spending signal to a specific workload investigation.
Unity AI Gateway
AI workloads introduce cost drivers that traditional compute controls do not fully address. Unity AI Gateway provides governance capabilities for supported model and MCP service traffic. Depending on the service and configuration, these can include usage tracking, rate limits, and budget-related controls.
Where it fits in a cost model
Control request volume. Rate limits can constrain excessive request traffic within their configured scope.
Apply budget guardrails. Supported budget controls can track usage against thresholds and may alert or restrict further requests, depending on the control and configuration.
Improve attribution. Available gateway usage information can help investigate requesters, models, token consumption, latency, and associated metadata.
Centralize governance. Routing supported external model-provider traffic through a governed gateway can provide a more consistent control point than managing every integration independently.
A key design consideration
AI cost governance needs both visibility and enforcement.
A dashboard may reveal that an agent is consuming more tokens than expected, but it will not necessarily stop additional requests. A rate limit or spending control may constrain usage, but it will not explain whether the increase came from a prompt change, a retry loop, or a rise in application traffic.
I would therefore connect gateway usage data to the broader cost-observability process and define an investigation path for unusual consumption.
SQL Alerts
AI/BI dashboards help people investigate when they open them. SQL alerts help identify conditions that need attention without depending entirely on someone checking a dashboard.
Databricks SQL alerts evaluate query results against configured conditions and can notify relevant recipients. They can be used for cost-related metrics derived from billing data.
Useful alert scenarios include:
Alert Example condition Follow-up action
Daily cost spike | Estimated daily cost exceeds an agreed threshold | Identify the workspace, team, or workload responsible |
Team budget warning | Month-to-date cost crosses a warning threshold | Review consumption with the team |
Unusual growth | Daily cost exceeds a historical baseline | Investigate changes in workload behavior |
Missing attribution | Unassigned usage exceeds an agreed threshold | Correct tagging or policy assignments |
Projected overrun | Forecast spend exceeds the agreed budget | Review optimization and scheduling options |
Thresholds should reflect the workload's normal behavior and the business impact of an overrun. A fixed threshold that is useful for a production data pipeline may be irrelevant for a small development workload.
Alerts are not spending caps
A SQL alert evaluates a condition; it does not inherently stop a running job, cancel an expensive query, or prevent new requests.
Use SQL alerts for detection and notification, and use the applicable budget or enforcement mechanisms when actual restrictions are required.
Compute policies
Compute policies help administrators constrain the configurations available for supported compute resources. They can establish defaults and restrictions around resource settings, compute sizes, and custom tags.
For example, a development policy could restrict worker counts and permitted node types while requiring an environment tag. A production policy might allow more capacity but require explicit ownership and operational controls.
The goal is not to prevent users from running legitimate workloads. It is to make expensive configurations deliberate rather than accidental.
Cost Dashboard Queries (Sample)
The following pattern targets Databricks and demonstrates how to estimate DBU costs using the applicable list price. It enriches usage records with identity, tags, and available workload metadata.
The examples assume that the finops schema exists and that the required system tables are accessible. Validate column availability and data types in the target environment before deploying the view.
Step 1: Build an enriched usage view
CREATE OR REPLACE VIEW finops.cost_usage_enriched AS WITH priced_usage AS (
SELECT
u.record_id,
u.account_id,
u.workspace_id,
u.usage_date,
u.usage_start_time,
u.usage_end_time,
u.sku_name,
u.usage_quantity,
u.usage_unit,
u.billing_origin_product,
u.custom_tags,
u.identity_metadata,
u.usage_metadata,
u.record_type,
p.pricing.default AS list_price_per_unit,
u.usage_quantity * p.pricing.default
AS estimated_list_cost_usd
FROM system.billing.usage AS u
LEFT JOIN system.billing.list_prices AS p
ON u.account_id = p.account_id
AND u.cloud = p.cloud
AND u.sku_name = p.sku_name
AND u.usage_unit = p.usage_unit
AND u.usage_start_time >= p.price_start_time
AND (
p.price_end_time IS NULL
OR u.usage_start_time < p.price_end_time
)
WHERE u.usage_unit = 'DBU'
)
SELECT
record_id,
account_id,
workspace_id,
usage_date,
usage_start_time,
usage_end_time,
sku_name,
usage_quantity AS dbus,
billing_origin_product,
record_type,
COALESCE(
identity_metadata.run_as,
identity_metadata.owned_by,
'unknown'
) AS user_identity,
COALESCE(
custom_tags['team'],
custom_tags['Team'],
'unassigned'
) AS team,
COALESCE(
custom_tags['cost_center'],
'unassigned'
) AS cost_center,
COALESCE(
custom_tags['project'],
'unassigned'
) AS project,
COALESCE(
usage_metadata.job_name,
CASE
WHEN usage_metadata.job_id IS NOT NULL
THEN CONCAT('job_id=', usage_metadata.job_id)
END,
usage_metadata.notebook_path,
CASE
WHEN usage_metadata.notebook_id IS NOT NULL
THEN CONCAT(
'notebook_id=',
usage_metadata.notebook_id
)
END,
CASE
WHEN usage_metadata.warehouse_id IS NOT NULL
THEN CONCAT(
'warehouse_id=',
usage_metadata.warehouse_id
)
END,
CASE
WHEN usage_metadata.cluster_id IS NOT NULL
THEN CONCAT(
'cluster_id=',
usage_metadata.cluster_id )
END,
billing_origin_product
) AS asset_name,
usage_metadata.job_id AS job_id,
usage_metadata.notebook_id AS notebook_id,
usage_metadata.warehouse_id AS warehouse_id,
usage_metadata.cluster_id AS cluster_id,
list_price_per_unit,
estimated_list_cost_usd
FROM priced_usage;
The view deliberately separates enrichment from reporting logic. Once validated, it can be reused by dashboards, SQL alerts, and periodic allocation reports.
Before using it for financial reporting, validate the following:
The SQL below uses estimated_list_cost_usd consistently. These queries are examples of the reporting pattern; validate the resulting aggregates against the billing semantics and data available in your environment.
Step 2: Analyze cost by user or execution identity
SELECT
user_identity,
SUM(dbus) AS total_dbus,
SUM(estimated_list_cost_usd) AS estimated_cost_usd,
COUNT(DISTINCT workspace_id) AS workspace_count,
COUNT(DISTINCT asset_name) AS asset_count
FROM finops.cost_usage_enriched
WHERE usage_date >= :start_date
AND usage_date <= :end_date
GROUP BY user_identity
ORDER BY estimated_cost_usd DESC;
This report can identify high-consumption identities, compare usage across workspaces, and highlight identities worth investigating.
Step 3: Analyze cost by team, cost center, and project
SELECT
team,
cost_center,
project,
SUM(dbus) AS total_dbus,
SUM(estimated_list_cost_usd)
AS estimated_cost_usd,
COUNT(DISTINCT user_identity)
AS identity_count,
COUNT(DISTINCT asset_name)
AS asset_count
FROM finops.cost_usage_enriched
WHERE usage_date >= :start_date
AND usage_date <= :end_date
GROUP BY
team,
cost_center,
project
ORDER BY estimated_cost_usd DESC;
This supports team showback, project cost reviews, and comparisons between environments when the relevant tags are available.
Keep the unassigned category visible. It is a useful operational measure of how much consumption cannot yet be associated with a team or cost center.
Step 4: Investigate high-cost assets
SELECT
asset_name,
team,
user_identity,
billing_origin_product,
SUM(dbus) AS total_dbus,
SUM(estimated_list_cost_usd)
AS estimated_cost_usd,
MIN(usage_start_time) AS first_usage,
MAX(usage_end_time) AS last_usage
FROM finops.cost_usage_enriched
WHERE usage_date >= :start_date
AND usage_date <= :end_date
GROUP BY
asset_name,
team,
user_identity,
billing_origin_product
ORDER BY estimated_cost_usd DESC;
Use this report to identify expensive jobs, notebooks, and other supported assets. It can help prioritize investigations into runtime, scheduling frequency, compute sizing, and repeated processing.
Step 5: Monitor unassigned consumption
SELECT
workspace_id,
billing_origin_product,
SUM(dbus) AS total_dbus,
SUM(estimated_list_cost_usd) AS estimated_cost_usd
FROM finops.cost_usage_enriched
WHERE usage_date >= :start_date
AND usage_date <= :end_date
AND (
team = 'unassigned'
OR cost_center = 'unassigned'
)
GROUP BY
workspace_id,
billing_origin_product
ORDER BY estimated_cost_usd DESC;
This query turns attribution quality into a measurable control. The results can feed a dashboard or alert, allowing the platform team to prioritize the workspaces and workload types with the largest unassigned consumption.
For SQL query-level investigation, enrich the analysis with system.query.history using the appropriate warehouse and time dimensions. For AI workloads, use the applicable gateway usage data where available. Document any allocation assumptions and avoid presenting estimated allocations as directly measured charges.
Connect the controls into an operating model
The features work best when each has a defined responsibility.
Capability Responsibility
Governed tags | Standardize metadata |
Serverless usage policies | Attribute supported serverless consumption |
AI/BI dashboards | Show trends and identify investigation targets |
Unity AI Gateway | Govern supported AI traffic and usage |
SQL alerts | Detect conditions requiring attention |
Compute policies | Restrict supported compute configurations |
Conclusion
Effective Databricks cost governance is an engineering practice that connects metadata, billing data, operational visibility, and enforcement.
Governed tags and serverless usage policies help make consumption attributable. AI/BI dashboards and SQL alerts make changes visible and actionable. Compute policies and Unity AI Gateway controls provide guardrails within their supported scopes. A reusable SQL model connects these capabilities to user-, team-, and asset-level investigation.
The goal is not simply to produce a lower bill. It is to make consumption explainable, ownership clear, unexpected changes detectable, and corrective action practical—without restricting legitimate data and AI workloads unnecessarily.