Optimize before you scale: Diagnosing and fixing Azure Databricks job delays
Uva Rani, Architect, AIF - Azure and Databricks
Prashant Panaskar, Senior Engineer
TL;DR:
Data teams should not treat every slow Azure Databricks job as a compute problem.
Capture evidence from baseline metrics, Query Profile, Spark UI, query history, and table metadata before changing anything.
Fix the dominant bottleneck, then rerun the same workload and verify that the right metric improved.
When an Azure Databricks job slows down, data engineering teams often add more compute because it feels like the fastest way to get back on track. That may help the next run finish sooner, but it does not explain the slowdown. The real issue may be the volume of data being read or shuffled, uneven data distribution, inefficient code execution, MERGE behavior, or time spent waiting for capacity.
Diagnosing that cause first is what makes the fix durable. It allows the data engineering team responsible for the workload to choose the smallest targeted change, keep cost under control, and reuse what it learns the next time the workload changes.
This blog post gives data teams a practical method for diagnosing a slow Azure Databricks job before resizing compute. It shows how to capture a baseline, read the execution evidence, map each symptom to a likely bottleneck, make one targeted change, and validate the result.
Use this blog as a diagnostic overview and the companion white paper for a deeper exploration of Azure Databricks performance optimization.
Start with the evidence, not the SQL
When a job is slow, do not start by reading the SQL from top to bottom. Start with what the engine actually did, because SQL shows intent while Query Profile and Spark UI show execution. Use the following sequence to move from evidence to a targeted and measurable fix:
Capture a comparable baseline, then identify the operator, stage, or waiting period that dominates the run.
Classify the bottleneck and form one testable hypothesis.
Change one thing, then rerun the same workload.
Compare the metric that should have improved.
Resize compute only when the evidence shows that capacity or memory is the limiting factor, or when a stated service-level objective justifies the additional cost.
After locating the operator, stage, or waiting period that dominates the run, use three questions to narrow the cause:
What consumed the most time or moved the most data?
What execution evidence explains that cost?
Is the user-visible delay caused by execution or by waiting for compute?
A good diagnosis starts with the dominant symptom, not the most familiar tuning knob.
Capture a baseline before changing anything
A useful baseline separates total elapsed time from execution and waiting time. It also captures data access, data movement, memory pressure, task behavior, the context of the run, and cost. To build that baseline, record the following details for each run:
Start with wall-clock runtime, execution duration, and waiting duration so you can see where the time is spent.
Record input or read bytes, files read, and files pruned to understand how the job accesses data.
Capture shuffle read and write volume along with spill bytes to assess data movement and memory pressure.
Review the spread of task durations and CPU or task time to understand the shape of execution.
Note the compute configuration, input data range or business date, runtime or warehouse size, and DBUs or another cost proxy so the run remains comparable.
Keep the comparison fair by using the same business date or a representative slice, avoiding cached-vs-cold comparisons, and not testing a query rewrite and a cluster resize at the same time. The following diagnostic workflow summarizes how to capture a comparable baseline, identify the dominant symptom, test one targeted change, and verify the result before resizing compute.

Figure 1: A simplified workflow for diagnosing and validating performance improvements
Map the symptom to the bottleneck
The table below is a good place to start when you are not sure where to look. Match what you are seeing to the relevant metrics, then use the execution profile and evidence to work out what is actually slowing the job down.
What you observe | Investigate | Likely cause | First action | Success indicators |
|---|---|---|---|---|
High read bytes | Scan operator, pruning, table metadata | Poor layout, missing or stale statistics, weak data skipping | Inspect filter selectivity, statistics and layout before choosing clustering or maintenance | Lower read bytes and better pruning |
Many small files | Table detail and table history | Fragmented incremental writes | Inspect table details and history before deciding whether compaction or automatic maintenance applies | Lower file count and scan overhead |
Large shuffle | Exchange, join, aggregate, window stages | Join, aggregation, repartition, wide rows | Reduce input, project fewer columns, verify AQE, broadcast when eligible | Lower shuffle bytes and join time |
One task is slow | Task-duration and input-size distribution | Skewed key or partition | Identify the skewed key, then assess AQE before adding a targeted strategy | Lower maximum task duration and a tighter task distribution |
High spill | Spark UI and memory pressure indicators | Memory pressure during shuffle or joins | Reduce shuffle, redesign the join, or right-size compute when evidence supports it | Lower spill bytes |
High CPU or task time | Execution path, expressions, UDFs (user-defined function) | Expensive parsing, Python UDFs, unsupported execution path | Built-in functions, Photon where eligible, precompute reused logic | Lower CPU or task time |
Slow MERGE | Target scan and file rewrite behavior | Broad match condition or poor target layout | Constrain the match when logically correct, then inspect runtime behavior and layout | Lower MERGE duration, target reads, and files read or written |
Faster but costlier | Billing and runtime for comparable runs | Oversized compute or an accepted SLA tradeoff | State the optimization goal and right-size compute when appropriate | Lower cost per comparable successful run, or a justified SLA tradeoff |
High waiting time | Query history and capacity signals | Queueing or capacity pressure | Investigate concurrency, capacity, and sizing before rewriting the query | Lower waiting duration |
Once you have narrowed down the likely cause, the next step is to read the execution evidence in more detail. The companion white paper walks through using Query Profile and Spark UI as a triage board before exploring each bottleneck in depth.
Investigate the five primary execution bottlenecks
The table above gives you a quick way to connect what you see with where to look next. Now let’s take a closer look at the five execution bottlenecks that most often sit behind those symptoms. We’ll cover waiting time and price-performance separately, since they can affect the overall result even when the execution plan itself is healthy.

