A replacement service can pass every test in a repository and still differ from the old system on real user requests. That gap is especially difficult to measure when replies are nondeterministic, production traffic must not be billed twice, and engineers cannot inspect the underlying customer content. In a November 25, 2026 engineering post, Anthropic described how it migrated its Messages API from Python to Rust while continuing feature work: run the model once, replay its output through the new implementation, compare behavior in production shadow traffic, and route differences through several verification loops. Anthropic reports about 70% less CPU per request and roughly 20% lower median time to first token. Its chart caption says the CPU figure covers one region and the time-to-first-token figure covers customers’ Claude Code requests over a shorter period; the chart also plots memory per request across all of production, but the text gives no memory percentage. These are company-reported outcomes from a specific service, not a general guarantee that Rust or AI-assisted rewrites will produce the same gains. Anthropic Engineering
Terms used here
- Shadow traffic: a copy of real production requests sent to the new system in parallel. Users still get the old system’s answer; the new one is only observed.
- Nondeterministic: the same input can give a different output each time. Model replies behave this way.
- Inference: running the model to generate a reply. Running it twice for one request costs twice the compute and gives two different replies.
- Time to first token: how long a client waits before the first piece of a streamed reply arrives.
- Fingerprint: a small, content-free description of a difference: where it happened and how big it was, not what the text said.
Why ordinary tests were not enough
The Messages API validates requests, builds prompts, applies safety classifiers, calls a model, streams output, and records usage. Its behavior also changed while the migration was underway. Anthropic identifies three specific obstacles: the Python implementation kept evolving, model replies could differ for the same request, and the team could not read customer requests or replies to diagnose mismatches. A conventional shadow test that calls both complete systems could also run inference twice, producing different answers and possibly duplicate usage or billing.
The team therefore separated deterministic API behavior from model generation. It ran the model only once, then replayed the same model output through the old and new API paths. It compared request handling and response processing around the model call, so differences were not confused with the model’s natural variation. To protect privacy, the system recorded the shape and location of differences rather than customer text. The public post describes fingerprints and metadata such as feature/model categories, not a process in which agents read live customer prompts. Anthropic’s migration account
The post shows what one record looked like, with made-up values: the step in the code (build prompt), which piece of the prompt (2), the first differing byte (17), and the length of each version (Python 190 bytes, Rust 190 bytes). Checkpoints located the difference in the code, and the fingerprint told one bug from another, because one bug tends to leave the same fingerprint on every request it affects. Agents also saw metadata about each request, but not its text, such as which model and features it used (prompt caching, tools or extended thinking).
This technique works only when the team can define what must match and can safely replay or record an equivalent input. It is not a universal substitute for tests: the request and response boundaries, privacy requirements, side effects, and nondeterministic components all determine what can be compared.
Turn mismatches into a repeatable signal
Comparing production systems can create a flood of near-identical records. Anthropic says a script grouped differences by fields and alerted a coordinating agent only when it found a new type. That reduced duplicate work and gave each distinct mismatch a stable unit of investigation.
The team then used nested loops:
- Fast local checks: An agent received a fingerprint, hypothesized a cause, and wrote a synthetic request or model reply to reproduce it against both codebases. These checks did not need to call the real model and reportedly took under a second.
- Human review before deployment: The agent proposed a fix and test, but an engineer reviewed the change. Anthropic gives an example where an agent made outputs match by copying a tool description into files; an engineer rejected the shortcut because the production Rust service still needed to load that description from the correct internal service.
- Slower production verification: After review and deployment to a test environment, shadow traffic checked whether the mismatch had disappeared in real requests. If it remained, the investigation returned to the local loop.
- Memory and regression checks: Review corrections became rules for later agents, additional tests or lints, and checks to catch future drift between the Python and Rust implementations.
The key design choice is that a verifier can report whether two outputs match, but cannot by itself decide whether a patch is maintainable, secure, or faithful to intended product behavior. The human review boundary supplied that judgment. Anthropic Engineering: verification loops
Adapting the pattern to a smaller migration
You do not need an AI agent or high-volume service to use the core idea. For a payment adapter, serializer, or protocol implementation, write down the behavior that must remain stable and construct representative inputs from tests or sanitized fixtures. Run both implementations on the same input, compare structured results, and record the first meaningful divergence rather than a huge raw diff. If part of the result is nondeterministic, isolate that part or inject the same generated value into both runs. If requests have side effects, use a fake dependency or read-only shadow environment rather than executing the operation twice against customers.
Here is a small version of the fingerprint idea in Python. It compares the bytes two implementations produced for the same input and keeps only the step name, the first differing position and the two lengths, never the payload itself:
def first_diff(a: bytes, b: bytes) -> int | None:
for i, (x, y) in enumerate(zip(a, b)):
if x != y:
return i
return None if len(a) == len(b) else min(len(a), len(b))
def fingerprint(step: str, old: bytes, new: bytes) -> dict | None:
pos = first_diff(old, new)
if pos is None:
return None # outputs match
return {"step": step, "first_diff": pos,
"old_len": len(old), "new_len": len(new)}
old = b'{"amount":"10.50","currency":"EUR"}'
new = b'{"amount":"10.5","currency":"EUR"}'
print(fingerprint("serialize", old, new))
print(fingerprint("serialize", old, old))
Run with Python 3.13.5, it prints:
{'step': 'serialize', 'first_diff': 15, 'old_len': 35, 'new_len': 34}
None
The new serializer drops a trailing zero. The record says where (byte 15 of the serialize step) and that the output got one byte shorter, which is enough to group every request hit by the same bug. Count records by (step, first_diff, old_len - new_len) and you have a list of distinct mismatches instead of thousands of raw diffs. A real system would compare at several checkpoints, as Anthropic did, so a difference is traced to the step that produced it.
Then make the rollout gradual. A local reproduction is a fast diagnosis tool, not proof of production parity. Gate deployment on code review, tests, and a controlled environment; monitor a small live sample or shadow stream; define what rollback signal looks like; and retain the old path until the new one has passed the required checks. Keep logs minimal and avoid recording secrets or user content when a fingerprint, field path, status code, or aggregate count can answer the diagnostic question.
If agents help with the fixes, give them an isolated place to work. Running a coding agent in its own Git worktree and sandbox keeps experiments away from the main checkout, which fits the fast local loop described above. And a match between two outputs is not the same as a correct output; validating LLM output beyond the JSON schema covers the business checks a format check misses.
Finally, set a measurable acceptance rule. Examples include an error-rate ceiling, no unexplained mismatch for critical fields, latency measured at a stated percentile, and an explicit sample window. A high match percentage can hide a severe rare mismatch, so segment results by operation and feature and inspect outliers. Anthropic itself reports that its match rate changed over the migration and that its measured performance results covered different scopes and periods. Treat such metrics as evidence to evaluate, not as a single universal score.
Conclusion
The useful lesson from Anthropic’s rewrite is to make correctness observable before moving traffic. Reuse one nondeterministic result where possible, compare old and new behavior at clear boundaries, turn repeated differences into regression checks, and keep human review between an automated match signal and production deployment. The measurements may motivate a rewrite, but production evidence and explicit acceptance criteria are what make the migration trustworthy.