Apache Spark is an open-source distributed analytics engine. It splits large datasets across a cluster of machines and processes them in parallel, using in-memory computation to achieve speeds 10-100x faster than Hadoop MapReduce. One unified API handles batch ETL, SQL queries, streaming, ML, and graph processing. Learn Spark hands-on at /learn/spark or ship a real batch lakehouse with /projects/logistics-batch-pipeline.
What is Apache Spark?
Apache Spark was created at UC Berkeley's AMPLab in 2009 and open-sourced in 2010. It became an Apache top-level project in 2014. Today it's the most widely-used engine for distributed data processing, deployed at companies like Uber, Netflix, Airbnb, and virtually every large data engineering team.
Spark's key innovation was moving computation into memory. Hadoop MapReduce writes intermediate results to disk after every step — Spark keeps data in RAM across a full pipeline. For multi-step transformations and iterative ML algorithms, this change is the difference between hours and minutes.
The primary interface for modern data engineering is the DataFrame / Spark SQL API, optimized by Spark's Catalyst engine and Tungsten execution layer. Around it sits a library ecosystem — Structured Streaming for stateful stream processing, MLlib for distributed machine learning, GraphX for graph analytics — all sharing the same cluster and unified API.
Master Spark in 8 hours, hands-on.
From DataFrame fundamentals to broadcast joins, partition strategy, Structured Streaming, and Delta Lake. Real cluster, real performance tuning.
Why does Spark matter?
- 10-100x faster than MapReduce via in-memory processing and DAG-aware execution
- Scales linearly from a laptop to thousands of nodes processing petabytes
- One API for batch, streaming, SQL, and ML — no separate stacks to maintain
- Catalyst optimizer rewrites your query plan, predicate-pushes, and prunes partitions automatically
- Adaptive Query Execution (AQE) re-plans joins and partition sizes at runtime
- Native readers for Delta Lake, Iceberg, Parquet, ORC, Avro — the lakehouse default
How does Spark work?
Spark uses a Driver–Executor model. The Driver process plans the job, builds a logical query plan, and hands physical tasks to executors. A Cluster Manager (YARN, Kubernetes, or Spark Standalone) allocates resources across nodes. Executors run tasks in parallel on partitioned data. Storage lives outside the cluster — S3, HDFS, Delta Lake, or Iceberg tables.
When you call an action (.write, .show, .count), Spark builds a DAG of stages, splits each stage into tasks (one per partition), and schedules tasks across executors. Failed tasks are retried automatically; lost partitions are recomputed from lineage.
A typical Spark batch job in Python (PySpark):
from pyspark.sql import SparkSession
from pyspark.sql.functions import col, sum
spark = (
SparkSession.builder
.appName('daily_etl')
.config('spark.sql.shuffle.partitions', 200)
.getOrCreate()
)
# Read raw events from S3
df = spark.read.parquet('s3://bucket/events/date=2026-01-01/')
# Transform: aggregate by user
result = (
df
.filter(col('event_type') == 'purchase')
.groupBy('user_id')
.agg(sum('amount').alias('total_spend'))
)
# Write to Delta Lake
(
result.write
.format('delta')
.mode('overwrite')
.save('s3://bucket/gold/user_spend/')
)
Spark vs pandas vs MapReduce
| Feature | Spark | pandas | MapReduce |
|---|---|---|---|
| Distributed across nodes | Yes | No (single machine) | Yes |
| In-memory processing | Yes | Yes | No (disk between steps) |
| Streaming support | Yes (Structured Streaming) | No | No |
| SQL support | Yes (Spark SQL) | Limited | No |
| ML library | Yes (MLlib) | No | No |
| Typical dataset size | GB to PB | Under 10 GB | GB to PB |
| Setup complexity | Medium | None | High |
Use pandas when the dataset fits in one machine's RAM — it's faster to write, faster to debug. Reach for Spark when data exceeds single-node memory, when you need cluster parallelism, or when you want one engine for batch, SQL, streaming, and ML. MapReduce is largely legacy — most teams migrated to Spark years ago.
What can you build with Spark?
- Batch ETL at scale — process terabytes of raw logs, events, or files into clean, partitioned tables
- Lakehouse transforms — read from Delta Lake, Iceberg, or Parquet; apply medallion architecture (bronze/silver/gold) at TB+ scale
- Near-real-time streaming — Structured Streaming processes Kafka topics with exactly-once semantics and watermarking for late data
- ML feature engineering — join 10+ tables, compute aggregates, and write feature vectors to a feature store in one job
- Interactive SQL — query petabyte-scale tables with Spark SQL or notebooks (Databricks, Jupyter) at sub-second latency on hot data
- Performance tuning playground — broadcast joins, partition pruning, AQE, bucketing — Spark exposes the full toolbox for 10x speedups
Build a real Spark lakehouse end-to-end.
Process a multi-GB logistics dataset through bronze → silver → gold, optimize from 45min to 5min, and deploy on Kubernetes with monitoring.
Common mistakes (and what to do instead)
- Calling
.collect()on large DataFrames — pulls all rows into the Driver's memory and OOMs it. Use.show(),.limit(), or write to storage instead. - Python UDFs instead of built-in functions — Python UDFs break Catalyst optimization and run 10-100x slower than equivalent SQL. Use
col(),when(), andpyspark.sql.functionswherever possible. - Wrong shuffle partition count — the default
spark.sql.shuffle.partitions=200is too high for small datasets, too low for large ones. Target ~128MB per partition. Enable AQE to let Spark adjust dynamically. - Iterating row-by-row with
.collect()+ aforloop — Spark is not pandas. Use DataFrame transformations,map(), or window functions to keep work on the cluster. - Not caching DataFrames that are reused — if you reference the same DataFrame twice, Spark recomputes it. Call
.cache()or.persist()before the second use. - Skewed joins on one hot key — one task can stall a whole job. Salt the key, broadcast the smaller side, or enable AQE skew handling.
Who is Spark for?
Spark is built for data engineers and ML engineers working with data that doesn't fit in one machine's RAM. If your daily workload includes lakehouse transforms, terabyte-scale aggregations, or streaming pipelines, Spark is the default engine.
Teams that benefit most:
- Platform teams running medallion lakehouses on Delta Lake or Iceberg at the petabyte scale
- Analytics engineering teams replacing slow warehouse jobs with Spark on cheaper object storage
- ML engineers running feature pipelines that join hundreds of millions of rows before training
- Streaming teams who need exactly-once semantics on Kafka topics with Structured Streaming
Frequently asked questions
Start shipping.
Three steps from a guide to a job-ready portfolio. Pick one and start now — the rest will follow.
Take the skill
Self-paced module with code, exercises, and a deliverable. Free preview, paid completion.
Start S0X · Spark →Ship the project
Production-grade build with starter kit + mentor code review. The artifact that gets you interviews.
Open P0X · Logistics Batch Pipeline →Pick a career path
The full progression — skills + projects + interview prep — for the role you actually want.
See paths →