A report takes an hour to refresh, and someone in the meeting says: "We need Spark." Sometimes that is true. More often the cause is the data model, unused columns or a query that reads the whole history instead of last month. Spark solves a different problem, and put in the wrong place it adds a cluster, a bill and a new point of failure.
Below: what Apache Spark is, when you really need it, where it sits in different data architectures and the mistakes I see most often.
What Spark is
Apache Spark is an open engine for distributed data processing. It splits a large job into pieces and runs them in parallel on several machines. The current line is Spark 4.x.
A few words you cannot do without:
- Driver receives your code (SQL, Python, Scala), builds an execution plan and hands out tasks.
- Executors are processes on the cluster machines that process the data.
- Partitions: data is split into chunks, and each task processes its own chunk.
- Laziness and the plan (DAG): transformations do not run straight away. Spark collects the chain of steps and runs it only when a result is needed (a write, a count, a display).
- Shuffle: to group or join data by key, rows with the same key have to meet in one place. They travel over the network between machines, and that is the most expensive part of the work.
An analogy: a warehouse and a crew of movers. The foreman (driver) assigns shelves, and each mover (executor) clears their own. When all boxes of one customer have to be stacked together, the movers carry them across the whole warehouse: that is a shuffle. The analogy is imperfect, because a mover is not slowed down by a network and an executor is: if one gets half of all the boxes, everyone else waits for them.
On top of the engine sit several modules. Spark SQL and DataFrames for tables (the most used), Structured Streaming for streams, MLlib for machine learning. You can write SQL, Python (PySpark), Scala, Java and R.
When you need Spark and when you do not
Spark pays off when data does not fit on one server, when transformations are heavy (large joins, years of history, raw event logs), when you process a stream of events, or when the platform you have already chosen runs on Spark.
It is overkill when data is small. A modern machine with an analytical engine such as DuckDB, or an ordinary PostgreSQL or SQL Server database, comfortably handles what most public institutions, programmes and mid-sized companies call "big data". A cluster for a table that fits in a laptop’s memory is slower: starting it and distributing tasks takes longer than the calculation itself.
Signs you do not need Spark yet:
- The whole data history fits in one database, and queries take minutes, not hours.
- The slow report is slow because of the model: unused columns, bidirectional relationships, complex measures.
- Nobody will maintain PySpark code after launch.
Spark in different architectures
Spark rarely stands alone. It is an engine inside a wider architecture, and its role differs in each. I described the overall picture in the article Data architecture types: 6 levels.
Classic Hadoop data lake. Own servers, files in HDFS, resources managed by YARN, tables described by Hive. Spark arrived here to replace slow MapReduce. Such systems still run in large organisations, but new projects rarely start on this design.
Cloud data lake plus data warehouse. Raw files sit in object storage (Amazon S3, Azure Data Lake Storage, Google Cloud Storage). Spark cleans and prepares them, and the result is loaded into a data warehouse (Snowflake, BigQuery, Synapse SQL) that reports use. It works, but it means two engines and two copies of the data to keep consistent.
Lakehouse. The data lake gains database properties: transactions, row updates, version history. Open table formats on top of Parquet files provide them: Delta Lake, Apache Iceberg, Apache Hudi. Data moves through layers following the medallion architecture: Bronze (as it arrived), Silver (cleaned and aligned), Gold (marts for reports). Spark moves data between the layers.
Streaming. Events arrive from Kafka or another queue, and Structured Streaming processes them in small batches and appends them to Bronze or straight to Silver. Before building a stream, ask who will look at the data every minute. Most management reports are fine with hourly or daily refreshes, and batch processing is far cheaper and simpler.
Managed platforms. Today Spark is more often rented than installed:
| Platform | Where Spark is | When to consider it |
|---|---|---|
| Databricks | the core of the platform, notebooks and jobs, Delta Lake | when heavy transformations and ML are central, any cloud |
| Microsoft Fabric | notebooks and Spark jobs for a Delta lakehouse | when reporting is on Power BI and the stack is Microsoft |
| Azure Synapse Analytics | Spark pools | existing systems; Microsoft publishes guidance on moving Spark pools to Fabric |
| AWS EMR, AWS Glue | clusters and serverless jobs | when the data is in AWS |
| Google Dataproc | managed Spark clusters | when the data is in Google Cloud |
The platform is decided more by the cloud and BI tool you already have than by Spark itself: PySpark code moves between them fairly easily, access, networking and cost settings do not.
How BI reads the result
Power BI or Tableau should not hit a Spark cluster on every user click. The report reads the finished Gold layer: fact and dimension tables in a star schema. The routes vary: import into a semantic model, the SQL endpoint of a lakehouse or warehouse (a SQL warehouse in Databricks), and in Fabric also Direct Lake mode, where a Power BI model reads Delta tables directly without a separate import.
The principle is the same: Spark prepares data on a schedule, and the report works with the result. How to build the model layer itself is covered in the article on the semantic model.
Mistakes that cost the most
- Spark for small data. A cluster, a team and a bill where SQL on one server would do.
- Small files. A stream or frequent loads write thousands of tiny files, and reads slow down many times. Regular compaction is needed (in Delta, the
OPTIMIZEcommand). - Data skew. One key (the largest region, say, or an "unknown" customer) holds half the rows. One task runs for an hour while the rest wait.
collect()to the driver. Callingcollect()ortoPandas()on a large table pulls all the data onto one machine, and the job fails out of memory.- Needless shuffles. Several groupings in a row, joining a large table with a small lookup without a broadcast. Every extra shuffle is data crossing the network.
- No partitioning strategy. Partitioning by a column nobody filters on, or by date down to the hour, which produces millions of tiny partitions.
- A cluster running around the clock. The job takes 20 minutes a day, and the cluster is paid for all 24 hours. Auto-termination and scheduled jobs fix this.
- No checks between layers. Spark faithfully carries errors from Bronze into Gold. Data quality checks between layers are needed as much as in any other architecture.
Checklist before you decide
- The data really does not fit in one database, or processing takes hours even after the model is optimised.
- You know which problem Spark solves: streaming, heavy transformations, ML, or a platform that has it built in.
- A table format (Delta, Iceberg) and layers are chosen, not just "we put files in the lake".
- BI reads the Gold layer, not the cluster directly.
- Someone will maintain the code, and the compute budget has auto-termination.
- Quality checks sit between the layers.
Where to start
Take the slowest load or report and see where the time goes: reading from the source, transformations or the model itself. If the bottleneck is the model or a query, Spark will not help. If it is volume and transformation complexity, compare two options: tuned SQL on one server and Spark on the managed platform your cloud offers. How to choose the overall reporting design is in the article BI architecture: four options. I help with this as part of data architecture and business intelligence.
When your team first talked about Spark, what was the real problem?
