In an RDB, a commit makes every change visible or none of them. Adding a column leaves the table a table, and reads see a consistent state while another transaction is writing. Store Parquet files in object storage, one directory per partition, and SQL still works, but those properties are gone. I wanted to know how the guarantees a backend engineer takes for granted get rebuilt on plain files.
Apache Iceberg records “which files make up this table right now” in metadata files, and a commit is an atomic swap of the single pointer to the latest metadata file. Commits become atomic, and earlier states remain as snapshots. Add metadata design such as column IDs and partition transforms, and the schema and partitioning can change without rewriting files. In exchange, every write leaves old files and snapshots behind, and they have to be cleaned up on a schedule.
Hive-Style Directory Tables
Before Iceberg, the common approach was the Hive-style directory table. A table is a directory, and every file under it is table data. Partitions are subdirectories named after their values.
s3://lake/events/dt=2026-08-25/part-0001.parquet
s3://lake/events/dt=2026-08-25/part-0002.parquet
s3://lake/events/dt=2026-08-26/part-0001.parquet
“The table is every file under this directory” is easy to define, and it has costs.
- Listing cost: planning a query means listing directories to find files. Listing in object storage is slow, and the number of calls grows with the number of partitions
- Partial writes are visible: if a job has written five of its ten files, a reader sees five. If the job fails, half-written files stay behind. Two jobs overwriting the same partition at once have no defined outcome
- Users must know the partition column: filter a table partitioned by
dtonevent_timealone and nothing is skipped; every file is read. Hive also cannot validate partition values. The Iceberg docs point out that writing2018-12-01instead of20181201produces silently incorrect results, not query failures - Schema changes: files can disagree on schema. Matching columns by name can bring back old values when a dropped column’s name is reused, and matching by position makes it impossible to drop a column in the middle
In backend terms, this is like writing several rows one at a time with no transaction. Intermediate states are visible, and a failure leaves only some of the rows.
Iceberg’s Metadata Tree
Iceberg is a table format: it defines a table by a list of files instead of a directory. The structure in the Iceberg spec has five levels.
- catalog: maps a table name to the location of its current metadata file, one pointer per table
- metadata file: records the table’s schema, partitioning (the partition spec), the list of snapshots, and which snapshot is current. Every change to the table creates a new metadata file
- manifest list: one per snapshot. It lists the manifest files that make up that snapshot
- manifest: a list of data files. For each file it records partition values and column statistics such as min and max
- data file: the Parquet (or similar) file holding the rows
A read goes from the catalog toward the data files. It finds the current metadata file in the catalog, reads the manifest list of the current snapshot, uses partition values and statistics in the manifests to drop files that cannot match, and opens only the data files that remain. No directory listing happens. One of the spec’s goals is planning a scan with O(1) remote calls.
Commits as Pointer Swaps
Writes follow the same structure. New data files are written first, then a manifest that lists them, a manifest list for the new snapshot, and a new metadata file. Until then, no reader knows the new files exist. The commit happens when the catalog’s pointer moves to the new metadata file.
The swap is atomic. The spec says every change to table state creates a new metadata file and replaces the old one with an atomic swap. Readers see either the table before the swap or the table after it. If a job fails before committing, its new files are not referenced by any metadata, so readers never see them.
Concurrent writers are handled with optimistic concurrency. Each job builds new metadata from the metadata it read, then asks the catalog to swap the pointer only if it still points at that same file. If another job committed first, the swap is rejected. The rejected job retries against the new state, and if both changes touched the same files, the commit can fail instead. This works like optimistic locking with UPDATE ... WHERE version = ? in a backend service. The more jobs write to one table at once, the more retries there are.
A read uses the snapshot it picked at the start until it finishes. The spec states that reads are isolated from concurrent writes and always use a committed snapshot. A commit that arrives during a query does not change the file list that query is reading. It behaves like the snapshot reads that MVCC (multi-version concurrency control) provides in an RDB.
Snapshots, Schemas, and Partitions
Snapshots and Time Travel
Every commit creates a new snapshot, and earlier snapshots stay in the metadata. The files they reference are not deleted either, so the table can be queried as it was at an earlier point. This is called time travel. In Spark SQL, the point is given as a timestamp or a snapshot ID.
SELECT * FROM db.events TIMESTAMP AS OF '2026-08-25 00:00:00';
SELECT * FROM db.events VERSION AS OF 10963874102873;
It helps when comparing against the state before a bad load, or reproducing a result from a specific time. A procedure also rolls the table back to an earlier snapshot.
Schema Evolution
Iceberg tracks each column by a unique ID, and data files are read by column ID, not by name. Adding, dropping, renaming, and reordering columns, as well as widening a type such as int to long, are metadata-only changes. No data file is rewritten. A rename keeps the ID, so old files still resolve, and a new column that reuses a dropped column’s name gets a new ID, so old values do not come back.
Running ALTER TABLE ... ADD COLUMN on a large table here involves none of the table copies or locks a backend engineer might expect.
Hidden Partitioning
In Iceberg, partition values are derived from a column through a transform. Declare “partition by the day of event_time” when creating the table, and writers no longer fill a separate dt column while readers filter on event_time alone. Iceberg maps the filter to the matching day partitions and skips the rest. The docs call this hidden partitioning.
CREATE TABLE db.events (
event_id STRING,
user_id STRING,
event_time TIMESTAMP
) USING iceberg
PARTITIONED BY (days(event_time));
Besides time units (year, month, day, hour), there are transforms such as bucket, which splits by hash, and truncate, which cuts strings or numbers. Since the partition column never appears in queries, users cannot get its format wrong.
Changing the partitioning is a metadata change as well. Move from daily to hourly partitions as the data grows, and existing files stay in the old layout while new files use the new one. Queries plan each layout separately and combine the results, which the docs call split planning. On a Hive-style table, the same change means rewriting the whole table.
Ways to Write
The usual ways to write to an Iceberg table from Spark are append, overwrite, and MERGE INTO.
- append: adds new data files without touching existing ones. Common for loading event logs
- overwrite:
INSERT OVERWRITEreplaces whole partitions. The Iceberg docs recommend dynamic overwrite mode, in which only partitions that have rows in theSELECTresult are replaced - MERGE INTO: updates, deletes, and inserts rows by key. The docs recommend
MERGE INTOoverINSERT OVERWRITEbecause Iceberg can then replace only the affected data files
Row-level changes are handled in one of two modes, set with the write.delete.mode, write.update.mode, and write.merge.mode table properties. The default is copy-on-write.
- copy-on-write: rewrites every data file that contains a changed row. Writes are expensive, but reads need no extra work
- merge-on-read: leaves the original file in place, writes separate delete information (“row N of this file is gone”), and applies it at read time. Writes are cheap, but reads slow down as delete information accumulates
Delete information started as delete files in format v2 and became deletion vectors, a per-file bitmap, in format v3. Which format version is available depends on the engine and its version.
Late Data and Idempotent Rewrites
Events do not always arrive on time. An app may have been offline and send later, or an outside source may deliver a file a day late. Rows need to land in dates that were already processed.
Appending only the late rows looks simple, but rerunning the job adds the same rows again. A common pattern in data pipelines is to recompute the last few days from the source data on every run and replace them with a dynamic overwrite. The same input gives the same output, and running it again does not add rows; the rewrite is idempotent. In Iceberg the overwrite is a single commit, so readers see either the old partitions or the new ones. If the window is large enough that recomputing it is costly, a keyed MERGE INTO is another option.
Maintenance
An Iceberg commit never edits files. It writes new ones and moves the pointer. Old files are still referenced by earlier snapshots, so they cannot be deleted right away. Over time, small files, old snapshots, and files nobody references accumulate. The Iceberg docs cover this cleanup as separate maintenance work.
Compacting Small Files
The more often a table is loaded, the more small files each commit leaves. The docs explain that many small data files mean unnecessary metadata and slower queries from file open costs. The rewrite_data_files procedure combines small files into larger ones. On a merge-on-read table, cleaning up accumulated delete information adds to this work.
CALL catalog.system.rewrite_data_files(
table => 'db.events',
where => 'event_time < TIMESTAMP "2026-08-31 00:00:00"'
);
Compaction is a commit too. It writes larger files and swaps the snapshot. The old small files stay in storage while earlier snapshots still reference them.
The where argument narrows what gets compacted. If a table rewrites its last few days on every run to absorb late data, compacting that range rewrites files that are about to be replaced. When a rewrite commit and a compaction commit hit the same partition, one of them can fail on conflict. So compaction is limited to partitions outside the rewrite window.
Snapshot Expiration
As long as a snapshot exists, the files it references cannot be deleted. expire_snapshots removes snapshots older than a given age from the metadata and deletes data files that no remaining snapshot references. Expired points can no longer be queried.
A longer retention period leaves more room to go back; a shorter one frees old files sooner and lowers storage cost. For a table that can be rebuilt from source data, I found a short period the lower-risk choice.
Orphan File Removal
An orphan file exists in storage but is not referenced by any metadata. The docs note that task or job failures can leave such files behind, and data files from a job that failed just before committing are the typical case. Snapshot expiration only deletes files recorded in metadata, so orphans have to be found separately. remove_orphan_files compares the files in storage against the metadata and deletes those that appear nowhere.
Files a running write has just produced are not in the metadata yet either, because they have not been committed. Cleanup that runs at that moment treats them as orphans and deletes them. The docs warn that it is dangerous to remove orphan files with a retention interval shorter than the time expected for any write to complete. So cleanup only deletes files older than a safety margin.
When to Use a Table Format
A table format provides atomicity and schema management, and in return the cleanup jobs have to be operated.
A table format fits when:
- Several jobs write the same table, or reads happen while writes are in progress
- Reprocessing that overwrites partitions or fixes rows is frequent
- The schema and partitioning change over time
Directories plus Parquet are enough when:
- One job writes, and reads happen only after it finishes
- Files are only added, never changed
- Files and partitions are few enough that listing cost does not matter
Delta Lake and Apache Hudi are table formats that solve the same problem, with different ways of recording file lists and different strengths.
Wrapping Up
A set of files in object storage is not a table on its own. Iceberg records the table’s file list in a metadata tree and treats an atomic swap of one pointer as the commit. Writing new files instead of editing old ones is what makes commits atomic and keeps past states around, and for the same reason small files, old snapshots, and orphan files build up. What a database handles internally is split between the table format and its maintenance jobs.
References
- Data Lakes and ETL for Backend Engineers — background on data lakes, the raw, staging, and mart layers, and idempotent reprocessing
- Optimistic and Pessimistic Locking — the same compare-version-then-swap approach as an Iceberg commit, on the RDB side
- What Isolation Levels Actually Prevent — the anomalies snapshot reads prevent, on the RDB side
- Apache Iceberg — Spec
- Apache Iceberg — Maintenance
- Apache Iceberg — Partitioning
- Apache Iceberg — Evolution
- Apache Iceberg — Spark Procedures