When you move from service databases to working next to a data pipeline, data lake, ETL, and Spark all arrive at once. My first questions were why the same data gets copied several times, and why a read replica of the service database is not enough. Mapping each term back to something familiar from backend work sorted them out.
Separate storage from transformation. A data lake is storage that keeps raw data cheaply and never throws it away. Inside it sit the raw, staging, and mart layers, each more refined than the last, and moving data from one layer to the next is the transformation, ETL or ELT. Spark is the engine that runs that transformation across many machines.
OLTP and OLAP
Service databases are built for OLTP (Online Transaction Processing). Insert one order, look up one customer, decrement one stock count. Each query touches a few rows, and indexes and transactions find those rows quickly and correctly.
Analytical queries are the opposite. “Revenue by city last month” scans the whole orders table and sums a single column. Queries like this are OLAP (Online Analytical Processing). Run them on the service database and the long scans take over disk and buffer cache, slowing down user requests. A read replica protects the service, but reading every row of row-oriented data still costs the same.
The difference comes from how data is laid out on disk. Row storage keeps a row’s columns together, which suits reading or writing one record whole. Column storage keeps each column’s values together, so a query reads only the columns it needs. Same-typed values also compress well.
That is why analytical stores and file formats are columnar. Apache Parquet, the usual file format in a data lake, is one of them. Parquet records statistics such as min and max for each column, so a reader can skip ranges that cannot match a filter.
Data Warehouses and Data Lakes
Analytical storage started with the data warehouse. Data from service databases is copied into tables with a fixed schema and analyzed with SQL. The schema comes first, and data that does not fit is rejected on the way in. This is schema-on-write, and it feels just like a relational database. A warehouse keeps storage and compute in one system, so SQL runs right where the data lives.
A warehouse is tidy but strict about what it accepts. Event logs whose shape keeps changing, files from outside vendors, and data nobody has found a use for yet are hard to fit into a schema up front. Warehouse storage was also expensive.
A data lake flips the order. Raw files land in object storage such as S3 or GCS as received, and the reader decides on structure. This is schema-on-read. Storage is cheap and formats are unconstrained, so everything can be kept. A lake, though, is only file storage with no compute of its own. Reading and computing over those files is the job of a separate engine.
The cost is just as clear. Without a record of who wrote what in which format, a lake quickly turns into a pile of files nobody trusts, often called a data swamp. A set of files is not a database table: no transactions, no enforced schema, no control over concurrent writers. A write that fails halfway leaves half-written files behind.
A lakehouse keeps the lake’s cheap storage and open file formats while bringing back what a warehouse provided. It applies a table format to the files. Table formats such as Apache Iceberg, Delta Lake, and Apache Hudi keep a separate record of which files make up a table right now, and use that record to provide atomic commits and schema management.
ETL and ELT
That covers storage. Next is transformation: pull data from the source (Extract), reshape it (Transform), and write it to the destination (Load). The order gives the name.
- ETL: transform, then load. Only cleaned tables reach the warehouse, and the raw data is discarded along the way
- ELT: load the raw data first and transform it afterward. The raw data stays, so the transformation can be rerun when its rules change
ELT became the common choice as storage got cheaper and compute engines got stronger. In a warehouse, the transformation runs as SQL inside the warehouse. In a lake, an engine such as Spark reads the lake’s files, transforms them, and writes the result back to the lake, with storage and compute kept apart.
It resembles an event log with read models (CQRS) in backend systems: keep what happened as it happened, and any read-friendly view of it can be rebuilt at any time.
Raw, Staging, and Mart Layers
With ELT, the same data lives in several layers depending on how refined it is. Names vary by team. One convention is raw, staging, and mart; another is bronze, silver, and gold (the medallion architecture). The roles are broadly the same.
- raw: data exactly as received. Never edited, only appended to. Mostly read by the pipeline itself, and where work starts again when a transformation had a bug or its rules change
- staging: one source, cleaned. Types fixed, names made consistent, duplicates and broken rows removed. It still looks roughly like the source and mostly serves data engineers as input to the next step
- mart: built around a question. Sources are joined and aggregated into tables such as daily product revenue or hourly sign-ups. Dashboards, analysis, and model training mostly read this layer
As long as a layer survives, every layer after it can be rebuilt. Reprocessing, recomputing past periods after a bug fix, depends on that. People reading a mart do not need to know how messy the sources are, and metric definitions live in one place, so each layer has its own responsibility.
Reprocessing requires a transformation job to produce the same output for the same input. If running the same date twice doubles the rows, reprocessing is impossible. So transformations usually rewrite a whole date directory (such as dt=2026-08-01) at a time, the same requirement as an idempotent API. Overwriting files wholesale is idempotent but not atomic, though. A failure midway leaves a half-replaced directory, and that gap is what a table format closes.
Spark as a Distributed Engine
Running transformations on one machine hits a ceiling quickly. Reading a day of events takes hours, and reprocessing a long period can take more than a day. Apache Spark is a distributed processing engine that splits those transformations across many machines. For a backend engineer, it works like a runner that takes a batch job written in SQL or the DataFrame API and spreads it over a cluster.
Spark’s runtime has one driver and many executors. The driver runs the user’s code, builds an execution plan, and hands out work. Executors read and compute the actual data. Data is split into partitions, and processing one partition is one task. More partitions let more executors work at once. A Spark partition is a unit of in-memory work, which is a different thing from the date directories above.
events = spark.read.parquet("s3://lake/raw/events/dt=2026-08-01/")
clicks = events.filter(events["type"] == "click") # not executed yet
by_user = clicks.groupBy("user_id").count() # not executed yet
by_user.write.mode("overwrite").parquet(
"s3://lake/mart/clicks_by_user/dt=2026-08-01/" # runs here
)
filter and groupBy are transformations, so calling them does not run anything. Spark only builds up a plan, and when an action needs a result (write here), it optimizes and executes the whole plan. This is lazy evaluation. Because Spark sees the whole plan before running it, it can read only the needed columns and apply filters while reading the files.
Cost depends heavily on the kind of transformation. One like filter, which handles each partition independently, is narrow. One like groupBy, which needs all rows with the same key in one place, is wide, and join is usually wide too. A wide transformation triggers a shuffle, redistributing data between executors. The execution plan is split into stages at each shuffle. The diagram simplifies this flow.
The Spark docs call the shuffle an expensive operation because it involves disk I/O, data serialization, and network I/O. When a Spark job is slow, the shuffle is the first place to look. If one key holds far more rows than the others, the single task handling it runs long; this is skew. The basic rule when writing a job is to cut rows and columns as much as possible before the shuffle.
Adoption Criteria
Lakes and Spark tend to arrive as data grows, but they are not needed from day one.
A lake and distributed processing fit when:
- Raw data must be kept for a long time and recomputed whenever rules change
- One machine cannot process a day of data within the time available
- Several sources in different formats must be joined in one place
A read replica or a single-node tool is enough when:
- The analysis covers a few small service database tables
- The questions are fixed, so raw data is rarely reread
- Nobody is available to run a pipeline
A common path is to start with ELT into a read replica or a managed warehouse, then move to a lake and Spark once keeping raw data and reprocessing become a burden. Streaming and job scheduling (orchestrators such as Airflow) are separate topics layered on top of this setup.
Conclusion
With raw data kept and idempotent transformations, every downstream layer can be rebuilt at any time. The data lake keeps that raw data, the layers separate the refinement steps, and Spark runs the transformations between layers across many machines. Separating storage from transformation shows which problem each tool solves.
References
- What RDB Transaction ACID Actually Guarantees — the atomicity and isolation that a set of files in a lake lacks, from the relational database side
- Event Sourcing and CQRS — keeping raw events and rebuilding read models, from the service side
- Apache Spark — Cluster Mode Overview
- Apache Spark — RDD Programming Guide
- Apache Parquet — Documentation