Sub topic 10
Serverless compute: cost trade-offs and attribution
This chapter assumes you know the compute types from earlier chapters, can query system.billing.usage, and understand custom tags. It covers what changes in cost behavior when Databricks manages the compute for you.
What serverless changes
With classic compute, you pay two bills. Databricks charges DBUs, and your cloud provider charges for the instances. With serverless compute, Databricks runs the infrastructure in its own account. You get one bill, in DBUs, and the infrastructure cost is built into the DBU rate.
Three consequences follow:
- The per-DBU rate is higher than the classic equivalent, because it includes infrastructure.
- There is no cloud bill to reconcile for this compute. Your cloud provider's cost tools will not show it.
- You cannot tune instance types, spot usage, or pools. Databricks manages those.
Where serverless saves money
Serverless starts in seconds, so you stop paying for idle capacity that you kept warm to avoid startup delay. It also scales to the workload without a cluster size to choose.
Serverless tends to win when:
- Workloads are bursty or intermittent, such as ad hoc SQL or short jobs.
- Startup time dominates runtime, so classic clusters spend much of their billed time launching.
- Teams currently over-provision or leave clusters running.
Classic jobs compute tends to win when:
- Workloads are long, steady, and predictable.
- You can use spot instances or committed cloud discounts to cut infrastructure cost.
- You have tuned instance types for the workload.
Compare on total cost per run, not on DBU rate alone. A higher rate can still produce a lower bill if the run is shorter and has no idle time.
Attributing serverless cost
You cannot tag a cluster you do not create, so attribution works differently. Serverless usage still lands in system.billing.usage, and you identify it by SKU name and by the metadata columns on each row.
Use these columns:
sku_name, where serverless SKUs containSERVERLESS.usage_metadata, which carries IDs such as the job ID, warehouse ID, or notebook ID.custom_tags, which holds tags inherited from a budget policy or from the job or warehouse itself.
Serverless attribution relies on tags applied to the resource or on a serverless budget policy. Compute that nobody tagged or assigned a policy to shows up with empty tags, so require a policy for serverless users and check for untagged usage regularly.
This query splits the last 30 days of serverless DBUs by job and team tag:
SELECT
usage_metadata.job_id AS job_id,
custom_tags['team'] AS team,
SUM(usage_quantity) AS dbus
FROM system.billing.usage
WHERE usage_date >= date_sub(current_date(), 30)
AND sku_name LIKE '%SERVERLESS%'
AND usage_unit = 'DBU'
GROUP BY usage_metadata.job_id, custom_tags['team']
ORDER BY dbus DESC;Rows with a NULL team are your unattributed spend. Rows with a NULL job ID come from other serverless products, such as SQL warehouses or notebooks, so group by usage_metadata.warehouse_id or usage_metadata.notebook_id for those.
To convert DBUs to estimated dollars, join to system.billing.list_prices as shown in the earlier chapter. Because the serverless rate includes infrastructure, this estimate covers the whole cost of that compute, unlike the classic estimate.
Controlling serverless spend
Cluster policies do not apply, because there is no cluster. Use these controls instead:
- Assign budget policies so usage carries a tag and can trigger budget alerts.
- Set budgets with alerts on serverless SKUs.
- Set timeouts and limits on jobs so a runaway query cannot run for hours.
- Review the
usage_metadatabreakdown for the top few consumers each week.
Exercise
A nightly job runs for 6 hours on a steady load, and your team already uses spot instances on classic jobs compute. A colleague proposes moving it to serverless because "there is no infrastructure bill." What should you compare before agreeing?
Show answer
Compare total cost per run, not the DBU rate. Classic cost is DBUs plus cloud instance cost (reduced by spot). Serverless cost is DBUs at a higher rate with infrastructure included. For a long, steady job that already benefits from spot, classic is often cheaper, but measure both using system.billing.usage and the cloud bill.
Exercise
Your serverless query shows many rows where custom_tags['team'] is NULL. What does this mean and what should you do?
Show answer
The usage is unattributed because no tag or budget policy reached that compute. Apply a budget policy or tags to the jobs and warehouses, and require a policy for serverless users so future usage carries a team tag.