Module 5: Apache Spark Fundamentals
Overview
Apache Spark is the main processing engine in this course. This module explains why Spark replaced Hadoop MapReduce for most work, how a Spark application runs (driver, executors, cluster manager, and jobs, stages and tasks), and the key ideas you need to use it well: partitions, transformations and actions, and lazy evaluation. You then run your first Spark application, compare it with pandas on a large file, and meet Spark’s low-level RDD API.
Estimated time: about 3 hours (1 hour lecture, 2 hours hands-on)
Learning objectives
By the end of this module, you should be able to:
- Explain what Spark is and why it is faster and easier to use than Hadoop MapReduce: in-memory processing, DAG scheduling and high-level APIs.
- Describe the parts of a Spark application (driver, SparkSession, executors, cluster manager) and how Spark splits work into jobs, stages and tasks.
- Explain partitions, and how the number of partitions relates to the number of cores doing the work.
- Distinguish transformations from actions and narrow from wide transformations, and explain lazy evaluation and why shuffles are expensive.
- Create a SparkSession, read data, run transformations and actions, and monitor the work in the Spark UI.
Before class
Make sure PySpark works on your machine: follow Python environment setup and run the check-setup notebook.
Prerequisites: map, filter, reduce and lambda from Module 2, and MapReduce from Module 4.
Lecture slides
Hands-on
Spark notebooks fail with UnsupportedClassVersionError or Java gateway process exited when Java is missing or too old. PySpark 4 needs Java 17 or later. See Python environment setup → Troubleshooting.
Hello Spark
Build a SparkSession, read a large CSV, and compare running times with pandas.
Spark APIs
The RDD and DataFrame APIs, including a word-count example.
Exercises
To be added.
Further reading
- Apache Spark documentation, including the PySpark quickstart
- Spark web UI guide
- Cluster mode overview: drivers, executors and cluster managers
- Damji et al., Learning Spark, 2nd edition (O’Reilly), chapters 1–3
- Leskovec, Rajaraman & Ullman, Mining of Massive Datasets, section 2.4 on Spark and how it extends MapReduce