Mhonn YbañezSRE, DevOps, AI Engineer
 Today I Learned
Read the full page

What are data lakes and data warehouses for?

Posted
Tags
databases, data-engineering, analytics

A production database is built for lots of small reads and writes. Analytics needs a few huge scans over everything, so the data gets copied somewhere built for that. A warehouse keeps it clean and structured for SQL, a lake keeps it raw and cheap for anything, and a lakehouse puts warehouse features on top of a lake.

In my serverless databases post, I guessed at one point that serverless databases were for the side stuff: metrics, analytics, ML, all synced from production. That guess was wrong, but the side it described is real. That's where data lakes and data warehouses live, and I realized I couldn't clearly say what the difference between them was.

The question I had

What are data lakes and data warehouses, and when would you use which?

What I found

Why not just query production?

Because production databases are built for a different shape of work.

  • Transactional (OLTP): the database behind the app. Lots of tiny reads and writes, like "get order 123" or "update this cart", and each one has to be fast.
  • Analytical (OLAP): questions like "revenue by region per month for the last three years". Few queries, but each one scans millions of rows.

Run that big scan on production and it fights the app for CPU, memory, and disk. The cache fills with old rows nobody else needs, and checkout gets slow because someone ran a report.

They also store data differently. A transactional database stores data by row, which is great for "give me this whole order". Analytical systems store it by column, which is great for "add up this one column across every row", because they only read the column they need, and similar values compress well.

So the data gets copied out into a system built for scanning.

Data warehouse: clean and structured

A warehouse holds data that's already been cleaned and shaped into tables with a fixed schema. The structure is decided before the data goes in (schema-on-write). You query it with SQL, and it's built to make those queries fast.

  • Who uses it: analysts, BI dashboards, finance reports.
  • Strength: reliable, consistent numbers. Everyone gets the same answer to "how many active users".
  • Weakness: getting new data in takes work, since it has to fit the schema first.
  • Examples: Snowflake, Google BigQuery, Amazon Redshift.

Data lake: raw and cheap

A lake is a pile of files in object storage like S3 or Google Cloud Storage. Anything goes in, in any format: database exports, logs, JSON events, images, CSVs. The structure gets decided when you read it (schema-on-read).

  • Who uses it: data engineers and data scientists, ML training jobs.
  • Strength: cheap storage, keeps everything, and you don't have to know today what you'll ask tomorrow.
  • Weakness: without care it becomes a data swamp: nobody knows what's in it, what's current, or what's safe to trust.
  • Querying it: engines like Spark, Trino, or Amazon Athena read the files directly. The data is usually stored in columnar files like Parquet, so scans stay efficient.

One thing that surprised me: a lake isn't automatically cheaper overall. The storage is cheap, but you pay separately for the compute that queries it.

Lakehouse: warehouse features on top of a lake

The lakehouse is the attempt to get both. You keep the data as files in the lake, but add an open table format on top, like Apache Iceberg, Delta Lake, or Apache Hudi. The format adds a layer of metadata that turns a folder of files into something that behaves like a table:

  • transactions, so a half-finished write doesn't show up in a query
  • a schema, and the ability to change it safely
  • time travel, so you can query the table as it was last week

"Lakehouse" is a term Databricks made popular. The line between the three is getting blurry, since many warehouses can now read Iceberg tables straight from a lake.

Side by side

WarehouseLakeLakehouse
What goes inCleaned, structured tablesAnything, rawAnything, organized as tables
SchemaDecided before loadingDecided when readingTracked by the table format
Main usersAnalysts, BIData engineers, MLBoth
StorageManaged by the warehouseObject storageObject storage
ExamplesSnowflake, BigQuery, RedshiftS3 with Athena or SparkIceberg or Delta Lake tables, Databricks

The difference isn't really the hardware anymore. Warehouses like Snowflake and BigQuery already split compute from storage, the same trick from the serverless databases post. The real difference is how structured the data is and who decides that structure, and when.

How the data gets there

ETL vs ELT:

  • ETL (extract, transform, load): clean and reshape the data first, then load the finished tables into the warehouse.
  • ELT (extract, load, transform): load the raw data first, then transform it inside the warehouse with SQL (tools like dbt). This got popular once warehouse compute became cheap and elastic.

Batch vs change data capture:

  • Batch: copy everything (or everything that changed) on a schedule, like every night. Simple, but the analytics side is always hours behind.
  • CDC (change data capture): read the database's own change log and stream each change out as it happens. In Postgres that's the WAL, the same log that serverless databases ship to their storage layer. Debezium is a common open source tool for this. The analytics side stays minutes or seconds behind instead of hours.

What they're used for

  • Dashboards and reports: the warehouse's main job. Revenue, active users, funnel numbers.
  • Ad-hoc questions: "did that change last month affect returns?" answered with SQL instead of a new feature.
  • ML training data: models need lots of history, often raw. This is usually the lake, and it's where the training data in my ML model lifecycle post would come from.
  • Logs and events: high volume, mostly cold, occasionally needed. Cheap lake storage fits.
  • Retention and compliance: keep years of records without keeping them in the production database.

Takeaway

Production databases answer "what is true right now" for one user at a time. Warehouses and lakes answer "what happened" across everyone. A warehouse is for questions you already know you'll ask, a lake keeps everything for questions you haven't thought of yet, and a lakehouse is trying to make that a single system.