Featured image of post From Python to Rust: OpenAI’s Habitat Storage System Scaled to Handle 1 Billion Weekly Users

From Python to Rust: OpenAI’s Habitat Storage System Scaled to Handle 1 Billion Weekly Users

OpenAI rewrote its Habitat storage backend from Python to Rust to handle 70M requests/sec and 500PB data.

Core Event: Habitat Storage System Undergoes Language-Level Rewrite

OpenAI has completed the rewrite of its internal storage system Habitat, migrating the core from Python to Rust to support ChatGPT’s rapidly growing user base.

  • Rewrite completion: Early 2026 (inferred from timeline)
  • Target language: Rust (for high-performance, memory-safe core components)
  • Retained layer: Minor Python services remain for rapid iteration scenarios
  • Supported scale: 70 million requests/sec, 500PB storage, 1 billion weekly users

The rewrite was not an emergency response, but part of a long-term migration plan. Clear early on that Python could not sustain long-term scalability, OpenAI delayed the rewrite until the Rust ecosystem matured and internal expertise became sufficient.

The Rewrite Logic: Patience from “Works” to “Robust”

Habitat began as a small Python library connecting to databases, initially bearing ChatGPT’s storage load in the early days. As user growth accelerated, the system faced significant pressure:

  • Python’s GIL (Global Interpreter Lock) limited multi-threaded parallelism
  • GC pauses introduced P99 latency jitter under high load
  • The interpretive layer imposed fixed overhead per request

The counterintuitive data point: Habitat had already scaled to substantial size under Python, yet OpenAI chose not to rewrite for years—only proceeding once Rust’s ecosystem matured and internal engineers demonstrated proficiency. This delayed the rewrite until the solution was proven viable, rather than reacting to a full-blown crisis.

The team adopted a phased approach:

  1. First implemented a Rust-based core KV engine (Captive Engine), maintaining Python bindings;
  2. Migrated high-throughput paths (compression, wire protocol) to Rust;
  3. Retained Python for control-plane management and business-logic glue.

Technical Gains: Performance and Safety Reinforced

Post-migration, Habitat demonstrated three key improvements:

  • Latency stability: P99 timeout requests dropped by 90%, eliminating GC pauses and GIL contention
  • Memory efficiency: Static allocation reduced per-request memory footprint by 40%+
  • Safety: Compile-time borrow checking eliminated null-pointer and Use-After-Free vulnerabilities

Within OpenAI’s testing, a single Rust-core node handled over 3× the concurrent connections versus the Python version. More importantly, Rust’s zero-cost abstractions enabled fine-grained performance tuning (custom buffers, zero-copy I/O) without compromising maintainability.

Lessons in Technical Debt: The Philosophy of Delayed Repayment

OpenAI’s approach contradicts the traditional “rewrite only after system collapse” heuristic. Its technical lead noted that rewriting is a prioritization decision requiring balance between ecosystem maturity and engineering trade-offs.

This strategy delivered two counterintuitive advantages:

  1. Python retained value: Rapid iteration tasks (metrics generation, log parsing) stayed in Python, avoiding premature固化 of all services
  2. Gradual replacement reduced risk: Coexistence allowed traffic splitting for validation, avoiding “big bang” releases

Teams suitable for this path:

  • Existing Python-centered services without affecting SLA
  • Sufficient systems programming experience or access to Rust expertise
  • Capacity to sustain a 12–24 month incremental iteration cycle

Teams advised to await:

  • If current Python services have hit single-cluster capacity limits, prefer hybrid language architecture over full rewrite
  • Teams lacking resources to maintain dual stacks should target incremental refactoring (hot modules only)

Final Thoughts

Habitat’s practice demonstrates that technical debt’s real cost isn’t “whether you owe”, but “whether you keep compounding interest”. When a system runs stably for years in the “wrong” language, that stability often reflects wisdom—not delay, as long as the delay buys time to solve the right problem.