Sub topic 3
Choosing a Databricks Runtime version and Photon
This chapter covers how to pick a Databricks Runtime (DBR) version for a cluster, and when to turn on Photon. It assumes you know what a driver and workers are, can read a JSON cluster definition, and have used a notebook attached to a cluster. The previous chapter described the cluster's structure. Here the focus is on the software image each node runs.
What the Databricks Runtime is
The Databricks Runtime is the set of software that starts on every node of a classic cluster. It bundles:
- Apache Spark, with Databricks changes.
- A Java, Scala, and Python environment, including preinstalled libraries.
- Delta Lake and other Databricks components.
- Operating system packages and drivers.
When you create a cluster you choose one runtime version. The driver and all workers use that same version. You cannot mix versions inside one cluster. Changing the version means editing the cluster and restarting it.
In the Clusters API and Jobs API, the version is a string in the spark_version field, for example 15.4.x-scala2.12. The x stands for the maintenance release. Databricks applies maintenance updates to the same version label, so a cluster that restarts may pick up newer patch-level fixes without a change to your definition.
Serverless compute does not expose this choice for the same purpose. Databricks manages the environment, and you select an environment version for the notebook or job instead. The serverless chapter covers that.
Runtime variants
The version number is only part of the choice. Databricks publishes several variants of each release.
| Variant | What it adds | Typical use |
|---|---|---|
| Standard | Spark, Delta Lake, and common libraries | Data engineering, SQL, general analytics |
| ML | Standard plus popular machine learning libraries, and GPU support on GPU node types | Model training and experimentation |
| Photon-enabled | The same runtime with the Photon engine turned on | SQL and DataFrame workloads that scan and join large tables |
In the cluster UI, the runtime list shows the standard and ML variants. In the API, ML versions use a -ml- string such as 15.4.x-cpu-ml-scala2.12 or 15.4.x-gpu-ml-scala2.12. Use GET /api/2.1/clusters/spark-versions to list the exact strings your workspace accepts. Do not guess them, because a wrong string makes cluster creation fail.
Long Term Support and non-LTS releases
Databricks releases new runtime versions regularly. Some releases are designated Long Term Support (LTS). The rest are non-LTS.
- An LTS release receives support for a longer period, so it is the safer default for production jobs.
- A non-LTS release gets new features sooner but reaches end of support sooner.
- When support for a version ends, Databricks stops fixing problems in it and may stop allowing new clusters on it.
Check the current support dates in the Databricks release notes before you commit to a version. The dates change, and this chapter does not list them.
The practical rule: use an LTS version for scheduled production work, and a newer version only when you need a specific feature from it.
How to choose a version
Work through these questions in order.
- Does a feature you need exist only in a newer version? If so, choose the oldest supported version that has it.
- Is the workload production? Prefer the current LTS release. Pin it explicitly in the job definition.
- Do your libraries constrain the version? Python and Spark versions change between runtimes. A library built for an older Python may fail to import on a newer runtime.
- Is this an ML workload? Choose the ML variant so you do not have to install and version-match the common libraries yourself.
- Will you use Unity Catalog features? Some governance features need a minimum runtime version. Also, the access mode you choose in a later chapter interacts with the runtime. Check the documentation for the minimum version of the feature you need.
Keep clusters of the same kind on the same version across a team. A shared version makes bugs reproducible and makes upgrades a single, planned change.
Upgrading a runtime safely
An upgrade can change Spark behavior, library versions, default configuration, and the Python version. Treat it as a code change.
- Read the release notes for every version between the old one and the new one. Note behavior changes and removed features.
- Create a test cluster, or a test job cluster, on the new version.
- Run the workload against a copy of representative data. Compare row counts, schema, and a few aggregates with the old results.
- Change the version in the production definition only after the comparison passes.
- Keep the previous definition in version control so you can roll back.
Edge cases to watch for:
- Library incompatibility. A cluster-installed library may not support the new Python version. The failure appears when you import it, not when the cluster starts.
- Changed defaults. A Spark setting whose default changed can alter results or performance without any error.
- Init scripts and custom images. Scripts that assume a specific operating system package or path can break.
- Unpinned versions. If a job uses a stale version string that has been retired, the run fails at cluster creation. Monitor for it before the retirement date.
What Photon is
Photon is a vectorized query engine written in C++ that Databricks built to run Spark workloads faster. It plugs in below the Spark API, so you do not change your code. Spark SQL and DataFrame operations that Photon supports run in Photon. Operations it does not support run in the normal Spark engine, in the same query.
Photon speeds up work such as scans, filters, aggregations, and joins, especially over Delta and Parquet data. It helps less, or not at all, for:
- Python user-defined functions (UDFs) that run row by row.
- Work dominated by small data, where startup and scheduling cost more than the computation.
- RDD-based code that bypasses the DataFrame and SQL layers.
- Operations Photon does not implement, which fall back to the standard engine.
Because Photon is part of the engine and not a library, you turn it on at the compute level. You do not import anything into a notebook.
Turning Photon on
In the cluster UI, you select the Photon option in the runtime settings. In the API, you set the runtime_engine field:
{
"cluster_name": "team-interactive-photon",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"autoscale": {
"min_workers": 1,
"max_workers": 4
},
"autotermination_minutes": 60,
"data_security_mode": "USER_ISOLATION",
"runtime_engine": "PHOTON"
}The accepted values for runtime_engine are PHOTON and STANDARD. If you leave the field out, the workspace default applies, which depends on the compute type and the workspace settings. Set the field explicitly in code so the definition says what it means.
Some node types do not support Photon. If you request Photon on an unsupported instance type, creation fails or the option is unavailable. The node type list in the UI shows which types qualify.
Photon and cost
Photon changes the bill. Photon-enabled compute is charged at a higher DBU rate than the same cluster without Photon. The cloud provider's virtual machine charge stays the same. A later chapter explains how DBUs and infrastructure charges combine.
Photon pays off when the speedup is larger than the rate increase. Roughly:
- If a job runs 2x faster and the DBU rate rises by less than 2x, the total cost falls.
- If the job barely speeds up, you pay the higher rate for no gain.
Faster runs also reduce the infrastructure charge, because the virtual machines run for less time. So the benefit counts on both parts of the bill.
Measure instead of assuming. Run the same job on a Standard cluster and a Photon cluster, and compare duration and total cost.
flowchart TDThe diagram below summarizes the decision.
Checking whether Photon was used
Enabling Photon does not guarantee that every operator ran in it. To check, open the query's details in the Spark UI or the query profile and look for Photon operators in the plan. Operators from the standard engine appear alongside them. If most of the plan is outside Photon, the benefit will be small. The usual causes are Python UDFs, unsupported expressions, or unsupported data sources.
Common mistakes
- Choosing a non-LTS version for a long-lived job. The version reaches end of support and the job must be changed under time pressure.
- Copying a node type or version string between clouds or workspaces. Both can differ, so list them with the API first.
- Enabling Photon everywhere. It raises the DBU rate for workloads that cannot use it.
- Changing the runtime on a shared cluster without notice. Everyone attached sees the restart and any behavior change.
- Reading a successful cluster start as a successful upgrade. Many incompatibilities appear only when code runs.
Exercise
A nightly production job runs mostly Python UDFs over a modest amount of data. A teammate proposes switching to the newest non-LTS runtime with Photon to "make it faster." Name two reasons to be cautious and say how you would decide.
Show answer
First, a non-LTS release reaches end of support sooner, so a long-lived production job is better pinned to an LTS release. Second, Photon speeds up SQL and DataFrame operators on large data, and row-by-row Python UDFs and small data gain little, while the higher DBU rate still applies. To decide, create a test job cluster on the proposed version, run the job on representative data with Photon on and off, and compare duration, cost, and result correctness. Check the release notes for behavior changes and library compatibility before changing the production definition.
Exercise
Which field in a Clusters API request turns Photon on, and what are its accepted values?
Show answer
The field is runtime_engine. The accepted values are PHOTON and STANDARD. If it is omitted, the workspace default applies, so set it explicitly in code.