Skip to main content

ACID transactions on Parquet,
with version history.

Delta Lake is an open table format: it stores the rows in Parquet and each change in a transaction log. This gives the table consistent reads, versions to go back in time, MERGE, UPDATE, and DELETE, and a single table for batch and streaming. See what happens in a commit, how a read rebuilds the table, and what happens when two writers write at the same time.

An open table format makes a set of data files work like an SQL table, which several engines read and write.

Delta Lake is one of the TDP table formats, alongside Apache Iceberg, and keeps the state of each table in a transaction log.

The log is the table

The table describes itself

Which files make up the table, with which schema and which partitions, is written in the log, stored alongside the data. The table can be read without a separate metastore and copied with ordinary file system tools.

One version per commit

All or nothing

Each commit is a new file in the log, with the next version number. The version appears whole or does not exist, and readers never see a half-finished write.

No locks

Multiple writers at the same time

With optimistic concurrency, each writer checks, before committing, whether another one changed the same files. If there is a conflict, the write fails, and the table stays intact.

On this page

Watch a commit happen​

A DELETE in Spark and a read in Trino, on the same table. Press Play or step through. Underlined names lead to the Glossary.

EnginesWho writes and who reads
SparkRuns a DELETE
TrinoReads the table
Transaction logWhat holds at each version
Current versionLatest checkpoint and following commits
New commitJSON file of the next version
Data filesWhere the rows live
Original fileHas rows to delete
Rewritten copyWritten for this commit
Step 1 of 5

1 Spark reads the current version

A DELETE reaches Spark. Before writing, Spark reads the table's latest version from the log and identifies which data files have rows that meet the condition: those are the ones that must be rewritten.

  1. Spark reads the current version. A DELETE reaches Spark. Before writing, Spark reads the table's latest version from the log and identifies which data files have rows that meet the condition: those are the ones that must be rewritten.
  2. The copy is written. Spark writes a new copy of each of those files, now without the deleted rows, with a new and unique name. The original file stays where it is, because no data file is overwritten, and for now no reader sees the copy.
  3. Check before committing. Spark checks whether another writer has committed, since the version it read, any change that conflicts with its own. With no conflict, it proceeds to the commit. With a conflict, the write fails with a concurrent modification exception, and the table stays as it was.
  4. The commit: a new file in the log. Spark writes to the log the JSON file of the next version, with the commit's actions: remove for the original file, add for the copy, and commitInfo with the operation performed. A log entry is never overwritten, and only one writer creates each version: with this file, the new version takes effect in full.
  5. Trino reads the new version. Trino rebuilds the table from the log and reads only the files listed as added, among them the copy. The original file becomes a tombstone: it stays in storage for reads that still use the previous version, until VACUUM deletes it after the retention period.
Figure 1 - A commit in Delta Lake. The new files are written first. The change only takes effect when the new version's file appears in the log.

Architecture​

One directory per table: the data files and, next to them, the transaction log.

Delta Lake architecture: transaction log and data files in the table directoryThe table directory holds the transaction log, in the _delta_log subdirectory, and the data files in Parquet. The _last_checkpoint file points to the version 42 checkpoint, which stores the complete state of the table at that version: the protocol and metaData actions and the add actions for the files present. After it come the commits for versions 43, 44 and 45, one JSON file per version, each with its own actions: version 43 adds a file, version 44 removes a file and adds its rewritten copy, and version 45 adds another file. The removed file stays in storage as a tombstone until VACUUM.TRANSACTION LOG_delta_log/DATA FILESParquet_last_checkpointpoints to the latest checkpointcheckpointversion 42…42.checkpoint.parquetprotocolmetaDataaddaddcommitcommitcommitversion 43version 44version 45…00043.json…00044.json…00045.jsoncommitInfoaddcommitInforemoveaddcommitInfoadddatafiledatafilerewrittencopydatafiletombstoneawaits VACUUM
Figure 2 - Delta Lake architecture: in the table directory, the transaction log, with the latest checkpoint and the following commits, and the data files that each add or remove action references. Underlined terms lead to the Glossary.

What the figure shows:

  1. The transaction log lives in the _delta_log subdirectory, inside the table directory. In the figure, it is the top band, with the checkpoint and the commits.
  2. The _last_checkpoint file points to the most recent checkpoint.
  3. The checkpoint, in Parquet, consolidates the complete state of the table at one version. In the figure, the version 42 one holds the entire state up to that point: the protocol and metaData actions and the add actions of the files that are present. metaData carries the schema and the partitions, and protocol says what a client needs to know to use the table.
  4. The commits come after the checkpoint: each one is a JSON file with one action per line, and commitInfo records the operation. In the figure, they are versions 43, 44, and 45: 43 adds one file, 44 removes one file and adds its rewritten copy, and 45 adds another.
  5. The data files, in Parquet, live in the table directory, next to the log. In the figure, they are the files that are present and the rewritten copy.
  6. The add and remove actions add and remove data files. In the figure, the green arrows connect each add to the file it references, and the dashed arrow connects the remove to the removed file.
  7. The tombstone is the file removed by version 44: it stays in storage until VACUUM.
Compared to Iceberg

