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
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:
pip install dbt-databricks);
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.
To go further, a few reliable resources:
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.
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.
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.
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;
system.billing.usage: the product behind the consumption, the day, the SKU.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.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.
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.
| Family | Examples | Use cases | Profile |
|---|---|---|---|
| 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 |
To find the matching EC2 instances, the AWS console remains a good starting point.
That leaves reading their names. Each letter has a meaning, detailed in the AWS documentation.
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.
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.
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.