Sub topic 6
Compute: clusters, SQL warehouses, and serverless
This chapter assumes you know what a workspace is and the split between the control plane and the compute plane. It also assumes you can read basic SQL and Python. Here you learn what compute is in Databricks and how to pick the right kind for a task.
What compute means
Compute is the set of virtual machines that run your code. Your notebooks, SQL queries, and jobs do not run in the control plane. They run on compute that Databricks starts in a compute plane. Data stays in cloud object storage, and compute reads and writes it. Because storage and compute are separate, you can stop compute without losing any data.
The main compute types
| Type | Best for | Lifetime | Typical user |
|---|---|---|---|
| All-purpose compute | Interactive notebooks, exploration | Started and stopped by a person, with auto-termination | Data scientists, engineers |
| Job compute | Scheduled or automated runs | Created for a run, deleted when it ends | Pipelines |
| SQL warehouse | SQL queries, dashboards, BI tools | Started on demand, stops when idle | Analysts |
| Serverless | Any of the above without managing VMs | Managed by Databricks | Anyone |
Clusters
A cluster is a group of machines that work together. One is the driver, which coordinates the work. The others are workers, which run tasks in parallel. All-purpose clusters can be shared by several people and attached to many notebooks. Job clusters are cheaper for the same work, because a run gets its own cluster and nothing sits idle afterward.
SQL warehouses
A SQL warehouse is compute tuned for SQL. You choose a size, such as 2X-Small or Large, rather than choosing machines. Warehouses can scale out to more clusters when many queries arrive at once. Use them for Databricks SQL, dashboards, and BI tools. A warehouse cannot run Python notebook code.
Serverless
With serverless compute, Databricks runs the machines in its own account instead of yours. Start-up takes seconds instead of minutes, and you do not set node types or versions. The trade-off is less control over configuration.
Attaching a notebook
A notebook does nothing until it is attached to compute. Once attached, you can run this cell to confirm what you are connected to:
print(spark.version)
print(spark.sparkContext.defaultParallelism)The first line prints the Spark version. The second shows how many tasks Spark can run in parallel. On serverless compute, sparkContext may not be available, so skip the second line there.
Common errors
- Leaving all-purpose compute running. It bills while it is up. Set auto-termination, for example after 30 minutes idle.
- Running scheduled work on all-purpose compute. Use job compute. It costs less and isolates runs from each other.
- Trying to run Python on a SQL warehouse. Warehouses accept SQL only. Use a cluster or serverless notebook compute.
- Waiting on a stopped cluster. Classic clusters take minutes to start. Serverless avoids this.
Exercise
A nightly pipeline runs a notebook that transforms data in Python. Which compute type should it use, and why not an all-purpose cluster?
Show answer
Use job compute, or serverless jobs compute. It is created for the run and deleted afterward, so you pay only while the work runs, and the run is isolated from other users. An all-purpose cluster would cost more and could be disturbed by interactive work.