Sub topic 1
What Delta Lake is and where it fits in Databricks
Delta Lake is the default table format on Databricks. Every later chapter in this tutorial (creating tables, appending, updating, merging, time travel, maintenance) assumes the model in this chapter. Here you will learn what a Delta table is on disk, what it adds over plain files, and which Databricks components it works with.
Prerequisites
This chapter assumes you can:
- Write basic SQL:
SELECT,INSERT,WHERE. - Work with PySpark DataFrames, including
spark.tableanddf.write. - Open a Databricks notebook and attach it to compute, such as a cluster, serverless compute, or a SQL warehouse.
- Read a table definition: columns, data types, and the idea of a schema.
You do not need to know anything about Delta internals yet.
What Delta Lake is
Delta Lake is an open-source storage layer. It sits between your compute engine, such as Apache Spark, and the files in cloud object storage, such as S3, ADLS, or GCS. It does not replace the storage or the engine. It defines how a set of files is organized so they behave like a reliable table.
A Delta table is a directory in storage with two kinds of content:
- Data files. These are ordinary Parquet files. Parquet is a columnar file format, which means values are stored column by column. This makes analytical scans fast and compresses well.
- A transaction log. This is a
_delta_logfolder of small JSON and checkpoint files. It records every change ever made to the table: which data files were added, which were removed, and what the schema is.
The log is what turns a pile of Parquet files into a table. A reader does not list the directory and read whatever it finds. It reads the log, works out which files make up the current version, and reads only those. The next chapter covers the log in detail.
What plain files lack
Object storage gives you cheap, durable files. It does not give you database behavior. Consider a directory of plain Parquet files that several jobs write to.
| Problem with plain Parquet | What Delta Lake does instead |
|---|---|
| A job fails halfway and leaves partial files that readers pick up | A write becomes visible only when its entry is committed to the log, so readers never see partial results |
| Changing one row means rewriting files by hand | `UPDATE`, `DELETE`, and `MERGE` are built in |
| Anyone can write a file with a different schema | The table schema is enforced on every write |
| No record of what the data looked like yesterday | Every commit creates a table version you can query or restore |
| Two writers can overwrite each other silently | Concurrent writes are checked for conflicts |
| Streaming and batch jobs need separate storage designs | The same table can be a batch source, a batch sink, a streaming source, and a streaming sink |
These behaviors are the reason Delta tables are described as having ACID guarantees: atomicity, consistency, isolation, and durability. You will see how each one works in the next chapter.
Where Delta fits in Databricks
Databricks describes its architecture as a lakehouse: the low-cost storage of a data lake combined with the table semantics of a data warehouse. Delta Lake is the table format that makes that possible. Several components work together.
- Compute. Clusters, serverless compute, and SQL warehouses run the queries. They are stateless with respect to your data. You can stop a cluster and the tables are unaffected.
- Delta tables. The format described above. In Unity Catalog, a table created without a format clause is a Delta table.
- Unity Catalog. This is the governance layer. It gives each table a three-level name,
catalog.schema.table, and controls who can read or change it. Examples in this tutorial usemain.sales.orders, meaning catalogmain, schemasales, tableorders. - Cloud storage. This is where the files live. For managed tables, Unity Catalog chooses the location. For external tables, you choose it. Chapter 3 covers the difference.
A Delta table is not a database server. There is no process holding the table open. All the state is in the files, which is why any number of clusters can read the same table at once.
Delta compared with neighboring technology
Delta is not the only open table format. Apache Iceberg and Apache Hudi solve a similar problem: they add a metadata layer over Parquet files. The core idea is the same, but the metadata layout and engine support differ. If your organization uses engines that read Iceberg, Databricks can expose Delta tables to them through Delta UniForm, which generates Iceberg metadata alongside the Delta log. Treat that as an interoperability option. This tutorial uses Delta directly.
Delta is also not a replacement for a transactional database such as PostgreSQL. Each commit rewrites files and writes a log entry. This is efficient for batches of thousands or millions of rows. It is a poor fit for workloads that update single rows many times per second.
Seeing a Delta table in practice
The following cells create a small table, add rows, and inspect it. Run them in a notebook attached to compute with access to a catalog you can write to. If main.sales does not exist in your workspace, replace it with a catalog and schema you own.
CREATE SCHEMA IF NOT EXISTS main.sales;
CREATE TABLE IF NOT EXISTS main.sales.orders_demo (
order_id BIGINT,
status STRING
);
INSERT INTO main.sales.orders_demo VALUES (1, 'new'), (2, 'new');
DESCRIBE DETAIL main.sales.orders_demo;DESCRIBE DETAIL returns one row of table metadata. Look at these columns:
formatshould bedelta.locationis the storage path that holds the data files and_delta_log.numFilesandsizeInBytestell you how many Parquet files back the current version and how large they are.
You did not write USING DELTA, yet the format is delta. In Unity Catalog, Delta is the default. The next chapters still write USING DELTA in some examples so the format is explicit.
You can read the same table from Python by name:
df = spark.table("main.sales.orders_demo")
df.show()
detail = spark.sql("DESCRIBE DETAIL main.sales.orders_demo")
detail.select("format", "numFiles", "sizeInBytes").show(truncate=False)Both the SQL and Python cells go through the same table. The language is a choice of interface, not a different storage path.
To see the version history that the log has recorded so far, run:
DESCRIBE HISTORY main.sales.orders_demo;You should see at least two rows: one for the table creation and one for the INSERT. Each row is a table version. Later chapters use this history for time travel and RESTORE.
Common mistakes at this stage
- Reading the folder as Parquet. If you point
spark.read.parquetat a Delta table's location, you read every data file in the directory, including files from older versions that the log has removed from the table. You get duplicate and stale rows. Always read Delta tables by name or withformat("delta"). - Editing files directly. Deleting or adding Parquet files in a table's directory without going through Delta corrupts the table's view of itself. The log would still reference files that no longer exist, or ignore files you added.
- Wrong catalog or schema. A
TABLE_OR_VIEW_NOT_FOUNDerror often means the session's current catalog or schema differs from what you assumed. Check withSELECT current_catalog(), current_schema();, or use the full three-level name. - Expecting database-style row locking. Delta uses optimistic concurrency, not locks. Conflicting writers fail and retry instead of waiting. See the chapter on concurrent writes.
What comes next
The remaining chapters build on this model in order. First you will see how the transaction log works and how managed and external tables differ. Then you will create tables with SQL and Python and define schemas and constraints. After that you will change data with append, overwrite, UPDATE, DELETE, and MERGE. The final chapters cover schema evolution, table history, concurrency, and maintenance.
Exercise
You run spark.read.parquet("<table location>") on a Delta table that has had several UPDATE operations, and the row count is higher than SELECT COUNT(*) on the table by name. Why, and how do you fix it?
Show answer
An UPDATE writes new data files and marks the old ones as removed in the transaction log, but the old files stay on storage until a later VACUUM. Reading the directory as plain Parquet ignores the log, so it counts rows from both old and new files. Read the table with spark.table("catalog.schema.table") or spark.read.format("delta") so Delta uses the log to select only the current files.
Exercise
Name two things a Delta table gives you that a directory of plain Parquet files does not, and state which part of the Delta table provides them.
Show answer
Any two of these are correct: atomic commits, schema enforcement, row-level UPDATE, DELETE, and MERGE, table versions for time travel, and conflict detection between concurrent writers. All of them come from the transaction log (_delta_log), which records each change as a versioned commit. The Parquet data files only hold the data.