The batch processing mental model
Batch processing in partition terms. Learn what a partition, a shuffle and a spill are, why "the job is slow" resolves into four named causes — skew, partition count, spill, over-scan — and why the write side carries one invariant: same date twice, same output.
At a glance
| When | Starting with batch processing on Spark; Turning 'the job is slow' into a named cause |
|---|---|
| Where | Batch Processing |
| Why | Batch failures cluster into four named causes — skew, partition count, spill, over-scan — and the write side has one invariant, so the mental model turns vague slowdowns into diagnoses. |
Learning objectives
- Name the four causes of a slow batch job: skew, partition count, spill, over-scan
- Explain what a shuffle does to a hot key
- State the idempotent-write invariant for re-runnable batch jobs
What you need
- A Spark job to inspect — its Spark UI stage view or event log
- The output table's partition layout (dt=... or equivalent)
Steps
- Batch processing recomputes per logical partition: `INSERT OVERWRITE partition(dt=...)` or Delta/Iceberg replace-where replace that partition atomically. (from pattern-idempotent-partition-overwrite )
- Never append to a partition you can recompute — the invariant is that running the same date twice yields identical output. (from pattern-idempotent-partition-overwrite )
- A shuffle moves data by key, and key skew on a join or group-by key is the first cause of a slow stage. (from runbook-spark-job-slow )
- The second cause is partition count: too few partitions after a filter, or too many after a shuffle. (from runbook-spark-job-slow )
- The third cause is spill to disk from an oversized partition. (from runbook-spark-job-slow )
- The fourth cause is reading far more data than needed (missing partition filter). (from runbook-spark-job-slow )
- When a job skews or slows, check the config reference and the tuning guide before changing code. (from ref-spark-docs )
Check yourself
- You can name the four causes of a slow batch job: key skew, partition count, spill, over-scan.
- A re-run for dt=2026-09-01 overwrites that partition and produces identical output.
Worked example
The four causes of a slow batch job — from runbook-spark-job-slow
- Key skew on a join or group-by key
- Too few partitions after a filter, or too many after a shuffle
- Spill to disk from an oversized partition
- Reading far more data than needed (missing partition filter)
The idempotent batch write — from pattern-idempotent-partition-overwrite
INSERT OVERWRITE partition(dt=...) # or Delta/Iceberg replace-where
The invariant: running the same date twice yields identical output.
Where the exact semantics live — from ref-spark-docs
Spark SQL, the DataFrame API, tuning and the configuration catalogue,
versioned per Spark release. The config reference alone resolves most
tuning debates.
Sourced from
Security scan
Last sweep 2026-10-24: 0 finding(s), 0 marked as examples.
Common gotchas
- Too few partitions after a filter, or too many after a shuffle: both look like 'Spark is slow'.
- Spill shows up as slow tasks, not failures — check spill bytes before paying for bigger executors.
- An empty partition and an absent partition both read as 'no data' downstream.
Production considerations
- Baseline shuffle/spill/scan metrics per run so regressions are visible before users feel them.
- Store the logical date explicitly as a partition column, not derived at read time.
Diagram
batch job
|
|- read --> partitions (unit of parallelism)
|
|- shuffle by key --> hot key --> skew
| > oversized partition --> spill to disk
|
|- scan --> missing partition filter --> over-scan
|
|- write --> INSERT OVERWRITE dt=... --> same date twice = same output
Registry stats
| Verification | community · Oct 21, 2026 |
|---|---|
| Completeness | 81 |
| Trust multiplier | ×1.25 |
| Composite | 34.15 · adequate |
| Freshness | 3 days since last source check |
| Difficulty | beginner |
| Version | 0.1.0 |
| License | CC-BY-4.0 |
| Security flags | none |
Did this solve your problem?
The batch processing mental model