Lakehouse transactions and tables
Explain atomic table snapshots, optimistic commit validation, delete semantics, and safe cleanup on object storage.
On this page
The question for today
What you’ll understand
- Distinguish immutable data objects from an atomically published table state.
- Trace a concurrent append and rewrite through optimistic commit validation.
- Budget file counts and retention while preserving snapshots and deletion correctness.
A directory containing columnar files is not yet a transactional table. A reader listing that directory during a producer's upload can see an incomplete batch, old and new versions together, or files belonging to an abandoned attempt. Table formats add metadata and commit rules that define which files constitute one logical state. Preserve that state across concurrent writes, schema changes, rewrites, deletion, and cleanup.
Publish membership, not an accidental directory listing
A table snapshot identifies the data and metadata needed to read one committed version. Writers can prepare immutable data files before publishing their membership in the table. In Iceberg, metadata and manifest structures describe snapshots and their files; the catalog's atomic update protocol determines the current metadata reference. A reader pins a snapshot instead of inferring membership from every object it happens to find under a path. Unreferenced objects from failed attempts are not automatically visible rows.
This does not mean all formats use one identical commit implementation. Delta Lake uses its transaction log to define committed table versions, while catalogs and storage systems impose specific requirements. Use a supported engine and compatible protocol features. Raw-file scans can ignore deletes and include obsolete files. Multi-table atomicity is a separate feature: one table's atomic commit does not by itself give a transaction over every table in a pipeline.
Validate what changed before committing
Optimistic concurrency lets a writer read a table version, prepare output, and then attempt a commit. If another writer changes the table, the system validates whether the operation can safely apply to the newer state or must retry. Two independent appends may be compatible under the format's rules. A rewrite or update based on removed input files can conflict with another operation that modifies those inputs. Retrying a metadata publication is different from blindly repeating a transformation computed from stale rows.
Deletes can be represented through rewritten data files or format-supported deletion metadata. Iceberg's position deletes identify rows through file paths and positions, while equality deletes identify values using declared field identities under applicable rules. Sequence and snapshot metadata determine applicability; an engine cannot ignore them and remain correct. Schema evolution also needs stable field identity so a rename does not accidentally reinterpret a different column. Verify that every reader supports the table's features before enabling new write behavior.
Compact and expire without breaking readers
Small files increase metadata, planning, and request overhead even when total data bytes are modest. Compaction rewrites them into fewer files and commits a new snapshot; old files may remain necessary for retained snapshots or active readers. An object being absent from the latest snapshot is therefore insufficient evidence that it can be immediately deleted. Expiration and orphan cleanup must respect retention, reader behavior, and in-progress writes, with safety intervals that match operational reality.
Time travel needs both metadata and the referenced data objects. Premature object-lifecycle deletion can leave named snapshots unreadable. Storage versioning helps recovery without replacing format-aware retention. Measure planning time, file counts, delete-file work, and scan bytes before choosing compaction frequency. Observe maintenance and test long-running readers during rewrite and cleanup.
Work it through
Explain the cost and correctness of a rewrite
A table has 512 GB in 1 MB files. A rewrite targets 256 MB files. Assume decimal units, exact sizing, and a hypothetical 0.2 ms serial metadata overhead per file. Ignore compression changes.
Convert 512 GB to 512,000 MB. At 1 MB each, the original layout contains 512,000 files.
At 256 MB each, the ideal rewritten layout contains 512,000/256 = 2,000 files, a factor of 256 fewer.
The hypothetical serial overhead changes from 512,000 × 0.2 ms = 102.4 seconds to 2,000 × 0.2 ms = 0.4 seconds; these are model components, not measured query runtimes.
Publish the replacement file membership through a table commit. Retain old files while required snapshots or supported active readers need them; deleting them immediately could break an otherwise valid old snapshot.
Compaction can reduce file-management work dramatically while requiring snapshot-aware retention to preserve correctness.
The living notebook
Explore the model
Interactive lab · reliability
Separate enough copies from a valid table state
Adjust replica count n and unavailable count k to inspect n−k available copies and majority floor(n/2)+1. This toy illustrates a count boundary only. It has no object catalog, table snapshots, optimistic commits, or file deletes; majority availability alone proves neither linearizability nor durability.
- Available replicas
- 4 of 5
- Majority needed
- 3
- Majority available?
- Yes
A replica count and a majority threshold, without a consensus protocol. Playback highlights fixed replica states. Having a majority alone does not establish linearizability, durability or failure independence. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forAvailable storage copies are useful, but readers still need a valid committed table membership and supported protocol.
Pause & reason
Check your understanding
Your turn
Try it yourself
Two writers read snapshot 10. Writer A appends independent new rows and commits snapshot 11. Writer B rewrites files that remain unchanged by A. May B always overwrite the catalog pointer with its original snapshot-10 result? Explain the required check.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Separate compatible logical changes from an unconditional stale metadata publication.
Compare with the solution
B must use the format and catalog's optimistic commit protocol, validate its assumptions against the current state, and preserve A's committed additions. A supported retry may be able to rebase the rewrite because A did not change its input files, but unconditional publication of B's old snapshot-10 membership could lose A's append. Compatibility is operation- and protocol-specific, so a table engine must perform the validation rather than a client guessing.
Keep the idea
Take it with you
- A table version is committed metadata defining file membership and interpretation.
- Optimistic commits validate concurrent changes instead of blindly replacing stale state.
- Compaction and expiration must preserve referenced snapshots and supported readers.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.