Figure 2: Five primary execution bottlenecks that can slow an Azure Databricks workload
Bottleneck 1: Workload scans too much data
This happens when the workload reads far more data than the business question requires. A selective SQL filter does not guarantee a selective physical read because the table layout must allow the engine to skip irrelevant files.
You will usually see high read bytes, a large number of files being read, weak pruning, and a scan operator that dominates the profile.
Begin by checking filter selectivity, table statistics, physical layout, file counts, partitioning or clustering, and maintenance history. Review the table details and history before deciding whether compaction, clustering, or automatic maintenance is appropriate.
If the fix works, read bytes should fall, pruning should improve, and less data should enter the rest of the plan.
Bottleneck 2: Workload shuffles too much data or suffers from skew
Spark can spend a lot of time redistributing data across tasks. Joins, aggregations, windows, distinct operations, and explicit repartitioning can all introduce this movement. Skew is related, but it is a distinct pattern in which one or a few partitions create a long tail even when total shuffle volume is not the main problem.
When excessive shuffle is the problem, shuffle reads or writes dominate execution, spills occur, or the plan moves more data than the logic requires. When skew is the problem, one or a few tasks run much longer or process much more data than the rest.
Start by reducing the rows and columns that enter the shuffle, removing unnecessary repartitions, and checking whether AQE (Adaptive Query Execution) is already helping. If the evidence points to skew, identify the key or partition that creates the long tail before considering a targeted strategy such as salting. Broadcast only when the smaller side is genuinely small and stable.
A successful shuffle fix should reduce shuffle bytes and stage time. On the other hand, a successful skew fix should reduce the longest task time and tighten the spread of task durations without creating new memory pressure.
Bottleneck 3: CPU-intensive work slows execution
Sometimes read bytes and shuffle look reasonable, but task time remains high because expressions, parsing, serialization, UDFs, or an execution path that cannot use efficient native processing consume CPU.
The evidence usually appears as high task time despite moderate input and shuffle. The hot path may include expensive parsing, regular expressions, JSON handling, Python UDFs, or repeated transformations.
Where possible, replace custom logic with built-in SQL or DataFrame functions, check whether the workload can use Photon, and consider precomputing expensive expressions that are reused. Photon cannot correct unsupported APIs, UDF-heavy paths, or inefficient application logic.
If the change works, CPU or task time should fall. Check I/O, shuffle, and cost as well to make sure the improvement has not created a new problem elsewhere.
Bottleneck 4: MERGE scans or rewrites too much data
A relatively small source update can still force Databricks to inspect or rewrite a large part of the target table. In incremental pipelines, the performance problem can therefore shift from reading data to updating it.
Typical signs include MERGE duration growing faster than source volume, high target read bytes, many files being read or written, small files appearing after frequent updates, or slower downstream reads.
Begin by narrowing the target search space only when the predicate remains logically correct. Review any valid date, tenant, region, or source-system constraints along with the target layout, runtime behavior, and file health before adding custom repartitioning or write workarounds.
When the fix works, MERGE duration, target read bytes, and the number of files read or written should fall without slowing downstream queries.
Bottleneck 5: Application code performs unnecessary work
Application code can ask Spark to do work that the business logic does not need. Common examples include repeated scans, wide projections, unnecessary actions, accidental recomputation, and caching without evidence.
You may find SELECT *, repeated scans or actions, the same lineage being recomputed, unmeasured repartitions or distinct operations, or data being cached out of habit.
Start by selecting only the columns the job needs, combining repeated scans or actions, and using the Spark UI to confirm whether the same work runs more than once. Cache an expensive intermediate result only when it is reused enough to justify the memory and storage cost.
If the changes work, repeated execution and unnecessary scans should decrease. Data movement and memory pressure should also improve when they were part of the original problem.
Check factors outside the execution plan
Separate waiting time from execution time
A workload can have a healthy execution plan and still deliver poor wall-clock performance because it waits for compute capacity. This delay sits outside the five primary execution bottlenecks, but it still affects what the user experiences.
Waiting is likely to be the issue when it accounts for a significant share of total duration, especially on shared SQL warehouses or busy job compute.
Use query history to separate execution time from waiting time. If waiting is significant, investigate concurrency, capacity, and sizing before rewriting the query.
A successful change should reduce waiting duration while leaving execution behavior consistent.
Evaluate cost and price-performance
Price-performance is a validation check rather than an execution bottleneck. A workload may finish faster simply because it uses substantially more compute, so you need to judge the speed improvement against the stated SLA and cost objective.
The tradeoff deserves a closer look when runtime improves but DBUs or compute cost rise enough to weaken the value of the change across comparable successful runs.
Start by stating the optimization goal. A strict SLA may justify paying more for lower latency, while a nightly batch with a generous window may place more value on reducing DBUs.
The change is worthwhile when cost per comparable successful run improves or when the SLA clearly justifies the higher cost.
An investigation that cuts runtime from 18 minutes to 7
Take a daily incremental pipeline that reads a large event table, filters it to the current processing window, joins it with a reference dataset, and MERGEs the result into a curated Delta table.
The first run takes 18 minutes from start to finish, 16 minutes of execution and 2 minutes waiting for compute. It reads 4.8 TB across 1.9 million files, shuffles 640 GB, spills 85 GB, and has one task that runs for 9.4 minutes. Its DBU proxy is 42.
The 9.4-minute task and 640 GB of shuffle both deserve attention, but neither tells the whole story. Query Profile shows that most of the input comes from the scan, and the tasks become reasonably balanced once that scan is complete. That points to data access as the best place to start.
The working hypothesis is that the table is not organized around the pipeline’s selective filters, so Databricks is opening far more files than it needs.
To test that, we improved the table layout with an appropriate clustering strategy and made sure useful Delta statistics are available. It does not resize compute or rewrite the join in the same test.
Metric | Before | After | Result |
|---|---|---|---|
Runtime | 18 min | 7 min | Improved |
Read bytes | 4.8 TB | 620 GB | Strong improvement |
Files read | 1.9 M | 240K | Strong improvement |
Shuffle | 640 GB | 625 GB | Mostly unchanged |
Spill | 85 GB | 12 GB | Improved |
Longest task | 9.4 min | 3.1 min | Improved |
DBU proxy | 42 | 17 | Improved |
The results back up the hypothesis. Read bytes drop from 4.8 TB to 620 GB, and the number of files read falls from 1.9 million to 240,000. Runtime, spill, the longest task, and the DBU proxy improve as well. Shuffle barely changes, which is a strong sign that the join was not the main problem. The real issue was how the job accessed the data.
These numbers are only an example and should not be treated as performance thresholds. The important pattern is to compare the same metrics before and after the change and to use ranges that make sense for the workload, data volume, access pattern, runtime, and compute configuration.
Conclusion
A slow Azure Databricks job becomes easier to fix once the data engineering team responsible for the workload can describe the problem in measurable terms. High read bytes, excessive shuffle, long-running tasks, CPU pressure, spill, inefficient MERGE behavior, unnecessary code execution, waiting time, and cost each point to a different investigation.
The goal is not to apply every optimization available. It is to use the execution evidence to identify the dominant issue, make one targeted change, and check whether the metric expected to improve actually moves. This keeps the diagnosis clear and makes the result easier to trust.
For a deeper look at the techniques, metrics, and validation steps behind Azure Databricks performance optimization, read the complete white paper.
Recent Blogs

