Skip to content
Tech Interview Prep
Technical interview guide

Distributed Data Processing

How frameworks like Spark parallelize work across a cluster: partitioning, shuffling, and their costs.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v5
Editorial status
Reviewed

Scope: Apache Spark 4.2 documentation, Apache Beam and Apache Hadoop current 2026-08-31.

Overview

Curated: · Written: · Reviewed:

Distributed Data Processing

In one line

Spark splits a dataset into partitions, runs one task per partition on executor cores, and pays for a shuffle whenever a step needs rows with the same key on the same machine. Reach for it when the work divides by partition and the bytes crossing the shuffle, plus the slowest partition, are what you must control.

Key definitions

  • Partition: the unit one task reads and writes. Tasks per stage equal partitions per stage.
  • Narrow dependency: each child partition reads a bounded set of parent partitions, so the operators pipeline in one stage.
  • Wide dependency: grouping, repartitioning, most joins and global sorts. Each one creates a shuffle boundary.
  • Shuffle: map-side blocks written to disk, fetched over the network, sorted or hashed, and spilled when memory runs out.
  • Lineage: the recipe for recomputing a lost partition from its parents. Checkpointing truncates it.
  • Straggler: a task far slower than the median, usually because one partition holds a hot key.

Formulas and complexity

Stage waves for P partitions on C cores:

waves=⌈PC⌉\text{waves} = \left\lceil \frac{P}{C} \right\rceil

With even tasks, stage time is about waves times per-task time. One oversized partition sets the stage time no matter how many cores you add. Driver launch floor for N tasks at launch rate r:

tlaunch≈Nrt_{\text{launch}} \approx \frac{N}{r}

20,000 tasks at 2,000 launches per second need about 10 s of driver time before any work runs, even on 200 cores where each 50 ms task finishes in a fraction of that.

How it works

Transformations build a lazy plan. An action runs it. Narrow operators stay in one stage; the shuffle boundary ends the stage. A filter on a derived expression of a non-partition column cannot prune partitions, so filter on the partition column itself.

Scan Parquet partitions Narrow: filter and withColumn Shuffle write: map blocks Shuffle read: fetch and sort Reduce: aggregate or join Write output files

The Spark UI reports shuffle write and shuffle read per stage. Read the bytes and the p50 to p99 spread of each, not just the stage total.

When to use and when not to

SituationChooseWhy
Small dimension, current statistics, fits in every executor heapBroadcast join (hint or threshold)The large side is not shuffled
Both sides largeSort-merge joinBoth sides shuffle; spill bounds memory
Hot key owns one partitionFilter invalid keys, pre-aggregate, or salt with a second aggregationOne task otherwise owns the remaining work
Reused, expensive intermediateCache or persist, then unpersistAvoids recomputing lineage per action
Long lineage, iterative job, or lost-executor recomputeCheckpointTruncates lineage; adds durable I/O
External writes under retriesIdempotent sink or attempt-aware commitRetries and speculation duplicate attempts

Traps interviewers probe

  1. Adding executors to a skewed stage. Fix: compare p50 with p99 task input. Split or salt the hot key; more executors cannot divide one partition.
  2. Raising spark.sql.shuffle.partitions to fix a slow stage. Fix: more partitions means more tasks, more scheduler work and more shuffle metadata. Set the count from bytes and target task duration, then measure.
  3. Trusting stale statistics for a broadcast. Fix: refresh ANALYZE and check the plan. A broadcast must fit in each executor heap, so cap it by size, not by hope.
  4. Non-idempotent writes under retries or speculation. Fix: key the write so a replay upserts the same rows, or commit only through an attempt-aware protocol.
  5. Caching everything. Fix: cache only reused, expensive data, and unpersist when done.

Interview tips

Open with the boundary: "The cost sits at the shuffle and in the slowest partition, so I start with bytes across the boundary and the task spread." Then name the join or aggregation type and its memory cost.

Expect these follow-ups: why a narrow dependency is cheaper than a wide one; how adaptive execution splits skewed partitions and where it does not help; what a driver loss does compared with an executor loss; how a retried task avoids duplicate output.

30-second outline:

  1. Name the stage boundary and the operator that causes it.
  2. Give the shuffle bytes and the p50 to p99 task spread.
  3. State the cause: volume, skew, stale statistics or undersized memory.
  4. Pick the fix from the table and say what it costs.
  5. Say how you verify it: the same output, a smaller tail, and the bytes that moved.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.