Distributed Compute · Knowledge Base

Apache Spark

Spark from the internals out. Jobs, stages, and tasks; the structured APIs and Spark SQL; shuffles, skew, and tuning — and the streaming, lakehouse, and production patterns interviews actually probe.

30 chapters4 levelszero → advanced
Start
01

Foundations

6 chapters
02

Structured APIs & Spark SQL

8 chapters
07

Reading & Writing Data: Sources & File Formats

Data sources and formats (CSV, JSON, Parquet, ORC, Avro), schema inference vs explicit schemas, partitioned reads/writes, and save modes.

Parquet/ORCCSV/JSONSchemaPartitioned I/OSave modes
Read chapter →
08

Core DataFrame Operations

The everyday API: select/selectExpr and filter for rows and columns, withColumn/lit/cast/when to shape them, and sort/distinct/limit — plus the null and dedupe traps, chained into a readable, performant pipeline.

select/filterwithColumn/castwhen/otherwisesort/distinctChaining
Read chapter →
09

Working with Different Data Types

Strings, dates and timestamps, nulls, and complex types (arrays, maps, structs), plus regex and type casting.

StringsDates/timestampsNullsArrays/maps/structsCasting
Read chapter →
10

Aggregations & Grouping

groupBy and agg, multiple aggregations, rollup and cube, and pivot tables at scale.

groupByaggrollup/cubepivotAggregate functions
Read chapter →
11

Joins in Spark

Join types (inner, outer, semi, anti) and the join strategies Spark picks: sort-merge, shuffle-hash, and broadcast.

Join typesSort-mergeShuffle-hashBroadcastJoin keys
Read chapter →
12

Window Functions

Ranking, lead/lag, and running aggregates over partitions, with window frame specifications.

Rankinglead/lagRunning aggregatesFramesPartition by
Read chapter →
13

Spark SQL & the Catalyst Optimizer

SQL over DataFrames and temp views, and how Catalyst turns a query into a plan: parse → analyze → optimize → physical, with pushdown and pruning.

Spark SQLTemp viewsCatalystLogical/physical plansPushdown
Read chapter →
14

UDFs & the Pandas API on Spark

User-defined functions, pandas/Arrow UDFs, the Pandas API on Spark, and why to prefer built-ins over UDFs.

UDFspandas UDFsArrowPandas APIWhen to avoid
Read chapter →
03

Execution, Performance & Tuning

10 chapters
15

How Spark Runs on a Cluster

The execution lifecycle end to end: application, jobs, stages, and tasks; the DAG scheduler and shuffle boundaries.

ApplicationDAG schedulerStagesTasksShuffle boundary
Read chapter →
16

Partitioning & Parallelism

Partitions as the unit of parallelism: repartition vs coalesce, partition sizing, and partition pruning.

PartitionsrepartitioncoalesceSizingPruning
Read chapter →
17

The Shuffle: Spark's Performance Killer

What triggers a shuffle, how shuffle read/write works, where it spills, and the strategies that reduce or avoid it.

Wide depsShuffle read/writeSpillAvoiding shufflesPre-aggregation
Read chapter →
18

Data Skew & Salting

Detecting skew in the Spark UI and fixing straggler tasks with salting, isolate-and-broadcast, and AQE skew joins.

SkewStragglersSaltingIsolate-broadcastAQE skew
Read chapter →
19

Caching, Persistence & Checkpointing

cache and persist, storage levels, when caching helps or hurts, and truncating long lineage with checkpointing.

cache/persistStorage levelsWhen to cacheCheckpointingLineage
Read chapter →
20

Broadcast Joins, Shared Variables & Bucketing

Broadcast joins for dimension lookups, broadcast variables and accumulators, and bucketing to avoid shuffles on writes.

Broadcast joinBroadcast varsAccumulatorsBucketingDimension lookups
Read chapter →
21

Memory Management & Tungsten

The executor memory model (execution vs storage), off-heap memory, Tungsten code generation, and diagnosing OOM and spills.

Memory modelOff-heapTungstenCodegenOOM/spill
Read chapter →
22

Adaptive Query Execution & Cost-Based Optimization

Runtime optimization with AQE (coalesce partitions, skew joins, join switching) and cost-based optimization from table statistics.

AQECoalesceSkew joinJoin switchCBO/stats
Read chapter →
23

Performance Tuning & Debugging with the Spark UI

A repeatable tuning method: reading the Spark UI, the configs that matter, finding bottlenecks, and fixing the small-files problem.

Spark UIKey configsSmall filesBottlenecksTuning method
Read chapter →
24

Spark Configurations

The configs that actually matter and how to size them: executor cores/memory/overhead, partitions, AQE, and worked example configs for 10 GB, 500 GB, and 10 TB jobs, with the formulas to derive your own.

executor memory/coresoverheadshuffle partitionsSizing formulas10GB/500GB/10TB
Read chapter →
04

Streaming, Lakehouse & Production

6 chapters