In Apache Iceberg, the catalog holds a pointer to the current metadata file, and the commit is the swap of that pointer. In Delta Lake, the current version is the highest-numbered one in the log, next to the data, and the commit is the creation of that version's file. In both formats, the change is published at once, and readers see a whole version.

The name of a commit​

Each table version is a file with a predictable address inside the table directory.

Click each part of the path.

Table directory

Everything that makes up the table lives here: the data files, at the root or in subdirectories, and the transaction log. With the metadata alongside the data, the table can be copied or moved with ordinary file system tools.

See in the Glossary
mytable — Table directory
Everything that makes up the table lives here: the data files, at the root or in subdirectories, and the transaction log. With the metadata alongside the data, the table can be copied or moved with ordinary file system tools.
_delta_log — Transaction log
Holds the commits, in JSON, the checkpoints, in Parquet, and the _last_checkpoint file. Since the name starts with an underscore, the directory is not mistaken for a data file subdirectory.
00000000000000000043.json — Commit
One table version. The name is the version number, padded with leading zeros. The content is JSON, with one action per line, applied on top of the previous version. The checkpoint of this same version would be called 00000000000000000043.checkpoint.parquet.

The leading zeros make the alphabetical order of the files match the order of the versions.

That is why, from the version of the checkpoint indicated in _last_checkpoint, a reader finds the newest commits without listing the entire log.

From the log to the table​

Four commits, one checkpoint, and one question: which files make up the table at each version?

ReaderSpark or Trino
ReadRebuilds the requested version
CheckpointThe consolidated state
_last_checkpointPoints to the recent checkpoint
CheckpointState of version 2, in Parquet
CommitsOne JSON per version
Version 0protocol, metaData, add f1
Version 1add f2
Version 2remove f1, add f3
Version 3add f4
Data filesThe table's rows
f1Written in version 0
f2Written in version 1
f3Copy of f1, in version 2
f4Written in version 3
Step 1 of 7

1 Version 0: the table is born

The first commit brings the protocol action, with the minimum reader and writer versions, the metaData action, with the schema, the partition columns, and the configuration, and an add for the first data file. At version 0, the table is f1.

  1. Version 0: the table is born. The first commit brings the protocol action, with the minimum reader and writer versions, the metaData action, with the schema, the partition columns, and the configuration, and an add for the first data file. At version 0, the table is f1.
  2. Version 1: an INSERT. An insert writes f2 and commits with add f2. The existing files do not change. At version 1, the table is f1 and f2.
  3. Version 2: a DELETE rewrites f1. The delete writes f3, a copy of f1 without the deleted rows, and commits with remove f1 and add f3. At version 2, the table is f2 and f3; f1 stays in storage as a tombstone, until the retention expires.
  4. A checkpoint consolidates version 2. The version 2 checkpoint stores, in Parquet, the result of applying commits 0, 1, and 2: protocol, metaData, add f2, add f3, and the remove of f1, kept while it is a tombstone. The _last_checkpoint file now points to it.
  5. Version 3: one more file. A new insert writes f4 and commits with add f4. The checkpoint does not change: it still describes version 2.
  6. A read of the latest version. The reader opens _last_checkpoint, loads the version 2 checkpoint, and applies only commit 3. For each file, the most recent reference wins, and the result is f2, f3, and f4: only these files are read. The remove of f1 does not enter the read. It serves VACUUM.
  7. Time travel to version 1. A query with VERSION AS OF 1 cannot use a checkpoint newer than the requested version. The reader applies commits 0 and 1 and arrives at f1 and f2, the table as it was. This only works while those commits and the f1 file remain retained.
Figure 3 - From the log to the table. Each commit adds or removes files. The checkpoint consolidates the state, and the read applies only what came after it.

A table's state at a version is its snapshot: the protocol, the metadata, the files present, and the tombstones.

Time travel reaches a version as long as its log and data files are retained: log cleanup, after checkpoints, and VACUUM, on the data files, define that limit. See Versions and time travel.

Two writers at the same time​

Both read the same version. The result depends on whether they touched the same files.

With optimistic concurrency, nobody locks the table.

At commit time, each writer compares its change with what others have committed since the version it read. If the changes do not overlap, its change enters as a new version, in the table's serial order. If they overlap, the write fails with a concurrent modification exception, and the table stays as it was.

Concurrent operationINSERTUPDATE, DELETE, MERGE INTOCompaction
INSERTNo conflict
UPDATE, DELETE, MERGE INTOMay conflictMay conflict
CompactionNo conflictMay conflictMay conflict

Compaction, here, is the rewriting of files recorded with dataChange equal to false, which only reorganizes existing data.

Where a conflict is possible, it only happens if the two operations act on the same set of files. An UPDATE with date > '2010-01-01' and a DELETE with date < '2010-01-01' may touch the same files in a table not partitioned by date. With the table partitioned by date, the sets separate and the conflict disappears.

When the conflict happens, the exception name gives the reason, such as ConcurrentAppendException, when another operation added files to the partition that was read, or ConcurrentDeleteReadException, when another operation deleted a file that was read.

A self-describing table​

