Data Engineering Reference/Distributed Batch Compute

MapReduce to DAG Execution

Map/Shuffle/Reduce lineage, DAG schedulers, narrow vs wide transformations, and why Spark replaced raw MapReduce for most workloads.

3/5Overview: 30m

MapReduce in one minute

  1. Map — read split, emit (key, value) pairs in parallel
  2. Shuffle — sort/group by key across the cluster (expensive network I/O)
  3. Reduce — aggregate per key

Bottleneck: shuffle moves all data across the network. Everything since MapReduce optimizes what gets shuffled and when.

DAG execution engines

Spark, Flink batch, Tez, Beam — all compile a DAG of stages:

ConceptMeaning
TransformationLazy operation (map, filter, join) — builds DAG
ActionTriggers execution (count, write)
StageGroup of tasks separated by shuffle boundaries
TaskUnit of work on one data partition

Narrow transformations (map, filter) — no shuffle, pipelined in one stage. Wide transformations (groupBy, join) — shuffle required, new stage.

Why Spark won

  • In-memory caching between stages (vs MapReduce always to disk)
  • Generality — same engine for SQL, ML, streaming
  • Lazy optimization — Catalyst optimizer sees full DAG

MapReduce still matters conceptually — interviewers say "shuffle" and mean the same network pain.

Cluster roles (YARN/K8s)

ComponentRole
DriverBuilds DAG, schedules tasks, collects metadata
ExecutorRuns tasks, holds cached partitions
Cluster managerAllocates containers/pods

Link to OS: executors are JVM processes with heap limits — OOM kills tasks.

Link to Databases

Reading Parquet from S3 is partition pruning at file level — the DAG engine skips directories. Storage layout (Topic in Databases) and compute partitioning (here) must align.

Interview answer template

"Word count is map → shuffle by word → reduce. The shuffle is O(data) network. I'd partition input by hash upfront if the downstream join key is known — co-locate early to skip a shuffle."

Further Reading

Hands-On Tasks (Optional)

Pipeline design drills and whiteboard exercises — DAG sketches, partition plans, backfill strategies. Assumes Databases and SQL fundamentals are in place.

  • Sketch a word-count DAG

    Draw stages for: read text → tokenize → map to (word,1) → shuffle by word → reduce sum. Mark which steps are narrow vs wide transformations.

    15m