home
diamond Go Premium
Data Engineering Path  ·  PySpark

Spark Architecture: Theoretical System Design

Series Data Engineering & Distributed Systems Series
Estimated Time ~30 Mins Quiz
Quiz Overview FAANG-style senior Spark engineering scenarios covering Driver OOM collect crashes, lineage fault recovery, reduceByKey vs groupByKey shuffle boundaries, and Client vs Cluster deployment modes.

Scenario 1: Driver OutOfMemory (OOM) on `.collect()`

Problem: A PySpark job filters a 15TB dataset down to 45GB. Calling .collect() instantly crashes the Driver with java.lang.OutOfMemoryError: Java heap space.

Solution:

  1. JVM Mechanics: .collect() pulls all distributed partitions across the network into the single Driver JVM process. Since 45GB exceeds spark.driver.memory (e.g. 4GB), the Driver heap overflows and crashes.
  2. Safe Alternatives:
  3. Preview records with .take(100) or .first().
  4. Write directly to distributed storage via .saveAsTextFile("hdfs://...").
  5. Process elements inside worker executors using .foreach().

Scenario 2: Lineage Fault Recovery & Wide Dependencies

Problem: Executor 4 crashes during an active RDD write. How does Spark recover Partition 3?

Solution:

  1. Narrow Recovery: For narrow dependencies (map, filter), Spark consults the RDD lineage graph and recomputes only the single lost Partition 3 on a healthy worker node from the parent partition.
  2. Wide Shuffle Boundaries: For wide dependencies (reduceByKey), data is shuffled across nodes and written to shuffle files. Losing a partition post-shuffle requires re-executing all tasks from the entire stage preceding the shuffle.

Scenario 3: `reduceByKey` vs `groupByKey`

Problem: Auditing legacy PySpark code comparing groupByKey().mapValues(sum) vs reduceByKey(a + b).

Solution:

  1. Map-Side Combine: reduceByKey performs local pre-aggregation inside mapper buffers before network shuffle. groupByKey sends all raw key-value pairs over the network.
  2. Executor OOM Risk: On skewed datasets, groupByKey forces millions of raw values into a single executor's memory list, causing frequent JVM heap crashes.

Scenario 4: Deployment Modes (Client vs Cluster)

Mode Driver Location Network Topology & Use Case
Client Mode Local Client Terminal / Laptop High WAN latency RPCs. Ideal for interactive Jupyter notebooks & debugging.
Cluster Mode Inside Cluster Rack (ApplicationMaster) Sub-millisecond local gigabit RPCs. Essential for production ETL pipelines.
Find this content helpful? ☕ Buy me a coffee

Entity Details

Create New Item

celebration
Enjoying the free content?

Create a free account to track your progress and save your place.

Create Free Account
help

Submit Technical Query

Have a question or run into an issue? Describe it below, upload an optional screenshot, and our engineering team will answer it!

image Attach image (optional)

Submit Feedback

build Free Developer Utility Free Tool
gavel

Privacy & Legal Disclaimer

1. Client-Side Browser Processing

All utility tools on DeepEngineerHub (including Image to PDF, Text Formatters, JSON Converters, and Encryptors) execute 100% locally within your client browser using WebAssembly and JavaScript. No uploaded images, text, or documents are transmitted, collected, or stored on remote servers.

2. Limitation of Liability ("As-Is" Provision)

Tools and services are provided free of charge for convenience and educational purposes "as-is" without warranties of any kind. DeepEngineerHub shall not be held liable for any data loss, formatting inconsistencies, or indirect damages resulting from tool usage.

3. Open Source & Third-Party Software

Certain utilities utilize open-source client libraries (such as jsPDF, Mermaid.js, Pyodide) licensed under MIT, Apache, or BSD open licenses. All intellectual property remains with their respective copyright holders.