CertSafari
    Databricks Certified Data Engineer Associate· Lessons

    Domain 6 · Lesson 27/33

    Spark UI stage metrics: diagnosing skew, spill, shuffle and I/O bottlenecks

    Identify common performance bottlenecks such as data skew, shuffling, and disk spilling by interpreting stage-level metrics in the Spark UI

    19 min read
    2% of exam
    10 sources
    Published 22 Oct 2026
    Docs as of 17 Oct 2026

    What you will be able to do

    • Find the longest stage of a slow job and read its Input, Output, Shuffle Read and Shuffle Write columns and its task count
    • Recognise spill in the stage details and choose a fix that matches its cause
    • Tell data skew apart from other slowdowns by comparing the Max task metric with the 75th percentile in Summary Metrics
    • Explain when adaptive query execution splits a skewed partition and when the skew stays
    • Diagnose a slow stage that has no skew or spill: a single task, an I/O-bound stage, or an expensive operator in the SQL DAG

    Key concept

    Longest-stage diagnosis — Most of a slow job's runtime usually sits in one or a few stages. Find the longest one, then read its I/O columns, task count and per-task distribution to name the cause: spill, skew, heavy I/O or missing parallelism.

    1.Reading the longest stage in the Spark UI

    A slow job is easier to fix after you find the one stage that takes most of its time. Code tells you what the job should do. The Spark UI tells you what the cluster actually did: which jobs ran, how long each stage took, how much data moved and where tasks failed. Diagnosis follows a fixed order. Open the jobs timeline, look at the longest stage, check it for skew or spill, check whether it is I/O bound, and only then look for other causes. The timeline can also show failing jobs, long gaps between jobs, or many small jobs. Each of those patterns has its own diagnosis and does not lead into the stage-level steps below.

    To find the longest stage, open the longest job, scroll to the stage list at the bottom of the job page and sort it by duration. Four columns give a first view of where that stage's time goes. Write the numbers down, because the I/O check later uses them.

    I/O columns on the job page's stage list
    ColumnWhat it measures
    InputData the stage read from storage, such as Delta Lake, Parquet or CSV files
    OutputData the stage wrote to storage
    Shuffle ReadShuffle data the stage read
    Shuffle WriteShuffle data the stage wrote

    The task count is the next thing to check, and it splits the investigation in two. A stage with one task has no parallelism: one core does all the work and the rest of the cluster waits. That case has its own diagnosis, covered below. A stage with many tasks needs a closer look, so click its description to open the stage page. The stage page shows spill statistics at the top and per-task Summary Metrics further down.

    Checkpoint 1 of 10· Put it in order

    A Databricks job runs far longer than it used to. Put the Spark UI diagnosis steps in the order that Databricks' Spark UI guide fixes.

    1. 1.Open the stage page and check it for skew or spill
    2. 2.Use the recorded I/O numbers to decide whether the stage is I/O bound
    3. 3.Find the longest stage of the longest job and note its I/O columns and task count
    4. 4.Open the jobs timeline to spot major issues such as failing jobs, gaps or many small jobs
    5. 5.Look for other causes of the slow stage runtime

    Sources12

    2.Spill: when execution memory runs out

    Spill means Spark ran low on execution memory and wrote data to disk. Spark uses execution memory for shuffles, joins, sorts and aggregations. When the data for one of those operations doesn't fit, Spark writes the overflow from memory to disk and reads it back later. That round trip can be expensive. Spill is most common during shuffles, so a large sort-merge join or a wide aggregation is the usual place to find it.

    Check for spill before skew. When a stage has spill, the stage details at the top of the stage page show spill statistics, as Spill (Memory) and Spill (Disk) values, next to metrics such as Peak Execution Memory. If no spill statistics appear, the stage has no spill. A spilling stage still completes. It is just slow, and that separates it from a memory failure. When executors run out of memory, Spark removes them and retries their tasks, and repeated failures fail the stage. A stage that completes slowly and shows spill is a spill problem, not an out-of-memory problem.

    Each fix for spill targets a different cause:

    • Too few shuffle partitions for the data: set spark.sql.shuffle.partitions=auto so Spark chooses the partition count from the query plan and input size.
    • Too much data per row or per query: process fewer rows or columns, or shrink large strings, arrays, maps and structs.
    • Not enough memory: total executor memory sets how much fits before Spark spills, so use instances with more memory. For complex batch ETL that joins many tables, use fewer, larger workers to shuffle less data.
    • Oversized streaming micro-batches: limit the input rate of the Structured Streaming query.

    Checkpoint 2 of 10· Check yourself

    A sort-merge join stage finishes, but it now takes 40 minutes instead of 8. The top of its stage page shows non-zero Spill (Memory) and Spill (Disk) values, and no executors were removed. What does this tell you about the stage?

    Checkpoint 3 of 10· Exam question

    A data engineer is troubleshooting a slow stage that performs a large sort-merge join. In the stage detail page of the Spark UI, the Summary Metrics show non-zero values for both Spill (Memory) and Spill (Disk), and the stage takes far longer than similar joins on smaller datasets. What is the most likely cause of this behavior?

    Sources34

    3.Data skew: reading the task distribution

    Skew means one or a few tasks run much longer than the rest of their stage. While those tasks finish, the other cores sit idle. Cluster utilisation drops, and the stage lasts as long as its slowest task. You can't see this in the stage's total duration. You can see it in the distribution of per-task metrics.

    To check for skew, scroll down to Summary Metrics on the stage page and compare the Max column with the 75th percentile. In a healthy stage the two are about the same. If Max exceeds the 75th percentile by 50% or more, the stage may have skew. Take a stage whose median task takes 3 minutes, 75th percentile 4 minutes and Max 12 minutes. Max is three times the 75th percentile, far past the 1.5× line. A few tasks carry much more data than their peers. Spill would show up in the spill statistics. A slow cluster or broken autoscaling would slow every task, not just a few.

    The same comparison works for data size as well as time. In a groupBy stage where most tasks read 2–3 MB of shuffle data and a handful read over 500 MB, the rows were partitioned by key, so the large partitions belong to a few hot keys holding most of the records. Shuffle partitioning sends all rows with the same key to the same task. A key with a disproportionate share of rows therefore produces one very large partition, however many partitions there are.

    Pick the fix based on where the skew comes from:

    • Hot keys in a join or aggregation: salt them. Append a random bucket suffix to the skewed keys, then group and aggregate in two stages. The suffix turns one hot key such as US into several distinct keys such as US_0, US_1 and US_2, so its rows hash to different partitions and several tasks share the work. Because those pieces are now separate groups, each holds only a partial result, and the second aggregation stage combines them back into one result per original key.
    • Skew built into how a stored table is laid out: use liquid clustering. It is Databricks' way of organising a Delta table's data files by chosen clustering keys, and it is recommended in place of partitioning for new Delta tables. Databricks lists tables with a significantly skewed data distribution among those that benefit from it.
    • Skewed output partitions in a stage that writes a table: use the REBALANCE hint, which splits oversized output partitions. Spark ignores this hint when AQE is not enabled.

    Checkpoint 4 of 10· Match them up

    Each slow stage below has a different root cause. Match each one to its recommended fix.

    Tap a term, then the definition that fits it.

    Checkpoint 5 of 10· Exam question

    A data engineer notices that one stage in a Spark job takes far longer to finish than the surrounding stages. In the Spark UI's Stages tab, the stage detail page shows a Max task duration of 12 minutes while the 75th percentile task duration is only 4 minutes, and most tasks finish within 3-5 minutes. Which condition does this metric pattern most strongly indicate?

    Checkpoint 6 of 10· Exam question

    While reviewing a stage that performs a wide groupBy aggregation, a data engineer sees in the Spark UI that shuffle read size varies dramatically across tasks: most tasks read 2-3 MB of shuffle data, but a handful of tasks read over 500 MB each. What does this pattern most likely indicate?

    Sources35

    4.When adaptive query execution splits skew, and when it stays

    Adaptive Query Execution (AQE) re-optimises a query at runtime using statistics from completed stages. One of those runtime optimisations targets skewed joins. AQE detects skew from shuffle file statistics. It then splits a skewed partition into smaller pieces so that no single task gets the whole hot key.

    AQE's skew handling has limits. It works only on sort-merge joins and shuffle hash joins, and the join type decides which side it can optimise. Even then, a partition counts as skewed only if it passes both size thresholds. It must be larger than spark.sql.adaptive.skewJoin.skewedPartitionFactor times the median partition size (default 5.0). It must also be larger than spark.sql.adaptive.skewJoin.skewedPartitionThresholdInBytes (default 256MB). A partition that is ten times the median but only 100 MB fails the byte threshold, so AQE leaves it alone.

    So skew can stay even when AQE is on. You see it as a Max task metric that is still far above the 75th percentile in Summary Metrics. To find the operator involved, open the job's Associated SQL Query and click the operators in the DAG. Each one reports metrics such as output rows, peak memory and spill size. If the skewed partitions fall below the thresholds, lower skewedPartitionFactor and skewedPartitionThresholdInBytes. If the join is a broadcast join, or the skew sits in an aggregation, use salting or a table-layout fix instead.

    Checkpoint 7 of 10· Check yourself

    With AQE enabled and default skew settings, a sort-merge join stage still shows Max task duration at four times the 75th percentile. The median shuffle partition is 15 MB, and the few skewed partitions are about 150 MB each. Why is the skew still there, and what should you try first?

    Sources3678

    5.Single-task stages: no parallelism to use

    A long stage with one task is a bottleneck that more hardware can't fix. One CPU does the work and the rest of the cluster may sit idle. The cause is almost always something in the code or the input that forces the data into one partition. Find the cause, and the fix follows from it.

    Common causes of a single-task stage and their fixes
    CauseWhy it makes one taskFix
    Expensive UDF on small dataSmall input can land in one partitionRewrite with native functions, or repartition() before the UDF
    Window function without PARTITION BYThe window spans the whole datasetAdd a PARTITION BY clause if the logic allows
    Unsplittable file type such as gzipEach file is read by one taskIngest the files once into a Delta table and query that
    multiLine on JSON or CSV readsA record may cross line boundaries, so Spark can't split the file and one task must read each whole fileSet multiLine only when records span lines
    Schema inference on a large fileInference reads the file in one passSpecify the schema
    repartition(1) or coalesce(1)Forces all data into one partitionRemove them, unless you need a single output file

    Checkpoint 8 of 10· Match them up

    Four long stages each run exactly one task. Match each code or input pattern to the fix that restores parallelism.

    Tap a term, then the definition that fits it.

    Sources9

    6.I/O-bound stages and shuffle volume

    After you rule out skew and spill, a stage with many tasks can still be slow simply because it moves more data than the cluster can handle in the time available. A rule of thumb tests for this: each CPU core reads and writes about 3 MB per second. To apply it, take the largest of the stage's four I/O columns, divide by the total number of cores across all workers, then divide by the stage duration in seconds. A result around 3 MB per second means the stage may be I/O bound.

    Here is a worked case. A stage shows 90 GB of Shuffle Read on a cluster with 64 worker cores and runs for 500 seconds. 90,000 MB ÷ 64 cores ≈ 1,406 MB per core, and ÷ 500 s ≈ 2.8 MB/s. That is at the per-core ceiling. The stage is shuffle-bound, and its tasks are not stuck on some other problem.

    The column that is largest tells you which fix to try:

    • Large Input: reading is the cost. Store the data in Delta tables, use liquid clustering to improve data skipping, enable Photon, make the query more selective, or use the disk cache when the stage reads the same data repeatedly.
    • Large Output: writing is the cost. Reduce rewrites, for example by optimising a merge or using deletion vectors, and consider Photon or a larger cluster.
    • Large Shuffle Read or Shuffle Write: the stage spends its time moving data between executors for joins or aggregations. Set spark.sql.shuffle.partitions to auto so Spark sizes the shuffle from the query plan and input size.

    Checkpoint 9 of 10· Match them up

    Throughput on the longest stage of each job works out to about 3 MB per second per core. Match each I/O reading to the fix that fits it.

    Tap a term, then the definition that fits it.

    Sources10

    7.Slow stages with little I/O: finding the operator in the SQL DAG

    If a stage is slow but reads, writes and shuffles little data, the query itself is usually the bottleneck. To find which operator, open the SQL DAG by clicking Associated SQL Query at the top of the job page. Some nodes show their duration directly, and others show it when you click them. These times add up executor time across all tasks, so they are not elapsed wall-clock time, but they correlate with both elapsed time and cost. Start with the node that has the largest time.

    The type of the expensive node points to the cause:

    • A scan or write node that touches tens of thousands of files or more points to a small-file problem. Files should be at least 8 MB, and partitioning on too many columns or on a high-cardinality column is the most common cause. Running OPTIMIZE might help on reads, and Databricks also recommends enabling predictive optimization and reconsidering the file layout. On writes, optimized writes are another option.
    • A UDF node can be the bottleneck. To check, comment the UDF out and compare speed.
    • A Cartesian or nested loop join is very expensive. Confirm that it is intentional.
    • A node with few input rows and far more output rows indicates an exploding join or explode().

    For a UDF you can't replace with native functions, compare the task count with the core count. If the stage has fewer tasks than the cluster has cores, repartition before applying the UDF. Smaller partitions also lower the memory each task needs, because a task running a UDF may load its whole partition into memory.

    Repartitioning a DataFrame to the core count before applying a UDFpython
    (df
        .repartition(num_cores)
        .withColumn('new_col', udf(...))
      )

    Checkpoint 10 of 10· Fill the gap

    You can't rewrite a slow Python UDF with native functions. Its stage runs 4 tasks on a cluster with 32 cores. Which call completes the guide's sample so that every core gets work before the UDF runs?

    (df
        . ? (num_cores)
        .withColumn('new_col', udf(...))
      )

    Sources8

    Sources

    (10)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “If the jobs timeline shows failing jobs, long gaps between jobs, or many small jobs, skip the remaining steps”
      ↩︎ Reading the longest stage in the Spark UI
      “Look at longest stage Look for skew or spill Determine if longest stage is I/O bound”
      ↩︎ Checkpoint
    2. 2.
      “Scroll to the list of stages at the bottom of the job page and order them by duration”
      ↩︎ Reading the longest stage in the Spark UI
      “A single task means the stage runs with no parallelism, so only one core does the work while the rest of the cluster waits.”
      ↩︎ Reading the longest stage in the Spark UI
      “Finding the longest stage, and reading its I/O and task count, narrows the problem down to a specific cause such as spill, skew, high I/O”
      ↩︎ Key concept
      “A single task means the stage runs with no parallelism, so only one core does the work while the rest of the cluster waits.”
      ↩︎ Exam trap 3
    3. 3.
      “Spill happens when Spark runs low on execution memory, which Spark uses for shuffles, joins, sorts, and aggregations.”
      ↩︎ Spill: when execution memory runs out
      “The stage details at the top of the stage page show spill statistics when the stage has spill”
      ↩︎ Spill: when execution memory runs out
      “Total executor memory determines how much data fits in memory before Spark spills it to disk.”
      ↩︎ Spill: when execution memory runs out
      “If the Max duration exceeds the 75th percentile by 50% or more, the stage might have skew.”
      ↩︎ Data skew: reading the task distribution
      “The other cores sit idle while those tasks finish, which results in poor cluster utilization and longer jobs.”
      ↩︎ Data skew: reading the task distribution
      “If a few key values hold most of the data in a join or aggregation, append a random bucket suffix to the skewed keys”
      ↩︎ Data skew: reading the task distribution
      “Spark ignores the hint if AQE isn't enabled.”
      ↩︎ Data skew: reading the task distribution
      “adaptive query execution (AQE) splits skewed partitions automatically, but only when a partition exceeds both of its size thresholds”
      ↩︎ When adaptive query execution splits skew, and when it stays
      “adaptive query execution (AQE) splits skewed partitions automatically, but only when a partition exceeds both of its size thresholds”
      ↩︎ Exam trap 2
      “If the skew comes from how a stored table is laid out, use liquid clustering, which is suited to tables with heavy data skew.”
      ↩︎ Checkpoint
      “Broadcast joins are never skew-optimized, and the join type determines which side AQE can optimize.”
      ↩︎ Prediction
      “adaptive query execution (AQE) splits skewed partitions automatically, but only when a partition exceeds both of its size thresholds.”
      ↩︎ Checkpoint
    4. 4.
      “When executors run out of memory, Spark removes them and retries their tasks.”
      ↩︎ Spill: when execution memory runs out
      “If the stage completes but is slow and shows spill, see Skew and spill.”
      ↩︎ Exam trap 1
    5. 5.
      “Databricks recommends that you use liquid clustering instead of partitioning for new Delta tables.”
      ↩︎ Data skew: reading the task distribution
    6. 7.
      “A partition is considered as skewed if its size is larger than this factor multiplying the median partition size”
      ↩︎ When adaptive query execution splits skew, and when it stays
      “spark.sql.adaptive.skewJoin.skewedPartitionThresholdInBytes | 256MB”
      ↩︎ When adaptive query execution splits skew, and when it stays
    7. 8.
      “Click an operator to see metrics such as output rows, peak memory, and spill size.”
      ↩︎ When adaptive query execution splits skew, and when it stays
      “These times are cumulative and represent the sum of executor time across all tasks, not elapsed wall-clock time.”
      ↩︎ Slow stages with little I/O: finding the operator in the SQL DAG
      “If the query reads tens of thousands of files or more, the table might have a small file problem.”
      ↩︎ Slow stages with little I/O: finding the operator in the SQL DAG
      “Cartesian joins and nested loop joins are very expensive.”
      ↩︎ Slow stages with little I/O: finding the operator in the SQL DAG
      “a small number of input rows and far more output rows”
      ↩︎ Slow stages with little I/O: finding the operator in the SQL DAG
      “These times are cumulative and represent the sum of executor time across all tasks, not elapsed wall-clock time.”
      ↩︎ Exam trap 4
    8. 9.
      “Adding workers doesn't help, because Spark can't spread the work across them.”
      ↩︎ Single-task stages: no parallelism to use
      “Without a PARTITION BY clause, the window spans the whole dataset, so one task processes every row.”
      ↩︎ Single-task stages: no parallelism to use
      “Spark can't read files such as gzip files in multiple parts, so one large task reads each file.”
      ↩︎ Single-task stages: no parallelism to use
      “If you read the same files repeatedly, ingest them one time into a Delta Lake table and query the table instead.”
      ↩︎ Checkpoint
    9. 10.
      “Each CPU core can read and write about 3 MB per second.”
      ↩︎ I/O-bound stages and shuffle volume
      “If the result is around 3 MB per second, the stage might be I/O bound.”
      ↩︎ I/O-bound stages and shuffle volume
      “the stage spends a lot of time shuffling data between executors for joins or aggregations”
      ↩︎ I/O-bound stages and shuffle volume
      “If the Shuffle Read or Shuffle Write column is large, the stage spends a lot of time shuffling data between executors for joins or aggregations.”
      ↩︎ Checkpoint

    Spotted a mistake, or was something unclear? Tell us.