R440 · Infrastructure for agents at scale › Consistency and storage tradeoffs

Writes go to exactly one database: retiring 77 Postgres instances under live traffic

Read the original

storage-migrationfoundationdbpostgresmetadata-storesbackpressurekubernetes-operatorsproduction-incidentsvendor

Source: "From Postgres to FoundationDB", Benny Nazimov, Pinecone engineering blog, 30 November 2026. A few arithmetic derivations are not covered here; the surrounding figures are stated.

The problem, stated honestly

At its 2024 peak the serverless data plane ran about 77 managed Postgres databases across AWS, GCP and Azure, and in under three years the team "merged about a hundred changes that resized, re-tiered or retuned these databases" — roughly a fifth of which only recorded console work already done during an incident. By the end of September 2026 the last one was gone.

What those databases held was metadata, not bulk data: "which files make up an index right now, where each namespace… keeps its data, which workers are alive". Four groups per cluster — a vector directory mapping vector IDs to files and offsets, WAL metadata, control databases, and a system database holding the mappings that say where a namespace's data lives. Of the mappings: "Nothing rebuilds them if they're lost."

The article is unusually willing to name its own mistake. The original design "created PG tables, plural, per Pinecone index", and a buggy checker created an index every five seconds — "about 17,000 a day, per environment, across seven environments" — leaving millions of empty tables. The verdict: "The worst of it was mostly on us."

Two pressures followed. In August 2024 the cloud provider warned that a database was approaching transaction-ID wraparound — Postgres uses 32-bit IDs — and freezing "took manual vacuums that ran for more than 40 hours". And the structural limit: "every write to a shard still goes through a single primary, so the only ways to grow a shard are a bigger machine or splitting it by hand." Growth in namespace count, not data volume, is what that could not absorb.

Worth noting what they did not claim. A connection pooler "would probably have handled the connection limits" — offered as a hypothetical, not a reason to migrate. And object storage was never a candidate for this data, because "metadata is tiny and read very frequently".

Where everything went

The split is by mutability and size, not by importance. Bulk, immutable data — vectors, WAL contents, index files — went to object storage. Small, hot, consistency-sensitive metadata went to FoundationDB, one FDB cluster per Pinecone cluster.

Object storage absorbed two pieces in stages: the vector directory moved in 2025 into a per-slab object file, and WAL metadata plus the consistency layer only moved in December 2025, because the object store "didn't support conditional writes until late 2024" — a dependency on a storage primitive, dated precisely.

FDB holds the system and control databases. The key layout is a hand-rolled secondary-index scheme over a single record: RECORDS.pack((index, id)) for the record itself, then BY_NAMESPACE.pack((index, namespace, deleted_at)), BY_INDEX_STATUS.pack((index, status, id)) and BY_STATUS.pack((status, id)) as index entries, with COUNTS.pack(index) maintained by atomic add. Values are protobuf. Each write puts the record and all its index entries in one transaction, which is the point of choosing FDB — "fully serializable transactions across any set of keys" — and atomic counters can be incremented "without conflicting with each other (as long as they don't also read it)".

The migration rule worth stealing

The first design was dual-write. A teammate replaced it with a rule that is better than the thing it replaced:

in any phase of a migration, a write goes to exactly one database, while reads are allowed to fall back.

Dual-write makes every write a distributed transaction across two systems you do not trust equally, and leaves you reconciling divergence you created. One writer and a falling-back reader means there is always exactly one answer to "where is the truth right now", and the fallback is pure latency, never correctness.

The rule then gets applied differently to four classes of data, which is the second thing to take:

Ephemeral (leases): loss is acceptable, so switch and move on.

Single-service: switch writes, copy the remainder afterwards.

Derived and rebuildable (manifests, reconstructible from the WAL): four phases. Writes stay on Postgres while reads try FDB and fall back; writers switch to FDB, where a rolling restart means old and new pods publish side by side for a few minutes; a backfill from Postgres that replaces an FDB manifest only if the Postgres one is newer, judged by recorded WAL position; then reads stop falling back. Before each cluster cutover, "a verification pass compared those WAL positions." The scheme deliberately accepts dropping a competing manifest, because "that only costs work".

Source of truth (mappings): a per-index state machine, because "every write had to know which side of the move its index was on". Reads and writes on Postgres; copy rows while writes continue; freeze writes for a couple of seconds while the diff is copied; then both on FDB. Smallest indexes first, the largest — "whales" — one at a time. A continuous FDB backup "that trails the live database by well under a minute, plus daily snapshots" was required before any of it.

So the headline "migrated live without stopping writes" needs its footnote: reads were never blocked and other indexes kept taking writes throughout, but each index took a write freeze, typically under a second and at worst about three and a half seconds.

What it cost in latency

FDB is slower for the common case and faster for the batch case. At p95, a one-namespace lookup ran 0.8–1.2 ms on Postgres against 1.2–2.4 ms on FDB; creating 100 namespaces at once ran 16–25 ms on Postgres against 8.5–15 ms on FDB, measured at 10, 10,000 and 90,000 namespaces. A footnote puts Postgres at 1.4–2× faster on single-key reads.

That regression is affordable only because of a cache: query routers answer "about 98%" of lookups without touching the store. Anyone copying this architecture without that hit rate is accepting the slower number on every read.

