Rapidly scaling online storage to serve over 1 billion ChatGPT users
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.
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.
- Scaling PostgreSQL to power 800 million ChatGPT users
OpenAI mediumAdept
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.
- Scaling recommendations service at OLX
OLX Tech mediumAdeptOLX scaled a Python FastAPI recommendations service to tens of thousands of requests per second with p99 latency under 10ms by systematically removing event-loop stalls. Key steps were making I/O non-blocking (offloading the sync ScyllaDB driver to threads, swapping boto3 for aioboto3), which cut latency over 40% and raised throughput over 50%. Batching fan-out ScyllaDB queries halved p99, and replacing Pydantic with slotted dataclasses everywhere except request inputs cut latency over 30%. Raising GC thresholds (gen0 700→7000, gen1/2 10→20) removed bimodal pauses and dropped homepage p99 from 52ms to 12ms.
- How Meta built the infrastructure for Threads
Meta Engineering mediumAdeptThreads reached 100 million sign-ups in five days on existing shared Meta infrastructure rather than purpose-built systems, illustrated through two components: ZippyDB and Async. ZippyDB, a multi-tenant key/value store, absorbs sudden demand by shifting unused allocations and slack between keyspaces via config changes. It scales out with a zero-downtime resharding protocol that remaps logical shards to new physical shards, which let the team proactively prepare Threads keyspaces for 100x growth just before launch. Async (XFaaS), a serverless deferred-execution platform, queued the far-higher-than-expected follow-graph imports and notification jobs and rate-limited their execution to protect downstream services such as the social graph database.
- Beyond rate limits: scaling access to Codex and Sora
OpenAI mediumAdept
OpenAI replaced hard rate-limit stops for Codex and Sora with a real-time access engine that treats rate limits, free tiers, credits, promotions and enterprise entitlements as layers in a single decision waterfall evaluated per request. Rate limits are consumed synchronously, and credits are checked in the same request but debited asynchronously through a streaming processor. Three chained datasets (product usage events, monetization events, balance updates) make every outcome auditable and replayable. Idempotency keys prevent double-debits, per-account serialized atomic transactions pair each balance decrement with an attributed record, and brief overshoots from the async delay are automatically refunded, trading strict enforcement for provable correctness.