<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Vladimir Pirotskiy]]></title><description><![CDATA[Notes from a lead full-stack developer: Next.js, TypeScript, Node.js and Rust, AI coding agents in production, MCP and evals, open-source pull requests. Measure]]></description><link>https://pirotskiy.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 00:49:27 GMT</lastBuildDate><atom:link href="https://pirotskiy.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[I moved a search API from NestJS to Rust. Rust saved about 1 ms.]]></title><description><![CDATA[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…]]></description><link>https://pirotskiy.hashnode.dev/i-moved-a-search-api-from-nestjs-to-rust-rust-saved-about-1-ms</link><guid isPermaLink="true">https://pirotskiy.hashnode.dev/i-moved-a-search-api-from-nestjs-to-rust-rust-saved-about-1-ms</guid><category><![CDATA[Rust]]></category><category><![CDATA[PostgreSQL]]></category><category><![CDATA[nestjs]]></category><dc:creator><![CDATA[Vladimir Pirotskiy]]></dc:creator><pubDate>Thu, 26 Nov 2026 13:37:04 GMT</pubDate><content:encoded><![CDATA[<p>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.</p>
<h2>The language was not the reason</h2>
<p>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.</p>
<p>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.</p>
<p>What the measurements did show was structural:</p>
<ul>
<li>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.</li>
<li>The API contract was loosely pinned: the spec typed 31 of 80 responses, and the clients copied the types by hand.</li>
</ul>
<p>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:</p>
<ul>
<li>one home per rule: rules kept as data, the decision logic in database views next to the data it reads;</li>
<li>a contract generated from the code, not written next to it;</li>
<li>one modular service, with dead routes deleted before porting, so nothing unused gets a second life.</li>
</ul>
<p>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.</p>
<h2>Making the cutover boring</h2>
<p><strong>Byte parity.</strong> 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.</p>
<p><strong>Contract tests on every deploy lane</strong>, plus a gate that runs the service against a test database before a release goes anywhere.</p>
<p><strong>OpenAPI from the Rust types.</strong> 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.</p>
<h2>The crates</h2>
<ul>
<li><strong>axum</strong>, plus <code>axum-extra</code>'s <code>Query</code> for repeated keys like <code>?brand=a&amp;brand=b</code>.</li>
<li><strong>tokio</strong>.</li>
<li><strong>tokio-postgres with deadpool-postgres</strong>, 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.</li>
<li><strong>cornucopia</strong>: typed Rust generated from plain SQL files. Nullability is marked by hand.</li>
<li><strong>moka</strong> for the in-process cache, version 0.12.16 or later (it has a fix for an LRU race).</li>
<li><strong>OpenTelemetry</strong>: OTLP sent straight to Google Cloud's telemetry endpoint.</li>
</ul>
<h2>Seven traps</h2>
<p><strong>1. A timeout cancels nothing on the database.</strong> 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 <code>statement_timeout</code> as the backstop.</p>
<p><strong>2. Cached prepared statements and catch-all filters.</strong> A query like <code>WHERE ($2::text IS NULL OR brand = $2)</code> 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: <code>query_typed</code>, which does not keep a prepared statement, or forcing custom plans.</p>
<p><strong>3. Error Reporting does not read Rust panics.</strong> Google's Error Reporting groups stack traces of the languages it knows. For Rust, log the error in the <code>ReportedErrorEvent</code> shape with <code>context.reportLocation</code>, and it groups.</p>
<p><strong>4. Cloud Run CPU is not always there.</strong> 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 <code>worker_threads</code> explicitly.</p>
<p><strong>5. Graceful shutdown has 10 seconds.</strong> Cloud Run sends SIGTERM and waits 10 s. Draining requests and flushing telemetry must fit inside that.</p>
<p><strong>6. Tests that trust the clock flake.</strong> 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.</p>
<p><strong>7. One pool per test case is slow.</strong> A golden test of 348 cases, each with its own connection pools, took 3 to 6 minutes. Sharing the pools fixed it.</p>
<h2>One search detail that carried over</h2>
<p>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.</p>
<h2>What I would not claim</h2>
<p>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.</p>
<p>If you want to see how I write Rust services in the open, <a href="https://github.com/Vladimir-Pirotskiy/mcp-commerce-evals">mcp-commerce-evals</a> is an axum and MCP project with its evals and limits written down. More about my work: <a href="https://pirotskiy.com/">pirotskiy.com</a>.</p>
]]></content:encoded></item><item><title><![CDATA[Parts search starts from the bike, not the part number]]></title><description><![CDATA[A buyer who needs a spare part rarely knows its number. They know their machine: a road bike, 11-speed, disc brakes, a 12x142 rear axle. So parts search…]]></description><link>https://pirotskiy.hashnode.dev/parts-search-starts-from-the-bike-not-the-part-number</link><guid isPermaLink="true">https://pirotskiy.hashnode.dev/parts-search-starts-from-the-bike-not-the-part-number</guid><category><![CDATA[search]]></category><category><![CDATA[mcp]]></category><category><![CDATA[Rust]]></category><dc:creator><![CDATA[Vladimir Pirotskiy]]></dc:creator><pubDate>Thu, 26 Nov 2026 05:48:55 GMT</pubDate><content:encoded><![CDATA[<p>A buyer who needs a spare part rarely knows its number. They know their machine: a road bike, 11-speed, disc brakes, a 12x142 rear axle. So parts search has to start there, and the hard part is not matching words but deciding what fits. I built search that starts from the machine on a commercial parts platform; that code is not mine to publish, so here is the same idea on an open-source reference store with an invented catalog, where every number below can be rerun: <a href="https://github.com/Vladimir-Pirotskiy/mcp-commerce-evals">mcp-commerce-evals</a> (Rust, MIT).</p>
<h2>Compatibility is data, with dimensions</h2>
<p>The store's catalog has 500 parts, and each one lists what it fits as tags in five dimensions: drivetrain speed, bike type, wheel size, brake type and axle standard. One rule decides whether a part fits a bike:</p>
<pre><code class="language-rust">pub fn is_compatible(fits: &amp;[String], required: &amp;[String]) -&gt; bool {
    required.iter().all(|req| match dimension_of(req) {
        Some(dim) =&gt; {
            let constrained = fits.iter().any(|t| dim.contains(&amp;t.as_str()));
            !constrained || fits.contains(req)
        }
        None =&gt; fits.contains(req),
    })
}
</code></pre>
<p>A part that lists no tag in a dimension does not care about it: a saddle fits any drivetrain. A part that lists some tags in a dimension fits only a bike with one of them: an 11-speed chain does not fit a 12-speed bike. Before the rule runs, what the buyer typed is made canonical, so <code>11 speed</code> becomes <code>11-speed</code>, <code>Disc Brakes</code> becomes <code>disc-brake</code>, <code>29er</code> becomes <code>29in</code> and <code>MTB</code> becomes <code>mountain</code>.</p>
<h2>Filter, do not only match words</h2>
<p>The tags are also indexed as text, so a sentence works on its own: "a chain that fits my 11-speed road bike" drops the filler words and searches for <code>chain</code>, <code>11speed</code> and <code>road</code>. But a long sentence mixes words about the part with words about the bike, and the bike words can win.</p>
<p>"rear hub for a 12x142 thru axle frame with an 11-speed disc brake setup", sent as text only, returns five thru axles first. "Thru axle" and "12x142" are in their titles; the first expected hub is 9th. The same need sent as <code>query: "rear hub"</code>, <code>category: "hub"</code> and <code>fits: ["12x142", "11-speed", "disc-brake"]</code> returns five hubs, all of them right.</p>
<p>The filters have their own trap. "11-speed chain, in stock, under $30" with <code>fits: ["11-speed"]</code>, stock and price filters but no category returns chain lube first. Lube lists no compatibility tags, so by the rule above it fits every bike and passes every fit filter, and the word "chain" is in its title. Add <code>category: "chain"</code> and the search returns exactly the three expected chains. Universal parts are correct for the rule and noise for the buyer: a fit filter needs a category next to it.</p>
<p>That is why the store's <code>search_products</code> tool takes free text plus <code>brand</code>, <code>category</code>, <code>fits</code>, <code>in_stock_only</code> and <code>max_price_usd</code>, and its description tells the assistant what <code>fits</code> looks like. The hub query shows what it is worth when the assistant turns "my bike" into filters instead of pasting the sentence.</p>
<h2>The eval marked a good question wrong</h2>
<p>The repo measures the store twice: tool-level, by calling the search tool directly, and assistant-level, by letting a model shop through the tools and scoring the part id it commits to. On the 8 compatibility queries the tool-level hit@1 is 0.88 (95% interval 0.53 to 0.98); the one miss is the hub query above. With an assistant on top, Claude Haiku (3 trials per query) and Claude Sonnet (1 trial) both scored 0.88 on the same kind.</p>
<p>The misses were not retrieval failures. On "disc rotor that works on my e-bike" twelve rotors fit by tag: five centerlock and seven 6-bolt, in 180 or 203 mm. Both models listed rotors and asked two questions: is the hub 6-bolt or centerlock, and which diameter. Haiku did that in all three trials and committed nothing; Sonnet committed <code>none</code>.</p>
<p>Both questions are right. A rotor has to match the hub's mount, and the frame or fork caps the diameter, as Sonnet's reply added. In this catalog the hub and the rotor both record their mount, but as plain attributes: mount is not one of the five dimensions, so no fit filter can use it. And the catalog has no frames or forks, so nothing records a maximum rotor size. The scorer rewards committing to a part, so asking back counts as a miss.</p>
<p>"skewer for my road bike" shows the other way to handle a missing fact. In one of three trials Haiku asked whether the bike is quick-release or thru-axle and committed nothing. Sonnet wrote "I'm assuming your bike has quick-release dropouts", named the 12x142 and 12x100 thru axles it would offer otherwise, and committed to a skewer. Same uncertainty, but the buyer gets an answer and a way to correct it.</p>
<p>Three things I take from it:</p>
<ul>
<li>The assistant found holes in the compatibility model before any buyer did: brake mount should be a dimension that constrains both rotors and hubs, and the maximum rotor size belongs to the frame and fork.</li>
<li>"Asked a fair question" should be its own outcome in an eval, not a failure. Otherwise the score pushes you toward an assistant that guesses.</li>
<li>When one answer is far more likely, "assume it, say so, commit" serves the buyer better than a list of questions. The tool description is the place to ask for that.</li>
</ul>
<h2>What I would not claim</h2>
<p>Eight compatibility queries is a small sample, and the interval runs from 0.53 to 0.98. I wrote the catalog and the queries myself, so this shows that compatibility can be modelled and measured, not how well any real store does. The model runs had no fixed temperature, so a rerun will differ.</p>
<p>The rule, the tags and the eval are in the repo: <a href="https://github.com/Vladimir-Pirotskiy/mcp-commerce-evals">github.com/Vladimir-Pirotskiy/mcp-commerce-evals</a>. The first post, on what the evals measured overall: <a href="https://dev.to/pirotskiy/i-measured-how-well-an-ai-assistant-shops-through-mcp-here-is-what-broke-1hp">I measured how well an AI assistant shops through MCP</a>. More of my work: <a href="https://pirotskiy.com/">pirotskiy.com</a>.</p>
]]></content:encoded></item><item><title><![CDATA[I measured how well an AI assistant shops through MCP. Here is what broke.]]></title><description><![CDATA[An assistant that shops for a buyer can fail in two ways: it finds the wrong part, or it finds the right part and then reasons badly about it. Most demos…]]></description><link>https://pirotskiy.hashnode.dev/i-measured-how-well-an-ai-assistant-shops-through-mcp-here-is-what-broke</link><guid isPermaLink="true">https://pirotskiy.hashnode.dev/i-measured-how-well-an-ai-assistant-shops-through-mcp-here-is-what-broke</guid><category><![CDATA[mcp]]></category><category><![CDATA[Rust]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Vladimir Pirotskiy]]></dc:creator><pubDate>Wed, 25 Nov 2026 18:36:52 GMT</pubDate><content:encoded><![CDATA[<p>An assistant that shops for a buyer can fail in two ways: it finds the wrong part, or it finds the right part and then reasons badly about it. Most demos show neither. So I wrote a small open-source harness that measures both, against any store that speaks MCP over HTTP: <a href="https://github.com/Vladimir-Pirotskiy/mcp-commerce-evals">mcp-commerce-evals</a> (Rust, MIT).</p>
<h2>What is in it</h2>
<ul>
<li><strong>A reference store</strong>: an MCP server with four tools (<code>search_products</code>, <code>get_product</code>, <code>check_availability</code>, <code>create_cart</code>) over a generated catalog of 500 bicycle parts from 14 fictional brands. Everything is invented, so you can run it in a minute without an account or a key.</li>
<li><strong>44 buyer queries of eight kinds</strong>: exact part number, plain description, compatibility, typo, synonym, filter, adversarial, and <code>no_match</code> for things the catalog does not sell. The expected ids come from catalog attributes, never from running the search.</li>
<li><strong>Two levels of evals.</strong> Tool-level calls the search tool directly and reports hit@1, hit@5, MRR, recall@10 and nDCG@10 with 95% intervals. Assistant-level lets a model shop through the tools and scores the part id it commits to.</li>
</ul>
<pre><code class="language-sh">cargo run --release -p reference-store
cargo run --release -p mcp-commerce-evals -- --url http://127.0.0.1:8787/mcp
</code></pre>
<h2>What the numbers said</h2>
<p>Tool-level, 40 ranked queries: hit@1 0.90, hit@5 0.93, MRR 0.91. With an assistant on top (Claude Haiku, 3 trials per query, 132 runs): pass@1 0.94.</p>
<p>The misses are the useful part:</p>
<ul>
<li><code>STO-HT-1O64</code> ranked 9th: the letter O is not read as a zero inside a part number. A buyer typing from a worn label does this all the time.</li>
<li>"11-speed chain, in stock, under $30" found chain lube first. Without a category filter, lubes outrank chains.</li>
<li>A hub query ranked 9th because axle parts outrank hubs.</li>
</ul>
<p>None of these show up in a demo where someone asks for "a chain".</p>
<h2>What I would not claim</h2>
<p>40 queries is small: one query moves a rate by 2.5 points, and for a kind of six queries the interval runs from 0.44 to 0.97. I wrote the catalog and the queries myself, so this shows that the harness measures, not that one search engine beats another. Latency is a loopback round trip to an in-memory index, not a production figure.</p>
<h2>Why it matters</h2>
<p>If you put an MCP endpoint on a real store, the assistant becomes one more buyer, and it needs the same thing a search page needs: a test set and a gate in CI. The CLI turns a score into an exit code (<code>--min-hit5</code>, <code>--min-mrr</code>, <code>--min-accuracy</code>), so a ranking regression fails the build like any other test.</p>
<p>The repo, the full tables and the caveats: <a href="https://github.com/Vladimir-Pirotskiy/mcp-commerce-evals">github.com/Vladimir-Pirotskiy/mcp-commerce-evals</a>. More of my work: <a href="https://pirotskiy.com/">pirotskiy.com</a>.</p>
]]></content:encoded></item></channel></rss>