Why OpenAI Refused to Shard Postgres at 800 Million Users
Every scaling talk follows the same script. User count crosses some line, someone says the word "shard," and the team starts shopping for a distributed database. OpenAI crossed that line a long time ago and did the opposite. The metadata database behind ChatGPT, the one carrying user accounts, workspaces, organization permissions, and conversation structure, runs on a single PostgreSQL primary with roughly 50 read replicas. One writer. Hundreds of millions of users. Millions of queries per second.
The claim comes from a Postgres Conference New York talk by OpenAI engineer Nikhil Rothu in June 2025, and it has been recirculating through architecture blogs this month. Numbers quoted from a conference stage deserve some skepticism, and I will get to what they do not prove. But the reasoning behind the choice is solid engineering, and it corrects a reflex most teams have.
The reflex everyone has
The standard playbook says that at hyperscale you need Vitess, CockroachDB, Spanner, or hand-rolled sharding by user_id. The playbook is not wrong in general. It is wrong when applied without measuring what the workload actually does. And ChatGPT's metadata workload does something specific: it is overwhelmingly reads, a split the talk puts at over 95 percent.
Once you accept that number, the architecture almost writes itself. Reads scale horizontally: add a replica. Writes do not: they need agreement, and agreement is the expensive part. So OpenAI scaled the cheap axis to about 50 replicas and kept the expensive axis on one large machine. A modern bare-metal server with over a hundred cores and a terabyte of RAM absorbs tens of thousands of write transactions per second, which is roughly what remains once reads go elsewhere and the append-heavy writes move out.
The replica tree and write amplification
Fifty replicas create a problem of their own. PostgreSQL replicates through the write-ahead log, so one committed write must stream to every replica. One write becomes fifty network copies, and the primary pays the network and CPU cost for each. That is write amplification, and it turns the primary into a fan-out bottleneck long before storage is the issue.
The fix is a tiered replica tree. Instead of all 50 replicas pulling WAL directly from the primary, first-tier replicas pull from it and second-tier replicas cascade from their parents. The primary's fan-out drops from 50 to a handful. The cost is latency: a third-tier replica can sit seconds behind its parent, which is fine for analytics and stale-tolerant reads and dangerous for anything user-facing. Replication depth becomes a menu. Pay in staleness or pay in primary load, per consumer.
The connection problem nobody sketches
Whiteboards draw boxes and arrows. They do not draw connections. PostgreSQL forks an operating system process per connection, roughly 10MB each, so 10,000 client connections burn 100GB of RAM and set the kernel scheduler on fire before a single query runs. ChatGPT runs on thousands of stateless service pods, which multiplies that pressure.
PgBouncer in transaction mode collapses tens of thousands of client connections onto a few hundred real database connections. The classic gotcha applies, and any stack this size lives with it: session state such as prepared statements, advisory locks, temp tables, and SET leaks between clients in transaction mode, so the application either avoids session-level features or pins sessions explicitly. This is the unglamorous layer that makes a single primary survivable.
Moving the append-heavy writes out
The cleverest piece is what is not in Postgres at all. Chat messages are append-heavy, high-throughput writes that do not need the same transactional guarantees as billing, so they go to Azure Cosmos DB and blob storage. What stays on the primary is genuine state mutation: account creation, plan changes, organization roles, permissions.
This is write offloading rather than sharding, and the difference matters. Sharding splits the same table across machines and inherits cross-shard joins, resharding migrations, and a routing key in every query across every service. Offloading removes a class of writes whose requirements were different in the first place. One approach keeps ACID where ACID pays. The other buys ACID everywhere and pays for it everywhere.
The discipline you pay for instead
None of this works on a sloppy codebase. What the talk describes as the cost of the single primary is engineering discipline:
- No N+1 ORM queries. A loop that fetches a conversation and then every message individually gets the primary killed at this scale, so query patterns are policed in review.
- Aggressive caching of hot reads like workspace config, feature flags, and auth checks in Redis in front of the replica fleet.
- Rate limiting as an architectural component rather than a product feature. A single primary is one blast radius, so abusive clients get cut off at the edge before they reach SQL.
Compare Nextdoor's older scaling ladder: pool connections with PgBouncer, then split reads onto replicas with a session-pinning window for read-your-own-writes, then shard by neighborhood_id only as a last resort. Same philosophy, different endpoint. Nextdoor eventually sharded because its write volume kept growing in the sharded tables themselves. OpenAI did not have to, because its writes stayed small once the chat volume moved out.
When the single primary actually breaks
The honest limits. A write storm hits a single primary with no recourse: you cannot add a replica to spread writes, and failover to a promoted standby is one global event rather than a per-shard one. The design also rests on a trust assumption, the 95 percent read split. Products change. A feature that doubles write volume makes the whole architecture wrong, and the migration you deferred comes due with interest.
The reported five-nines reliability deserves a footnote too. It comes from OpenAI's own framing of its metadata layer, not a third-party audit, and the metadata database is not the whole system. The talk is also from mid-2025, and architecture at that pace moves. Treat every number as directional. The reasoning is what is worth stealing.
What to copy on Monday
Before sharding anything, measure your read-to-write split and your actual write rate in transactions per second. Most teams arguing about CockroachDB are running 300 writes per second on hardware that could handle 30,000. Then work the ladder in order: put PgBouncer in transaction mode in front of the primary, push reads to replicas with a pinned-session window for read-your-own-writes, move append-heavy log-like writes to a store built for appends, and make the ORM prove it is not doing N+1 on every page load.
If you are still write-bound after all that, shard. You will arrive at that decision knowing which table deserves it and which shard key survives your access patterns, instead of sharding everything on a hunch and paying the routing tax forever.
OpenAI's real lesson is not "never shard." It is that sharding is a write problem, and most read-heavy products have a read problem wearing a write problem's costume. Check which one you have before you buy the distributed database.
Comments