r/Backend • • 3d ago

Anthropic is moving its Messages API from Python to Rust. Would you consider switching languages for performance?

15 Upvotes

39 comments sorted by

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.

12

u/wrd83 3d ago

I believe it is a pretty known thing that python is way slower than go/java/javascript.

But getting more than 200krps out of those becomes tricky.

If you are willing I believe getting 600krps+ out of rust or c++ is possible.

Then comes the fact that the majority of services are not CPU bound but IO bound through the database.

If you factor in employee cost, you need quite some scale between java und rust to offset this through server cost.

Now with AI this perhaps has become cheaper, because code migration may be a 1 time cost rather than an employment contract.

But the runtime cost of slow languages is known. And for USA if you hire a quite senior engineer it can easily be 500k to 1m.

6

u/Technical-Donkey-42 2d ago

Which is why my point still holds. Skipping a baseline benchmark against a modern GC runtime makes it impossible to know how much of that CPU win actually required Rust versus just leaving Python and doing a clean rewrite. I do not want to believe whether something is possible or not, based on assumptions people have of some runtimes, without first assessing all the options.

2

u/theelderbeever 2d ago

As someone who writes rust APIs for their job while other parts of the company write go APIs, the CPU difference between the two on these workloads is low. The major difference I generally see is persistent resident memory use which as long as you switch out rust's default allocator is always significantly lower than go. Aside from that it's mostly about language preference. That said I would choose rust over go 11/10 times because I just genuinely don't like the language. The Anthropic blog isn't anything special and has nothing to do with rust other than the bun runtime also happens to be written in rust at this point.

1

u/Lilacsoftlips 2d ago

They can test all the different jvm configs they want, and will probably get pretty close on cpu, if not matching it. But it will use more ram and it will take longer to build, and it will take engineering time and effort to optimize the cold starts. 

We have an older Java fleet, and something like 20% of our thousands of apps are on Java 11 or lower. I’ve been looking at what to do about this problem and building generic tools for migrations. If their apps were already jvm I would stick with it because jvm to modern spring actually ports with minimal logic changes. But once you have an oracle for the app behavior, and standard ways to manage config and initialization per language, the effort is surprisingly similar to just go to rust or go. I am not recommending that internally but I am not nearly as opinionated about it as I was before starting this. 

1

u/Technical-Donkey-42 2d ago

Rust is notorious for some of the slowest compile times in the industry. What is the actual issue with using more RAM? Not taking advantage of RAM in a server instance just means paying for idle hardware. Java intentionally trades abundant RAM to save scarce CPU cycles and maximize throughput.

2

u/immaculate_plum 2d ago

Also, how slow Python is really depends on what you're doing. If your application is already spending 90% of the time waiting for IO, which many backends do, there's just not that much room for improvement, and most applications don't have enough traffic for this to really matter.

Closing that gap is also sometimes is easily done by switching the Python implementation, e.g. to PyPy with its jit.

1

u/foresterLV 2d ago

manual memory management runtime will always outperform GC though, there is nothing vibe about that - just pure fact of life. the only reason why we ever ended with GC is that it allows humans writing code to make less mistakes and deliver faster. with agents this is not a problem anymore and especially on rust where compiler validates memory usage. 

3

u/Technical-Donkey-42 2d ago

In manual memory management (including Rust), every allocation requires a corresponding deallocation. A moving GC doesn't free individual objects at all, but it turns allocations into cheap pointer bumps and trades extra RAM to nearly eliminate the CPU cost of high allocation rates. You cannot just bolt this onto Rust without adding a thick runtime on top of it. On smaller or less concurrent programs, Rust can be much faster. On larger, highly concurrent, long-running, allocation-heavy server backends, Rust can easily be slower than a GC runtime like the JVM or CLR. And the debt one will be paying with Rust for async is significant. Not even talking about compile times.

