Skip to the page
Tecyfy

Databricks interview question · hard

You have a Delta table that's frequently updated. You need to perform an analytical query that requires a consistent snapshot of the data. You use df = spark.read.table("my_delta_table"). Are you guaranteed to get a consistent snapshot? What are the alternatives to ensure consistency?

The short answerYes for a single query: a query on a Delta table reads one committed version of the table, so concurrent writes never give it a half-written or mixed view.

The full answer

Yes for a single query: a query on a Delta table reads one committed version of the table, so concurrent writes never give it a half-written or mixed view. If you need several queries to see the same version, pin it explicitly with time travel.

Why one query is consistent. Delta Lake commits each write as a new table version in its transaction log. A reader resolves which version is current when its query starts and reads only the files of that version. Writers that commit afterwards create later versions, which the running query ignores. Databricks describes this as readers seeing a consistent snapshot of the table the job started with.

Where it can still surprise you. A DataFrame is a plan, not data. df = spark.read.table("my_delta_table") followed by two actions, such as df.count() and then df.write..., can resolve the table again and see a newer version if a writer committed in between. The two results may then disagree.

Ways to get one fixed snapshot for a whole analysis:

  1. Pin the version (or timestamp) with time travel:

    version = spark.sql("DESCRIBE HISTORY my_delta_table LIMIT 1").first()["version"]
    df = spark.read.option("versionAsOf", version).table("my_delta_table")
    

    In SQL: SELECT * FROM my_delta_table VERSION AS OF 123, or on Databricks my_delta_table@v123. Every query using that version sees identical data.

  2. Materialise what you need once, for example df.cache() followed by an action, or write the intermediate result to a table, then run all later steps against that.

  3. Run the whole analysis as one query (one SQL statement or one DataFrame action) where possible.

Limits to know: time travel needs the old data files, so a version older than the table's file retention (7 days by default) can be removed by VACUUM, and history older than the log retention (30 days by default) disappears. Do not run VACUUM to get consistency: it only deletes old files and makes older versions unreadable.

Last updated 16 October 2026