Start studying
Module 13 · Data Engineering Basics Module contents
Module 13  ·  Card 4 / 13intermediate

Apache Spark

Apache Spark is an open source engine for processing large datasets across a cluster of machines.

It keeps data in memory between steps where it can, which makes it much faster than engines that write to disk after every step.

Code is written with DataFrames in Python, Scala, SQL or R, and Spark spreads the work across the cluster.

For example, a Spark job can join a year of website logs with customer records and total the visits per customer.

Spark plans the whole job before running it, so steps are lazy and nothing runs until a result is requested.

Learn in depth ↓
Module 13 · Data Engineering Basics · 13 concepts
In depth  /  15 lines

Apache Spark, in more detail

Apache Spark is one of the most widely used engines for large scale data processing.

It exists to make distributed processing feel close to working with a single table.

It brings batch jobs, SQL and streaming together in one engine.

A Spark application has a driver, which plans the work, and executors, which run it on the cluster's machines.

Data is held in DataFrames that are split into partitions across the executors.

Transformations, such as filter and groupBy, describe steps without running them.

Actions, such as count or writing a file, trigger the planned steps to run.

The optimiser rewrites the plan before running it, for example applying filters early so less data is read.

PySpark is the Python interface, and much of its DataFrame code looks similar to pandas.

Spark SQL lets the same data be queried with ordinary SQL.

Structured Streaming applies the same DataFrame ideas to continuous streams.

Caching keeps a DataFrame in memory when several steps reuse it, avoiding recomputation.

Small data runs slower in Spark than in pandas, because planning and coordination have a fixed cost.

In practice, most Spark tuning is about partitions, shuffles and memory rather than code style.

The usual mistake is collecting a huge DataFrame back to the driver, which overloads that 1 machine.

Want the full technical article? Wikipedia ↗
Test yourself

One question on this card. Every option explains itself once you pick, right or wrong.

Question 1
In Spark, an analyst writes a filter and a groupBy on a huge DataFrame, but nothing seems to happen until they ask for the result. Why?
Data Engineering Basics

13 concepts in this module, then a graded test with every answer explained.

Study this module →
↑↓ move↵ openesc close