Even if an agent writes memory safe Rust, it is still stuck with an AOT compiler that lacks the runtime a JIT uses to aggressively inline and optimize code. A runtime that can be tremendously helpful in giving you top notch observability as well. Profile real-world workloads under load instead of picking a language based on low-level dogma, automatically assuming that manual memory management will always outperform GC in every scenario without measuring. You might find surprising results.

2

u/foresterLV 2d ago edited 2d ago

arenas and pooling are very simple concepts that do not require complicated runtimes and are used both in manual memory models and inside GCs. in theory your reasoning is right - GC could figure out a lot in auto mode, in practice if you look at what java ir c# framework developers do to speed things up - they do zero allocation practices, shared pools, and arenas. essentially skipping GC as much as possible on framework level because there is no such thing as free GC allocation - it always have costs.

as of JIT it's again cool theory, in practice it simply don't work as nice and the reason being is that JIT have no compute power/time to make as much optimizations as AOT can do, especially in classic c++/rust complations which are brutal blasting on 16+ desktop cores in parallel to build whole program optimization analysis where compute (and RAM) costs are almost have no bounds. JIT needs to start working immediately on one or two cores and limited ram, essentially only being able to do incremental optimizations. plus whole program optimization - JIT have no way to transform all byte code into gigantic single program and figure out ahead of time who calls what and what can be completely eliminated or inlined. 

with agentic coding the slow cows like java or c# IMO are completely irrelevant. go survives because of fast AOT compilation, C# survives because it also has  AOT mode, rust is no compromises raw control and power. leaving GC for lazy human programmers hehe.

1

u/Technical-Donkey-42 2d ago

You misunderstand what JITs actually do best, it is a good opportunity to read more on this topic. Anyone who has used arenas knows you have to tie memory layout directly to execution lifetimes, and that's hard to build in practice. Every struct holding a reference into an arena gets infected with a lifetime parameter that bubbles up through enclosing structs, traits, and async Future boundaries, making it much harder to store or share data across threads. Java and C# operate at a completely different scale than smaller Rust programs, and they don't need two separate languages for business logic and low-level optimizations when both already have MemorySegments, Span<T>, and SIMD intrinsics these days.

1

u/foresterLV 2d ago

yes arenas are quite niche. though zero allocation seems to be pretty much name of the game in modern c# framework runtime and they achieve it with next thing that works on GC - pools. 

for backend scale - if architecture is split into microservices with clear interface boundaries choosing language/platform in my experience with agentic coding pretty much nails down to simple things - size of image, startup time, memory usage and compute density (how much cpus are needed to do X amount of requests per second). and vm-based frameworks with JIT pretty much loose on every step with maybe being able to win on density if it's unoptimized code where GC wins . they cannot beat carefully optimized low level aot languages without GC though, the question is if you have time to optimize or not. 

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

Would you rewrite an existing production system just for performance?

Oh, I actually know quite a few of teams who are doing it. Rust has three key things going for it:

  • The language is strict and the compiler and other tools around it help surface bugs early and prevent regressions. Management loves it for that. LLMs love it, too.
  • No GC means no overhead for memory, so infra costs can be reduced.
  • Code is compiled ahead of time and doesn't have JIT. So, running programs tend to be fast enough, and teams do not have to learn how to profile and optimize Rust from the very beginning. This helps with migration and gives teams warm feeling of assurance.

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:

Is Python still good enough for large-scale backend systems?

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.

Would you rewrite an existing production system just for performance?

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.

Will AI-assisted coding make language migrations much easier?

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.

1

u/--San-- 2d ago

JIT can be faster than AOT compilation, that's why profile guided optimization exists.

2

u/ray591 2d ago
  • Is Python still good enough for large-scale backend systems?

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.

  • High CPU usage 
  • High memory usage
  • Low throughout relative to Rust, Go, Java, C#, TS on Bun
  • Duck typed at runtime 

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
  • Yes
  • No
  • Yes
  • Yes
  • Yes

0

u/EnvironmentalLet9682 2d ago

Idk i would never use python on the backend to begin with.