Git gave code cheap rollbacks, parallel branches and merges. Data never got the same deal — because data is huge; one copy is a terabyte. But a trend is changing that: the people editing data are turning into AI clusters. Once scale and frequency go up an order of magnitude, branching, rollback and merge move from “nice feature” to “the only way this can be safe.”
That’s the starting point of Git4Data. MatrixOne has already built these primitives into a database. My question: can DuckDB do the same?
1. Start with what DuckDB already has
DuckDB is not a blank slate. It already has the three foundations of MVCC:
| Capability | DuckDB’s implementation |
|---|---|
| Transaction visibility | TransactionData(transaction_t, VisibilityBound), Sees(ts) = ts < visibility_bound || ts == transaction_id |
| Versioned storage | Each row group’s ChunkVectorInfo records insert/delete commit ids |
| Commit numbering | Commit ids are issued from current_start_timestamp++ |
In other words, every row group in DuckDB already carries “when was this row inserted, when was it deleted.” That’s the skeleton of a time machine.
2. What’s missing: three pieces
| Gap | Why it matters | Implementation |
|---|---|---|
| Retention | Today, checkpoint reclaims old row groups — history isn’t “unreadable”, it’s “deleted” | Pin a watermark so GC/checkpoint can’t cross it |
| Registry | Something must remember “snapshot snap_01 is pinned at commit id N”, across processes and crashes | Persist references (snapshots/branches) |
| Read at pin | A syntax and execution path that reads a table at a pin instead of “latest” | AT (SNAPSHOT => 'name') + a scan over a synthetic TransactionData |
Of the three, the counterintuitive one is retention. Most people think “versioning” means “I can read old versions.” The real gate is whether the old version still exists. DuckDB reclaims row groups that are no longer visible at checkpoint (measured: after checkpoint, a 1M-row table’s old version simply disappears). So Git4Data’s first-order problem is retention, not query syntax.
3. Feasibility verdict
Feasible — and less work than expected, because DuckDB’s MVCC already stores each row’s history. The three things to build:
- Two watermarks:
LowestVisibilityBound()(active transactions only) for releasing locks and cleanup, andLowestRetentionBound()(active + pinned snapshots) for retention; - Persist the pins: commit ids are not durable across processes; they must be written with the references, or after restart a pin points at a past that no longer exists;
- One historical read path: grammar + binding + a table function that scans at a given bound.
The next three posts cover these: snapshots and retention, the branch primitives, and the engineering of moving the registry into tables.
Related
- Implementing Git for Data on DuckDB (Part 3): Branches, diff, pick, merge — The Version Primitives of Data
- Implementing Git for Data on DuckDB (Part 4): Moving Metadata into Tables — Transactions, Crash Consistency and ‘Hidden but Readable’
- Rewriting Lucene in C++ (Part 1): Byte-Level Compatibility — When Java Reads a C++-Written Index
Get the next essay
New essays on products, business and tech — plus what the experiment's numbers actually say.