Talk
Intermediate

How I made FastAPI 6x Faster: From Python to Rust Without Rust

Review Pending

Session Description

Building fast Python APIs is a solved problem. You pick FastAPI, write clean async code with type hints, and deploy with Uvicorn or Gunicorn. For most use cases, this works perfectly fine. But, it's too SLOW!

But there are some scenarios where Python's performance ceiling becomes a bottleneck. These is real world, we have HIGH throughput applications where every millisecond of latency matters, and where horizontal scaling becomes prohibitively expensive.

Example scenarios:

  • How would you handle 30,000+ requests per second on a single server without rewriting your entire codebase in Go or Rust?

  • How do you keep your FastAPI decorator syntax and Pydantic validation while getting 6x better performance?

Given: You have an existing FastAPI application with thousands of lines of code

When: You need 10x better throughput without changing your API contract

Then: What options do you have besides "rewrite everything in a compiled language"?

Even though we can optimize Python code, add more workers, or scale horizontally, we eventually hit fundamental limits of the Python runtime. These performance-critical scenarios require a different approach, one that doesn't force you to abandon Python! In this session, I will demonstrate FastrAPI, an open-source framework that delivers Rust-level performance while keeping your familiar Python syntax. I will show real benchmarks, explain the architecture, and demonstrate how to migrate existing FastAPI applications with a single line change, and most importantly, ALL THE OPTIMIZATIONS and MICRO-OPTIMIZATIONS (From Branch Predictions to Hashing algorithms).

Performance Comparison

  • FastrAPI: 31,360 req/sec, 0.59ms avg latency

  • FastAPI + Gunicorn (1 worker): 937 req/sec, 21ms avg latency

  • FastAPI + Gunicorn (16 workers): 3,882 req/sec, 4.84ms avg latency

Drop in Migration

- from fastapi import FastAPI
+ from fastrapi import FastrAPI
app = FastrAPI()

@app.get("/hello")
def hello():
    return {"Hello": "World"}

The ability to:

  • Use same FastAPI decorator syntax (@app.get, @app.post)

  • Achieve 6x performance improvement over FastAPI + Gunicorn in real-world benchmark

  • Maintain full Pydantic integration for request/response validation

  • Handle 30,000+ requests per second with sub-millisecond average latency

  • Add middleware (CORS, GZip, TrustedHost, Session) exactly like FastAPI

  • Migrate existing applications by changing a single import statement

  • Deploy with a simple serve() method - no Uvicorn, Gunicorn, or worker management

  • Leverage Rust's type safety and memory efficiency without writing Rust code

  • Run async Python handlers on Tokio's high-performance runtime

  • Build production APIs with minimal memory overhead and maximum throughput

Key Takeaways

  1. Understanding the performance gap: Learn why Python web frameworks hit performance ceilings and how Rust can bridge that gap (with concrete benchmarks of pyo3)

  2. How Python 3.14's GIL removal affects PyO3 and FFI frameworks right now, what changes for FastrAPI's architecture, and whether free threading actually delivers the performance gains everyone's hoping for in production scenarios.

  3. Deep dive into every FastrAPI feature built from scratch including the routing system mapping Python decorators to Axum's router, Pydantic integration without GIL bottlenecks, middleware architecture for CORS/GZip/Sessions, and response types with zero-copy serialization.

  4. An optimization timeline on how I optimized the framework from 11K+ reqs/s base barebones requests to 35K+ reqs/s, showing exactly what changes made the difference.

  5. Guide to tools like pyo3-asyncio for async bridging, pythonize, sonic-rs for serialization, and arc/mutex patterns using parking_lot, dashmap vs papaya instead of hashmap - with before/after performance comparisons for each optimization.

  6. Real issues I have encountered during development - GIL deadlocks, memory leaks across FFI boundaries, Python exception handling in Rust, async runtime conflicts, and how I fixed it

  7. How I reverse-engineered FastAPI's API surface to make migration literally one import change - handling edge cases, maintaining decorator behavior, ensuring error messages match FastAPI's, and the testing strategy to validate compatibility.

  8. Learn actionable steps to either adopt FastrAPI for your projects or build your own Python Rust hybrid libraries with practical migration guide

  9. When to use FastrAPI vs FastAPI (and when to build your own): Decision framework based on actual production scenarios - latency requirements, request volume, cost of horizontal scaling, team expertise, and the FastrAPI feature roadmap. Plus a starter template if you want to build similar Python-Rust hybrids for your use case.

References

Session Categories

Introducing a FOSS project or a new version of a popular project
Technology architecture
Engineering practice - productivity, debugging

Speakers

Preetham Pemmasani
Creator, FastRAPI
https://preetham.top/
Preetham Pemmasani

Reviews

0 %
Approvability
0
Approvals
0
Rejections
0
Not Sure
No reviews yet.