Systemsfor Aravinda
0 / 78 core
Week 8 · Modern systems

The lakehouse

1.5 hours · core path

Read first: Choosing a database, Object storage

In one sitting

A warehouse is a curated store with a schema and SQL, and a lake is files in object storage, cheap and messy. A lakehouse puts a table format such as Iceberg or Delta over those files so readers see a snapshot and a manifest, not a half-written drop. It is the wrong tool for one service and one database.

Someone will eventually point at a pile of files and call it a table. Sometimes that is the right pile: many readers, years of history, more than one engine. Sometimes you already have a database, and the pile is a way to lose a transaction you used to have. The difference is whether a reader can see a half-written drop.

Core concepts

Three layers, and they are not synonyms.

A warehouse is a curated store. Data has a schema. You query it with SQL. Someone already decided what a row means, and the loader rejected or repaired what did not fit. You pay for that curation with a pipeline and with a system that wants to own the bytes. When the questions are known and the data is the product, a warehouse is a boring answer in the best way.

A lake is files in object storage. The data plane is cheap. The files are immutable blobs, and a metadata service maps a key to where the bytes are. This is not a POSIX filesystem. An overwrite is usually a new object plus a pointer swing, not an edit in the middle of a block. The lake is messy because nothing in the object store agrees, by itself, which set of files is “Tuesday.” A writer can be halfway through uploading a drop, a batch of new files for a partition, while a reader lists the prefix. Multipart upload exists because one PUT of a huge object is fragile, and a failed part leaves a partial object. Checksums belong on the bytes. A lake without a table format will serve whatever is visible at list time.

A lakehouse puts a table format over those files. Iceberg and Delta are the two names worth saying. The format adds three things the raw prefix does not have.

  • A snapshot is a committed version of the table. Readers open a snapshot id and stay on it.
  • A manifest lists the files that belong to that snapshot, and no others.
  • More than one engine can read the same snapshot. A batch job and an interactive SQL engine agree on which files exist because they agree on the snapshot, not because they listed a prefix at the same moment.

Schema evolution is a feature of the format. You add or change a column in the table metadata. Old files stay as they are. Readers apply the schema from the snapshot they opened. You do not rewrite every historical file to add a field, and two engines do not invent two different interpretations of the same bytes.

The commit is a pointer swing, the same shape as an object overwrite, one level up. The writer uploads new data files. They are invisible to readers, because no snapshot names them yet. The writer builds a manifest that lists the complete file set for the new version. Then it publishes a new snapshot by swinging one piece of metadata. A reader who already opened the old snapshot keeps reading the old manifest. A reader who opens the table after the swing sees the new manifest entire, or the old one entire. They do not see ten of Tuesday’s files and none of Monday’s.

That is the fix for the half-written drop. In the raw lake, the writer deletes Monday’s files as it uploads Tuesday’s. A reader lists the prefix in the middle, gets a torn set, and computes a daily total on a fraction of the day. With snapshots, Monday’s manifest remains the committed table until Tuesday’s manifest is complete and the pointer moves. A crash after the uploads and before the swing leaves orphan files. Readers on the old snapshot still see a whole table. A cleanup job later deletes files no snapshot references. Until that job runs, you are storing extra bytes. That is a retention choice, not a torn read.

This is a lot of machinery. Choosing a database comes first. If the design is one service and one database, query the database. You already have transactions, a schema, and a primary. A lakehouse adds a catalog, a commit protocol, file writers, and a second engine so you can scan rows you could already read. Do not reach for it because a diagram of “the modern data stack” had a box you have not used yet.

Object storage is the right base when you do want it: immutable files, a cheap place to keep history, checksums on the bytes, multipart for the large ones. The table format is the metadata that makes a prefix into a table. The files alone are not the table.

flowchart LR
  writer[Writer] --> files[New data files]
  files --> manifest[New manifest]
  manifest --> snap[Snapshot pointer]
  snap --> reader[Reader on one snapshot]

The reader binds to the snapshot, never to “whatever objects exist in this prefix right now.” The new files are reachable only after the pointer moves.

A worked example

You keep traces from an agent: every tool call, for offline evals. The live path that decides whether a refund happened does not read this pile. It reads the transactional store that holds the idempotency key. The pile is for people and jobs that scan history.

