Tuesday at 08:45, a price-feed job wrote bad prices into shop.products — the $29.99 desk lamp went out the door at $9.99, the $49.99 kettle at $19.99. Orders flowed for three days before anyone noticed. On Friday someone fixed the prices by hand, but finance wants the full damage report: what did the table look like Tuesday at noon? Exactly which rows changed, and when?
In a plain Parquet lake, that’s archaeology — digging through overwritten files and hoping your backups are labeled. In Delta Lake, it’s two queries. Every write to a Delta table is a version, and every version stays queryable. Time travel isn’t a premium feature or a backup strategy. It’s just how the storage format works.
Every write is a version
Delta Lake keeps a transaction log — an ordered journal of every commit — next to your data files. The first write creates version 0; every INSERT, UPDATE, DELETE, and MERGE after that appends a new version. Querying “the table” with no qualifier simply means “the latest version.”
The log is inspectable. DESCRIBE HISTORY shows every version, newest first, with who ran what and when:
DESCRIBE HISTORY shop.products;
version | timestamp | userName | operation | operationParameters
4 | 2026-10-09 11:05 | priya | UPDATE | {"predicate": "..."}
3 | 2026-10-08 14:20 | marco | DELETE | {"predicate": "..."}
2 | 2026-10-06 08:45 | etl_svc | UPDATE | {"predicate": "..."}
1 | 2026-10-05 16:40 | priya | WRITE | {"mode": "Append"}
0 | 2026-10-05 09:12 | priya | WRITE | {"mode": "Overwrite"}
That table is your first debugging tool. When something looks wrong, the answer to “what happened?” is usually right there in the operation column — no Slack archaeology required.
Reading the past: VERSION AS OF and TIMESTAMP AS OF
This is the whole trick:
-- the table exactly as of version 2
SELECT * FROM shop.products VERSION AS OF 2;
-- the table as it looked Tuesday at noon
SELECT * FROM shop.products TIMESTAMP AS OF '2026-10-06 12:00:00';
Both forms work against catalog names and path-based tables (the delta. prefix with a backtick-quoted path). The DataFrame API has the same two knobs:
df = spark.read.format("delta").option("versionAsOf", 2).load("/data/shop/products")
df = spark.read.format("delta").option("timestampAsOf", "2026-10-06 12:00:00").load("/data/shop/products")
Time travel reads are cheap in the way that matters: they don’t copy anything. The engine replays the log up to the requested version and reads only the data files that were live then. The current table is untouched — you’re reading, not rewinding.
Try it live — the lab below replays the exact five-commit history from the story above:
| sku | name | price | stock |
|---|---|---|---|
| BT-100 | Desk lamp | $29.99 | 40 |
| K-201 | Kettle | $49.99 | 25 |
| M-300 | Mug | $12.99 | 100 |
| W-410 | Wallet | $39.99 | 60 |
| P-600 | Pillow | $24.99 | 50 |
| sku | price | stock | _change_type | _commit_version | _commit_timestamp |
|---|---|---|---|---|---|
| P-600 | $24.99 | 50 | insert | v1 | 2026-10-05 16:40 |
| BT-100 | $29.99 | 40 | update_preimage | v2 | 2026-10-06 08:45 |
| BT-100 | $9.99 | 40 | update_postimage | v2 | 2026-10-06 08:45 |
| K-201 | $49.99 | 25 | update_preimage | v2 | 2026-10-06 08:45 |
| K-201 | $19.99 | 25 | update_postimage | v2 | 2026-10-06 08:45 |
| B-550 | $89.99 | 30 | delete | v3 | 2026-10-08 14:20 |
| BT-100 | $9.99 | 40 | update_preimage | v4 | 2026-10-09 11:05 |
| BT-100 | $29.99 | 40 | update_postimage | v4 | 2026-10-09 11:05 |
| K-201 | $19.99 | 25 | update_preimage | v4 | 2026-10-09 11:05 |
| K-201 | $49.99 | 25 | update_postimage | v4 | 2026-10-09 11:05 |
A few things worth noticing while you play. First, the timestamp buttons: picking a commit’s exact timestamp lands on that version, but the “between commits” button shows the real rule — TIMESTAMP AS OF resolves to the latest version committed at or before that instant, not the nearest one. Second, the “before v0” button: a timestamp earlier than the first version is an error, not an empty result. And if you ask for a version that doesn’t exist, Delta tells you the valid range instead of guessing.
Timestamps are trickier than versions
Prefer VERSION AS OF whenever you mean a specific write. Timestamps have three sharp edges:
- Resolution is at-or-before. If two commits land seconds apart and you copy a timestamp from
DESCRIBE HISTORYoutput, you can easily resolve to the version before the one you wanted. Versions are exact; timestamps are fuzzy. - Copied directories break timestamp travel. A version’s timestamp comes from its log file’s own timestamp, so if you copy a whole Delta table directory somewhere new, time travel by timestamp can silently resolve wrong. Version-based travel is unaffected.
- History isn’t infinite. Old versions disappear once their data files are vacuumed away and the log moves on (more on retention below).
VERSION AS OF 2on a table whose v2 files are gone fails — it doesn’t return stale data.
None of this makes timestamps useless — “what did this look like Tuesday at noon” is a genuinely timestamp-shaped question — but treat the timestamp as a way to find a version, then pin the version number in anything reproducible.
Undoing a write: RESTORE appends, never rewinds
Reading the past is safe. Changing the present is what RESTORE is for:
-- undo everything back to v2: a new version with v2's data
RESTORE TABLE shop.products TO VERSION AS OF 2;
-- or by timestamp
RESTORE TABLE shop.products TO TIMESTAMP AS OF '2026-10-06 12:00:00';
Python equivalent: DeltaTable.forName(spark, "shop.products").restoreToVersion(2) (or restoreToTimestamp(...)).
Here’s the part everyone gets wrong on the first try: RESTORE does not delete history. It appends a brand-new version whose contents equal the target version — a metadata-only operation that points the new commit at the old version’s files. Versions 0 through 4 are still there, still time-travelable, still in DESCRIBE HISTORY. The restore itself shows up as the newest entry.
That design has two consequences worth knowing. First, a restore resurrects deleted rows — if v3 deleted the backpack and you restore to v2, the backpack is back (until vacuum removes the old files). Second, RESTORE counts as a data-changing operation: if a streaming job reads this table, the restore’s log entries look like brand-new data, and reprocessing them can produce duplicates. Restore during a quiet window, or be ready to handle it downstream.
And if you truly want old versions gone — not just superseded — that’s VACUUM, which deletes data files no longer referenced by any retained version. Restore never does that.
What changed between versions: the change data feed
Time travel answers “what did it look like.” The change data feed (CDF) answers “what exactly changed” — row by row, with before-and-after images. It’s how you build incremental downstream pipelines without rescanning the whole table.
One prerequisite, and it’s a hard one: CDF only records changes made after you enable it. There is no backfill.
-- at creation
CREATE TABLE shop.products (sku STRING, price DOUBLE, stock INT)
TBLPROPERTIES (delta.enableChangeDataFeed = true);
-- or on an existing table (captures only future changes)
ALTER TABLE shop.products SET TBLPROPERTIES (delta.enableChangeDataFeed = true);
Then read changes with the table_changes table-valued function:
SELECT sku, price, stock, _change_type, _commit_version, _commit_timestamp
FROM table_changes('shop.products', 1, 3);
The start and end versions are inclusive — this reads every change committed in v1, v2, and v3. (Omit the end to read from the start through the latest version.) Timestamps work as bounds too.
Every change row carries the table’s columns plus three metadata columns:
| Column | Values |
|---|---|
_change_type | insert, update_preimage, update_postimage, delete |
_commit_version | the version that committed the change |
_commit_timestamp | when that commit landed |
The update_preimage / update_postimage pair is the elegant bit: instead of just “row X was updated,” you get the row before and the row after as separate records, so a downstream consumer can compute the delta itself — old price vs. new price, no join back to history required. Deletes carry the deleted row’s last values. Inserts are plain insert rows.
The DataFrame API has the same capability for batch and streaming reads:
changes = (spark.read.format("delta")
.option("readChangeFeed", "true")
.option("startingVersion", 1)
.option("endingVersion", 3)
.table("shop.products"))
A common pattern: feed table_changes (or a streaming CDF read) into your silver-to-gold job so it processes only what changed since the last run — the incremental pipeline without the watermark bookkeeping.
The retention fine print
Time travel is bounded. Old data files are eventually removed by VACUUM, and the transaction log itself has a retention window — after that, old versions are simply gone, and VERSION AS OF on them fails rather than returning something stale. Two table properties govern this (delta.logRetentionDuration for the log, delta.deletedFileRetentionDuration for removed files); the defaults are generous but not infinite, and lowering them trades storage savings against how far back you can travel. If “query last quarter’s table” is a real requirement — audits, ML reproducibility — set retention deliberately and make sure your vacuum schedule respects it. CDF data follows the same retention: vacuum the table’s files and the recorded change history goes with them.
Git for data, minus the merge conflicts
The mental model that sticks: a Delta table is a tiny version-control system where every commit is queryable, every mistake is undoable without destroying evidence, and every diff is one function call away. DESCRIBE HISTORY is your git log, VERSION AS OF is your checkout, RESTORE is a revert commit (not a force-push), and table_changes is your diff.
The finance damage report from the intro? It’s a timestamp query and a CDF range — ten lines of SQL, no backup restoration, no incident war room. That’s the whole pitch: the past is just another query away.
Sources
- Query an older snapshot of a table (time travel) — official Delta Lake docs:
VERSION AS OF/TIMESTAMP AS OFsyntax, DataFrame options - Change data feed — official Delta Lake docs: enabling CDF,
table_changes, the change schema - Use change data feed on Databricks — Databricks docs: batch reads, inclusive start/end versions
- Delta utility commands (RESTORE) — official Delta docs source:
RESTORE TABLE ... TO VERSION AS OF,restoreToVersion/restoreToTimestamp