The two incidents, which are the real content

The migration tool had no rate limit. Over 660,000 rows hit FDB in under a minute, peaking around 190,000 writes/s (47,000 rows/s, four writes per row at about 75 bytes each) against a "ballpark" of roughly 20,000 writes/s per core — "roughly 4 times" the estimate. The hottest storage server took about double the average. The storage queue went from 50 MB to the 1.5 GB emergency brake in about two minutes; ratekeeper then cut the global limit to about 10 transactions per second, and the cluster was effectively down for about four minutes. Two causes, both named: the tool "should have used FDB's batch priority", and the query routers did not retry retryable FDB errors, which turned throttling into failure. After tuning — four knobs, --shards, --index-parallelism, --fdb-write-concurrency, --fdb-write-batch — about 250 rows in flight gave roughly 13,000 rows/s against a 12,500 estimate, with the queue below the throttle line.

The transferable lesson is about where backpressure lives. FDB's ratekeeper is global and applies to everything, reads included, so a tool that saturates it does not degrade itself — it degrades the production workload sharing the cluster. A bulk loader needs a priority class and a rate limit before it needs speed.

The operator deleted every storage pod at once. A patch changed a sidecar image, which forced pod recreation. The old operator looked up availability zones "in an environment variable that's never set", so all storage pods appeared to be in one zone — and a zone's worth of pods can be replaced together. With redundancy_mode: double and five storage servers, that should have been data loss. It was not, for a reason worth internalising: "the operator only deleted the pods", and each new pod reattached to its existing disk. Separately, one GCP cluster suffered "a full read and write outage for about 25 minutes". The fix was to upgrade the operator (fdb-kubernetes-operator #2465, released v2.27.0 in May 2026; they were running v2.22.0) and to configure deletion one process group at a time.

Note the shape of this bug: an unset environment variable collapsed a safety partition into a single bucket, and the safety mechanism then did exactly what it was told. Nothing failed. The input to the invariant was silently empty.

What self-hosting actually means

Stated plainly: "You usually have mostly yourself to blame if something goes wrong, and there are no support tickets to file."

The concrete cost is tooling. "Moving off PG meant losing psql", and FDB's CLI works only with raw keys and bytes, so "reading them raw was a non-starter". They built fdbsql, a read-only SQL shell over Apache DataFusion, plus a pc_introspect protobuf derive macro. Budget for rebuilding the inspection layer, not just the storage layer.

Two verification practices are worth copying. An invariant checker rebuilds the index keys from the records and diffs them, running after every FDB test — so the hand-rolled secondary indexes have a continuous consistency oracle rather than a one-off audit. And a TLA+ model of the migration, written with a coding agent, explored 1.5 million states and found a bug in the runbook.

The cost claim, and why it needs an asterisk

The headline is "about 20× less" for everything those databases held. No absolute spend and no baseline methodology are given, and the chart shows spend only relative to the peak month.

Elsewhere the same article says the FDB clusters "cost about a third of the databases they replaced". The article does not reconcile the two ratios. They are not necessarily inconsistent — 20× plausibly covers the whole former footprint, including what moved to object storage and the databases that simply should never have existed, while a third compares like-for-like replacement — but a reader cannot tell which comparison the headline makes. A footnote adds that spend was grouped "by database name" across three clouds while FDB was counted by nodes and disks, which are different accounting units.

The like-for-like figure is the one to quote. A 3× saving on replaced infrastructure is a strong result; 20× includes cleaning up a self-inflicted per-index table explosion, and that saving was available without changing databases at all.

Tradeoffs

Serializable transactions over any key set, bought with slower point reads. Justified here by the atomicity requirement on records-plus-indexes and by a 98% cache hit rate. Without both, the trade inverts.

Automatic rebalancing, paid for in operational surface. FDB "handles by splitting and moving key ranges across its servers on its own", which is what a single-primary shard could not do — and in exchange you own the operator, the knobs, the backups and the upgrades.

Hand-rolled secondary indexes. A key-value store gives you transactions and nothing else; every index is application code, hence the invariant checker. About 40,000 lines were deleted overall, but what remains includes index maintenance that a relational engine used to do.

Six months, and not a wholesale replacement. "We still run plenty of Postgres outside the data plane, and even a bit of SQLite sneaks in." The migration was scoped to the component whose scaling limit was binding.

Failure modes

Dual-writing during a migration. It manufactures the divergence you then have to reconcile. One writer, falling-back reads.

Treating all metadata as one migration. Ephemeral, derived and source-of-truth data need different mechanisms; only the last needs a write freeze, and only the derived kind can be backfilled by recency comparison.

Running a bulk loader at default priority. Global backpressure means your migration throttles production, and a client that does not retry retryable errors converts throttling into an outage.

Assuming a replacement-safety invariant holds when its input may be empty. An unset environment variable put every pod in one zone. Assert that the partition has more than one member.

Deriving capacity from a per-core throughput figure. The advertised number was exceeded fourfold, and load landed unevenly — the hottest server took twice the average.

Migrating a store with no rebuild path without a verified backup first. "Nothing rebuilds them if they're lost."

Quoting a cost ratio without its baseline. Two ratios appear in one article for overlapping scopes.

Review checklist

Connections

See R440 on the knowledge map

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.