Learn

Open Lakehouse project

Spark Masterclass

An open, runnable online book on Apache Spark 4.3

Spark Masterclass is a free, Apache-2.0-licensed online book that teaches Apache Spark 4.3 by running it. It has 92 chapters in 14 parts, from how Spark runs your code through Spark SQL, Spark Connect, file formats, performance, Structured Streaming, lakehouse tables, Spark Declarative Pipelines, machine learning, production operations, extension APIs and engine internals. Each chapter has the exact code that ran, pinned to pyspark 4.3.0, and the real output saved next to it, including the query plans Spark printed and the metrics the Spark UI reported. The examples use one month of public New York City taxi trip data and run on a laptop.

What every chapter has

Most Spark material stops at the API. Spark Masterclass follows each call through planning, execution, storage and failure, and it shows the evidence for each step.

  • The exact code that ran. A script under code/ in the repository, pinned to pyspark==4.3.0, that produces every result the chapter states.
  • Its real output. Saved next to the script: the query plans Spark printed and the numbers the Spark UI reported.
  • Diagrams of the mechanism. Where the data goes, which operator runs, and what the engine keeps.
  • Figures and animations from saved output. So that a shuffle, a plan or a commit is visible, not only described.

What the book covers

The book has 92 chapters in 14 parts. Read it from the start, or go directly to the part about the mechanism you need to understand. Each chapter title links to the chapter in the online book.

Part I: BackgroundChapters 1 to 4

  1. 1.From MapReduce to Spark
  2. 2.Inside a Spark application
  3. 3.From RDDs to a SQL engine
  4. 4.One engine for batch and streaming

Part II: Getting startedChapters 5 to 8

  1. 5.How Spark runs your code
  2. 6.Installing Spark 4.3
  3. 7.Quick start
  4. 8.Setting Spark configurations

Part III: DataFrames and the other APIsChapters 9 to 14

  1. 9.DataFrames, columns and schemas
  2. 10.Cleaning values
  3. 11.Joins
  4. 12.RDDs today
  5. 13.pandas API on Spark
  6. 14.Datasets and Encoders in Scala

Part IV: Spark SQLChapters 15 to 23

  1. 15.The language, the catalog and the tools
  2. 16.Tables, DDL and writes
  3. 17.Hive tables and the metastore
  4. 18.Spark SQL in depth
  5. 19.Aggregation: GROUP BY, grouping sets, ROLLUP, CUBE and pivots
  6. 20.Procedural SQL
  7. 21.Time series
  8. 22.Geospatial data in Spark 4.3
  9. 23.Metric views

Part V: Spark ConnectChapters 24 to 30

  1. 24.Why Spark Connect should be your default
  2. 25.Inside the Spark Connect protocol
  3. 26.Session observability
  4. 27.Spark Connect clients beyond Python
  5. 28.Building an application on a Connect client
  6. 29.Writing a Spark Connect client
  7. 30.Spark Connect in production

Part VI: Files, formats and data sourcesChapters 31 to 39

  1. 31.Files as files, globs and metadata
  2. 32.Text, logs and CSV
  3. 33.JSON: inference, drift and quarantine
  4. 34.Structs, arrays, maps and higher-order functions
  5. 35.VARIANT: landing, profiling and editing
  6. 36.XML, Avro and Protobuf
  7. 37.Documents, images, audio and tables for blobs
  8. 38.Spark on object storage
  9. 39.Databases over JDBC

Part VII: PerformanceChapters 40 to 47

  1. 40.Reading query plans
  2. 41.Statistics, the cost-based optimizer and partition pruning
  3. 42.Partitions, caching, memory and spill
  4. 43.Python on Spark
  5. 44.Python UDTFs
  6. 45.Parquet and ORC from the inside
  7. 46.Project Feather
  8. 47.Acceleration

Part VIII: StreamingChapters 48 to 53

  1. 48.Structured Streaming fundamentals
  2. 49.Streaming messy data
  3. 50.Stateful processing with transformWithState
  4. 51.Real-time Mode
  5. 52.Inside a checkpoint and the state store
  6. 53.Kafka with Spark in depth

Part IX: Lakehouse tablesChapters 54 to 55

  1. 54.Tables: Delta and Iceberg, MERGE and time travel
  2. 55.Apache Iceberg with Spark

