Anthropic reports its Rust Messages API uses about 70% less CPU per request after a Claude-assisted rewrite verified against shadowed production traffic.
What Anthropic actually reported
Anthropic's engineering team published an account on 25 November 2026 of how it moved the Messages API from Python to Rust. The Messages API was first built in Python in 2023, and traffic grew roughly 1,800 times between early 2024 and the autumn of 2026. The company describes a full rewrite carried out largely by Claude agents, and it reports measured production results rather than benchmark claims. The most useful part of the article is not the language choice but the method used to prove that the new service behaves exactly like the old one while customers keep sending live traffic. Readers who run production services will recognise the underlying problem: a rewrite is only valuable if the new system can be shown to behave like the old one for every request customers actually send.
Why a partial rewrite was not enough
The team first moved only a parsing step into Rust, which cut API CPU usage by about 8% to 10%. The gain was limited because each token still crossed between Python and Rust three times. That boundary cost pushed the team toward a complete rewrite of the request path. Anthropic notes that by May 2026 Claude was writing more than 80% of the code the company merged. The lesson is that incremental gains can stall when two runtimes must exchange data constantly, and that a larger change can be justified when the boundary itself is the cost.
Verification was the real bottleneck
Three facts made checking the rewrite difficult. The Python API kept changing during the migration, Claude's replies are nondeterministic, and engineers could not read customer requests. The team used the production API as an oracle and shadowed traffic, running the model once and replaying its output to the Rust implementation so both could be compared on identical inputs. About 700 existing integration tests were tightly coupled to the Python implementation, and an audit of the ported tests found more than 100 weakened assertions. Exhaustive testing was also impractical: the full option space translates to 12 days of tests at a second each, for one model. Weakened assertions matter because they let broken behaviour appear to pass, so a high pass rate alone is weak evidence that a port is faithful.
Passing tests was not the same as parity
In April the Rust API passed about 98% of its tests, yet Anthropic still did not treat the rewrite as ready, because the tests were tied to the Python implementation and could not show that production behaviour matched. The team therefore compared real traffic: the Rust service had to produce the same output as the Python service on the same shadowed inputs. To keep the comparison private, diffs were recorded by step, prompt piece, first differing byte and length, without storing any text.
Loops that guided the agents
Anthropic describes three feedback loops. An inner loop ran agents in a cloud sandbox with input and output checks. An outer loop validated fixes against shadowed production traffic. A memory loop stored corrections as rules, such as porting exactly what Python does, and that rule surfaced seven more places where the port had relied on a guess. Taken together, the loops turned verification into something the agents could run themselves, while the stored rules meant a lesson learned once was applied to every later port.
The results and the lessons
According to Anthropic, the Rust API uses about 70% less CPU per request and median time to first token fell by about 20%. Public traffic moved to Rust in September 2026. The team's lessons are that verification is the new bottleneck, that a production system can act as a verifier when no tests exist, that verifier signals must point to the failing location, and that human review is still required. For engineering leaders, the transferable idea is to build the comparison oracle before delegating a large migration to agents. The article also shows the value of treating agents' mistakes as reusable knowledge, since each stored rule improved later ports instead of fixing a single bug.
No comments:
Post a Comment