Besides the files, the log stores the schema, the compatibility rules, and the history of each change.

Schema and partition

The metaData action carries the schema, the partition columns, and the table configuration, and the most recent one is the one that holds. Each write goes through schema validation: a column the table does not have or a type different from the column's makes the write fail. Columns can be added or reordered through DDL or in the write itself, with schema evolution enabled.

Protocol and table features

The protocol action says what a client must implement to read or write the table: the minimum reader and writer versions and the table features in use, enabled table by table. A newer version of Delta Lake always reads and writes tables from earlier versions, and some features require all of the table's clients to be upgraded. See Protocol.

History

The commitInfo action records, in each commit, the operation and who ran it. DESCRIBE HISTORY returns this history, from the most recent commit to the oldest, with the metrics of each write, and free text can accompany the commit, through the userMetadata option.

Table properties

They adjust the behavior of each table and live in the metaData action itself. A table can, for example, accept only appends, with no record deletion or value changes, and have defined how long the history is kept and how long a removed file is stored before it can be deleted.

Time travel and RESTORE

VERSION AS OF and TIMESTAMP AS OF read the table at an earlier version, and RESTORE returns the table to an earlier state, by version or by timestamp. Both depend on the log and the files of that version still being retained. See Time travel.

Why Delta Lake​

Isolation

Always-consistent reads

ACID transactions with serializable isolation: readers use a consistent snapshot of the table, even with writes happening at the same time.

Scale

Distributed metadata

Spark's distributed processing handles the metadata of petabyte-scale tables, with billions of files, and a query can be planned on a single machine or in parallel.

Batch and streaming

One table for both

The same table is a batch table and a streaming source and sink. Whoever follows the log knows what came in during a period, which makes incremental processing efficient.

Updates

MERGE, UPDATE, and DELETE

Merge, update, and delete operations serve cases such as change data capture (CDC), slowly changing dimensions (SCD), and streaming upserts.

Versions

Going back in time

Data versioning makes it possible to undo changes, keep complete audit trails, and reproduce machine learning experiments.

Connectors

Several engines, the same table

Spark, Flink, Hive, Trino, and other engines read and write Delta tables through their own connectors.

Where it comes from

Delta Lake is an independent open source project and, since 2019, has been part of the Delta Lake Project, a sub-project of the Linux Foundation Projects. The code is distributed under the Apache 2.0 license.

In the TDP editions​

Available in the TDP editions
EditionVersionDocumentation
TDP Datacenter3.3.0TDP Datacenter components
TDP Kubernetes4.0.1 · chart tdp-deltalake 3.0.3Configuration in TDP Kubernetes

In TDP Datacenter​

In TDP Datacenter, Delta Lake tables are queried by Trino, and format support lives in the services' configuration, in Ambari.

Trino connector

The Delta Lake connector can be enabled in use.deltalake, in the connectors-properties configuration. The deltalake catalog uses the delta_lake connector and the Hive Metastore address, in hive.metastore.uri. The connector reads the transaction log directly and therefore notices when other systems change the data. See Trino.

Catalog in OpenMetadata

The creation of a Delta Lake data service in OpenMetadata can be enabled in deltalake.enabled, with the integration turned on in integration.enabled, in the openmetadata_integration configuration. See OpenMetadata.

In TDP Kubernetes​

In TDP Kubernetes, the tdp-deltalake chart delivers scheduled maintenance jobs for Delta Lake tables, with Spark as the runtime.

Maintenance jobs

VACUUM, OPTIMIZE, OPTIMIZE Z-ORDER, and DESCRIBE HISTORY, in maintenance.jobs.*. Each job is enabled in enabled, has its schedule in schedule, and processes the tables listed in tables or, with the list empty, all the Delta tables registered in the Hive Metastore. OPTIMIZE Z-ORDER processes only the listed tables, with the columns of each one. OPTIMIZE Z-ORDER and DESCRIBE HISTORY come disabled. The role of each job is in Scheduled maintenance.

Spark runtime

Each job runs Spark in its own pod, with the image defined in maintenance.spark.image.*, which already includes the Delta Lake and S3A libraries. The jobs do not need a Spark cluster. The Spark cluster that the chart can bring up, in spark.enabled, comes disabled and is not used by the jobs. The Delta Lake SQL extensions and catalog go in maintenance.spark.config, in the spark.sql.extensions and spark.sql.catalog.spark_catalog properties.

Storage

S3-compatible, through the S3A endpoint in maintenance.spark.config. The credentials arrive through the s3-credentials Secret, with the access-key and secret-key keys.

Who reads and writes the tables

Spark, with the optional tdp-spark.deltaLake.enabled block, which adds the Delta Lake SQL extension and catalog. The Spark image includes the Delta Lake libraries. Jupyter also reads and writes the tables maintained by the chart. See Where Spark and Trino find the tables.

Next steps​

Sources​

Delta Lake - Documentation

Delta Lake - Transaction Log Protocol

Delta Lake - Concurrency control

Delta Lake - Table batch reads and writes

Delta Lake - Table deletes, updates, and merges

Delta Lake - Table utility commands

Delta Lake - Feature compatibility and protocols

Delta Lake - Table properties