Part 1 covered why teams pick Rust and what Anthropic got from it. This part is practical: the stack we build Rust backends on, the two ways to migrate an existing Python or Node.js API, how to prove the new one matches the old, and when to skip Rust. Anthropic's write-up is the public reference for what works at scale; the rest is our approach.
TL;DR
- Our default stack: Tokio, axum (or Actix Web), SQLx, Serde and Cargo.
- Moving one function into Rust (PyO3 for Python, NAPI-RS for Node.js) is cheap, but it pays only when data rarely crosses the boundary. Anthropic's incremental step, Rust parsing output called from Python, saved only 8–10% CPU, because each token crossed the boundary three times.
- A full rewrite needs a referee: run the old API as the oracle and compare outputs on shadowed traffic.
- Tests are not enough. In April about 98% of Anthropic's tests passed while only about a quarter of production inputs matched.
- Skip Rust when the database is the bottleneck, traffic is modest, or the team can't absorb the learning curve.
Our default Rust stack
| Layer | Crate | Role |
|---|---|---|
| Async runtime | Tokio | The runtime the server runs on |
| Web framework | axum (or Actix Web) | Routes and request handlers |
| Database | SQLx | Queries checked at compile time; Postgres, MySQL, MariaDB, SQLite |
| Data formats | Serde | JSON and other formats in and out |
| Build | Cargo | Dependencies, builds, crates.io |
| Interop | PyO3 / NAPI-RS | Rust inside Python (built with maturin) or pre-compiled Node.js addons |
We default to axum on Tokio and use Actix Web when a team already knows it. SQLx checks queries at compile time, so a query that no longer fits the schema, such as one using a renamed column, fails the build instead of failing in production.
Two ways to migrate
Piece by piece
PyO3 or NAPI-RS
Keep the Python or Node.js service; move one hot function into a Rust module.
Low risk, ships in small steps.
Pays only if data crosses the boundary rarely. Anthropic's incremental step, Rust parsing output called from Python, cut CPU just 8–10%: each token crossed Python and Rust three times.
Rewrite the hot path
Rust owns the request
The old service hands the request to Rust, which does the rest.
Where Anthropic got about 70% less CPU per request.
Needs a full verification plan before real traffic moves.
01Is the database or a third-party API the bottleneck?
YES → Don't reach for Rust yet; fix queries, caching or the call patternNO ↓
02Is the slow part one function with a big input and a small result?
YES → Move it into Rust with PyO3 or NAPI-RSNO ↓
03Does the hot path touch data at every step (per token, per row, per message)?
YES → Rewrite the whole path in Rust; a crossing per item eats the gainNO ↓
profile first, then decide
How to verify a rewrite: the old API is the referee
Anthropic treated its Python production API as an oracle. Real requests were shadowed to the Rust version and the outputs compared. The model was called once and its output replayed, so both sides saw the same input. No customer text was read; comparisons used checkpoints and fingerprints. A script ran every 10–30 minutes and alerted a coordinating Claude agent when a new kind of difference appeared.
Tests alone would have misled them. In April about 98% of tests passed, but only about a quarter of production inputs matched. Per Anthropic's charts, the match rate started at 24%, dipped to 6.5% in early May before climbing to 99.6%. Exhaustive testing was never an option: 20 on/off options make more than a million combinations, about 12 days at one second each.
- 01
Old API as oracle
The current service's answers are the truth the new one must match.
- 02
Shadow real traffic
Copies of live requests go to the Rust service; users only see the old one.
- 03
Call once, replay
Slow or paid dependencies are called once and replayed to both sides.
- 04
Compare fingerprints
Hashes and checkpoints, not raw customer data.
- 05
Alert on new diffs
A scheduled job groups mismatches and flags any new kind.
- 06
Switch in stages
Move traffic in slices once the match rate holds; keep the old path as fallback.
Where AI coding agents fit
Anthropic ran Claude in three loops: an inner loop in a sandbox with a sub-second input check and a fake model, an outer loop that fixed pull requests against shadowed traffic, and a memory loop of notes, CLAUDE.md, tests, lints and merge checks. Per Anthropic's charts, merged changes went from under 100 per two weeks to about 1,000 in late June and over 3,000 from August 10.
Their sharpest line: "A verifier can tell an agent whether the outputs matched, but not whether the fix is good enough to ship." That is the line we hold too. Agents write a lot of code; an engineer decides what ships.
When NOT to choose Rust
- The database or an outside API is the bottleneck. A faster server waits just as long.
- Traffic is modest and the bill is fine. Anthropic moved after about 1,800x growth.
- The product changes weekly and nobody on the team knows Rust. At Google, only a third felt as productive in Rust within two months.
- Fast rebuilds matter to your workflow: 55% of respondents in Rust's 2025 compiler survey wait over 10 seconds for one.
- You can't hire or train for it. Stack Overflow 2025: 14.8% of respondents use Rust, 57.9% use Python; our inference is a smaller hiring pool.
- Python threads are fighting over the GIL: try Python 3.13's free-threaded build, or one PyO3 module, first.
How we'd migrate yours
- Profile: find the hot path and what it costs today.
- Pick the shape: one PyO3 or NAPI-RS module, or a rewrite of the whole path.
- Build on the default stack, with SQLx-checked queries.
- Shadow, compare and switch in stages, with the old service as fallback.
If your API is hitting CPU or latency limits, our custom software development team can profile it and tell you whether Rust is worth it before any code is written.
The whole series
- Part 1: Why Rust, and what Anthropic's migration shows
- Part 2: How we build and migrate a backend in Rust (this post)
