# What Database Does ChatGPT Use? How OpenAI Scales PostgreSQL

800 million people use ChatGPT. The main Postgres database behind it has **one single machine** that takes every write sent to it.

If you've done any system design prep, your instinct is the same as mine was: that database should have been split up (sharded) a long time ago. OpenAI never split it. And it doesn't fall over.

I read OpenAI's engineering post on this, "[Scaling PostgreSQL to power 800 million ChatGPT users](https://openai.com/index/scaling-postgresql/)" (Bohan Zhang, January 2026), and drew the whole thing on one page. Every number below comes from that post. Where something is my opinion, I say so.

![800 million users, one main database](https://cdn.hashnode.com/uploads/covers/63ba759195025da0eece5055/b12fb541-0de7-4309-a89c-223d74f18d0b.png align="center")

## The short version

- **One main Postgres machine** takes all the writes. A backup waits on standby.
- **Nearly 50 copies** (read replicas) in regions around the world answer the reads, and a cache in front answers most of them.
- The load grew **more than 10x in one year**, to millions of queries per second.
- **Four habits** keep the one writer alive: push reads away, guard the writer, reuse connections, put limits everywhere.
- The result: **five nines** of availability and **one** top-severity Postgres incident in 12 months.

## The setup

![The setup: one main machine and about 50 copies](https://cdn.hashnode.com/uploads/covers/63ba759195025da0eece5055/94af66f1-24ad-4152-8cd1-3f20cbf98d0a.png align="center")

Here's the shape in plain words first.

There is **one main machine** that accepts every save. Engineers call it the *primary*. It runs on Azure's managed PostgreSQL (flexible server), with a *hot standby*: a second machine that stays in sync and takes over if the primary dies.

Every change on the primary is copied to **nearly 50 other machines**, spread across multiple regions. These are *read replicas*. They can answer questions ("show me this conversation") but they don't accept saves.

In front of all of that sits a **cache**, a fast shortcut that remembers popular answers, so most reads never touch a database at all.

The reason this works at all is one line in OpenAI's post: their workloads are **primarily read-heavy**. People read far more than they write. Reads can be spread across 50 machines. Writes to this database can't, so every one of them still lands on the primary.

## The pressure

That load isn't standing still. OpenAI says it grew **more than 10x over the past year**, and the system now handles **millions of queries per second**.

So the real question isn't "how does one database serve 800 million people". It's "how do you stop one writer from getting crushed while traffic multiplies?" Their answer is four habits.

## Habit 1: Push reads away from the primary

![Habit 1: send reading away](https://cdn.hashnode.com/uploads/covers/63ba759195025da0eece5055/d5e81ef1-1e6f-43e3-ab4c-61870fb82bba.png align="center")

Reads go to replicas wherever possible, and the cache serves most of the read traffic.

The clever part is what happens when the cache **misses**. Imagine a popular item drops out of the cache. Thousands of requests ask for it at the same moment, they all miss, and they all run to the database together. That's a *cache stampede* (also called a *thundering herd*), and it can flatten a database that was perfectly healthy a second earlier.

OpenAI uses cache locking (leasing): when requests miss on the same key, **only one of them** goes to Postgres to fetch the data. Everyone else waits for the cache to refill. One trip instead of a flood.

> **Interview tip (my take):** if you put a cache in your design, say what happens when it misses or fails. "One request per key refills it, the rest wait" is exactly the answer interviewers want to hear.

## Habit 2: Guard the one writer

Since every write lands on one machine, OpenAI works hard to send it fewer writes:

- **Write-heavy work that can be split moves out**, to sharded systems such as Azure Cosmos DB.
- They **fixed bugs that caused redundant writes**, where the app saved the same data more than once.
- Big bulk updates (*backfills*) are **rate-limited**, so a background job can't swamp the primary.
- **No new tables** are allowed on this Postgres. New workloads default to the sharded systems instead.

This is the part people miss. **OpenAI did shard. Just not this database.** They moved out the work that was easy to split and kept the hard-to-split core on one primary.

## Habit 3: Reuse connections

![Habit 3: reuse connections](https://cdn.hashnode.com/uploads/covers/63ba759195025da0eece5055/6dcd38b8-9903-4e87-9bf0-f4750f954416.png align="center")

Every app server that talks to Postgres opens a connection, and opening one isn't free. Azure's Postgres allows **5,000 connections** per instance. A sudden spike of new servers or retries can use them all up, and then nobody can connect.

So OpenAI puts **PgBouncer**, a connection pooler, in front of the database. Instead of every request opening its own connection, the pooler keeps a set of connections open and hands them out. In OpenAI's benchmarks, the average time to connect dropped from **50 ms to 5 ms**.

## Habit 4: Put limits everywhere

![Habit 4: limits everywhere](https://cdn.hashnode.com/uploads/covers/63ba759195025da0eece5055/ed4a7c16-002f-4334-ad79-f7c71e2c5cc8.png align="center")

Rate limits sit at **four layers**: the application, the connection pooler, the proxy and the individual queries. If one layer lets too much through, the next one catches it.

Two smaller rules matter a lot:

- **No overly short retry intervals.** When something fails, clients retry. If they all retry instantly, the retries become a second wave of traffic, often bigger than the first. Spacing them out stops a small failure from turning into a storm.
- **Schema changes get a strict 5-second timeout.** Changing a table's structure can lock it. If the change can't finish in 5 seconds, it's stopped, instead of freezing writes for everyone.

## The result

![The result](https://cdn.hashnode.com/uploads/covers/63ba759195025da0eece5055/d8ef5dfd-6fb7-4204-9edd-4871b326c7e8.png align="center")

According to OpenAI's post:

- **Low double-digit millisecond p99 latency** on the client side. In plain words: 99 out of 100 requests come back within low double-digit milliseconds. Tens, not hundreds.
- **Five nines** of availability (99.999%).
- **One** top-severity (SEV-0) Postgres incident in 12 months. It came during the ImageGen launch, when **over 100 million new users signed up in a week** and writes jumped **more than 10x**.

## So why not just shard it?

OpenAI answers this directly. Sharding this Postgres would mean **changes to hundreds of application endpoints** and could take **months or even years**. With a read-heavy workload and all the habits above, the single primary still has room to grow.

They're not ruling sharding out for the future. It's just not a near-term priority.

## What I'd take into a system design interview

This part is my opinion, not OpenAI's:

1. **Ask for the read/write ratio before you shard.** A read-heavy system can go much further on one primary than most people assume. Replicas and a cache scale reads; only writes force a split.
2. **Protect the single writer on purpose.** Move the easy-to-split write traffic elsewhere, kill duplicate writes, throttle background jobs.
3. **Name the failure modes.** Cache stampede, connection storm, retry storm. Each one has a small, specific fix: one request per key, a pooler, retries spaced out.
4. **Sharding is a cost, not a badge.** It buys write capacity and charges you complexity in every part of the app. OpenAI paid that cost only for the work that was cheap to move.

## The whole thing on one page

![ChatGPT's database on one page](https://cdn.hashnode.com/uploads/covers/63ba759195025da0eece5055/f30bcdad-914a-4f56-8d98-190f9e792c2d.png align="center")

Save it for your next interview. I post one of these every week, each one a real system from a real company's own engineering blog.

- **Watch it in 48 seconds:** [Instagram Reel](https://www.instagram.com/archandalgorithms/)
- **Next week:** how Discord stores trillions of messages.

## Want to run a system like this yourself?

I'm building a game where you keep systems like this one alive while the traffic climbs: add replicas, place the cache, stop the stampede before it hits your one writer.

[**Join the waitlist**](https://physisync.co.in)

---

*Source: OpenAI engineering blog, "*[*Scaling PostgreSQL to power 800 million ChatGPT users*](https://openai.com/index/scaling-postgresql/)*", Bohan Zhang, 22 January 2026. I'm not affiliated with OpenAI; all figures are theirs.*
