Home / Databricks on Azure

Databricks on AzureTroubleshootingIntermediate

Azure Databricks serverless notebook and job errors: dependencies, memory and unsupported features

Code that works on a classic cluster fails on serverless. Match the error to the cause, then fix caching, Spark config, streaming triggers, library installs and out-of-memory failures.

Deepak Bhardwaj7 min read

Applies toAzure Databricks serverless compute for notebooks and jobs (Python and SQL), Unity Catalog workspaces

A notebook runs on a classic cluster and fails as soon as you attach it to serverless. Or a serverless job that has run for months stops during environment setup. Start with where it failed: before your code, in Python, or in Spark.

Note

Support on serverless changes often. Check the current limitations page and the environment version release notes before you rewrite code.

Symptom to cause

Symptom Likely cause Fix
Fails before the first line of code Dependency can't be resolved, downloaded or built Step 2
Session stops right after adding a library The library pulled in PySpark Step 2
Wheel installs on one run and fails on the next Wheel built for one CPU architecture Step 2
Error on sparkContext, .rdd or sc RDD APIs aren't supported; serverless uses Spark Connect Step 3
Error on CACHE TABLE, cache() or checkpoint() Caching is restricted Step 3
Error setting a Spark property Only a short list can be set Step 3
INFINITE_STREAMING_TRIGGER_NOT_SUPPORTED Stream has no trigger set Step 4
Python process killed, notebook loses its variables Notebook Python memory exhausted Step 5
UDF fails on memory UDF sandbox memory limit Step 5
Notebook query stops after about 2.5 hours Default execution timeout Step 6
Connection times out to a database or API Network policy or firewall Not covered here; see below

For network failures, go to serverless network design with NCCs or storage firewall 403s.

Step 1: get the real error

Serverless doesn't give you the Spark UI or the Spark driver and executor logs. Use the run output and the query profile instead.

# Full job run, to find the task run IDs
databricks jobs get-run <run-id>

# Error and trace for one task (use the task's run_id, not the parent run's)
databricks jobs get-run-output <task-run-id>

In the output, compare error and error_trace. If no line of your code appears in the trace, look at the environment first.

To find the same failure in other jobs, query the system tables:

SELECT workspace_id, job_id, run_id, task_key, period_end_time, result_state, termination_code
FROM system.lakeflow.job_task_run_timeline
WHERE period_start_time >= current_timestamp() - INTERVAL 3 DAYS
  AND result_state IN ('FAILED', 'ERROR', 'TIMED_OUT')
ORDER BY period_end_time DESC;

If unrelated jobs began failing together, suspect the package index, a base environment edit or a network policy change.

Step 2: fix dependency failures

Dependencies resolve before your code runs. Nothing in a notebook cell, including setting an environment variable, can change that resolution.

Check these in order:

  1. PySpark in the tree. Don't install pyspark or a package that depends on it. Remove it and reset the environment.
  2. File paths. Wheels must be on a /Workspace/... or /Volumes/... path that the run-as identity can read.
  3. Architecture. Compute can be x86_64 or aarch64, and can change between runs. Prefer pure-Python wheels (py3-none-any), or provide both builds.
  4. Maven, init scripts and cluster libraries. None of these carry over. Move them to the environment, or leave that job on classic compute.
  5. Unpinned versions. If nothing changed on your side, a new release probably did. Pin it.

Check the architecture and find which package asks for PySpark, from a notebook that still starts:

import platform, sys
from importlib.metadata import distributions

print(sys.version, platform.machine())

for dist in distributions():
    requires = dist.requires or []
    if any(r.lower().startswith("pyspark") for r in requires):
        print(dist.metadata["Name"], dist.version, "->", [r for r in requires if "pyspark" in r.lower()])

Ignore optional extras, marked extra ==, unless you asked for them.

Define the environment in code

For Python script and wheel tasks in a bundle, keep the environment in the job definition:

resources:
  jobs:
    nightly_load:
      name: nightly_load
      environments:
        - environment_key: default
          spec:
            environment_version: "5"
            dependencies:
              - requests==2.32.3
              - /Volumes/ops/shared/wheels/ops_lib-1.4.0-py3-none-any.whl
      tasks:
        - task_key: load
          environment_key: default
          spark_python_task:
            python_file: ../src/load.py

The versions are examples. Use the ones you tested. Notebook tasks use the settings saved in the notebook's Environment panel unless the job sets one.

Tip

If you rebuild a wheel, increase its version. Environments are cached, and the same version number can give you the old code. To clear a notebook's cache, use Reset to defaults in the Environment panel. A new session alone doesn't clear all of it.

Step 3: replace unsupported code

Classic code On serverless
sc.parallelize(rows) spark.createDataFrame(rows, schema)
df.rdd.map(...) DataFrame functions, pandas UDF or mapInPandas
df.cache() Remove it, or write an intermediate table. Newer environment versions may allow it as a preview
CACHE TABLE / REFRESH TABLE Remove it
df.checkpoint() Write to a Delta table and read it back
Global temp view Session temp view, or a table to share results
Cluster environment variable Job parameter or widget
dbfs:/ path Unity Catalog volume
${var} in SQL Parameter markers
R or Scala notebook Classic compute, or a JAR task for Scala

Most spark.conf.set calls can be deleted. At the time of writing, the properties you can set are:

  • spark.databricks.execution.timeout
  • spark.sql.ansi.enabled
  • spark.sql.files.maxPartitionBytes
  • spark.sql.legacy.timeParserPolicy
  • spark.sql.session.timeZone
  • spark.sql.shuffle.partitions

Warning

Serverless runs with ANSI mode on, and its session time zone defaults to UTC. A job that swallowed bad casts on classic can now fail, and date boundaries can move if the cluster used another zone. Compare results before you switch a production job.

Find what needs changing with a search across your repo:

Get-ChildItem -Recurse -Include *.py,*.sql,*.ipynb |
  Select-String -Pattern 'sparkContext|\.rdd\b|CACHE TABLE|\.checkpoint\(|GlobalTempView|dbfs:/|processingTime|spark\.conf\.set' |
  Select-Object Path, LineNumber, Line

Step 4: fix streaming triggers

Serverless notebooks and jobs don't run processing-time or continuous triggers. Leaving the trigger out also fails, because that's an infinite stream. Process what's available and stop:

(spark.readStream.table("ops.bronze.events")
   .writeStream
   .option("checkpointLocation", "/Volumes/ops/silver/checkpoints/events")
   .trigger(availableNow=True)
   .toTable("ops.silver.events"))

Schedule the job at the latency you need. If you need an always-on stream, use a Lakeflow pipeline or classic job compute.

Caution

Keep the same checkpoint location when you change only the trigger. A new checkpoint can reprocess the source and duplicate data in the target.

Step 5: fix out-of-memory failures

There are three separate memory pools, and only one has a switch.

Where it fails How to recognize it Fix
Notebook Python process toPandas(), collect(), pandas or ML code in the failing cell Reduce the data, then set Memory to High in the Environment panel
UDF sandbox Failure inside a Python UDF Smaller batches, less state per UDF. The limit isn't user-configurable
Spark query Large join or aggregation with no Python Filter earlier, fix skew and row explosion. High memory doesn't help here

Aggregate in Spark before you bring data to Python:

# Instead of df.toPandas() on the full table
summary = (df.groupBy("region", "status")
             .count()
             .limit(10000)
             .toPandas())

High memory has a higher DBU rate, so set it on the notebook that needs it only. Check the current preview status and sizes.

Step 6: set timeouts on purpose

Interactive notebook queries default to a 9,000-second timeout. Jobs have no query timeout by default, so a hung query runs until something stops it. Set the limit explicitly:

spark.conf.set("spark.databricks.execution.timeout", "14400")  # seconds

For jobs, also set timeout_seconds on the task.

Prevent it next time

  • Pin every dependency and the environment version in source control.
  • Mirror packages in a private index so a yanked release doesn't stop production.
  • Test environment version upgrades in dev before changing production.
  • Run the code search from step 3 in CI.
  • Set failure notifications on every serverless job.