Quick revision
The short answer
When 199 of 200 tasks finish in 20 minutes and one runs for 5 hours, the cause is almost always data skew: one key, such as a very large business customer, holds a big share of the rows, and after the shuffle one task owns all of them. In the short term we split the hot key with salting, turn on adaptive skew handling where the engine supports it, or process the largest customers on a separate path. In the longer term we make the job incremental, partition its input by date and customer, alert at the expected finish time, and track per-task duration and input size per key.
What to remember
In this answer, we saw that one task running far longer than the rest points to data skew, where one huge customer's rows land in one task after the shuffle. We met tomorrow's deadline by salting the hot key, using adaptive skew-join handling where it applies, or processing big customers separately, and we stopped the slow growth by making the job incremental over date-partitioned input, adding an alert at the expected finish time and tracking per-task and per-key metrics.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
When 199 of 200 tasks finish in 20 minutes and one runs for 5 hours, the cause is almost always data skew: one key, such as a very large business customer, holds a big share of the rows, and after the shuffle one task owns all of them. In the short term we split the hot key with salting, turn on adaptive skew handling where the engine supports it, or process the largest customers on a separate path. In the longer term we make the job incremental, partition its input by date and customer, alert at the expected finish time, and track per-task duration and input size per key.
Why this question is asked
Batch jobs rarely fail suddenly; they get slower month by month until one morning they miss a deadline. This one went from 2 to 7 hours, and the executor metrics already contain the diagnosis. Interviewers ask this because reading those metrics, recognising skew and knowing both the quick fix and the structural fix is everyday senior data engineering. In this answer, we will read the metrics, explain how skew arises in a shuffle, apply short-term fixes to meet tomorrow's deadline, and then change the job so it stops growing with history.
1Reading the Executor Metrics
Spark splits a job into stages and each stage into tasks, one per partition of data, which run in parallel across executors. A stage finishes only when its last task finishes. If 199 tasks take 20 minutes and one takes 5 hours, the cluster sits mostly idle for four hours and forty minutes waiting for that one task. Adding executors cannot help, because the slow task runs on one core no matter how many cores we have.
So the question is why one task has so much more work. The Spark UI answers it: in the stage's task table, sort by shuffle read size. If the slow task read, say, 60 GB while the others read 300 MB each, the work is unevenly divided. That is data skew.
2How One Customer Ends Up in One Task
Building statements means grouping rows by customer. To group, Spark shuffles: it sends every row to a partition chosen by hashing the customer id, so all of one customer's rows meet in one task. That is correct and usually balanced, because most customers are similar in size.
But a year ago the company signed a very large business customer whose transaction count has grown steadily. If that customer now has 30 percent of all rows, the task that owns its hash partition processes 30 percent of the data alone, while 199 tasks share the rest. Every month that customer grows, the job gets slower, which matches the slide from 2 to 7 hours.
| Task | Customers | Shuffle read | Duration |
|---|---|---|---|
| 0 to 198 (each) | about 2,500 each | about 300 MB | about 20 minutes |
| 199 | about 2,500, including customer 81442 | 60 GB | 5 hours |
3Short-Term Fixes for Tomorrow's Deadline
The first fix is salting. We add a random suffix to the hot key so its rows spread over many partitions, aggregate each piece partially, and then combine the partial results by the real key. It works for any computation that can be split and combined, such as sums, counts and per-month subtotals.
Notice that we salt only the known hot keys; salting every key multiplies the rows for no benefit. Where the slow stage is a join rather than an aggregation, Spark's adaptive query execution can split skewed join partitions automatically with spark.sql.adaptive.enabled and spark.sql.adaptive.skewJoin.enabled, which are on by default in recent Spark 3 versions (check yours). For statement steps that cannot be combined, such as rendering one document per customer, the cleanest fix is a separate path: process the few largest customers in their own job, split by account or by month, and run the rest as before.
4Making the Job Incremental
Salting gets us under the deadline, but the job still recomputes all history every night, so it will keep growing. Most of a customer's statement data does not change from one night to the next: last month's transactions are final. An incremental job processes only new or changed data each day and merges it into the previous result. For example, it computes yesterday's per-customer, per-month subtotals and adds them to the stored totals, then renders statements from those totals.
To make that cheap, the input must be partitioned by date, and ideally by customer bucket, so the job reads only yesterday's partitions instead of scanning a year of files. Reruns also become small: if one day was wrong, we recompute that day's partition and merge again, instead of reprocessing everything.
5Seeing the Problem Before It Breaks the Deadline
The job missed its deadline twice before anyone acted because the only alert was on failure. A job that is still running at 06:00 has not failed. So we add an SLA alert at the expected finish time, for example a warning if it has not finished by 04:30 and a page at 05:30, which gives people time to act.
We also export metrics per run: duration of each stage, the slowest task divided by the median task, and input size per key for the top customers. A ratio that creeps from 3 to 15 over a few months is a clear early warning of skew, long before the deadline is at risk.
6Follow-up questions
When would moving this job to streaming be worth it?
Only if the business needs statements or balances that are fresh during the day, or if spreading the work across the day would remove a real capacity problem. Statements are produced on a schedule by nature, so an incremental batch usually gives most of the benefit at a fraction of the cost. If customers start expecting live balances, a stream that keeps per-customer running totals becomes worth it, and the nightly statement can then be rendered from those totals.
Why not just give the job a bigger cluster?
Because the slow task runs on one core. More executors make the 199 short tasks finish sooner, but they cannot split the one task that holds the giant customer. Only redistributing that customer's rows helps.
Does salting change the results?
No, as long as the operation can be combined. Sums and counts of the partial groups add up to the same totals. Operations like a median cannot simply be combined from partial medians, and need a different approach.
7Conclusion
In this answer, we saw that one task running far longer than the rest points to data skew, where one huge customer's rows land in one task after the shuffle. We met tomorrow's deadline by salting the hot key, using adaptive skew-join handling where it applies, or processing big customers separately, and we stopped the slow growth by making the job incremental over date-partitioned input, adding an alert at the expected finish time and tracking per-task and per-key metrics.
Open with
One task out of 200 running five hours while the rest finish in twenty minutes is data skew. The job groups by customer, so the shuffle sends all of a customer's rows to one task, and if one large business customer now has, say, a third of all rows, that task does a third of the work alone.
Then, if they want more
More executors will not help, because that task runs on one core. To get back under the deadline quickly, I would salt the hot keys: add a random suffix to those customers, aggregate the pieces in parallel, and combine the partial sums by the real key.
If the skewed stage is a join, I would make sure Spark's adaptive skew-join handling is on. For steps that cannot be split, I would process the few biggest customers on a separate path. Longer term, the real problem is that we recompute all history every night.
I would make the job incremental, processing only yesterday's data and merging it into stored totals, with input partitioned by date and customer bucket so reruns touch only what changed.
And I would add an alert at the expected finish time, not only on failure, plus metrics on per-task duration and input size per key, so we see skew growing months before it breaks the deadline.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "What is the likely cause, how do you get the job back under its deadline, and what...": https://scrivio-interview-library.netlify.app/architecture/storage-and-pipelines/b272354e35/