Delta Lake time travel lets you read or restore an older version of a table, and this simple interview guide shows how with SQL and PySpark. Imagine this. It is Friday evening. A teammate runs a wrong DELETE on the production sales table and 2 lakh rows disappear. In a normal data lake built on plain Parquet files, this is a disaster. You hunt for backups and pray.
⚡ Quick summary: Delta Lake time travel
- Use VERSION AS OF or TIMESTAMP AS OF to read an older version of a table.
- RESTORE rolls the table back to an earlier version.
- VACUUM and retention settings decide how far back you can travel.

With Delta Lake, the fix can be one line of SQL. This feature is called time travel, and it is one of the most asked Delta Lake topics in data engineering interviews for Databricks and Spark roles.
Let’s break it down in simple words, with small SQL and PySpark examples you can try yourself.
What is Delta Lake time travel?
Time travel means you can read a table exactly as it looked at an older point – either by version number or by date and time.
Every time you write to a Delta table (INSERT, UPDATE, DELETE, MERGE, OVERWRITE), Delta does not change old files in place. It writes new files and records a new version in the transaction log (the _delta_log folder). Version 0 is when the table was created, then 1, 2, 3 and so on.
Because the old files are still there for some time, Delta can rebuild any older version. Think of it like Google Docs version history, but for a big data table.
Step 1: See the table history – Delta Lake time travel
Before you travel, you need to know where to go. DESCRIBE HISTORY shows every version with its timestamp, operation and user.
-- SQL
DESCRIBE HISTORY sales;
-- only the latest operation
DESCRIBE HISTORY sales LIMIT 1;The same thing in PySpark using the DeltaTable API:
from delta.tables import DeltaTable
dt = DeltaTable.forName(spark, "sales") # or DeltaTable.forPath(spark, "/data/sales")
(dt.history()
.select("version", "timestamp", "operation")
.orderBy("version", ascending=False)
.show(truncate=False))Here you might see that version 7 was a DELETE. So version 6 is the last “good” copy.
Step 2: Read an old version (VERSION AS OF / TIMESTAMP AS OF) – Delta Lake time travel
You can query an old version without changing anything. This is perfect for checking or comparing data.
-- by version number
SELECT * FROM sales VERSION AS OF 6;
-- by time
SELECT * FROM sales TIMESTAMP AS OF '2026-11-13 18:00:00';
-- short form using @
SELECT * FROM sales@v6;In PySpark, use the versionAsOf or timestampAsOf read options:
# by version
df_v6 = spark.read.option("versionAsOf", 6).table("sales")
# by timestamp, path-based table
df_old = (spark.read.format("delta")
.option("timestampAsOf", "2026-11-13 18:00:00")
.load("/data/sales"))Step 3: Find what changed between two versions – Delta Lake time travel
A very common interview follow-up: “How will you find the rows that were deleted?” Simple – compare the old and the current version.
old_df = spark.read.option("versionAsOf", 6).table("sales")
new_df = spark.read.table("sales")
deleted_rows = old_df.exceptAll(new_df) # rows present before, missing now
print(deleted_rows.count())In SQL, the same idea uses EXCEPT:
SELECT * FROM sales VERSION AS OF 6
EXCEPT
SELECT * FROM sales;Step 4: Roll back the table with RESTORE – Delta Lake time travel
Reading old data is nice, but to actually fix the table you use RESTORE.
RESTORE TABLE sales TO VERSION AS OF 6;
-- or by time
RESTORE TABLE sales TO TIMESTAMP AS OF '2026-11-13 18:00:00';# PySpark
dt = DeltaTable.forName(spark, "sales")
dt.restoreToVersion(6)
# dt.restoreToTimestamp("2026-11-13")Two important points that interviewers love:
- RESTORE does not erase history. It adds a new version to the log (for example, version 8 with operation RESTORE). Versions 7 and older are still in the history, so you can still time travel to them.
- RESTORE is a data-changing operation. If a streaming job reads this table, it may process the restored rows again and create duplicates downstream. Plan for that.
The catch: VACUUM and retention
If Delta kept every old file forever, your storage bill would keep growing. So Delta gives you VACUUM, which deletes data files that the current version no longer needs and that are older than a retention period.
-- see what would be deleted, without deleting
VACUUM sales DRY RUN;
-- delete old files, keep the last 7 days (168 hours)
VACUUM sales RETAIN 168 HOURS;Once VACUUM removes those files, you cannot time travel to versions that needed them. Reading such a version will fail with a missing-file error. This is the number one trap in real projects.
Two table properties control how far back you can go:
delta.logRetentionDuration– how long the history (log entries) is kept. Default: 30 days.delta.deletedFileRetentionDuration– how long removed data files are kept before VACUUM can delete them. Default: 7 days.
So with default settings, you can safely count on roughly the last 7 days of time travel. If you need more, increase both:
ALTER TABLE sales SET TBLPROPERTIES (
'delta.logRetentionDuration' = 'interval 60 days',
'delta.deletedFileRetentionDuration' = 'interval 30 days'
);Longer retention means more storage cost. Delta also has a safety check that blocks very short retention values (like RETAIN 0 HOURS) by default, because they can break running jobs and time travel. Do not turn that check off unless you fully understand the impact.
Real-world uses of time travel
See where the Delta Lake time travel matters in real projects.
- Undo mistakes: wrong DELETE, bad MERGE or a buggy overwrite.
- Audit and debugging: “What did this report show yesterday at 9 AM?”
- Reproducible ML: train a model on a fixed version so results can be repeated.
- Data quality checks: compare today’s load with the previous version to catch sudden drops in row count.
But remember: time travel is not a long-term backup. For months or years of history, use proper backups, table clones or SCD Type 2 style history tables.
Common interview questions (with short answers)
Use this short script to explain the Delta Lake time travel with confidence.
- How does time travel work internally? Every commit is recorded in
_delta_log. Old data files stay until VACUUM removes them, so Delta can rebuild any version from the log. - VERSION AS OF vs TIMESTAMP AS OF? The first uses the exact version number; the second picks the version that was current at that time.
- Why did my time travel query fail? Most likely VACUUM already deleted the files for that version, or the log entry is older than the log retention.
- Does RESTORE delete newer versions? No. It creates a new commit; newer versions remain in history until VACUUM cleans their files.
In short, Delta Lake time travel is your safety net for bad writes, as long as VACUUM has not removed the old files. Related: read our explainer on Adaptive Query Execution.
Key takeaways on the Delta Lake time travel
- Every write to a Delta table creates a new version in
_delta_log. - Use
DESCRIBE HISTORYto find versions, andVERSION AS OF/TIMESTAMP AS OF(orversionAsOf/timestampAsOfin PySpark) to read them. - Use
RESTOREto roll back; it adds a new version and does not wipe history. VACUUMdeletes old files and limits how far back you can travel. Defaults: 30 days log, 7 days deleted files.- Time travel is a safety net, not a backup strategy.
FAQ on the Delta Lake time travel
These quick answers cover the most common questions about the Delta Lake time travel.
Q1. Is time travel available only on Databricks?
No. It is part of open-source Delta Lake, so it works with Apache Spark plus the delta-spark package too. Some shortcuts and defaults can differ by platform version, so check your platform docs.
Q2. Does reading an old version change the table?
No. SELECT ... VERSION AS OF is read-only. Only RESTORE changes the current table.
Q3. Can I undo a RESTORE?
Yes, as long as the files still exist. Since RESTORE is just another version, you can restore again to the version before it.
Q4. How long can I time travel by default?
Plan for about 7 days, because that is the default deleted-file retention used by VACUUM. History entries are kept for 30 days by default.
Q5. Should I run VACUUM with RETAIN 0 HOURS to save space?
Usually no. It can break time travel and running jobs. Delta blocks it by default for this reason.
Related reading: Adaptive Query Execution (AQE) in Spark: The Simple Interview Guide · PySpark UDF vs Pandas UDF vs Built-in Functions: The Simple Interview Guide
