Featured image of post From Python to Rust: OpenAI Habitat's 10x Growth Refactoring Journey

From Python to Rust: OpenAI Habitat's 10x Growth Refactoring Journey

OpenAI rewrote ChatGPT's storage backend from Python to Rust, supporting 70 million requests per second and 500PB of data.

Core Event: Habitat Storage System Completes Language-Level Rewrite

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

  • Rewrite completion: Early 2026 (inferred from the timeline in the source)
  • Target language: Rust (for high-performance, memory-safe core components)
  • Retained layer: A small number of peripheral Python services remain for rapid iteration scenarios
  • Supported scale: 70 million requests per second, 500PB storage, 1 billion weekly users

This rewrite was not a reactive emergency but rather a language evolution path that OpenAI anticipated early on—well before technical bottlenecks materialized, the team had already determined that Python could not sustain long-term scaling requirements.

Rewrite Logic: A Decade of Discipline from “Works” to “Withstands”

Habitat began as a small Python library connecting to databases, gradually taking on ChatGPT’s core storage workload. As user volume grew exponentially, the system faced significant pressure:

  • Python’s GIL (Global Interpreter Lock) constrained multithreaded parallelism efficiency
  • Garbage collection latency caused noticeable P99 latency jitter under high load
  • The Python interpreter layer that every request had to traverse imposed a fixed overhead

The striking contrast: Habitat had already reached substantial scale during its Python era, yet OpenAI chose not to rewrite for several years—waiting until the Rust ecosystem matured and internal engineers had deep enough hands-on experience—rather than waiting until the system collapsed entirely.

The team adopted a phased strategy:

  1. First, write the core KV engine (Captive Engine) in Rust while retaining the Python binding layer;
  2. Migrate high-throughput paths (such as object compression and transport protocols) to Rust;
  3. Reduce the Python layer to serving only as the control plane and business logic glue.

Technical Evolution: Dual Gains in Performance and Safety

After migrating to Rust, Habitat revealed three key improvements:

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

In OpenAI’s testing, a single Rust core node could handle over 3× the concurrent connections of its Python predecessor. More critically, Rust’s zero-cost abstractions made fine-grained performance control (such as custom buffer pools and zero-copy I/O) possible without sacrificing code maintainability.

Rewrite Lessons: The Philosophy of “Deferred Repayment” for Technical Debt

OpenAI’s approach upends the conventional wisdom that “you need a system crash to justify a rewrite.” Their technical lead has noted that rewriting is a matter of prioritization—weighing ecosystem maturity timing rather than patching in place.

This strategy yields two counterintuitive advantages:

  1. Python still contributes value: Rapid iteration on peripherals (such as monitoring metric generation and log parsing) remains in Python’s hands, preventing all services from prematurely ossifying
  2. Incremental replacement keeps risk manageable: During the coexistence period of old and new implementations, stability can be validated through traffic splitting rather than a “big bang” rollout

Teams suited for a similar path:

  • Those running centralized Python services where performance bottlenecks have not yet impacted SLAs
  • Teams with some systems programming experience or the ability to bring in Rust specialists
  • Those able to sustain a 12–24 month long iteration cycle

Teams that should hold off:

  • If current Python services have already hit single-cluster ceilings with no room for horizontal scaling, prioritize a mixed-language architecture over a complete rewrite
  • When engineering resources are insufficient to support maintaining two implementation stacks in parallel, opt for incremental refactoring (e.g., rewriting only hot-path modules)

Final Thoughts

Habitat’s practice demonstrates that the cost of technical debt lies not in “whether you owe it,” but in “whether you’re continuously compounding the interest.” When a system runs stably on the wrong language for years, it often reflects greater engineering wisdom than frequent rewrites—provided that stability is buying time rather than concealing problems.