Beyond “read a snapshot”, a data version system has two very practical abilities: point-in-time recovery (PITR) and zero-copy clone. This post covers the trade-offs in implementing them.

1. PITR: find the newest reference not later than T

A reference (snapshot or branch) is essentially “a name plus a commit id (pin)”. PITR needs no extra log; it does:

given time T:
  find references with created <= T
  take the one with the largest created
  restore to it

That is recovery based on the reference sequence, not WAL replay. The upside is simplicity and consistency with the snapshot system; the downside is precision tied to how often you create references — if two references are an hour apart, you can only restore to before that hour.

So restore_at must define its semantics:

  • the time argument is VARCHAR (not TIMESTAMP), to align with the reference time format;
  • the boundary is inclusive (not later than T);
  • restoration is transactional: failure rolls back, leaving no half state.

2. Clone: file-level zero-copy

The intuitive way to clone a database is copying files. Modern filesystems offer something cheaper:

PlatformMechanism
macOS / APFSclonefile
Linux / XFS, Btrfsthe FICLONE ioctl

These are copy-on-write: cloning is instant, and only later writes actually copy blocks. Measured clone cost is essentially zero.

Key design point: a clone must carry its references. The cloned database isn’t just a data copy; snapshots and branches must survive — otherwise “continue versioning on the clone” breaks.

3. Reference namespace

Snapshots and branches share one namespace, deliberately:

  • AT (SNAPSHOT => 'x') or AT (BRANCH => 'x') must resolve a name uniquely;
  • if both registries allowed the same name, bare names would be ambiguous (we hit a phantom self-merge that way).

Internal references use a __ prefix (__pitr__, __merge_base__, __live__), and user-created __ names are rejected — so system and user references never collide.

4. Three real traps

① References in rolled-back transactions

We assumed “a reference created inside a transaction disappears on rollback”. Measured: it survives. The fix was to tag references with transaction identity and clean them on rollback.

② Quotas after clone

A clone copies references, but quotas count references. Cloning can immediately exceed a quota; check beforehand.

③ Cross-file coordination

If two database files share the same underlying data (via clone), retention policies must coordinate — otherwise one database’s cleanup destroys the other’s history. We mark this explicitly as unsolved.

5. Summary

  • PITR is “find the newest reference”, not WAL replay: simple, but limited by reference density;
  • Clone uses COW for near-zero cost, but must carry references;
  • A shared namespace plus a __ prefix keeps references unambiguous;
  • Coordinating retention across files sharing data is the real hard problem.

Get the next essay

New essays on products, business and tech — plus what the experiment's numbers actually say.