Databricks · Performance

Diagnosing a Slow Databricks Job: Skew, Shuffle or Data Skipping?

A practical guide to finding the bottleneck in a slow Databricks job (data skew, excessive shuffle or poor data skipping) before adding more compute.

Pandiarajan KuppusamyAssociate Technical Architect - Data & Analytics at iLink Digital5 min read
Data engineer reviewing a Databricks job on a laptop in a data centre

Key takeaways

  • Check first whether the time went into compute setup or into execution.
  • Skew: a few tasks do most of the work. AQE splits skewed partitions only in sort-merge and shuffle-hash joins.
  • Shuffle: filter rows and columns before joins, and check shuffle read/write and spill before changing partition settings.
  • Data skipping: liquid clustering is the recommended layout for new tables and replaces partitioning and ZORDER.
  • Increase compute only after the execution evidence shows that compute capacity is the constraint.

Why is your Databricks job slow?

A slow Databricks job is often caused by one of three problems: data skew, excessive shuffle, or poor data skipping. Each has a different remedy. Scaling up first can increase cost without removing the bottleneck: one oversized task can still hold up a stage, a shuffle still moves data, and a scan still reads unnecessary files.

The fastest route to a fix is to identify where time is spent, then apply the optimization that addresses that cause. Databricks provides useful automation, especially adaptive query execution (AQE), liquid clustering and predictive optimization, but each has limits.

Scaling up first can increase cost without removing the bottleneck.

Start with the evidence: How to diagnose a slow Databricks job

First check whether the time went into compute setup or into execution. For each task run, system.lakeflow.job_task_run_timeline records setup_duration_seconds and execution_duration_seconds. Use it rather than job_run_timeline, whose duration columns are only populated for legacy single-task jobs. If execution time grew, inspect the slowest stage.

SignalLikely causeWhat to inspect
One or a few tasks run much longer than the restSkewCompare max task duration with the 75th percentile; inspect partition sizes and key distribution.
Large shuffle read/write or disk spillExcessive shuffle / memory pressureStage metrics, join and aggregation plan, rows and bytes exchanged.
Many files or bytes read despite selective filtersPoor data skipping / file layoutScan metrics, filter columns, file statistics and clustering layout.
Match what you see in the slowest stage to its likely cause before changing the job.
Flow chart: check setup versus execution time, inspect the slowest stage, then match the signal to data skew, excessive shuffle or poor data skipping
Separate setup time from execution time first, then match the slowest stage to its likely cause.Illustration: iLink Digital

1. Data skew: a few tasks do most of the work

Skew occurs when a small number of keys hold a disproportionate share of the data. Those keys create oversized partitions, so a few tasks run far longer while other executors sit idle. Null, default or highly popular values are common causes.

How Databricks helps: AQE splits skewed partitions in sort-merge and shuffle-hash joins, but never in broadcast joins or full outer joins. It doesn’t apply to streaming queries, and it doesn’t touch skew in aggregations or window functions; those need a design change.

  • Inspect the key distribution and identify dominant or null keys.
  • Pre-aggregate when it reduces the rows entering a join; verify that the aggregation itself is not skewed.
  • For skew outside joins, redesign the operation, for example with salting or a two-stage aggregation.

2. Excessive shuffle: too much data moves between stages

Joins, aggregations, distinct operations and sorts can redistribute data across executors. Large shuffle volumes increase network, disk and memory pressure; spill occurs when execution memory is insufficient and data is written to disk.

Databricks approach: AQE uses runtime statistics to coalesce small partitions after a shuffle, and switches a sort-merge join to a broadcast hash join when one side is under 30 MB (spark.databricks.adaptive.autoBroadcastJoinThreshold). Separately, setting spark.sql.shuffle.partitions to auto turns on auto-optimized shuffle, which sizes the initial partition count from the query plan and input size instead of the fixed default of 200.

  • Filter rows and select only needed columns before joins.
  • Pre-aggregate when it materially reduces join input; broadcast only when the plan and table size make it suitable.
  • Check shuffle read/write, spill and the physical plan before changing partition settings.

3. Poor data skipping: reading files the query does not need

Delta data skipping uses per-file statistics (including minimum and maximum values) to skip files that cannot match a filter. It works best when the layout keeps similar values together, and Databricks’ answer to that layout problem has evolved:

Evolution of Delta table layout: partitioning, Z-ordering, liquid clustering and automatic clustering, with the limit or gain of each
From partitioning and Z-ordering to liquid clustering and CLUSTER BY AUTO: how Databricks table layout has evolved.

Databricks approach: Liquid clustering is the recommended layout for all new tables, including streaming tables and materialized views. It is generally available from Databricks Runtime 15.4 LTS, takes up to four clustering keys, and replaces partitioning and ZORDER; a table can’t combine them. Choose keys from your most common filters. On tables under 10 TB, extra keys can slow down single-column filters.

  • CLUSTER BY AUTO lets Databricks choose keys from the table’s query history and change them when the savings outweigh the cost. It needs a Unity Catalog managed table, Databricks Runtime 15.4 LTS or above, and predictive optimization.
  • Plain OPTIMIZE clusters incrementally. After enabling clustering or changing keys, run OPTIMIZE ... FULL (Databricks Runtime 16.0 and above) to recluster existing data; on large tables this can take hours.
  • Predictive optimization runs OPTIMIZE, VACUUM and ANALYZE automatically on Unity Catalog managed tables and is enabled by default. External tables still need a maintenance owner.

Putting it together: modernize the table layout

Example: a nightly query filters sales.orders by order_date and customer_id. The table is partitioned by date and Z-ordered by customer_id, but small files are accumulating and maintenance is taking longer.

SQL
-- 1. Replace partitioning with liquid clustering (Databricks Runtime 18.1+)
ALTER TABLE sales.orders
  REPLACE PARTITIONED BY WITH CLUSTER BY (order_date, customer_id);
-- Alternative on a Unity Catalog managed table with predictive optimization:
-- ALTER TABLE sales.orders REPLACE PARTITIONED BY WITH CLUSTER BY AUTO;

-- 2. Recluster existing data once (Databricks Runtime 16.0+); this rewrites the table
OPTIMIZE sales.orders FULL;

-- 3. Drop ZORDER BY from the old OPTIMIZE job (not allowed on clustered tables)

Before you change the job

  • Did setup time or execution time grow?
  • Does the longest stage show skew, heavy shuffle/spill, or excessive file reads?
  • Are clustering keys aligned with common filters, or is CLUSTER BY AUTO suitable?
  • Are dominant/null keys creating skew in joins, aggregations or windows?
  • Is predictive optimization on for your Unity Catalog managed tables, and who owns maintenance for external tables?

Conclusion: Match the optimization to the bottleneck

Improving a slow Databricks job starts with understanding where time is spent. Skew, excessive shuffle, and unnecessary file reads call for different responses. Use execution evidence to choose the right optimization, and assess whether compute capacity is still a constraint after addressing query design and data layout.

iLink Digital’s Databricks services bring together data engineering, lakehouse architecture, performance tuning, and ongoing optimization to help enterprises improve how their data platforms operate. As a Databricks Silver Partner, iLink supports both implementation and the operational work required to maintain performance as workloads grow.

Investigating recurring slow jobs or rising compute costs?

Talk to iLink’s Databricks experts about your workload and optimization priorities.

Talk to an expert

Frequently asked questions

Why is my Databricks job slow?

A slow Databricks job is often caused by one of three problems: data skew, excessive shuffle, or poor data skipping. Check first whether the time went into compute setup or into execution, then inspect the slowest stage to see which one applies.

Does adaptive query execution (AQE) fix data skew?

Only in joins. AQE splits skewed partitions in sort-merge and shuffle-hash joins, but not in broadcast or full outer joins, not in streaming queries, and not in aggregations or window functions; those need a design change such as salting or a two-stage aggregation.

Should a new Delta table use liquid clustering or partitioning?

Liquid clustering is the recommended layout for all new tables. It is generally available from Databricks Runtime 15.4 LTS, takes up to four clustering keys and replaces partitioning and ZORDER; a table cannot combine them.

About the author

Pandiarajan Kuppusamy

Pandiarajan Kuppusamy

Associate Technical Architect - Data & Analytics at iLink Digital

With over a decade of experience in data engineering, Pandiarajan Kuppusamy works at the intersection of data architecture, platform engineering, and technology delivery. He specializes in building scalable data solutions across Azure Databricks, Azure Data Factory, and Microsoft Fabric, bringing together architectural thinking and hands-on engineering expertise. His work spans the full data solution lifecycle, from architecture and implementation to leading teams in building reliable, high-performing data platforms.

Together,
let’s focus on real

Start The Conversation