Hands fanning out a wad of hundred-dollar bills
Jolimoi Tech · Long read

Databricks
Cost Management

You pay for Databricks twice: the cloud that runs the machines, and DBUs, the license metered by the second. Read, tag, measure, then choose the compute: field notes from a startup on a tight budget.

By Alexis Blandin · 9 min read

Scroll down

This text went with a talk given at a Databricks meetup, where we were invited to share how we manage our costs. It first appeared on the Jolimoi tech blog in June 2024.

This is not about code optimization. Costs also depend on performance, from modeling to storage, but that topic deserves its own articles. This one covers managing and controlling Databricks costs, one topic after another.

Every company has its own view of its cloud spending, and Databricks is no exception. Here is ours, at Jolimoi:

A pile of receipts in black and white
Item 1

Read the bill

Before optimizing, know what you pay for.

It sounds obvious: start by understanding what the spending is made of. Databricks pricing looks more complex than other solutions' because it comes in two parts.

What a cluster costs

Cloud bill AWS

Data transfer cloud
Compute (EC2 instances) cloud
Storage cloud

Databricks bill license

DBU consumption per second
A Databricks cluster produces two bills.
Cloud costs, AWS in our case: mostly data transfer, compute and storage.
Databricks consumption, a kind of license counted in DBUs (DataBricks Units). It mostly follows the compute you put behind it: the bigger the cluster, the more you pay. It is billed on time consumed, by the second.
A cluster, its nodes, its DBUs
Driver30.5 GB
4 cores
Worker 130.5 GB
4 cores
Worker 230.5 GB
4 cores
4DBU/h
i3.xlargePhotonUnity CatalogRuntime 13.3
One driver and one worker, i3.xlarge with Photon: the cluster consumes 4 DBUs per hour.
Add an identical worker: 6 DBUs per hour. The correlation between the number of instances and the DBUs consumed is clear. Here, one instance is worth 2 DBU/h.

To go further, a few reliable resources:

Four blank tags hanging from strings
Item 2

Track the spending

Tag everything, then query the system tables.

Once you understand how the bill splits, you have to watch it. The first tool is the account console, which filters usage data by SKU, by workspace and by tag.

Databricks account console: filterable usage chart
The account console: a first read, useful if the tags are set right.

It does not replace a fine-grained cost analysis, but it is enough to start, on one condition: well-configured tags. Tagging remains a classic FinOps practice, and still a relevant one. Databricks sets some tags by default, and anyone can define their own convention.

A resource, before and after tags
cluster_id: 0617-084512-x7k2p9qa
???
jm:applicationdbt-nightly
jm:domaindata
jm:roleETL
jm:environmentproduction
jm:ownerdata team
jm:managedByterraform
jm:taggingVersion2
Data
show-back
Marketing
charge-back
Product
charge-back
Sample identifier and values.
Without tags, a resource boils down to an identifier. Nobody knows what it is for or who pays for it.
At Jolimoi, every cloud asset carries the same tags, Databricks included (except endpoints, which refused colons). jm:application is the most basic: feature, project, whatever the name, it is the key identifier of the usage. jm:domain names a division, a team or a business domain (marketing, data). jm:role states the function: front, back, security, ETL, data science.
jm:environment: production, integration, staging, sandbox. jm:owner: the key stakeholder, project owner, analyst or technical contact, in short the person responsible for the asset on the billing side.
jm:managedBy says how the asset was built: Terraform, CloudFormation, or nothing at all, meaning by hand. And jm:taggingVersion, because tagging conventions have versions too.
These tags give more readable information than a cluster ID. Above all, they enable show-back and charge-back to other business units, useful when the IT budget is spread across the company.

Usage data is available through several channels: the API, delivery to S3 and system tables, the last two still in preview at the time of writing, in June 2024.

To use this data in detail, go through the system tables: system.billing.usage for usage, system.billing.list_prices for the price of each Databricks SKU at a given time.

Schema of the system.billing.usage table in Catalog Explorer
The schema of system.billing.usage.

Databricks provides a list of sample queries and templates. You can also write your own.

SELECT  billing_origin_product  , usage_date  , usage.sku_name  , SUM(usage_quantity) AS dbu_count  , CAST(pricing["default"] AS FLOAT) AS pricing  , (dbu_count * CAST(pricing["default"] AS FLOAT)) AS total_price  , custom_tags["jm:application"] AS applicationFROM system.billing.usageINNER JOIN system.billing.list_prices ON usage.cloud = list_prices.cloud  AND usage.sku_name = list_prices.sku_name  AND usage.usage_start_time >= list_prices.price_start_time  AND (    usage.usage_end_time <= list_prices.price_end_time    OR list_prices.price_end_time IS NULL  )GROUP BY  billing_origin_product, usage_date, usage.sku_name  , pricing["default"], custom_tags["jm:application"]ORDER BY usage_date DESC, dbu_count DESC;
The query starts from system.billing.usage: the product behind the consumption, the day, the SKU.
The join with list_prices finds the price in force at the time of consumption: same cloud, same SKU, and a validity window that contains the usage period, or that is still running.
We sum the DBUs consumed and multiply them by the default price to get a cost.
The jm:application tag becomes a column: cost reads by application, no longer by cluster identifier.
We group by day, product, SKU and application, from most recent to most expensive.

