Until October 2026 I led engineering on a commerce platform. Its search API ran on NestJS. In October we replaced it with a Rust service: in production on 8 October, the old service deleted on 10 October. I can't name the client or publish the code, so this post keeps to what carries over to other projects: why we moved, how we made the cutover boring, and the traps that cost us time.

The language was not the reason

Before deciding, on 28 and 29 September, we measured the service we had. Container CPU sat at a p50 of about 2.4%. On 2 October we profiled search and autocomplete: 98 to 99% of their time was in PostgreSQL, and porting the request handling to Rust saves about 1 ms per request. Speed was not the argument, and I don't credit the move with it.

Search did get much faster over the same weeks. The rewrite went together with database work: we reworked the data, the queries and how the database serves reads. Together they took p95 of a full search, on a fixed set of 170 real queries, from 2.2 s (23 September) to 0.5 s (11 and 12 November). The language's own share of that is the 1 ms above; the rest came from the database side, which is where the time was going.

What the measurements did show was structural:

  • Of about 250 fix commits in four months, 57% fixed a domain rule. Most were one code path skipping a filter that another path applied. One rule existed in 2 to 30 copies.
  • The API contract was loosely pinned: the spec typed 31 of 80 responses, and the clients copied the types by hand.

None of that is specific to NestJS. Our own estimate was that changing the language alone would remove about 2% of the bug classes, the runtime and null-handling ones. The rest had to come from structure imposed during the rewrite:

  • one home per rule: rules kept as data, the decision logic in database views next to the data it reads;
  • a contract generated from the code, not written next to it;
  • one modular service, with dead routes deleted before porting, so nothing unused gets a second life.

The decision record also lists what did not count: how long the rewrite would take, and how hard Rust is. That ruled out Go's main advantages, so Go was weighed and dropped. Rust's case, in the record's words: compile-time types end to end and explicit query cancellation. And one reason is mine: Rust is closer to how I think about software, and I like where the language and its ecosystem are going. That is a preference, and I would rather say so than dress it up.

Making the cutover boring

Byte parity. The previous framework migration on this codebase took 3.5 weeks to reach production and 11 weeks to finish, and differences in behaviour turned up after merge. So this time parity was a gate: the new service ran next to the old one, and before the cutover it had to return the same bytes for the same request. Same bytes, not "equivalent JSON": no judgement calls about which difference matters. Any diff is either a bug or a decision you write down.

Contract tests on every deploy lane, plus a gate that runs the service against a test database before a release goes anywhere.

OpenAPI from the Rust types. utoipa generates an OpenAPI 3.1 document. 3.1 and not newer, because openapi-typescript, on the TypeScript side, reads 3.0 and 3.1 only.

The crates

  • axum, plus axum-extra's Query for repeated keys like ?brand=a&brand=b.
  • tokio.
  • tokio-postgres with deadpool-postgres, not sqlx. We needed to cancel a running query on the server, and to be sure a cancelled transaction start could not leave a transaction open on a pooled connection.
  • cornucopia: typed Rust generated from plain SQL files. Nullability is marked by hand.
  • moka for the in-process cache, version 0.12.16 or later (it has a fix for an LRU race).
  • OpenTelemetry: OTLP sent straight to Google Cloud's telemetry endpoint.

Seven traps

1. A timeout cancels nothing on the database. When a Rust future is dropped, the code stops waiting; Postgres keeps running the query. Worse, the pool can hand that still-busy connection to the next request. The fix: send a cancel request, throw the connection away instead of returning it to the pool, and keep statement_timeout as the backstop.

2. Cached prepared statements and catch-all filters. A query like WHERE ($2::text IS NULL OR brand = $2) is fine with a plan made for the actual parameters. Prepared and cached, it can switch to a generic plan after five runs, one plan for every combination of nulls, and that plan is bad for most of them. The fix: query_typed, which does not keep a prepared statement, or forcing custom plans.

3. Error Reporting does not read Rust panics. Google's Error Reporting groups stack traces of the languages it knows. For Rust, log the error in the ReportedErrorEvent shape with context.reportLocation, and it groups.

4. Cloud Run CPU is not always there. When CPU is allocated only during requests, background work between requests starves: cache refreshes, telemetry exporters. And startup CPU boost doubles the CPUs the process sees at start, so tokio's default worker count is wrong for the rest of the instance's life. Set worker_threads explicitly.

5. Graceful shutdown has 10 seconds. Cloud Run sends SIGTERM and waits 10 s. Draining requests and flushing telemetry must fit inside that.

6. Tests that trust the clock flake. Tests that judged the service by the CI runner's clock failed whenever the runner stalled. They now read the limits from config and assert on log lines, not on how long something took.

7. One pool per test case is slow. A golden test of 348 cases, each with its own connection pools, took 3 to 6 minutes. Sharing the pools fixed it.

One search detail that carried over

Deep pagination: page 1 is exact, results stay stable within the top 1,000, and past that the total reads "1,000+", as a lower bound. Counting every match exactly is a cost few buyers ever see the benefit of.

What I would not claim

We have no before-and-after comparison of memory, CPU, image size, cold start, instance count or cost, so I make no claim about any of them. Of the speed-up above, the language accounts for about 1 ms; the rest is the database work. A second API, for an internal tool, moved from Bun to Rust a few days later, on 14 October, in the same workspace.

If you want to see how I write Rust services in the open, mcp-commerce-evals is an axum and MCP project with its evals and limits written down. More about my work: pirotskiy.com.