Peter Mattis on distributed databases and AI-amplified experts
- YT :: https://www.youtube.com/watch?v=0GzwuYGvKA4
- Original title :: Distributed databases with Peter Mattis
Peter Mattis — co-creator of GIMP and GTK, early Gmail storage engineer, Colossus founding team member, now co-founder and CTO of Cockroach Labs — walks through thirty years of storage systems, keeps landing on B-trees, and explains why AI got him back to writing code. He wrote about 100K lines a year before AI, stopped coding from 2022 to 2024, and now ships what he calls database-grade code faster than ever. His argument: AI amplifies domain experts and pushes quality up, provided you are strict with agents about testing.
GIMP and an early lesson on competition
GIMP started as a side project with his college roommate (later Cockroach co-founder Spencer Kimball) because a compilers course bored them. Weeks before release someone on Usenet announced a program that did everything GIMP did and more; they shipped anyway and never heard from that person again. His lesson: a dozen people have probably had your idea, most never build it, and a pre-announcement shouldn't put you off. GIMP also drew Google's attention, since the first Google logo was made in it. He turned down a 2001 offer over the commute, then joined in April 2002.
Gmail, google3 and Colossus
- Gmail (codename Caribou): he built the backend threading, message storage and indexing. B-trees mapped messages to threads and tracked unread counts on top of GFS. It launched on 1 April 2004 with a GB of storage when rivals offered about 4 MB, "shock and awe". Ads came from Paul Buchheit reusing existing ad code over one night. Invites throttled load and created hype.
- google3: Google2 was one huge Makefile. He laid the foundation for BUILD files, a stripped-down Python that compiled down to Make ("make is assembly language for dependencies"). That became Blaze, then Bazel and Buck outside Google.
- Colossus: the successor to GFS, built because the single GFS master capped clusters at about 1,000 machines. Its metadata (file names, chunk lists) went into Bigtable, while Bigtable itself runs on Colossus. They broke the circular dependency with a foundational Bigtable that didn't use Colossus, a hack that ran for years. Reed–Solomon erasure coding replaced 3x replication with roughly 2x overhead and better redundancy (for example 9 chunks where any 5 rebuild the data).
Hardware got fast, so do the napkin math
A first read from GCS or S3 still takes 20–30 ms because it is bound by disk, while NVMe SSDs read in 30–50 µs and in-zone network round trips have dropped from milliseconds to about 100 µs. Software should target "speed of light numbers", meaning machine scale rather than human perception. A side fact: the fastest way to move data across the globe is up through Starlink, because light in fiber is much slower than in vacuum. HFT firms use microwave links between New York and Chicago. Performance work goes all the way down to cache lines, avoiding synchronization, and data layout.
Beating standard libraries
- C++ B-tree map: a colleague found
std::map(a red-black tree) wasting memory in Gaia, Google's user/identity system. Mattis wrote a B-tree map that matched almost all of STL map's semantics, except pointer stability. It was smaller (fewer pointers) and faster (better spatial locality). His explanation of B-trees: small sorted arrays of about 8 items (a linear scan often beats binary search), split when full, with parent nodes linking them. - Go Swiss tables: the runtime's map was hard to beat. On a long flight to Bangalore he got some benchmarks faster, combined ideas from the Go issue tracker, used the result at Cockroach, and the Go team took it the rest of the way into the runtime.
Takeaway: when something on a profile doesn't add up, ask why. Even mature libraries can be improved.
Cockroach Labs
After Google Goggles and the photo-sharing startup Viewfinder (acqui-hired by Square in 2012), Mattis, Kimball and Ben Darnell built a Spanner-like database. They had designed it at Viewfinder, shelved it, and restarted it at Square. This time they took VC money right away, because good VCs are sharp mentors. The name comes from cockroaches being unkillable: you can kill nodes or a whole region and it keeps running. Customers usually arrive after a disaster (a big bank lost a region to weather) or after outgrowing the largest RDS instance. Their position is that manual sharding turns application developers into bad database developers.
- Spanner vs Colossus: a storage system handles large append-only files, while a database handles small typed rows. Append-only storage underneath is what leads to LSM trees (LevelDB → RocksDB → Cockroach's own Pebble, which Mattis wrote around 2019).
- Sharding: naive hash sharding forces painful resharding. Consistent hashing (Cassandra) moves only part of the data. Cockroach, like Bigtable and Spanner, splits one contiguous key space into ranges with an index over them, "if you squint, it's a B-tree". Database indexes are B-trees too ("The Ubiquitous B-Tree").
- Consistency: ACID basics. Serializability gives the simplest programming model and prevents the double-spent $100. With eventual consistency you can read a stale secondary, which pushes work onto the application. Cockroach writes to all replicas and makes that fast.
- Raft: consensus needs at least 3 replicas (with 2, a crash leaves you unable to tell what was committed). Reads go to one replica, and the quorum read happens only during recovery. The default is 3 replicas, 5 for system tables. Across regions, latency is set by the speed of light, so batch your reads and writes rather than doing serial round trips.
- About 110–150 people in R&D. "Mission critical" means tier-0 systems: trading, banking, DoorDash orders, shopping carts.
How AI brought him back to coding
His peak was about 100K lines a year against an industry rule of thumb of about 36K. Following standard advice, he moved into meetings from 2022 to 2024. He came back because you can't coach engineers on AI tools you don't use yourself. Copilot-style autocomplete got him started, Sonnet and then Opus kept him going, and over Thanksgiving 2025 a long-wanted benchmarking matrix (CPUs × disks × nodes) appeared in four days. He recently wrote a 10K-line optimized Rust B-tree in about 30 minutes. In January, while exploring with models as a sparring partner, he hit what he calls a research breakthrough in autoscaling. That work is now heading toward a launch, with nearly 100% of engineers using agents. Non-engineers built 500–1,000 internal mini-apps in a couple of months.
He compares the work to being a hands-on architect or tech lead for a 30–40 person org without the people management. Gergely objects to calling it "management", since the human side is missing. Mattis's conclusion: ambition has to rise.
His setup
He used Emacs for 20+ years, moved to VS Code (tired of his setup breaking and Emacs lagging behind), then to Claude Code in VS Code terminal tabs, and about six weeks ago to the Claude desktop app. He keeps the Codex desktop app around as a second model for adversarial review of critical designs. He always uses the best model (Fable, Astra) to avoid deciding case by case. He runs 5–10 sessions at once, which is his cognitive limit, each with anywhere from 3 to about 100 subagents through dynamic workflows. Being in the zone now feels less intense but broader, like a professor whose swarm of research assistants reports back within hours instead of months.
How AI can raise quality
More code means more defects per line, unless you are firm with the agents:
- Agents are lazy about testing, but easier to discipline than humans. Tell them to use property-based, metamorphic and deterministic simulation testing.
- Every commit can get an adversarial security review from one or more agents.
- Small UX defects no longer have an excuse. Their designer skips Figma and sends PRs in HTML/CSS/JS.
- Guardrails beat review. Fable built a check that decompiles code to confirm a test-only abstraction compiles down to a few instructions in production, so the agent can verify there are no regressions on its own.
Is code review done?
Mattis was an early C++ readability reviewer at Google. He still reads most agent output, but less carefully, the way you trust a senior engineer more than a junior. He expects that within a year or two we will stop reading code much, as we stopped reading compiler assembly, and that AI will check the low-level output instead of humans.
100x engineers and sorcerers
His analogies: agents are a car that pulls up while you're walking, and you have to learn to drive. We are now in the F1-driver era, where experts push the tools much harder. AI stretches the existing skill spectrum (Boris Cherny and Thibault were already strong engineers). Pair programming with an android was what it felt like a year ago. Now domain experts are sorcerers: if you know the right incantations, you get magic. Ask Fable to "build a distributed database like CockroachDB" without expertise and you get something hollow. Specify the storage layer, networking, data structures and runtime and you get something real. Terence Tao's ChatGPT sessions read like talking to a peer.
Advice for leveling up
- He used to learn by reading Jeff Dean's (fast) and Sanjay Ghemawat's (elegant) CLs. Now ask AI to take apart great code at any level: diagrams, ELI5, even in French.
- Use AI to become a domain expert in your business (payments, for example), not only a better coder.
- Be curious beyond your own area, and take the agency to keep using the tools, since any course is out of date.
- He feels he learned more in the past year than in the previous five. It's exciting and also exhausting, and Gergely notes that nobody is immune to that.