Another option: the cost observability dashboard published on GitHub. It does not work very well, and one wonders why it is not in the samples gallery.

Databricks cost observability dashboard
The cost observability dashboard.
Aisle between two rows of server racks
Item 3

Choose the compute

Instance families, runtimes, cloud commitments.

Each option depends on the use cases, so only a few general recommendations. The first: assess instance types and families. The Databricks UI offers a wide choice: storage- or memory-optimized, general purpose, with GPUs, with or without Delta cache accelerated.

FamilyExamplesUse casesProfile
General purpose (M)m5.large
m5.xlarge
Balanced compute, memory and networking. Suits a wide variety of applications.Moderate CPU and memory
Compute (C)c5.large
c5.xlarge
Compute-bound applications: batch processing, machine learning inference, data transformations.High CPU, little memory
Memory (R)r5.large
r5.xlarge
Memory-hungry applications: large in-memory caches, real-time big data analytics, high-performance databases.Lots of memory, moderate CPU
Storage (I)i3.large
i3.xlarge
I/O tasks: fast, sequential reads and writes on large volumes, NoSQL, warehousing, large-scale data processing.High IOPS, large local storage
Accelerated (P, G)p3.2xlarge
g4dn.xlarge
Applications that require GPUs: deep learning, AI, video processing, high-performance computing.GPUs for parallel computing, high memory bandwidth
AWS instance families, summarized.

To find the matching EC2 instances, the AWS console remains a good starting point.

AWS EC2 console: comparing instance types
Comparing instances in the EC2 console.

That leaves reading their names. Each letter has a meaning, detailed in the AWS documentation.

Reading an instance name
c7gn.xlarge
The first letter gives the family: c for compute-optimized instances.
The digit gives the instance generation.
Next comes the processor family: g for Graviton, the AWS ARM processor. Careful: Graviton instances do not support some Databricks features.
An optional letter flags an additional capability: n for enhanced networking.
After the dot, the instance size.

Beyond these generalities, the best advice: monitor your workload and watch how the cluster's memory and CPU respond. Same for sizing the driver node.

The Delta cache is not worth dwelling on with recent runtimes: from Databricks Runtime 14.2, the CACHE SELECT command is ignored. Picking the latest runtime almost always brings good news on performance anyway. Just check that your code runs on it.

Not directly tied to Databricks, cloud providers also offer their own discount levers. At AWS: Savings Plans, more flexible and better discounted, and Reserved Instances, which are not the best option. The principle: you commit your consumption on an instance family, and AWS grants you a discount, bigger if you pay part or all of it upfront. AWS even computes recommendations from your past consumption.

Savings Plans recommendation, per month
Current spend, on demand$1,638.37
Spend after commitment$1,264.17
Savings$374.20
AWS estimate from May 2024: one-year Compute Savings Plan, paid entirely upfront, computed over the last 30 days.
On our account, the recommendation starts from a monthly on-demand spend of 1,638 dollars.
With a commitment, the same consumption costs 1,264 dollars a month.
374 dollars saved every month, 23% of the spend concerned, without touching a line of code. A good starting point.
AWS console: Savings Plans recommendations
The AWS recommendations screen.
Golden light trails in a long exposure
Item 4

Photon or no Photon?

Have you really done the math?

Last point, and not the least. According to Databricks, Photon is a cost-effective solution:

“Photon is a high-performance Databricks-native vectorized query engine that runs your SQL workloads and DataFrame API calls faster to reduce your total cost per workload.”

Photon seems a given when the goal is speed, for instance on a job cluster that has to deliver its results before shutting down. But the math is worth doing.

Same r5d.xlarge driver, runtime 14.3
Without Photon
0.9 DBU/h
With Photon
1.8 DBU/h
 
Take the same node, an r5d.xlarge with 32 GB and 4 cores. Without Photon, it consumes 0.9 DBU per hour.
Turn Photon on: 1.8 DBU per hour. By default, Photon means paying double. It is that simple.
The only question that matters: does Photon also cut your time in half?
Do the math
Job DBU bill: ×1.33
DBUs only: a shorter job also cuts the instance's cloud bill, which does not double with Photon.

This is not(yet) a conclusion.

Still to cover: job and cluster configuration, auto-termination, cluster pools, fleet and spot instances, and SQL warehouses. The principle does not change: two bills, which you only cut once you have learned to read them.