Assumptions:

  • 1,000,000 traces a day.
  • Each trace is about 10 KB. That size is an assumption so the bytes are visible. Your real traces may be larger once you include the observation.
  • A nightly rewrite publishes one file per hour, 24 files, as a drop that replaces the previous day’s files. The 24 is a choice of layout, not a format requirement.
  • Two engines read the table: a batch job that builds an eval set, and an interactive SQL session a person uses while debugging a bad refund. Both should see a whole day or the previous whole day, never a blend.
1 day = 86,400 s
shortcut ≈ 100,000 s
1,000,000 traces / 86,400 ≈ 11.6 writes/s into the landing path

assumption: 1,000,000 × 10 KB = 10 GB of new bytes per day, one copy
30 days × 10 GB = 300 GB of traces if you keep a month and never duplicate
old snapshots you have not expired sit on top of that 300 GB

Eleven writes a second is not an online-transaction problem. A single database would accept this rate and would also be the wrong place to scan 300 GB of history beside the refund path. The live refund lookup wants a point read. The eval job wants a scan. Those are two access patterns. Putting both on the transactional primary is how a nightly scan competes with the keyed reads that stop double charges. Landing the scans on files is reasonable. Landing them on a raw prefix is where the torn read appears.

The half-written drop. The job deletes the previous day’s 24 files and streams the new 24 into the same prefix. A reader lists the prefix halfway.

assumption: the reader lists after 10 of 24 new files are visible
and after the old files are already deleted
the reader sees 10 hours and believes it saw the day
10 / 24 of the traces is not the day
a sum, a count, or an eval score on that list is a fiction

Nothing in the object store ties those 10 files into a commit. List is not a snapshot. A multipart upload that is still open is worse: the reader may observe a key whose bytes are not finished, unless you only publish keys after the upload completes and the checksum matches. Check the checksum, then publish. Do not list-and-pray.

The snapshot version of the same rewrite. The job uploads 24 new files beside the old ones. It writes a manifest that names all 24 and their checksums. It swings the snapshot pointer. Before the swing, both engines still see yesterday’s complete manifest. After the swing, both see today’s. A reader that started on snapshot 41 finishes on snapshot 41 even if snapshot 42 commits mid-query. There is no 10-hour day.

If the job crashes after uploading 10 files and before the swing, those 10 are orphans. The committed snapshot still names yesterday’s 24. The eval job is stale by a day, which you can alert on by watching snapshot age, and it is not silently short. Cleanup deletes the orphans once you are sure no snapshot references them. If you skip cleanup, the 10 GB a day understates what you store, because every failed attempt leaves files.

Schema evolution, same traces. You add a column for the idempotency key id so a later eval can join a model claim to the ledger. In the table format, that column appears in the snapshot metadata. Old files do not gain a new physical field overnight. Readers of an old snapshot do not pretend the column existed. Readers of the new snapshot see it, and they know which files predate it. If you instead encode the schema by hoping every engine infers columns from whatever files happen to be in the prefix, the batch job and the SQL session will disagree the week the field appears in 10 files and not in 14. That disagreement is another half-written drop, wearing a schema.

Where you should refuse. The agent service has one database for tasks, users, and idempotency keys. A proposal arrives to store the tasks themselves as an Iceberg table so “we only have one copy.” You would give up the transaction that writes the business row and the outbox together, you would add a commit protocol the request path does not need, and you would still have to answer a point read for “did this key already refund.” Transactions on one database are the right tool when you still have one database. The lakehouse is for the trace scan, beside that database, with a lag you state. It is not a replacement for the row the refund depends on.

Who the user is matters. The eval owner can wait for the next snapshot. The person owed a refund cannot wait for a manifest commit to learn whether you already charged them. Serve that read from the transactional store. Use the lake to ask which prompts produced bad tool calls last week.

Tradeoffs

Choice What you gain What you spend
Warehouse table Schema and SQL on curated rows A loader, and you left the cheap file pile behind
Raw lake prefix Cheap landing, any writer can drop files Readers see a half-written drop, and engines disagree
Iceberg or Delta snapshot A manifest commit, many engines, one consistent set of files A catalog, cleanup, and snapshot expiry you must actually run
Keep every snapshot You can reread the table as it was Bytes grow without a bound, on top of daily ingest
One database for everything Transactions you already understand A large scan sits on the same primary as the keyed refund
OLTP plus a lakehouse copy The user path stays pointed and small Lag between the row and the snapshot, and a pipeline to operate
Rewrite files in place Looks like an update List-during-write returns a torn partition

