Curated summary
Scaling PostgreSQL to power 800 million ChatGPT users
Scaling PostgreSQL to 800 Million ChatGPT Users
OpenAI has scaled PostgreSQL to support ChatGPT and its API for roughly 800 million users, with load growing more than 10x over the past year. The core finding is that a single-primary PostgreSQL deployment, backed by nearly 50 read replicas across regions, can handle millions of queries per second for read-heavy workloads when paired with careful engineering. Write-heavy workloads are moved to sharded systems such as Azure Cosmos DB, and the team applies a set of protective measures to keep the system stable under traffic spikes. The result is low double-digit millisecond p99 latency and five-nines availability.
Cracks in the Initial Design
- Early growth was handled by scaling up instance sizes, adding read replicas, and applying application and database optimizations.
- Recurring SEVs followed a pattern: an upstream failure, such as a cache outage, an expensive join surge, or a write storm from a feature launch, spikes database load. Latency rises, requests time out, and retries amplify the load into a cascading failure.
- PostgreSQL's MVCC design struggles with write-heavy workloads. Updating a row copies the entire tuple, which causes write amplification, read amplification from dead tuples, table and index bloat, and complex autovacuum tuning.
Keeping a Single Primary Viable
- Write-heavy, shardable workloads are migrated to Azure Cosmos DB, and application logic is optimized to reduce unnecessary writes.
- New tables are no longer added to the PostgreSQL deployment; new workloads default to sharded systems.
- Full sharding of PostgreSQL was judged too costly, since it would require changing hundreds of endpoints over months or years. It remains a future option rather than a near-term priority.
Protective Measures
- Reducing primary load: Reads are offloaded to replicas wherever possible. Application bugs causing redundant writes are fixed, lazy writes smooth spikes, and backfills are rate-limited.
- Query optimization: A 12-table join was identified as a cause of past SEVs. Complex joins are moved to the application layer where feasible. ORM-generated SQL is reviewed, and timeouts such as
idle_in_transaction_session_timeoutprevent idle transactions from blocking autovacuum. - Single point of failure: Critical reads are served from replicas so they survive a primary outage. The primary runs in high-availability mode with a hot standby, and each region has multiple replicas with spare capacity.
- Workload isolation: Requests are split into low- and high-priority tiers on separate instances, and the same approach is applied across products to contain noisy neighbors.
- Connection pooling: PgBouncer runs in statement or transaction mode, cutting average connection time from 50 ms to 5 ms. Proxies, clients, and replicas are co-located in the same region, and each replica runs its own PgBouncer deployment behind a Kubernetes Service.
- Caching: A cache locking and leasing mechanism ensures that only one request per missed key queries PostgreSQL, while others wait for the cache to refill, which prevents cache-miss storms.
- Replica scaling: The primary must stream WAL to every replica, which strains it as the count grows. Cascading replication, where intermediate replicas relay WAL, is being tested with the Azure team to scale past a hundred replicas.
- Rate limiting: Limits are applied at the application, connection pooler, proxy, and query layers. Retry intervals are kept from being too short, and the ORM can block specific query digests to shed load during surges.
- Schema management: Only lightweight schema changes are allowed, with a strict 5-second timeout. Indexes are created or dropped concurrently, and new tables go to sharded systems. Backfills are rate-limited and can take over a week, which preserves stability.
Results and Outlook
- The deployment handles millions of QPS for read-heavy workloads, with nearly 50 replicas and near-zero replication lag.
- Over the past 12 months, there has been only one SEV-0, during the ChatGPT ImageGen launch, when write traffic surged more than 10x as over 100 million users signed up in a week.
- Remaining write-heavy workloads are being migrated, cascading replication is in progress, and sharded PostgreSQL or alternative distributed systems are under consideration for the longer term.
Related reading
Continue with another curated summary.
OpenAI2026-10-22 Rapidly scaling online storage to serve over 1 billion ChatGPT users (Part II)
Read original
OpenAI2026-09-10 Rapidly scaling online storage to serve over 1 billion ChatGPT users
Read original
Datadog2026-06-04 When failover isn’t safe: Building high-availability PostgreSQL on Kubernetes
Read original
Datadog2026-03-23 When upserts don't update but still write: Debugging Postgres performance at scale
Read original