Skip to main content
All worked examplesData Engineer / Big Data
Dive Deep (Amazon)

Debugging Severe PySpark Partition Skew & Out-Of-Memory (OOM) Crashes on a 15TB Event Stream

Question: “Tell me about a complex PySpark or distributed computing bottleneck you diagnosed where standard cluster scaling failed.”
Illustrative composite pattern — tailor it with your own project history.Adapt this question in Story Studio

1. Situation & Stakes

A nightly PySpark batch job aggregating 15TB of clickstream and checkout events across 120 worker nodes repeatedly failed with java.lang.OutOfMemoryError: Java heap space and executor heartbeat lost.

Scale & Timeline: Nightly 04:00 AM SLA failing consistently for 4 consecutive days, stalling executive attribution reports; processing 15TB uncompressed JSON across 120 m5.4xlarge AWS EMR instances.
Business Risk: The business lost visibility into $18M in daily campaign revenue, and compute costs ballooned by $1,800/night from repeated failed retries.

2. Task & Ownership Mandate

I took lead responsibility for diving into the Spark UI DAG visualization, identifying the root cause of the task straggler skew, and restructuring the join architecture to guarantee stable sub-hour completion.

Success Criteria: Job completion in under 60 minutes with zero executor OOM drops and a 50%+ reduction in AWS EMR cluster compute hours.

3. Technical Action & Trade-Offs

  • Inspected the Spark UI Stage breakdown: discovered that while 1,999 tasks completed in under 45 seconds, a single straggler task processed 142GB of shuffle data due to 38% of records having a null or guest customer_id.
  • Implemented two-phase salted key joins: appended a random salt (0 to 19) to skewed keys in the probe table, replicated the dimension lookup table with 20 salted rows, and aggregated in two parallel stages.
  • Tuned Adaptive Query Execution (AQE): enabled spark.sql.adaptive.skewJoin.enabled and tuned spark.sql.adaptive.skewJoin.skewedPartitionFactor to 3.
  • Eliminated memory spills to disk by increasing spark.sql.shuffle.partitions from default 200 to 2,400, aligning partition sizes to an optimal 128MB.
Key Architectural Trade-Offs
  • Switched from SortMergeJoin to BroadcastHashJoin for dimensions under 100MB by bumping spark.sql.autoBroadcastJoinThreshold to 64MB.
  • Configured KryoSerializer instead of default Java serialization, reducing shuffle payload serialization overhead by 32%.

4. Quantified Results

  • Slashed end-to-end execution runtime from 8.2 hours (with frequent failures) down to 24 minutes (95% performance improvement).
  • Reduced EMR cluster footprint from 120 nodes down to 48 nodes, saving $28,500/month ($342,000/year).
  • Achieved 100% SLA reliability over the subsequent 6 months without a single OOM failure.

Business Impact: Restored daily executive marketing attribution by 05:00 AM, unblocking the performance marketing team to optimize high-yield ad spend.

5. Executive Reflection (Learning Agility)

  • Executive Hindsight: In hindsight, throwing larger AWS EC2 hardware at distributed computing problems is an anti-pattern. Analyzing Spark UI shuffle read bytes always isolates the algorithmic flaw.
  • Learning Agility: Deepened my intuition for distributed hash partitioning mechanics, data salting math, and the power of Spark 3.x Adaptive Query Execution.
  • Systemic Impact: Built the standard cluster sizing and AQE baseline configuration template now packaged into our company-wide Terraform EMR module.

Interviewer Follow-Up Probes (Prepare for These Next)

  • Q1.How did you choose the number of salt buckets (0-19) vs a larger number like 100?
  • Q2.Why did BroadcastHashJoin fail when the dimension grew beyond 100MB?
  • Q3.How does Spark AQE dynamically coalesce and split skewed shuffle partitions at runtime?
Make It Authentic

Turn your own real project into this format

Never memorize someone else's story. Log your metrics in Karyika and synthesize an authentic, first-person STARR response.

Adapt in Story Studio