Sub topic 3
Choosing a Databricks Runtime version and Photon
This chapter assumes you know what a cluster's driver and workers do, and that you can read a JSON cluster definition. You will learn how the Databricks Runtime (DBR) version is chosen, what Photon changes, and which mistakes cause the most trouble.
What the Databricks Runtime is
The Databricks Runtime is the image that every node in a cluster boots from. It bundles a specific Apache Spark version, Delta Lake, Python, Java, Scala, and a set of preinstalled libraries. The driver and all workers run the same runtime version.
You pick the runtime with the spark_version field. The value 15.4.x-scala2.12 means runtime 15.4, with the x standing for maintenance updates that Databricks applies automatically, and Scala 2.12.
Runtime flavors and support
Runtimes come in a few flavors, and the flavor affects how long you can rely on a version.
| Flavor | Use it for | Notes |
|---|---|---|
| Standard | General data engineering and analytics | Default choice |
| ML | Model training and tuning | Adds ML libraries; GPU variants exist |
| LTS (long-term support) | Production jobs | Supported for longer, so upgrades are less frequent |
Non-LTS releases are supported for a shorter time. For scheduled production work, prefer an LTS version, such as 15.4 in the examples in this tutorial. Check the Databricks release notes for the current support dates, because they change.
Photon
Photon is a vectorized query engine written in C++. It replaces parts of Spark's execution for SQL and DataFrame operations. It is most useful for large scans, joins, aggregations, and writes to Delta tables. Code that runs mainly Python UDFs or RDD operations sees little benefit, because those parts do not run in Photon.
You enable it through the runtime_engine field. This example turns Photon on in a cluster definition:
{
"cluster_name": "photon-demo",
"spark_version": "15.4.x-scala2.12",
"node_type_id": "i3.xlarge",
"num_workers": 2,
"runtime_engine": "PHOTON"
}The value STANDARD turns it off. Some node types do not support Photon, and the UI only offers it where it works. Photon-enabled compute is billed at a higher DBU rate. A query that finishes faster can still cost less overall, so measure total cost on a real workload instead of assuming.
How a version choice plays out
Common errors
- Floating to a new runtime by accident. Hard-code
spark_versionin jobs. Do not change it casually. A minor runtime change can upgrade Spark, Python, or library versions and alter behavior. - Library conflicts. A library you install can clash with one bundled in the runtime. Check the runtime release notes for the preinstalled versions before pinning your own.
- Using an ML runtime for plain ETL. It works, but it carries libraries you do not need and can slow cluster startup.
- Assuming Photon always saves money. Test it on your own workload before you standardize on it.
- Running an expired runtime. Databricks ends support for old versions, and these may disappear from the cluster creation list. Upgrade on a schedule, and test in a development cluster first.
Serverless compute removes this choice for you. Databricks manages the runtime and applies upgrades, which a later chapter covers.
Exercise
A nightly production job uses mostly Python UDFs and the team wants stable behavior for a year. Which runtime flavor would you choose, and would you enable Photon?
Show answer
Choose an LTS runtime, because it is supported longer and needs fewer upgrades. Leave Photon off by default, because Python UDFs do not run in Photon and the higher DBU rate would add cost with little speedup. Test with Photon only if the job also has heavy SQL or DataFrame stages.