r/Backend • u/No_Tomorrow9387 • 3d ago
Anthropic is moving its Messages API from Python to Rust. Would you consider switching languages for performance?
15
Upvotes
r/Backend • u/No_Tomorrow9387 • 3d ago
20
u/Technical-Donkey-42 3d ago edited 3d ago
Did they even consider another GC language? Otherwise, we can't really draw any meaningful conclusions. It's just based on vibes, because developer social media loves a "rewrite it in Rust" story. There's no real engineering discussion here unless we actually compare how SOTA Generational ZGC stacks up against Rust on these workloads, and how observability and costs differ between the two.
EDIT: This seems to be their blog posts about this: https://www.anthropic.com/research/migrating-api-to-rust
Zero mention of any runtime comparison. In 2024, an engineer suggested Go or Rust and got shut down and then in 2026 they tried an incremental approach. Claude weakened more than 100 test assertions and took 5 months of human-gated loops to reach parity. And the wins are localised, not global.
5
u/elch78 3d ago
- Would you rewrite an existing production system just for performance?
of course.
I can recommend Kent Beck's talk "3X Explore, Expand, Extract". It was a paradigm shift for me.
https://www.youtube.com/watch?v=lOcXdXRxFgA
In a nutshell:
Explore: priority speed > quality. Objective: learn if there is a real problem to solve and if the solution fits.
Expand: if the system has proven it's value and problems arise the effort for optimization is justified. That's where considering a rewrite is valid if it seems necessary. A rewrite in another language is a big effort (not so big with AI anymore) but if it is the right thing to do, of course, why not?
Extract: the system has been optimized and runs without much maintenance. The cash cow phase.
3
u/pthierry 3d ago
Part of why I like Haskell is that it's a very high-level language but it makes it easy to produce very fast running code.
In a previous job, we were managing a pretty big Rails backend and we slowly came to the conclusion that we would need to rewrite it and we planned to do it with Elixir, because the switch would be relatively smooth and Elixir's performance is really good too.
I generally like to start from a place where good performance is easy and great performance is available if needed. That's one of the reasons I don't like Python too much.
3
u/ainovationsllc 3d ago
Worth noticing what that migration actually was before taking a lesson from it. That's a hot path proxy layer at absurd scale with extremely well defined behavior, and the part that made it survivable isn't the language or the AI, it's the shadow testing. They could run both versions against real production traffic and diff the outputs until they were confident. If you have that, a rewrite is an engineering project. If you don't, it's a gamble with your evenings.
For most backends Python is not the bottleneck. I'd say the large majority of "Python is too slow" situations are actually the database, N+1 queries, serialization, chatty service calls, no caching, or an architecture that does ten times more work than it needs to. Those all follow you to Rust, and now they're in a language where iterating on the fix is slower. The language is genuinely the ceiling when you're CPU bound in your own code, or paying per request interpreter overhead at very high QPS, or fighting GC pauses in a latency budget measured in milliseconds. Those are real and they do happen, they're just rarer than the headline suggests.
So no, I wouldn't rewrite an existing production system purely for performance, unless I'd measured it, fixed the obvious things first, and could point at a specific wall the runtime itself was hitting. And then I'd move one hot path, not the system. Carve out the thing that's actually burning CPU, put it behind the same interface, leave everything else alone. Most of the benefit, a fraction of the risk.
On AI making migrations easier, it changes the cost of typing the code. It doesn't change the cost of being wrong. The expensive part of a port is never the first draft, it's the undocumented behavior nobody remembers implementing, the edge case that only shows up for one customer, and the months of watching production to find out what you quietly broke. A week to the initial core code sounds incredible and probably is, but the verification was still the long pole, and that's the part the article is quietly telling you.
On learning Rust, do it if you want to, it'll make you better at thinking about memory and ownership regardless of whether you ship it. Just don't learn it because a company a thousand times your size did a thing. If you want a pragmatic middle for throughput with a much gentler team cost, Go is still the sensible answer for most shops.
2
u/_wassap_ 3d ago edited 3d ago
- Learning is as cheap as it can be right now. Perfect time to "re-visit" and discover new skills
- Python was never my preferred choice for backend languages, ever. I much prefer a stable full batteries framework (Node/Nest, Spring, Laravel).
- No most likely not, if im facing performance issues I would go for semi-monolith or micro service patterns (Laravel core, whatever is I/O bound will be handled async by Swoole and whatever is too big for PHP to handle gets I/O'ed to mini Go microservices). Laravel (or RoR, Symfony whatever) would only take care of the core ecosystem, the core routing, the core business framework for scalability and enforcing standards. A bit similar to how Expo/RN make use of Native modules (in swift or kotlin) through custom bridges.
In short: I would explore any other strategy of scaling horizontally and vertically before I made a decision by migrating to another language- Understanding how the language work on hardware layer is often more useful than to "rust go brr"
- Ofc , as you can see with shopify and plenty others that are ditching RN in favor of native development
2
u/Free-Good9203 3d ago
The key detail in Anthropic's story is the 1,800x traffic surge on a latency-critical API gateway where JSON parsing, SSE streaming, and interpreter/event-loop overhead actually become a real chunk of compute spend.
For 99% of backend teams, Python is rarely the real ceiling. Slow SQL queries, missing composite indexes, N+1 ORM loops, and unbuffered external API calls eat 90% of latency long before the GIL shows up.
The middle ground that works best in practice is keeping orchestration and business logic in Python (fast to review, test, and audit) and only pushing proven hot paths into Rust/PyO3 or Go once profiling shows CPU time is actually stuck in Python. The part more teams should copy from Anthropic regardless of language is the shadow-testing step before cutting live traffic over.
2
u/andreicodes 2d ago
Oh, I actually know quite a few of teams who are doing it. Rust has three key things going for it:
Most shops I know migrate from Python or Node, but I also encountered groups that migrate away from Java and even Golang (that one was truly unexpected).
To answer your other questions:
100%. Every language is good: Python, Ruby, Java, etc. Unless your infra budget is truly staggering and unless you are unhappy with the language you've chosen I wouldn't migrate. Most perf problems can be solved by picking better algorithms, optimizing queries and doing light profiling and GC tweaking. LLMs can help with all of that, too.
I would profile it first and fix what I already have. But I can also see myself picking one or two hot scenarios and reimplementing them in Rust.
As long as you have good tests. Otherwise you'll end up with a solid mixture of new AI-generated code with AI-generated bugs.
Also, while AI can write good enough code in any language I would still make sure the team knows the language and is comfortable writing code in it by hand, too. You can outsource coding, you can't outsource the expertise.
2
u/ray591 2d ago
It never was imho
3
u/YahenP 2d ago
In my whole career, I have never seen a programming language be the performance bottleneck. The bottleneck is usually in the architecture or in how it's implemented. In very rare cases, it's the hardware.
2
u/DrAmoeba 3d ago
Technically speaking, most optimized python libs already strive for this: they use underlying C dependencies.
I'm already learning Rust because of this but I will not abandon python, python is IMO still the fastest language there is for AI development. (It's the easiest anguage to review at a glance)
Already have two backends in fastapi with their highest traffic routes migrated to rust, tho we see no reason to migrate the whole system, since many domains are still evolving.
I'd say we couldn't migrate those routes without AI, the required time wouldn't fit with our daily demand. I think it's a fair future for backend engineering and honestly I'm happy to have a reason to learn a low level language again, it forces us to recognize and think about concepts which are easily left behind on the job.
1
u/Discordbothost 3d ago
I'd load-test the slow endpoint and split its time into app CPU and waits on the database or upstream services. If the p99 spike is mostly waiting for a pooled connection, I'd fix that bottleneck before trying a rewrite.
1
u/Amazing-Mirror-3076 3d ago
We are switching everything to rust, the gains are massive
1
u/dashingThroughSnow12 2d ago
Most backends could be served by a raspberry pi.
1
u/Special_Rice9539 2d ago
Yeah rust is becoming the standard across the industry right now. AI makes it very easy to program in it, which was the main barrier before.
If you’re not writing the code yourself anyways, then how fast a human can write something isn’t a huge consideration
1
u/Trender07 2d ago
isnt the inference and I/O slower than the language/runtime for the api? I guess you can say they saved some gigabytes of RAM tho
1
u/IncomeOk7237 2d ago
I'd only rewrite once profiling says the hot path is actually CPU bound in the language itself. Most Python backends I've seen spend their time waiting on the DB or upstream calls, and a rewrite doesn't fix that at all.
What usually works better is pulling the one hot piece out (parsing, serialization, some tight loop) into a Rust extension with PyO3, or a small separate service, and leaving the rest alone. For something like an API that streams tokens to a ton of open connections, memory per connection and tail latency matter a lot, so I get why they'd do it there. For a normal CRUD app it's probably not worth the months.
1
u/c-digs 2d ago
In 2026, you should not build a backend in Python for anything at scale.
If you are Anthropic the first 3 mean more instances, more CPU, more RAM, more $$$.
If you need absolute performance and aren going to read the code: everything in Rust.
Otherwise, Go, C#, or Java are all better options and have runtime types. Go and C# are lower memory footprint than Java. Then just whether you find Go or C# more readible.
1
u/theov666 2d ago
I think the more interesting shift here is not from Python to Rust, but from implementation-intensive engineering to decision- and verification-intensive engineering.
Anthropic's experience illustrates this particularly well. Despite passing 98% of its tests, the Rust implementation initially matched only around 25% of production inputs.
Even more interestingly, an agent proposed a workaround that passed behavioural verification but was rejected by an engineer because it violated the intended architecture.
This highlights an important distinction: behavioural equivalence is not architectural compliance.
I explored this exact problem in October, following GitHub's migration of the Copilot runtime to Rust:
https://mnemehq.com/insights/behavioral-equivalence-architectural-compliance-migration/
AI changes the economics of software migrations, but we still need independent verification of both system behaviour and architectural decisions.
Anthropic's experience reinforces that argument.
1
u/GodOfSunHimself 2d ago
I have always said that Python is the worst language for anything other than basic scripting.
1
u/DanKegel 2d ago edited 2d ago
Shit yeah, but maybe porting to golang as Microsoft did with the typescript compiler is an easier lift that would do.
My company uses both Go and Rust in production. At some point I imagine we'll start porting existing golang to rust for a bit more performance, but that feels far off.
As others have said, good test suites and especially shadow testing are key to successful change management, for changes from daily maintenance all the way to language ports.
1
u/beattyml1 2d ago
A super core service at a company with the scale of Anthropic that does one thing at extreme scale is almost always worth any performance gains possible. Very different performance factor than most of us ever deal with but I feel it’s the same base formula of if you can isolate a small enough set of extremely high performance code from a set of more complex business logic that changes frequently it’s often worth separating those and rewriting the high performance one from the perspective of performance in whatever language makes sense once you hit adequate sale for it to be worth the cost on some timeline and the added maintenance
1
u/Laicbeias 2d ago
You can glue things together in python. For performance intense areas you can write subsystens in rust.
But yes py can be slow. Mostly if you dont talk to the database or relay on abstractions. Most apps could get x10 - x50 if they would just write proper sql. So the bottleneck isnt any language its abstracting the db poorly
1
u/JackieChanX95 2d ago
If my backend was serving more than a (at best) few thousand concurrent users sure. Most here probably never hit those numbers
1
u/LavendarLightning 2d ago
I am considering java to go but never Rust, speed is part of the battle for me and more simplicity is worth it anywhere I can get it
0
u/0x80085_ 3d ago
0
u/EnvironmentalLet9682 2d ago
Idk i would never use python on the backend to begin with.