Lake, warehouse, lakehouse
Part of the free LogicWiz Data Engineering course, Module 4: Storage and file formats. The SQL and Python run in the app, on real Postgres and real Python in the browser.
It is 8:50 on Wednesday. Tess's dashboard shows yesterday at 40% of a normal day's orders. No alert fired, and nothing in the orders folder says anything went wrong. A Spark job was killed at 2 a.m., partway through moving its files into place on S3, and the dashboard counted what it found. Nora asks: "Why did the reader think a half-written folder was finished?"
You'll learn to
- Say what object storage promises, and what it does not
- Explain how a commit log turns files into a table
- Place storage, files, table format, catalog and engines in one stack
- Choose between a data lake, a warehouse and a lakehouse
Learn
A store that only swaps whole objects
Start with where the files live. Cloud object storage (Amazon S3, Azure Data Lake Storage Gen2, Google Cloud Storage) keeps objects in buckets. Each object is found by its key, a name such as lake/orders/order_date=2025-06-01/part-0.parquet. It costs cents per GB a month, is very durable, and is effectively unlimited.
The price is a very small set of moves. You can PUT a whole object, GET it (or a range of its bytes), LIST the keys that start with a prefix, DELETE and COPY. You cannot change the middle of an object or add to its end: you write a new one. On S3 and GCS a "folder" is only a shared prefix of keys.
What object storage will and will not do
Two groups of boxes. On the left the five things object storage can do: put a whole object, get it or a byte range, list keys by prefix, delete and copy. On the right what it cannot do: edit the middle of an object, append, lock, rename on S3, or change several objects together.
Read the left box as the full list of moves. Every problem in this lesson comes from the last two red boxes.
It promises one object at a time
Since December 2020, S3 is strongly consistent: after a write, every read and every listing sees it at once. That sounds like safety. It is a promise about one object.
A table is many objects, and two things are missing. There is no way to change several objects together, all or nothing. And S3 has no rename: "moving a folder" is a COPY and a DELETE for each object, one after another.
That is what hit SwiftKart. The Spark job wrote its files to a temporary place first, which is the careful thing to do. Then it began to move them into the table's folder, one by one. Then it was killed.
A job killed halfway through its commit
Five files are written under a temporary prefix, then copied one by one into the table folder. The job is killed after two; a reader lists the table folder and sees two of five files with no error.
Tasks write to a temporary prefix. Five files land under
_temporary/. No reader looks there, so nothing is visible yet.The commit starts. The driver "renames" part-0: a COPY into
orders/, then a DELETE of the temporary copy.part-1 follows. Two of the five files are now in the table's folder.
The driver is killed. Three files never move. Nothing in
orders/records that a commit was under way.A reader lists
orders/. Strong consistency means it sees exactly what is there right now: 2 files of 5, which is 40% of the orders, and no error.
A dashed box is a file that is not there. This way of committing (Hadoop's classic FileOutputCommitter) was designed for HDFS, the Hadoop file system you meet below, where rename is one atomic step. On S3 it is slow, because it copies every byte, and unsafe. The S3A committers reduce the damage; table formats remove it.
A lake: cheap, open, and trusting
Files on object storage, in folders any engine can read, are called a data lake. Spark, DuckDB, Athena, Trino and pandas can all open the same Parquet, JSON or CSV. It is cheap, no vendor owns your files, and it holds anything, logs and images included.
Its weaknesses come straight from the floor it stands on. A job that dies halfway leaves a half-written table, and readers read it. Two jobs writing at once can overwrite each other. Deleting one customer's rows means rewriting files by hand. Nothing checks the schema, so over the years a lake slowly turns into a data swamp.
See the first weakness for yourself. Guess first.
A half-written folder
import duckdb, os
os.makedirs("lake/orders", exist_ok=True)
src = "SELECT * FROM 'data/orders.csv'"
# A job writes the day's orders as three files...
duckdb.sql(f"COPY ({src} WHERE order_id <= 1030) TO 'lake/orders/part-0.parquet' (FORMAT PARQUET)")
duckdb.sql(f"COPY ({src} WHERE order_id BETWEEN 1031 AND 1060) TO 'lake/orders/part-1.parquet' (FORMAT PARQUET)")
# ...and crashes before it writes part-2.
n = duckdb.sql("SELECT COUNT(*) FROM 'lake/orders/*.parquet'").fetchone()[0]
print("a reader sees", n, "of 80 orders, with no error and no warning")
Nothing marks the folder as incomplete. Any reader that lists it at this moment gets 60 orders and reports them as the truth.
Write first, then flip one switch
The fix keeps the same files on the same storage, and adds a list.
Beside the Parquet files sits a small log: a numbered history of commits, each naming the files it added and the files it removed. A file counts only if a commit names it. This layer is called a table format. The three you will meet are Delta Lake, Apache Iceberg and Apache Hudi.
A writer works in two moves. First it writes its new data files, under new names, where no reader looks. Then it publishes them with one step on one small object. Either that step happens and readers see every new file, or it does not and they see none.
Three commits and a crash
A folder of data files beside a log folder. Each commit file names files to add or remove; a file that is written but not named by a commit is invisible, and a crashed job's file is never seen.
Version 0. The writer writes
a.parquet, then creates commit00000.json, which says "add a". The table is one file.Written, not yet committed.
b.parquetis on storage, but no commit names it. Readers still see version 0.Version 1. Commit
00001.jsonsays "add b". In that one step the table becomes a and b.A delete, as version 2. Parquet files are never edited. The writer writes
c.parquet(file a without the cancelled orders) and commits "add c, remove a". File a stays on storage, so older versions can still be read.A crash. Another job writes
crashed.parquetand dies before its commit. The file sits in the folder, but no commit names it, so no reader ever sees it.
Watch the right-hand box: the table changes only when a new commit file appears there. The example below runs exactly these five steps.
A tiny table format
import duckdb, json, os
os.makedirs("lake/orders/_log", exist_ok=True)
src = "SELECT * FROM 'data/orders.csv'"
def write_file(name, where):
duckdb.sql(f"COPY ({src} WHERE {where}) TO 'lake/orders/{name}' (FORMAT PARQUET)")
def commit(version, add=(), remove=()):
with open(f"lake/orders/_log/{version:05d}.json", "x") as f: # "x": fail if it exists
json.dump({"add": list(add), "remove": list(remove)}, f)
def files_at(version):
files = set()
for v in range(version + 1):
with open(f"lake/orders/_log/{v:05d}.json") as f:
c = json.load(f)
files |= set(c["add"])
files -= set(c["remove"])
return sorted(files)
def count_at(version):
paths = [f"lake/orders/{name}" for name in files_at(version)]
return duckdb.sql(f"SELECT COUNT(*) FROM read_parquet({paths})").fetchone()[0]
write_file("a.parquet", "order_id <= 1040")
commit(0, add=["a.parquet"])
write_file("b.parquet", "order_id > 1040")
commit(1, add=["b.parquet"])
write_file("c.parquet", "order_id <= 1040 AND status <> 'cancelled'")
commit(2, add=["c.parquet"], remove=["a.parquet"]) # delete the cancelled orders
write_file("crashed.parquet", "order_id > 0") # a job died before its commit
for v in range(3):
print("version", v, files_at(v), count_at(v), "orders")
print("files in the folder:", sorted(f for f in os.listdir("lake/orders") if f.endswith(".parquet")))
Version 2 deleted rows by writing a new file and dropping the old one from the table. The crashed file sits in the folder, but no commit lists it, so no reader sees it. Opening the commit file with mode "x" means "create it only if it does not exist": a second writer of version 2 would get FileExistsError. Real Delta Lake works this way.
The step that cannot half-happen
Everything rests on that one publishing step, so each format picks an operation that cannot stop halfway.
Delta creates the next log file, for example 00000000000000000008.json, with put-if-absent: the write succeeds only if no object has that name yet. Two writers cannot both create version 8. S3 has offered this since August 2024.
Iceberg asks its catalog to swap the table's pointer from metadata version 7 to version 8, but only if it still points at 7.
The log gives more than safety. You can read the table as it was at an older version (time travel), and MERGE, UPDATE and DELETE become safe. Lesson 4.6 opens the metadata itself.
What a Delta table looks like on storage
| Path | What it is |
|---|---|
| orders/deltalog/00000000000000000000.json | commit 0: added part-00000 and part-00001 |
| orders/deltalog/00000000000000000001.json | commit 1: added part-00002 |
| orders/deltalog/00000000000000000002.json | commit 2: removed part-00000, added part-00003 (a DELETE) |
| orders/part-00000-....snappy.parquet | no longer in the table, kept for time travel until VACUUM removes it |
| orders/part-00003-....snappy.parquet | ordinary Parquet, readable by any engine |
Plain Parquet data and a plain JSON log. Commit names are zero-padded to 20 digits so they sort in order as text. No engine owns the files.
Remember: a file is in the table only if a commit names it. Write the files first, then publish them all in one step.
A catalog finds the table by name
One question is left: how does an engine find the table at all? It asks a catalog: a service that maps a name such as swiftkart.sales.orders to where the table lives, with its schema and who may read it.
You will meet four. The Hive metastore is the original. AWS Glue Data Catalog is AWS's managed version of it. Unity Catalog is Databricks' catalog, with permissions and lineage. Apache Polaris speaks the Iceberg REST catalog, an open web API any engine can use.
For Iceberg the catalog is also where the switch is flipped: it holds the pointer to the table's current metadata file, and a commit is a request to move that pointer.
The lakehouse stack
Five stacked layers: engines such as Spark, Trino, DuckDB and Snowflake on top; then catalogs; then table formats Delta, Iceberg and Hudi; then the Parquet file format; then object storage S3, ADLS and GCS at the bottom.
Read it bottom to top: storage, the file format, the table format, the catalog, then the engines. Each layer is a separate choice. Open files, read by many engines through a shared catalog: that is what the word lakehouse is really about.
Catalogs side by side
| Catalog | Who runs it | APIs it speaks | Typical use |
|---|---|---|---|
| Hive metastore | you: a Thrift service on MySQL or Postgres | Hive Metastore (Thrift) | legacy Hive and Spark tables, partitions as folders |
| AWS Glue Data Catalog | AWS, serverless | Glue API, Hive-compatible | Athena, EMR, Redshift Spectrum; Iceberg on AWS |
| Unity Catalog | Databricks; open source since 2024 | its own REST API, Iceberg REST | Delta and Iceberg with grants, lineage, masking |
| Apache Polaris | open-sourced by Snowflake in 2024 | Iceberg REST | one Iceberg catalog shared by many engines |
Lake, warehouse or lakehouse
Now the three words people argue over make sense.
A data lake is the open files: cheap, and trusting.
A cloud warehouse (Snowflake, BigQuery, Redshift) stores tables in its own managed format. You get fast SQL, transactions and security with little to run. You pay more at scale, you are tied to the vendor, and it fits machine learning less well.
A lakehouse is a lake plus a table format plus a catalog plus warehouse-like engines. The files stay open Parquet on cheap storage, and the tables are ACID: each change is all or nothing, and readers never see a half-done one. Databricks coined the word around Delta Lake; Iceberg tables play the same part in Snowflake, AWS and Google Cloud. Most companies run a mix.
Where each fits
| Data lake | Warehouse | Lakehouse | |
|---|---|---|---|
| Storage | object storage | managed by the vendor | object storage |
| Transactions | none | yes | yes, via the table format |
| Format | anything | the vendor's own | Parquet plus Delta or Iceberg |
| Good for | raw history, ML, low cost | BI and SQL, easy to run | both, on one copy |
| Watch out for | swamps, partial writes | cost, lock-in | more to design and maintain yourself |
Why older job posts say Hadoop
Interviews and older job posts still mention Hadoop, so know the story.
Around 2006, Hadoop made it possible to store and process web-scale data on racks of ordinary servers. HDFS, its file system, split files into blocks and copied each block to several machines. MapReduce ran your code next to each block, then shuffled and combined the results. Hive, around 2010, added SQL on top, and its metastore recorded where each table's files lived.
They faded for clear reasons. Clusters were hard to run, and storage and compute were tied to the same machines. MapReduce wrote to disk between every step, so jobs were slow; Spark kept data in memory and replaced it. Object storage replaced HDFS, losing atomic rename on the way, and managed warehouses replaced most Hive SQL.
What Hadoop left behind
| Hadoop era | Today |
|---|---|
| HDFS on the cluster's own disks, atomic rename | S3, ADLS, GCS: storage apart from compute, no rename on S3 |
| MapReduce, disk between every step | Spark: the same map and shuffle ideas, in memory |
| Hive SQL compiled to MapReduce | Spark SQL, Trino, Snowflake, BigQuery |
| The Hive metastore: where tables live | still in use, and its successors: Glue, Unity Catalog, Polaris |
| Hive-style key=value folders | still everywhere (Lesson 4.3), hidden by Iceberg transforms |
The trap: a folder of Parquet files is not a table. It has no atomic commit, no safe way for two jobs to write at once and no reliable delete, and each reader decides for itself which files count. Strong consistency does not change that: it is a promise about one object at a time. If more than one job writes to it, or rows ever need fixing or deleting, use Delta Lake or Iceberg (or a warehouse). And a lakehouse still needs modelling: Module 5's facts and dimensions apply.
Azure: ADLS Gen2 with Databricks (Delta Lake, Unity Catalog), or Microsoft Fabric, whose OneLake stores Delta tables. AWS: S3, the Glue catalog and Athena, often with Iceberg, plus Redshift or Snowflake. Google Cloud: GCS and BigQuery, with BigLake for open formats. Snowflake and Databricks both work with Iceberg tables through REST catalogs now, and Delta's UniForm writes Iceberg metadata for the same files. Engine, catalog and storage are becoming separate purchases.
Numbers to remember
| What | Fact | Good to know |
|---|---|---|
| S3 strong consistency | since December 2020 | For every PUT, overwrite, DELETE and LIST, at no extra cost. Before that a LIST right after a write could miss new keys, and Hadoop needed add-ons (S3Guard, EMRFS consistent view) |
| Rename on S3 | none: a COPY and a DELETE per object | n objects, 2n requests, not atomic. ADLS Gen2 with the hierarchical namespace does have atomic directory rename |
| Put-if-absent on S3 | since August 2024: a PUT with If-None-Match: | A second writer gets 412 Precondition Failed. GCS offers the same with ifGenerationMatch=0 |
| Delta commit file name | 20 digits, zero-padded | 00000000000000000008.json is version 8 |
| Iceberg REST commit | sends requirements such as assert-ref-snapshot-id | If another writer got there first the server answers 409, CommitFailedException, and the client retries |
| Unity Catalog | open-sourced in June 2024 | catalog.schema.table, grants, lineage |
| Apache Polaris | open-sourced by Snowflake in 2024 | Implements the Iceberg REST catalog |
What changed at SwiftKart
SwiftKart turns the orders folder into a Delta table. The nightly job still writes its files first, but now nothing counts until one commit publishes them all. If a job is killed at 2 a.m., readers keep seeing the last complete version. Tess's dashboard can be a day behind. It can no longer show 40% of a day.
The raw clicks stay in the lake as cheap files, the analysts get exact SQL on the same copy, and the data scientists read the same Parquet. That is the lakehouse the three teams were each describing.
Lesson 4.5 goes one level down, into the Parquet file itself: how 40,000 values fit in 3 KB, and how a reader decides which bytes to fetch.
In one line
Object storage keeps each object safe but cannot change many together; a table format adds a commit log so new files appear all at once, and that turns a data lake into a lakehouse.
Interview corner
What is the difference between a data lake, a warehouse and a lakehouse?
A lake is files on object storage that any engine can read: cheap and open, but without transactions or enforced schemas. A warehouse such as Snowflake or BigQuery manages storage and compute for you and gives fast, governed SQL, at higher cost and with some lock-in. A lakehouse keeps open Parquet files on cheap storage but adds a table format (Delta Lake, Iceberg) and a catalog, giving ACID commits, time travel and MERGE, so BI and ML share one copy of the data and several engines can use it.
S3 has been strongly consistent since December 2020. Why do table formats still need a log?
Strong consistency is a promise about single objects: after a PUT, every GET and LIST sees it. A table change touches many objects, and S3 has no rename and no multi-object transaction, so a crashed or concurrent writer can leave readers looking at part of a change. A table format writes data files invisibly, then publishes them with one atomic step on one small object: Delta creates the next numbered log file with put-if-absent, Iceberg swaps the metadata pointer in its catalog with compare-and-swap. Readers trust only what that step published.
What does a catalog do in a lakehouse, and how does an Iceberg commit use it?
A catalog maps table names to their location and current metadata, and holds schemas and permissions: the Hive metastore, AWS Glue, Unity Catalog and Polaris are examples. For Iceberg it is also the commit point: it stores the pointer to the current metadata.json. A writer prepares a new metadata file and asks the catalog to move the pointer only if it still points at the version it read; with the REST catalog that is a POST with requirements such as assert-ref-snapshot-id, which fails with 409 if another writer won, and the client retries on the new version.
What was Hadoop, and why is it rarely chosen for new projects?
Hadoop was the first popular open-source platform for big data: HDFS stored files across many machines and MapReduce processed them in parallel, with Hive adding SQL on top. It faded because clusters were hard to operate, storage and compute were coupled, and MapReduce was slow because it wrote to disk between steps. Spark replaced MapReduce, cloud object storage replaced HDFS (losing HDFS's atomic rename, which is one reason table formats exist), and managed warehouses and lakehouses replaced Hive, though Hive-style partitions and the metastore idea live on.