Copy-on-Write Branching Gives Every PR and AI Agent an Isolated Production Data Copy in Seconds
Databricks blog authors Yasamin Tari and Kartik Mathur detail how Snorkel AI uses Lakebase's copy-on-write branching to reduce CI/CD test environment provisioning from approximately 20 minutes to under 60 seconds, noting that the same mechanism naturally applies to providing isolated data environments for AI Agents that can be autonomously verified.
The core contradiction of database testing environments is: tests are more meaningful the closer they are to production data, but replicating a production data set becomes increasingly expensive. Snorkel AI's approach demonstrates how copy-on-write branching transforms this contradiction from irreconcilable to negligible.
Snorkel AI builds data development tools for AI teams; its production database is an Amazon Aurora PostgreSQL cluster of approximately 2.5 TB. Each open Pull Request requires an independent Kubernetes namespace to deploy code and run the full test suite. Previously, restoring a copy of the production database for each PR took about 20 minutes, meaning developers opening PRs all day could not afford to wait for the merge queue. Shared staging databases, trimmed fixtures, or synthetic data would reintroduce the problems they were meant to solve: tests interfering with each other, stale schemas, and defects that only appear with real data shapes.
Databricks' Lakebase is a serverless database based on standard Postgres, with separated storage and compute, supporting writable branches created from any point in time. The key mechanism is that branches are copy-on-write: creating a branch is a metadata operation that does not copy any data. New branches share storage pages with their parent branches, and only the pages modified by that branch are written to new storage. This means creating a branch from a ~1 TB production copy takes the same amount of time as creating one from a 1 GB database—seconds, rather than the ~20 minutes required for a full restore.
The architecture involves four steps: First, continuous replication via AWS DMS synchronizes the production Aurora database to the main branch of Lakebase, keeping the main branch within about 2 minutes of production; DMS's Full LOB mode carries JSONB values of 10 to 20 MB. Second, when a PR opens, the CI pipeline calls the Lakebase API to create a new branch from the main branch, sets an expiration time, and passes connection details into the PR namespace, making the branch ready within a minute. Third, the application in the PR namespace connects to its branch via standard Postgres, running migrations, writing data, and modifying schemas without affecting production, the main branch, or other PRs. Fourth, when the PR is merged or closed, the pipeline deletes the branch; if the cleanup step fails to run, the branch automatically expires when its TTL elapses.