Skip to content
Bronze 7 min read · All formats 2 practice problems ↓

ACID on object storage

Databases promise ACID: a write happens completely or not at all, and readers never see a half-done change. Plain files in cloud storage promise none of that. This lesson shows what goes wrong without it, and how table formats bring those guarantees back.

Step 3 · Data lake & lakehouse · Bronze · Table formats, lesson 2 of 3

Read first: Open table formats (skip if you know it)

In plain words first

Updating a price list by swapping pages one at a time means a customer can read a list that is half old and half new. Printing the whole new list and replacing the old one in a single swap means every customer sees either the old list or the new one, never a mix.

Table formatstable format: A metadata layer (Delta Lake, Iceberg, Hudi) that turns a folder of data files into a table with commits, versions and a schema. Learn more → make every write that single swap: an atomic commitcommit: One atomic change to a table: a new version that lists which files were added and removed. Learn more →.

ACID, applied to tables

PropertyMeansPlain Parquet folder
AtomicityA write is all or nothingA job failing after writing 60 of 100 files leaves 60 visible files
ConsistencyData always meets the table's rules (schema, constraints)Any job can write any schema into the folder
IsolationConcurrent readers and writers do not see each other's partial workA reader listing during a write sees some new files and some old
DurabilityCommitted data survives failuresProvided by the object storeobject storage: Cloud file storage such as Amazon S3, Azure Data Lake Storage or Google Cloud Storage: cheap and huge, but with no transactions of its own. Learn more → itself

What object storage guarantees

  • Durable: objects are replicated; S3 is designed for 99.999999999% durability.
  • Strongly consistent: since December 2020, S3 gives read-after-write consistency for all operations, including listings. ADLS and GCS are also strongly consistent.
  • Atomic per object: a single PUT either fully succeeds or does not happen.
  • No atomic rename: S3 has no real directories; "renaming" a folder copies and deletes every object, which is slow and not atomic. HDFS-era commit protocols that relied on renaming a temporary folder are slow and unsafe on S3.
  • No multi-object transactions: nothing lets you publish 100 files atomically.

The trick: one small atomic write

Table formats never need to make 100 files appear atomically. They write the data files first, invisible because no metadata references them, then perform one atomic operation that switches the table to a new file list.

Write · data files

The job writes 100 new ParquetParquet: A columnar file format: values of each column are stored together, so queries read only the columns they need. Learn more → files with unique names. Readers ignore them: the current metadata does not list them.

Commit · one atomic step

Delta: create _delta_log/00000000000000000043.json only if it does not already exist. Iceberg: ask the catalogcatalog: The service that maps table names to their current metadata and controls who can access them. Learn more → to swap the table pointer from metadata v42 to v43 only if it still points to v42.

Success · visible at once

Readers that start now see version 43 with all 100 files. Readers already running continue on version 42, unaffected: that is snapshotsnapshot: A complete, consistent version of a table at one moment. Readers always see one snapshot, never a half-finished write. Learn more → isolation.

Failure · nothing visible

If the job dies before the commit, the 100 files are orphans that no version references. Readers never see them; a cleanup job deletes them later.

The commit step needs a "create if absent" or compare-and-swap primitive. HDFS and ADLS offer atomic rename; GCS offers conditional writes; S3 added conditional writes (If-None-Match) in 2024. Before that, multi-writer Delta tables on S3 needed an external coordinator such as DynamoDB, and Iceberg relies on its catalog (Glue, a REST catalog, a database) for the atomic swap.

Consistency and isolation in practice

  • Schema enforcement rejects writes that do not match the table schema, and constraints such as NOT NULL or CHECK (Delta) are validated before commit.
  • Readers get snapshot isolation: each query reads one consistent version.
  • Writers use optimistic concurrency: they check at commit time whether a concurrent commit conflicts with theirs, and retry or fail. See Concurrency and conflicts.

Try it yourself

Each example says what it shows, then the output from a real run and what to notice in it, so you can follow without running anything. To try one yourself, paste it into a local Spark session with Delta Lake, with spark already created: each builds its own data.

Goal: Replace one day of a table in a single atomic commit.

Production patternPySpark · Replace one day atomically with replaceWhere
import os

path = os.path.abspath("lab/acid/daily_sales")
schema = "day STRING, country STRING, amount DOUBLE"
spark.createDataFrame(
    [("2025-03-01", "IN", 100.0), ("2025-03-02", "IN", 80.0),
     ("2025-03-03", "US", 60.0)],
    schema).write.format("delta").mode("overwrite").partitionBy("day").save(path)

# Reprocess one day. One commit: readers see the old day or the new one, never half.
fixed = spark.createDataFrame(
    [("2025-03-02", "IN", 85.0), ("2025-03-02", "US", 20.0)], schema)
(fixed.write.format("delta").mode("overwrite")
      .option("replaceWhere", "day = '2025-03-02'")
      .save(path))
spark.read.format("delta").load(path).orderBy("day", "country").show()

Output from a real run

