ChatGPT Postgres
800M
users
1
primary
~50
read replicas
Millions
of queries/s
Low double-digit ms
p99
99.999%
available
1
SEV-0 in 12 months
Initial design
Healthy
Today
Healthy
1
Normal traffic
2
Cache misses spike
3
Primary database goes down
Fig 1
Today
Drag to turn · tap a number
What’s on the floor · today
1
ChatGPT and API apps
ChatGPT and the API. Bugs that wrote twice are fixed, lazy writes smooth spikes, clients back off before retrying, and connections go through PgBouncer.
2
Rate-limit gate
Rate limits at four layers: application (this gate), connection pooler, proxy and query. Above a ceiling it sheds traffic, so a sudden spike cannot overwhelm the database.
3
Cache
Serves most reads. Cache locking and leasing: one request per missed key fetches from PostgreSQL; the rest wait for the refill.
4
PgBouncer behind a Kubernetes Service
Each read replica has its own Kubernetes deployment of PgBouncer pods, all behind one Kubernetes Service, co-located with clients and replicas. Average connection time fell from 50 ms to 5 ms in OpenAI’s benchmarks.
5
PostgreSQL primary
Still one unsharded writer. It takes the writes and only the reads that are part of write transactions. The ORM can rate-limit or block an expensive query’s digest, and schema changes are lightweight only, with a 5-second timeout.
6
Hot standby
A hot standby, continuously synchronised, promoted quickly when the primary fails. Reads carry on from the replicas meanwhile.
7
Azure Cosmos DB
Azure Cosmos DB takes shardable, write-heavy workloads, and every new table: PostgreSQL accepts no new ones. Write-heavy workloads that are harder to shard are still being moved.
8
Read replicas
Nearly 50 across regions, several per region with headroom, split into high- and low-priority instances; products and services are kept apart the same way. Six are drawn. WAL from the primary, or through a relay with cascading replication (in testing).
9
Robot trays and depot
Each tray carries one query slip from the apps through the machines and back; one tray stands for many queries. Hover a tray to read its slip.