Expiring snapshots is part of the design, not housekeeping you will get to later. A format that supports time travel will keep every version you forget to drop. The 300 GB figure was one copy of the latest month, under a 10 KB assumption. Every unexpired rewrite is another copy of some of those bytes. Name the retention the way you would name it for a log.

Pitfalls

  • Listing a prefix and calling the result a table. Mid-drop you see a fraction of the files, and every aggregate on that list is wrong while looking complete.
  • Publishing an object before the multipart upload finishes and the checksum matches. The manifest then names bytes that are torn inside a single file, which a snapshot does not magically repair.
  • Using the lake as the source of truth for a charge or an idempotency key. Snapshot lag and a missed commit become a second refund. The key lives in the transactional store.
  • Reaching for a lakehouse when you have one service and one database. You take on manifests and a second engine to reimplement a transaction you had.
  • Forgetting snapshot expiry. Failed attempts and old versions accumulate as orphans and as history nobody still reads. The storage bill becomes “every rewrite,” not “thirty days of ingest.”
  • Inferring the schema from whichever files are visible. Two engines, two schemas, the week a column rolls out. Put the schema on the snapshot.
  • Letting a batch scan and the user path share one primary because you refused the lakehouse and also refused to separate the workloads. The lakehouse is optional. The separation is not, once the scan is large.
  • Treating a successful pointer swing as proof the new data is right. The swing proves the manifest is what readers will see. It does not prove the job included every hour. Alert on what the snapshot contains, and alert on commit success too.

In the interview

Draw the three layers in the first five minutes. Warehouse: curated schema and SQL. Lake: files, cheap, no commit. Lakehouse: Iceberg or Delta, snapshots and manifests, so two engines read one consistent set. Then tell the half-written drop: a reader listing a prefix during a replace sees a torn day, and a snapshot hides new files until the manifest is complete. Say you would not put one service’s only database into a table format.

Skip file-format trivia and a product tour. If you mention bytes, label the record size as an assumption and show the multiplication.

The question that usually follows is either “what does the reader see if the writer crashes” or “why not use this for the user record.” Crash: old snapshot remains, new files are orphans, cleanup comes later, no torn read. User record: point reads and transactions stay on the database; the lakehouse takes the scan, with lag you state.

Check yourself

A job deletes yesterday's 24 files while uploading today's. A reader lists the prefix and sees 10 files. What is wrong with the daily total?

The reader observed a half-written drop. Ten of twenty-four hours is not a day, and the old files are already gone, so there is no complete copy in that prefix either. A list is not a commit. Any count, sum, or eval score on those 10 files is a fraction wearing a full day’s name.

What does a reader bound to snapshot 41 see if snapshot 42 commits halfway through the query?

Snapshot 41’s manifest, the whole way through. The new files become visible only to readers who open 42. The pointer swing publishes an entire manifest, so this reader does not pick up a mix of the two versions mid-scan.

The writer crashes after uploading 10 files and before swinging the snapshot pointer. What do readers see, and what is left behind?

Readers still see the previous snapshot, complete. The 10 files are orphans that no manifest names. A cleanup job can delete them later. You are stale by one interval, which is detectable, and you are not serving a torn table. Skipping cleanup is how those orphans become permanent storage.

You have one service and one database for tasks and idempotency keys. Why is a lakehouse the wrong place for those rows?

Those rows need a transaction and a point read on the user path. A lakehouse adds snapshots, manifests, and a file commit so that large scans and several engines can share history. You would give up the simpler transaction and still need a keyed lookup for the refund. Keep the rows in the database. Put traces you scan offline in the table format if the scan should not live on that primary.

You add a column to traces. Why can two engines disagree if the schema lives only in the files?

During the rewrite, some files have the column and some do not, and a half-written drop makes that worse. Each engine infers a schema from the files it happens to open. The snapshot is supposed to hold the schema so both engines apply one definition, and so old files remain legible as old files instead of as broken new ones.

Based on: Iceberg and Delta snapshots and manifests; Object storage pointer swings, multipart upload, and checksums; Snapshot isolation and MVCC.