+----------+-------+------+
|       day|country|amount|
+----------+-------+------+
|2025-03-01|     IN| 100.0|
|2025-03-02|     IN|  85.0|
|2025-03-02|     US|  20.0|
|2025-03-03|     US|  60.0|
+----------+-------+------+

What to notice:

  • Only 2025-03-02 changed: India 80 → 85, and a new US row. The other days are untouched.
  • Readers see the old day or the new one, never a half-written mix.
  • If the new data had a row from another day, the write would fail instead of touching that day.

Goal: Fail an overwrite halfway, on plain Parquet and on Delta, and compare what is left.

ExplorePySpark · A failed overwrite: plain Parquet loses the data, Delta keeps it
from pyspark.sql import functions as F

good = spark.range(0, 1000)
good.write.mode("overwrite").parquet("lab/acid/plain")
good.write.format("delta").mode("overwrite").save("lab/acid/delta")

# A job that fails halfway: ANSI mode raises on the bad cast while files are written.
bad = spark.range(0, 1000).withColumn(
    "x", F.when(F.col("id") == 999, F.lit("boom")).otherwise(F.col("id").cast("string"))
          .cast("int"))

attempts = {
    "plain parquet": lambda: bad.write.mode("overwrite").parquet("lab/acid/plain"),
    "delta": lambda: (bad.write.format("delta").mode("overwrite")
                         .option("overwriteSchema", "true").save("lab/acid/delta")),
}
for name, write in attempts.items():
    try:
        write()
    except Exception as e:
        print(f"{name}: the overwrite failed ({type(e).__name__})")

try:
    rows = spark.read.parquet("lab/acid/plain").count()
    print("parquet rows after the failure:", rows)
except Exception as e:
    print("parquet after the failure: unreadable,", type(e).__name__)
rows = spark.read.format("delta").load("lab/acid/delta").count()
print("delta rows after the failure:", rows)

Output from a real run

plain parquet: the overwrite failed (NumberFormatException)
delta: the overwrite failed (Py4JJavaError)
parquet after the failure: unreadable, AnalysisException
delta rows after the failure: 1000

What to notice:

  • Both overwrites failed, on the bad value boom.
  • Plain Parquet is now unreadable: the old files were deleted before the new ones were finished.
  • Delta still has all 1,000 rows: no commit was made, so readers still see the previous version.

Common mistakes

  • Relying on folder renames on S3 — Not atomic and slow; use a table format or a proper committer.
  • Deleting data files directly in storage — The metadata still lists them; reads fail.
  • Assuming multi-writer safety everywhere — Check that your storage and catalog provide the needed atomic primitive.

Key takeaways

  • Object stores are durable and consistent per object but have no multi-file transactions or atomic renames.
  • Table formats write data files first and publish them with one atomic metadata write.
  • Readers get snapshot isolation; failed jobs leave only invisible orphan files.
  • The atomic step needs put-if-absent or a catalog compare-and-swap.

Interview prep

THE QUESTION

"How can you get ACID transactions on S3, which has no transactions?"

Make the commit a single atomic operation on one small object or catalog entry. Data files are written first and are invisible until referenced; the commit (a new log entry with put-if-absent, or a catalog compare-and-swap) publishes them all at once. Readers use snapshots of the metadata, so they are isolated; failures leave only unreferenced files. Mention S3's strong consistency since 2020 and conditional writes since 2024.

Avoid: "S3 is now strongly consistent, so it supports transactions". Consistent reads are not multi-file atomic commits.

Follow-ups · answer out loud, then open

Follow-up"Why is a plain Parquet folder not safe for concurrent writers?"
A job writes many files; readers listing the folder mid-write see half the files. Two writers overwriting the same folder can interleave. A failed job leaves partial files. There is no single point where the change becomes visible all at once.
Scenario"Two Delta writers on S3 commit at the same moment. What prevents both from writing commit 00042?"
The commit needs put-if-absent: only one writer may create a given log file. S3 now supports conditional writes, and before that Delta used a coordination service such as DynamoDB (the S3 multi-cluster LogStore). The loser retries: it checks for conflicts with commit 42 and tries 43.
Trap"Readers lock the table while they read."
No locks. Readers read a snapshot: the set of files listed at one version. Writers add files and commit a new version; old readers keep their snapshot.

Check yourself

3 questions

A job crashes after writing data files but before committing. What do readers of a Delta or Iceberg table see?

Show the answer

The previous version, unchanged. Uncommitted files are not referenced by any version.

Why are rename-based commits a problem on S3?

Show the answer

A folder rename is a copy and delete of every object: slow and not atomic. S3 has no real directories, so renaming a folder is many separate operations.

Which isolation do readers get?

Show the answer

Snapshot isolation: each query sees one committed version. Queries read a fixed version of the metadata.

Practise this

Problems that use this, graded on hidden tests

Keep going

Up next · Table formats · lesson 3 of 3 · 6 min read
The medallion architecture
Bronze, silver and gold layers: what belongs in each, and where the pattern goes wrong.

Related lessons

Previous: Open table formats

Primary sources: Delta Lake: storage configuration · Amazon S3 consistency