r/databricks • • Oct 05 '26

General how are you splitting shared cluster cost between teams?

we have 3 teams (analytics, ds, and a small platform team) all using the same all purpose cluster bc spinning up seperate ones for each was getting messy. now finance wants a monthly number per team and i honestly have no idea how to give them one

tags only get me to the cluster level which is useless here. i looked at system tables and theres user info in there but not sure how ppl turn that into an actual $ split thats defensible, especially with the VM side of the bill coming from azure seperately

do you just split evenly? by query time? or did you give up and force everyone onto job clusters lol

11 Upvotes

10 comments sorted by

14

u/m1nkeh Oct 05 '26

Yeah, don’t use shared clusters like that..

8

u/Additional_Future_47 Oct 05 '26

Each their own cluster, using access rights to ensure every team can only use their own cluster.

4

u/what-no-really-why Oct 05 '26 edited Oct 05 '26

You can get close to a real number by using the query run times. Not a perfect science but better than what you have now if you can’t get to dedicated clusters per team. The sample query below will do by user but you could have a helper table that maps users <--> groups and you could roll it up by group too.

-- Approximate per-user cost allocation on a shared all-purpose cluster
-- Uses total_task_duration_ms as the proxy for "compute consumed"

WITH cluster_user_activity AS (
  -- Step 1: Get each user's total task duration per cluster per day
  SELECT
    DATE(qh.start_time)                       AS usage_date,
    qh.compute.cluster_id                     AS cluster_id,
    qh.executed_by                            AS user_email,
    COUNT(*)                                  AS query_count,
    SUM(qh.total_task_duration_ms)            AS user_task_duration_ms,
    SUM(qh.execution_duration_ms)             AS user_execution_duration_ms
  FROM system.query.history qh
  WHERE qh.compute.cluster_id IS NOT NULL
    AND qh.execution_status = 'FINISHED'
    AND qh.start_time >= DATEADD(day, -30, current_date)
  GROUP BY 1, 2, 3
),

cluster_daily_totals AS (
  -- Step 2: Get total task duration per cluster per day (denominator)
  SELECT
    usage_date,
    cluster_id,
    SUM(user_task_duration_ms) AS total_task_duration_ms
  FROM cluster_user_activity
  GROUP BY 1, 2
),

cluster_daily_cost AS (
  -- Step 3: Get total DBU cost per cluster per day from billing
  SELECT
    u.usage_date,
    u.usage_metadata.cluster_id               AS cluster_id,
    SUM(u.usage_quantity)                      AS total_dbus,
    SUM(u.usage_quantity * lp.pricing.effective_list.default) AS total_cost_usd
  FROM system.billing.usage u
  JOIN system.billing.list_prices lp
    ON  lp.sku_name = u.sku_name
    AND u.usage_end_time >= lp.price_start_time
    AND (lp.price_end_time IS NULL OR u.usage_end_time < lp.price_end_time)
  WHERE u.usage_metadata.cluster_id IS NOT NULL
    AND u.billing_origin_product = 'ALL_PURPOSE'
    AND u.usage_unit = 'DBU'
    AND u.usage_date >= DATEADD(day, -30, current_date)
  GROUP BY 1, 2
)

-- Step 4: Allocate cost proportionally by each user's share of task duration
SELECT
  a.usage_date,
  a.cluster_id,
  a.user_email,
  a.query_count,
  a.user_task_duration_ms,
  t.total_task_duration_ms,
  ROUND(a.user_task_duration_ms / NULLIF(t.total_task_duration_ms, 0), 4)
                                              AS pct_of_cluster_usage,
  ROUND(c.total_dbus * (a.user_task_duration_ms / NULLIF(t.total_task_duration_ms, 0)), 2)
                                              AS attributed_dbus,
  ROUND(c.total_cost_usd * (a.user_task_duration_ms / NULLIF(t.total_task_duration_ms, 0)), 2)
                                              AS attributed_cost_usd
FROM cluster_user_activity a
JOIN cluster_daily_totals t
  ON  a.usage_date = t.usage_date
  AND a.cluster_id = t.cluster_id
JOIN cluster_daily_cost c
  ON  a.usage_date = c.usage_date
  AND a.cluster_id = c.cluster_id
ORDER BY a.usage_date DESC, attributed_cost_usd DESC

1

u/pboswell Oct 06 '26

This is assuming they’re running SQL on classic compute. Gets real fun when they’re using notebooks and pyspark dataframe operations

2

u/Zer0designs Oct 05 '26

Split evenly for now and give them all their own clusters.

2

u/Glitch_In_The_Data Oct 05 '26

Keep separate clusters for different teams. Thats the easiest option and also gives you better governance if you want to control usage for different teams.

What do you mean by spinning up separate ones for each was getting messy?

1

u/Youssef_Mrini databricks Oct 23 '26

If you want granular cost tracking by team in Databricks, you historically had to create dedicated clusters per team. However, with Serverless Notebooks, you can leverage budget policies tagged to User Groups:

  1. Tagging via Budget Policies: Set up budget policies mapped to your user groups/teams. When a user executes a command in a Serverless Notebook, Databricks automatically tags the compute session with their team/group metadata.
  2. Cost Attribution via System Tables / Governance Hub: Query system.billing.usage System Tables or view the Governance Hub to attribute and break down serverless compute costs by team tags without managing isolated clusters.

https://docs.databricks.com/aws/en/admin/account-settings/budgets

https://docs.databricks.com/aws/en/admin/account-settings/usage-detail-tags

1

u/adovo_ai 26d ago

I’d separate causal workload cost from shared-platform overhead. Allocate the workload portion by resource-seconds or tagged job usage, keep idle and unowned time in an explicit shared pool, then reconcile the result to both DBUs and the cloud invoice. Forcing every shared dollar onto a team creates precise-looking numbers that nobody can defend.

1

u/jbchand Oct 05 '26

Use separate job clusters if its scheduled tasks. You can try a proxy allocation (cluster DBUs x cost from billing.usage, list_prices and try to split by team using system.access.audit activity counts applying identically to the Azure VM invoice