Sub topic 6
Compute: clusters, SQL warehouses, and serverless
This chapter assumes you know basic SQL and Python, understand that a virtual machine is a rented computer in the cloud, and know that a workspace is where you organize notebooks, tables, and jobs. You do not need to have created a cluster before.
By the end you will be able to name the compute types in Databricks, choose one for a given task, and recognize the common mistakes that waste time or money.
What compute means in Databricks
In Databricks, compute is the set of machines that run your code. Storage and compute are separate. Your tables live in cloud object storage, and compute is attached only when you need to work on them. Turning compute off does not delete data.
Every notebook cell, SQL query, and scheduled job needs compute. The main choice is which kind.
| Compute type | Typical use | Who manages the machines | Interactive? |
|---|---|---|---|
| All-purpose compute | Notebook development, exploration | You configure it | Yes |
| Job compute | Scheduled or triggered production runs | Created per run, then removed | No |
| SQL warehouse | SQL queries, dashboards, BI tools | Classic, pro, or serverless | Yes (SQL only) |
| Serverless compute | Notebooks, jobs, and SQL without cluster setup | Databricks | Yes |
Where compute runs
The control plane is Databricks' own part of the platform: the web application, job scheduler, and notebook storage. The compute plane is where your code runs.
- Classic compute runs in your own cloud account. The virtual machines appear in your subscription, and you pay the cloud provider for them as well as Databricks.
- Serverless compute runs in an account managed by Databricks. You do not see or configure the machines.
Clusters
A cluster is a group of virtual machines that work together. One machine is the driver. It runs your notebook code and coordinates the work. The others are workers, and they run the parallel tasks. Chapter on Spark covers this engine. Here it is enough to know that more workers let Spark process more data in parallel.
All-purpose compute
All-purpose compute is a cluster that you start and keep running while you develop. Several people can attach notebooks to the same cluster. It is flexible, and it is the most expensive way to run repeated production work, because it stays on while it is idle unless you set it to stop.
Key settings:
- Databricks Runtime version. A bundle of Spark, Delta Lake, Python, and libraries. Pick a long-term support version for stable work.
- Node type. The size of each virtual machine. Memory-heavy work such as large joins prefers memory-optimized types.
- Workers. A fixed number, or an autoscaling range such as 2 to 8. Autoscaling adds workers under load and removes them when idle.
- Auto-termination. Shuts the cluster down after a set number of idle minutes.
- Access mode. Controls who can use the cluster and whether Unity Catalog permissions are enforced.
Job compute
Job compute is a cluster that a job creates when a run starts and deletes when the run ends. Nobody attaches to it, and it is cheaper per unit of work than all-purpose compute. Use it for anything that runs on a schedule. The next chapters on jobs show how a notebook becomes a task.
Access mode and Unity Catalog
Access mode is a common source of errors. To query tables governed by Unity Catalog, the cluster must use a mode that supports it: standard (formerly "shared") for multi-user work, or dedicated (formerly "single user") for one user or group. A legacy mode with no isolation cannot enforce Unity Catalog permissions, so tables in Unity Catalog will not behave as expected there.
SQL warehouses
A SQL warehouse is compute built for SQL. It cannot run Python or Scala notebooks. It is the endpoint that the SQL editor, dashboards, and external tools such as BI applications or JDBC clients connect to.
There are three types:
- Serverless. Starts in seconds, runs in the Databricks account, and has the newest query engine features. This is the default choice when it is available in your region.
- Pro. Runs in your account, with more features than classic.
- Classic. Runs in your account with the basic feature set.
Warehouses come in T-shirt sizes such as 2X-Small to 4X-Large. A larger size runs each query faster, up to a point. More concurrent users call for scaling by adding clusters, not by raising the size. Each warehouse has its own auto-stop setting.
-- Run this in the SQL editor, attached to a SQL warehouse.
SELECT customer_id, SUM(amount) AS total_amount
FROM main.tutorial.orders
GROUP BY customer_id
ORDER BY total_amount DESC;The same table is reachable from a cluster:
from pyspark.sql import functions as F
df = spark.table("main.tutorial.orders")
display(df.groupBy("customer_id").agg(F.sum("amount").alias("total_amount")))Both reach the same Delta table by the same three-level name. The difference is the compute behind them.
Serverless compute for notebooks and jobs
Serverless compute for notebooks and jobs gives you compute without choosing node types or runtime versions. Databricks allocates resources, scales them, and applies updates. Start-up time is short, usually seconds, compared with several minutes for a new classic cluster.
Trade-offs to know:
- You have fewer settings to tune. Custom Spark configuration, some init scripts, and some library installs are limited.
- Features and regional availability vary, so check current documentation for your cloud.
- You pay for work done, not for idle machines you forgot to stop.
Choosing compute
Common errors and how to avoid them
- Leaving all-purpose clusters running. Set auto-termination, for example 30 to 60 minutes.
- Running production on all-purpose compute. Move scheduled work to job compute.
- Wrong access mode. If a Unity Catalog table is not visible or a permission check fails, check the access mode first.
- Over-sizing a warehouse. Start small and increase only if single queries are slow.
- Expecting a cold start to be instant. A stopped classic cluster or warehouse takes time to start. The first query waits.
- Missing permissions to create compute. Creating clusters is a workspace permission, separate from data access. Ask an administrator for access to a cluster policy or an existing cluster.
Exercise
A team runs a nightly notebook that rebuilds a table. It currently runs on a shared all-purpose cluster that stays on all day. Which compute type should replace it, and why?
Show answer
Job compute (or serverless jobs). It is created for each run and removed afterward, so nothing idles between runs. It also costs less per unit of work than all-purpose compute, and it keeps production runs separate from interactive development.
Exercise
An analyst only writes SQL and builds dashboards on Unity Catalog tables. Which compute fits, and what should you check if the dashboard is slow for one heavy query versus slow when many people open it?
Show answer
A SQL warehouse, serverless if available. If one heavy query is slow, increase the warehouse size. If many users at once cause waits, allow more clusters in the warehouse so it can scale out for concurrency.