Scaling PostgreSQL to power 800 million ChatGPT users
OpenAI serves millions of queries per second for ChatGPT and its API from a single unsharded Azure PostgreSQL primary plus nearly 50 geo-distributed read replicas, despite load growing more than 10x in a year. The approach is to keep the primary as idle as possible: move shardable write-heavy workloads to Azure Cosmos DB and ban new tables, push reads to replicas, kill expensive ORM-generated joins, and isolate high- and low-priority traffic onto separate instances. Supporting measures include PgBouncer pooling (connection time down from 50 ms to 5 ms), cache leasing to stop miss storms, multi-layer rate limiting with query-digest blocking, and schema changes capped at a 5-second timeout. The result is low double-digit millisecond p99 latency, five-nines availability and one SEV-0 in 12 months, and cascading replication is being tested to scale past 100 replicas.
Related posts
- Rapidly scaling online storage to serve over 1 billion ChatGPT users (Part II)
OpenAI mediumAdept
OpenAI's Habitat storage platform went from one shared Azure Cosmos DB container, to per-use-case dedicated containers, and back to a shared multi-tenant container. Shared containers suffered from logical partition key collisions, noisy neighbors on physical partitions, and "weak partitions" whose throughput shrank as storage-driven splits divided fixed RU/s. Dedicated containers fixed isolation but lost the smoothing effect of aggregate load, which pushed capacity planning onto every product team and caused launch-day SEVs. Hot-key throttling, QoS request tiering and a new serverless mode built with Azure (10K RU/s per physical partition, plus RU-usage-based splits) made shared tenancy work. Failover and failback outages at 20M+ QPS scale also led to co-managed operations with Azure, including joint monitoring and production-sized test accounts.
- PostgresBench: Measuring the impact of High Availability on Managed Postgres performance
ClickHouse mediumAdept
PostgresBench now measures the performance cost of high-availability configurations across managed Postgres services, comparing shared-nothing designs (ClickHouse Managed Postgres, RDS, Crunchy Bridge) that use streaming standbys with shared-storage forks (Aurora, Neon) that replicate WAL to a storage layer. On a 16 vCPU/64 GB instance with a 500 GB dataset, ClickHouse's NVMe-backed service dropped to 94% of single-node TPS with one async standby and 79% with two synchronous quorum standbys, with p99 latency rising 1.8x and 2.5x. RDS throughput was roughly flat, but its p99 rose to 1.7x with one sync standby and 6.3x (817 ms) with a two-standby quorum cluster. The vendor-run results claim 2-4x throughput advantages for ClickHouse over the other services at matched compute and comparable durability.
- Production Postgres on Railway: From First Deploy to High Availability
Railway mediumAdeptRailway Postgres can grow from a single private-networked database to a production setup with volume backups, point-in-time recovery, PgBouncer connection pooling and Patroni-based high availability, demonstrated with an orders API that uses idempotency keys so retries stay safe. PITR restores into a separate service for validation, and the guide stresses measuring RPO/RTO end to end, including validation and reconnection time. Transaction pooling breaks session settings, LISTEN, advisory locks and named prepared statements, so migrations should use an unpooled URL. In one small planned switchover test (primary, two replicas, etcd, HAProxy), writes were interrupted for about 17 seconds. That is a single observation, not a guaranteed failover time.
- Rapidly scaling online storage to serve over 1 billion ChatGPT users
OpenAI mediumAdept
Habitat, OpenAI's online storage platform, grew from a client-side Python library over Azure Cosmos DB into a centralized Python service handling 70M+ requests per second and 500+ PB across about 40 regions. It moved to a service because coordinating client-library rollouts across dozens of services had become slow and error-prone. Running Python at this scale meant fighting tail latency from asyncio event-loop scheduling delay, which the team measured directly and controlled by keeping per-process concurrency low and scaling out worker processes. Specific fixes included shrinking and jittering Statsig feature-flag config refreshes, and switching aiohttp's LIFO connection reuse to FIFO to break a metastable failure that concentrated load on already-slow processes.
- How we scale PgBouncer in ClickHouse Managed Postgres
ClickHouse mediumAdept
Because PgBouncer is single-threaded, ClickHouse Managed Postgres runs a fleet of PgBouncer processes sized to the core count, all binding one port via so_reuseport so the kernel load-balances connections behind a single endpoint. Peering between processes forwards cancel requests that land on the wrong process, and max_client_conn and max_db_connections are divided across the fleet so Postgres is never oversubscribed. On a 16-vCPU c7i.4xlarge with pgbench select-only load, a single process peaked near 87k TPS and degraded to 77k at 256 clients while pinned at one core. A 16-process fleet reached about 336k TPS (roughly 4x) using about 8 cores. At very low concurrency the single process is marginally faster, so the fleet pays off only once the pooler becomes the bottleneck.