Part X: Declarative PipelinesChapters 56 to 62

  1. 56.Your first ETL pipeline
  2. 57.The spark-pipelines CLI and the project
  3. 58.Configuring a pipeline
  4. 59.Declarative Pipelines
  5. 60.Medallion in practice
  6. 61.Change data capture
  7. 62.A pipeline end to end, and how SDP runs it

Part XI: Machine learning and applied algorithmsChapters 63 to 69

  1. 63.ML pipelines with MLlib, tracked in MLflow
  2. 64.MLlib beyond regression
  3. 65.Text analytics without an LLM
  4. 66.Similarity search
  5. 67.Entity resolution and connected components
  6. 68.Sketches: HLL, Theta and KLL
  7. 69.Calling models and services from Spark

Part XII: Running Spark in productionChapters 70 to 78

  1. 70.Submitting applications
  2. 71.Securing Spark
  3. 72.Determinism, retries and fault injection
  4. 73.Shipping Python dependencies
  5. 74.Observability
  6. 75.Testing and debugging PySpark
  7. 76.Spark on Kubernetes with the Spark Kubernetes Operator
  8. 77.Orchestrating Spark
  9. 78.Writing Spark pipelines with agents

Part XIII: Extending SparkChapters 79 to 87

  1. 79.Python data sources I
  2. 80.Python data sources II
  3. 81.Python data sources III
  4. 82.Python data sources IV
  5. 83.Shipping a source
  6. 84.A DSv2 connector in Java
  7. 85.Catalyst extensions
  8. 86.Spark Connect plugins
  9. 87.Capstone: your own connector

Part XIV: InternalsChapters 88 to 92

  1. 88.How Catalyst plans Python
  2. 89.The Python worker protocol
  3. 90.The VARIANT binary format
  4. 91.From wrong results to a fix
  5. 92.Building Spark from source

How to run the examples

Every example is designed to run on a laptop. The chapter environment pins pyspark==4.3.0, and the data is one month of public New York City taxi trip records, which the setup script downloads (the repository does not redistribute it).

Requirements:

  • Python 3.11 or later
  • Java 17, 21 or 25
  • uv, for the chapter environment
  • A POSIX shell for the data and utility scripts
git clone https://github.com/open-lakehouse/spark-masterclass && cd spark-masterclass
./code/common/get_data.sh   # one month of NYC taxi trips
cd code && uv sync          # creates the environment with pyspark 4.3.0
uv run python ch07/quickstart.py

Some chapters need more: Docker for catalogs, Kafka or Kubernetes with kind, extra Maven packages, or an NVIDIA GPU. Each chapter states its requirements at the start.

How the book is verified

Each technical result in the text comes from a script in the repository's code/ directory, and the output of that script is saved next to it. When the book quotes a query plan, a row count or a Spark UI metric, the saved output is the source. The prose is written in ASD-STE100 Simplified Technical English, a controlled language for technical text, and the repository includes a checker for it.

Frequently asked questions

What is Spark Masterclass?
Spark Masterclass is a free, open-source online book about Apache Spark 4.3. It explains how Spark plans and runs work, from DataFrames and SQL to Spark Connect, Structured Streaming, Spark Declarative Pipelines and engine internals, and it backs every technical result with runnable code and saved output.
Which version of Apache Spark does Spark Masterclass cover?
Apache Spark 4.3. The example environment pins pyspark==4.3.0, so the plans and output in the book come from that release.
What does Spark Masterclass cover?
92 chapters in 14 parts: Background, Getting started, DataFrames and the other APIs, Spark SQL, Spark Connect, Files, formats and data sources, Performance, Streaming, Lakehouse tables, Declarative Pipelines, Machine learning and applied algorithms, Running Spark in production, Extending Spark, and Internals.
How are the examples in Spark Masterclass verified?
Each technical claim is tied to a script in the repository's code/ directory and to the output that script saved, including printed query plans and Spark UI metrics. A reader can run the same script and compare the result.
Do I need a cluster or a managed platform to follow Spark Masterclass?
No. The examples are designed to run on a laptop with Python 3.11 or later, Java 17, 21 or 25, and uv. Some chapters need more, such as Docker for catalogs, Kafka or Kubernetes with kind, extra Maven packages, or an NVIDIA GPU; each chapter states its requirements at the start.
Is Spark Masterclass free?
Yes. The book is free to read online and its text and code are licensed under the Apache License 2.0, the same license as Apache Spark. Corrections are accepted as GitHub issues or pull requests.

Keep going