<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<title>Posts</title>
	<subtitle>Blog posts by Kaushal Rijal about software engineering, full-stack development, and AI systems.</subtitle>
	<link rel="self" type="application/atom+xml" href="https://blog.kaushalrijal.com.np/posts/feed.xml"/>
  <link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/"/>
  
	<updated>2026-10-31T00:00:00+00:00</updated>
	
	<id>https://blog.kaushalrijal.com.np/posts/feed.xml</id>
	<entry xml:lang="en">
		<title>Serene post template</title>
		<published>2026-10-31T00:00:00+00:00</published>
		<updated>2026-10-31T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/serene-post-template/"/>
		<id>https://blog.kaushalrijal.com.np/posts/serene-post-template/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/serene-post-template/">&lt;p&gt;This is a living template for future posts. Copy this file, remove the
sections you do not need, and replace the example text with your own.&lt;/p&gt;
&lt;h2 id=&quot;headings-and-inline-formatting&quot;&gt;Headings and inline formatting&lt;a class=&quot;zola-anchor&quot; href=&quot;#headings-and-inline-formatting&quot; aria-label=&quot;Anchor link for: headings-and-inline-formatting&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Use headings to organize a long post. Text can be &lt;strong&gt;bold&lt;/strong&gt;, &lt;em&gt;italic&lt;/em&gt;,
&lt;del&gt;struck through&lt;/del&gt;, or &lt;code&gt;inline code&lt;/code&gt;. You can add &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https://example.com&quot;&gt;links&lt;/a&gt;,
automatic URLs such as &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https://www.getzola.org&quot;&gt;https://www.getzola.org&lt;/a&gt;, and images.&lt;/p&gt;
&lt;h2 id=&quot;lists&quot;&gt;Lists&lt;a class=&quot;zola-anchor&quot; href=&quot;#lists&quot; aria-label=&quot;Anchor link for: lists&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Unordered list:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A short item&lt;/li&gt;
&lt;li&gt;An item with &lt;strong&gt;emphasis&lt;/strong&gt;
&lt;ul&gt;
&lt;li&gt;A nested item&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ordered list:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Research the problem&lt;/li&gt;
&lt;li&gt;Implement the solution&lt;/li&gt;
&lt;li&gt;Measure the result&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Task list:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot; checked=&quot;&quot;/&gt;
Write the first draft&lt;/li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;/&gt;
Review the draft&lt;/li&gt;
&lt;li&gt;&lt;input disabled=&quot;&quot; type=&quot;checkbox&quot;/&gt;
Publish the post&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;blockquotes-and-alerts&quot;&gt;Blockquotes and alerts&lt;a class=&quot;zola-anchor&quot; href=&quot;#blockquotes-and-alerts&quot; aria-label=&quot;Anchor link for: blockquotes-and-alerts&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;blockquote&gt;
&lt;p&gt;A normal blockquote is useful for quoting a person, a paper, or a useful
idea.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;Use a note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;Use a tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;markdown-alert-important&quot;&gt;
&lt;p&gt;Use important for a requirement the reader should not miss.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;markdown-alert-warning&quot;&gt;
&lt;p&gt;Use warning for a risky operation or a likely mistake.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote class=&quot;markdown-alert-caution&quot;&gt;
&lt;p&gt;Use caution for a destructive or irreversible operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;tables&quot;&gt;Tables&lt;a class=&quot;zola-anchor&quot; href=&quot;#tables&quot; aria-label=&quot;Anchor link for: tables&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Feature&lt;/th&gt;&lt;th&gt;Use it for&lt;/th&gt;&lt;th&gt;Enabled here&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Markdown&lt;/td&gt;&lt;td&gt;Most writing&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;KaTeX&lt;/td&gt;&lt;td&gt;Equations&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Mermaid&lt;/td&gt;&lt;td&gt;Diagrams&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Components&lt;/td&gt;&lt;td&gt;Richer blocks&lt;/td&gt;&lt;td&gt;Yes&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;code-blocks&quot;&gt;Code blocks&lt;a class=&quot;zola-anchor&quot; href=&quot;#code-blocks&quot; aria-label=&quot;Anchor link for: code-blocks&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Inline code is useful for short names. Fenced code blocks support syntax
highlighting:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;from&lt;/span&gt;&lt;span&gt; pathlib&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; import&lt;/span&gt;&lt;span&gt; Path&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; word_count&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; int&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    return&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; len&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;Path&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;read_text&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Code annotations are also supported:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; main&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span&gt; message&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;Hello, Serene&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; //&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; [!code highlight]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    println!&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span aria-hidden=&quot;true&quot; class=&quot;giallo-ln&quot;&gt;4&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;When documenting Tera syntax, wrap the example in &lt;code&gt;raw&lt;/code&gt; so Zola does not
evaluate it:&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;plain&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;{{ &amp;lt;figure src=&amp;quot;/img/example.png&amp;quot; alt=&amp;quot;Example&amp;quot; /&amp;gt; }}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;images&quot;&gt;Images&lt;a class=&quot;zola-anchor&quot; href=&quot;#images&quot; aria-label=&quot;Anchor link for: images&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The &lt;code&gt;figure&lt;/code&gt; component adds dimensions, alt text, and a caption:&lt;/p&gt;
&lt;figure&gt;
&lt;img src=&quot;/posts/serene-post-template.svg&quot; alt=&quot;A small blue and green landscape illustration&quot; height=&quot;360&quot; width=&quot;640&quot;&gt;&lt;figcaption&gt;&lt;p&gt;A local image can be colocated with the post. &lt;strong&gt;Captions support Markdown.&lt;/strong&gt;&lt;/p&gt;&lt;/figcaption&gt;&lt;/figure&gt;
&lt;p&gt;You can also use regular Markdown images:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/posts/serene-post-template.svg&quot; alt=&quot;A local Serene template illustration&quot; /&gt;&lt;/p&gt;
&lt;h2 id=&quot;mathematics&quot;&gt;Mathematics&lt;a class=&quot;zola-anchor&quot; href=&quot;#mathematics&quot; aria-label=&quot;Anchor link for: mathematics&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Set &lt;code&gt;math = true&lt;/code&gt; in the front matter to enable KaTeX. Inline math looks like
$E = mc^2$. Display math uses double dollar signs:&lt;/p&gt;
&lt;p&gt;$$
\int_0^1 x^2,dx = \frac{1}{3}
$$&lt;/p&gt;
&lt;h2 id=&quot;mermaid-diagrams&quot;&gt;Mermaid diagrams&lt;a class=&quot;zola-anchor&quot; href=&quot;#mermaid-diagrams&quot; aria-label=&quot;Anchor link for: mermaid-diagrams&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Set &lt;code&gt;mermaid = true&lt;/code&gt; to render diagrams:&lt;/p&gt;
&lt;pre class=&quot;mermaid&quot;&gt;

flowchart LR
    A[Draft] --&gt; B{Review}
    B --&gt;|Revise| A
    B --&gt;|Approve| C[Publish]

&lt;/pre&gt;
&lt;h2 id=&quot;serene-components&quot;&gt;Serene components&lt;a class=&quot;zola-anchor&quot; href=&quot;#serene-components&quot; aria-label=&quot;Anchor link for: serene-components&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Use a styled quote when a citation should stand out:&lt;/p&gt;
&lt;blockquote class=&quot;quote&quot;&gt;
&lt;div class=&quot;icon&quot; style=&quot;display: none;&quot;&gt;&lt;svg fill=&quot;currentColor&quot; xmlns=&quot;http://www.w3.org/2000/svg&quot;  width=&quot;10&quot; height=&quot;10&quot; viewBox=&quot;796 698 200 200&quot;&gt;
&lt;g&gt;
	&lt;path d=&quot;M885.208,749.739v-40.948C836.019,708.791,796,748.81,796,798v89.209h89.208V798h-48.26
		C836.948,771.39,858.598,749.739,885.208,749.739z&quot;/&gt;
	&lt;path d=&quot;M996,749.739v-40.948c-49.19,0-89.209,40.019-89.209,89.209v89.209H996V798h-48.26
		C947.74,771.39,969.39,749.739,996,749.739z&quot;/&gt;
&lt;/g&gt;
&lt;/svg&gt;&lt;/div&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;p&gt;Make every section earn its place.&lt;/p&gt;
&lt;/div&gt;&lt;div class=&quot;from&quot;&gt;
&lt;p&gt;— A useful writing rule&lt;/p&gt;
&lt;/div&gt;&lt;/blockquote&gt;
&lt;p&gt;Use a detail block for optional context:&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;&lt;span&gt;Show the implementation notes&lt;/span&gt;&lt;/summary&gt;
&lt;p&gt;This content is hidden until the reader opens it. It is useful for caveats,
long explanations, or implementation details that would interrupt the main
flow.&lt;/p&gt;
&lt;/details&gt;
&lt;p&gt;You can embed a YouTube video with a video ID:&lt;/p&gt;
&lt;div class=&quot;youtube&quot;&gt;
&lt;iframe src=&quot;https://www.youtube.com/embed/dQw4w9WgXcQ&quot; webkitallowfullscreen mozallowfullscreen allowfullscreen&gt;&lt;/iframe&gt;
&lt;/div&gt;
&lt;h2 id=&quot;footnotes&quot;&gt;Footnotes&lt;a class=&quot;zola-anchor&quot; href=&quot;#footnotes&quot; aria-label=&quot;Anchor link for: footnotes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Footnotes keep supporting details out of the main sentence.&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#1&quot;&gt;1&lt;/a&gt;&lt;/sup&gt; You can also
reuse a named footnote.&lt;sup class=&quot;footnote-reference&quot;&gt;&lt;a href=&quot;#note&quot;&gt;2&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;1&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;1&lt;/sup&gt;
&lt;p&gt;This is a regular footnote.&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&quot;footnote-definition&quot; id=&quot;note&quot;&gt;&lt;sup class=&quot;footnote-definition-label&quot;&gt;2&lt;/sup&gt;
&lt;p&gt;Footnotes can contain links, such as &lt;a rel=&quot;nofollow noreferrer external&quot; href=&quot;https://www.getzola.org/documentation/&quot;&gt;Zola&#39;s documentation&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&quot;a-final-checklist&quot;&gt;A final checklist&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-final-checklist&quot; aria-label=&quot;Anchor link for: a-final-checklist&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Before publishing a real post:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Replace the title, description, date, and tags.&lt;/li&gt;
&lt;li&gt;Keep only the front matter flags you actually need.&lt;/li&gt;
&lt;li&gt;Give every image useful alt text and explicit dimensions when using
&lt;code&gt;figure&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Test math, diagrams, embeds, and links with &lt;code&gt;zola serve&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Remove this tutorial post when it is no longer useful.&lt;/li&gt;
&lt;/ol&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Small now, sharp later: API versioning without regrets</title>
		<published>2026-10-27T00:00:00+00:00</published>
		<updated>2026-10-27T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/small-now-sharp-later-api-versioning-without-regrets/"/>
		<id>https://blog.kaushalrijal.com.np/posts/small-now-sharp-later-api-versioning-without-regrets/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/small-now-sharp-later-api-versioning-without-regrets/">&lt;p&gt;Additive changes, date-based versions, and deprecations users can plan around.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-fix&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix&quot; aria-label=&quot;Anchor link for: the-fix&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-i-d-do-differently&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;where-i-started-1&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started-1&quot; aria-label=&quot;Anchor link for: where-i-started-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-went-wrong-1&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong-1&quot; aria-label=&quot;Anchor link for: what-went-wrong-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; INDEX&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; CONCURRENTLY&lt;/span&gt;&lt;span&gt; idx_orders_created_at&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    ON&lt;/span&gt;&lt;span&gt; orders (created_at &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;DESC&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    WHERE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; status&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-fix-1&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix-1&quot; aria-label=&quot;Anchor link for: the-fix-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-i-d-do-differently-1&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently-1&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: additive changes, date-based versions, and deprecations users can plan around compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Killing my dev laptop fan: a Docker desktop postmortem</title>
		<published>2026-10-06T00:00:00+00:00</published>
		<updated>2026-10-06T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/killing-my-dev-laptop-fan-a-docker-desktop-postmortem/"/>
		<id>https://blog.kaushalrijal.com.np/posts/killing-my-dev-laptop-fan-a-docker-desktop-postmortem/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/killing-my-dev-laptop-fan-a-docker-desktop-postmortem/">&lt;p&gt;Filesystem mounts, VM memory, and the settings that finally cooled the machine.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h2 id=&quot;the-story-so-far&quot;&gt;The story so far&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-story-so-far&quot; aria-label=&quot;Anchor link for: the-story-so-far&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-measurement&quot;&gt;The measurement&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-measurement&quot; aria-label=&quot;Anchor link for: the-measurement&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-change&quot;&gt;The change&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-change&quot; aria-label=&quot;Anchor link for: the-change&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;numbers&quot;&gt;Numbers&lt;a class=&quot;zola-anchor&quot; href=&quot;#numbers&quot; aria-label=&quot;Anchor link for: numbers&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>A very long title to test how the post list wraps entries when someone writes something extremely wordy and unhelpful</title>
		<published>2026-09-16T00:00:00+00:00</published>
		<updated>2026-09-16T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/a-very-long-title-to-test-how-the-post-list-wraps-entries-when-someone/"/>
		<id>https://blog.kaushalrijal.com.np/posts/a-very-long-title-to-test-how-the-post-list-wraps-entries-when-someone/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/a-very-long-title-to-test-how-the-post-list-wraps-entries-when-someone/">&lt;p&gt;An intentionally long headline to check list wrapping and heading balance.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background&quot; aria-label=&quot;Anchor link for: background&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;how-it-works&quot;&gt;How it works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-it-works&quot; aria-label=&quot;Anchor link for: how-it-works&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: an intentionally long headline to check list wrapping and heading balance is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Concurrency models compared: goroutines, threads, and promises</title>
		<published>2026-08-26T00:00:00+00:00</published>
		<updated>2026-08-26T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/concurrency-models-compared-goroutines-threads-and-promises/"/>
		<id>https://blog.kaushalrijal.com.np/posts/concurrency-models-compared-goroutines-threads-and-promises/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/concurrency-models-compared-goroutines-threads-and-promises/">&lt;p&gt;Three ways to do two things at once, and the cost of each.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;a-short-history&quot;&gt;A short history&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-short-history&quot; aria-label=&quot;Anchor link for: a-short-history&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;the-design&quot;&gt;The design&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-design&quot; aria-label=&quot;Anchor link for: the-design&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;implementation-notes&quot;&gt;Implementation notes&lt;a class=&quot;zola-anchor&quot; href=&quot;#implementation-notes&quot; aria-label=&quot;Anchor link for: implementation-notes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;failure-modes&quot;&gt;Failure modes&lt;a class=&quot;zola-anchor&quot; href=&quot;#failure-modes&quot; aria-label=&quot;Anchor link for: failure-modes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;when-not-to-use-this&quot;&gt;When not to use this&lt;a class=&quot;zola-anchor&quot; href=&quot;#when-not-to-use-this&quot; aria-label=&quot;Anchor link for: when-not-to-use-this&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-caution&quot;&gt;
&lt;p&gt;A destructive or irreversible operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;a class=&quot;zola-anchor&quot; href=&quot;#further-reading&quot; aria-label=&quot;Anchor link for: further-reading&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; INDEX&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; CONCURRENTLY&lt;/span&gt;&lt;span&gt; idx_orders_created_at&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    ON&lt;/span&gt;&lt;span&gt; orders (created_at &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;DESC&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    WHERE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; status&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;a-short-history-1&quot;&gt;A short history&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-short-history-1&quot; aria-label=&quot;Anchor link for: a-short-history-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;the-design-1&quot;&gt;The design&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-design-1&quot; aria-label=&quot;Anchor link for: the-design-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: three ways to do two things at once, and the cost of each compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Backups are a feature: pg_dump and cron done properly</title>
		<published>2026-08-05T00:00:00+00:00</published>
		<updated>2026-08-05T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/backups-are-a-feature-pg-dump-and-cron-done-properly/"/>
		<id>https://blog.kaushalrijal.com.np/posts/backups-are-a-feature-pg-dump-and-cron-done-properly/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/backups-are-a-feature-pg-dump-and-cron-done-properly/">&lt;p&gt;Retention, verification, and the restore drill you should run this month.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; load_config&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; dict&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    with&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; encoding&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        return&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                (&lt;/span&gt;&lt;span&gt;line&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;a-better-model&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model&quot; aria-label=&quot;Anchor link for: a-better-model&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Making peace with plain old HTML forms</title>
		<published>2026-07-16T00:00:00+00:00</published>
		<updated>2026-07-16T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/making-peace-with-plain-old-html-forms/"/>
		<id>https://blog.kaushalrijal.com.np/posts/making-peace-with-plain-old-html-forms/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/making-peace-with-plain-old-html-forms/">&lt;p&gt;Progressive enhancement, no client state, and forms that work before JS loads.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: progressive enhancement, no client state, and forms that work before js loads is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Agent tool design: less is more</title>
		<published>2026-06-25T00:00:00+00:00</published>
		<updated>2026-06-25T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/agent-tool-design-less-is-more/"/>
		<id>https://blog.kaushalrijal.com.np/posts/agent-tool-design-less-is-more/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/agent-tool-design-less-is-more/">&lt;p&gt;Fewer, sharper tools beat a giant toolbox the model has to browse.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;a-short-history&quot;&gt;A short history&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-short-history&quot; aria-label=&quot;Anchor link for: a-short-history&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; load_config&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; dict&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    with&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; encoding&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        return&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                (&lt;/span&gt;&lt;span&gt;line&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-design&quot;&gt;The design&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-design&quot; aria-label=&quot;Anchor link for: the-design&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-important&quot;&gt;
&lt;p&gt;Something the reader should not miss.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;implementation-notes&quot;&gt;Implementation notes&lt;a class=&quot;zola-anchor&quot; href=&quot;#implementation-notes&quot; aria-label=&quot;Anchor link for: implementation-notes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;failure-modes&quot;&gt;Failure modes&lt;a class=&quot;zola-anchor&quot; href=&quot;#failure-modes&quot; aria-label=&quot;Anchor link for: failure-modes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>What my first production incident taught me about logging</title>
		<published>2026-06-04T00:00:00+00:00</published>
		<updated>2026-06-04T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/what-my-first-production-incident-taught-me-about-logging/"/>
		<id>https://blog.kaushalrijal.com.np/posts/what-my-first-production-incident-taught-me-about-logging/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/what-my-first-production-incident-taught-me-about-logging/">&lt;p&gt;The log line I needed didn&#39;t exist. Now every service I own has it.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;the-story-so-far&quot;&gt;The story so far&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-story-so-far&quot; aria-label=&quot;Anchor link for: the-story-so-far&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-measurement&quot;&gt;The measurement&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-measurement&quot; aria-label=&quot;Anchor link for: the-measurement&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-warning&quot;&gt;
&lt;p&gt;A risky operation or a likely mistake.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-change&quot;&gt;The change&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-change&quot; aria-label=&quot;Anchor link for: the-change&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;numbers&quot;&gt;Numbers&lt;a class=&quot;zola-anchor&quot; href=&quot;#numbers&quot; aria-label=&quot;Anchor link for: numbers&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Frontend performance: the 100ms budget</title>
		<published>2026-05-15T00:00:00+00:00</published>
		<updated>2026-05-15T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/frontend-performance-the-100ms-budget/"/>
		<id>https://blog.kaushalrijal.com.np/posts/frontend-performance-the-100ms-budget/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/frontend-performance-the-100ms-budget/">&lt;p&gt;Where input latency actually goes, and the measurements that locate the thief.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;the-story-so-far&quot;&gt;The story so far&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-story-so-far&quot; aria-label=&quot;Anchor link for: the-story-so-far&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;the-measurement&quot;&gt;The measurement&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-measurement&quot; aria-label=&quot;Anchor link for: the-measurement&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-change&quot;&gt;The change&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-change&quot; aria-label=&quot;Anchor link for: the-change&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;numbers&quot;&gt;Numbers&lt;a class=&quot;zola-anchor&quot; href=&quot;#numbers&quot; aria-label=&quot;Anchor link for: numbers&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;what-remains&quot;&gt;What remains&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-remains&quot; aria-label=&quot;Anchor link for: what-remains&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-warning&quot;&gt;
&lt;p&gt;A risky operation or a likely mistake.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-story-so-far-1&quot;&gt;The story so far&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-story-so-far-1&quot; aria-label=&quot;Anchor link for: the-story-so-far-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; load_config&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; dict&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    with&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; encoding&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        return&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                (&lt;/span&gt;&lt;span&gt;line&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-measurement-1&quot;&gt;The measurement&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-measurement-1&quot; aria-label=&quot;Anchor link for: the-measurement-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;the-change-1&quot;&gt;The change&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-change-1&quot; aria-label=&quot;Anchor link for: the-change-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: where input latency actually goes, and the measurements that locate the thief compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>The day I learned to fear feature flags</title>
		<published>2026-04-24T00:00:00+00:00</published>
		<updated>2026-04-24T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/the-day-i-learned-to-fear-feature-flags/"/>
		<id>https://blog.kaushalrijal.com.np/posts/the-day-i-learned-to-fear-feature-flags/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/the-day-i-learned-to-fear-feature-flags/">&lt;p&gt;Dead branches, stale config, and the cleanup ritual nobody scheduled.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-scene&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene&quot; aria-label=&quot;Anchor link for: setting-the-scene&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-naive-approach&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach&quot; aria-label=&quot;Anchor link for: the-naive-approach&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-the-profiler-said&quot;&gt;What the profiler said&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-the-profiler-said&quot; aria-label=&quot;Anchor link for: what-the-profiler-said&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-rewrite&quot;&gt;The rewrite&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-rewrite&quot; aria-label=&quot;Anchor link for: the-rewrite&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Notes on reading code you didn&#39;t write</title>
		<published>2026-04-03T00:00:00+00:00</published>
		<updated>2026-04-03T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/notes-on-reading-code-you-didn-t-write/"/>
		<id>https://blog.kaushalrijal.com.np/posts/notes-on-reading-code-you-didn-t-write/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/notes-on-reading-code-you-didn-t-write/">&lt;p&gt;A repeatable method for entering an unfamiliar repository and finding the truth.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-scene&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene&quot; aria-label=&quot;Anchor link for: setting-the-scene&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-naive-approach&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach&quot; aria-label=&quot;Anchor link for: the-naive-approach&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: a repeatable method for entering an unfamiliar repository and finding the truth is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Search that works without Elasticsearch</title>
		<published>2026-03-14T00:00:00+00:00</published>
		<updated>2026-03-14T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/search-that-works-without-elasticsearch/"/>
		<id>https://blog.kaushalrijal.com.np/posts/search-that-works-without-elasticsearch/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/search-that-works-without-elasticsearch/">&lt;p&gt;SQLite FTS5, trigram matching, and when to stop and hire a search engine.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; INDEX&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; CONCURRENTLY&lt;/span&gt;&lt;span&gt; idx_orders_created_at&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    ON&lt;/span&gt;&lt;span&gt; orders (created_at &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;DESC&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    WHERE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; status&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-fix&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix&quot; aria-label=&quot;Anchor link for: the-fix&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-i-d-do-differently&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>A tiny HTTP server in Rust, line by line</title>
		<published>2026-02-21T00:00:00+00:00</published>
		<updated>2026-02-21T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/a-tiny-http-server-in-rust-line-by-line/"/>
		<id>https://blog.kaushalrijal.com.np/posts/a-tiny-http-server-in-rust-line-by-line/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/a-tiny-http-server-in-rust-line-by-line/">&lt;p&gt;Tokio, a socket loop, and the pieces you&#39;d otherwise take for granted.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;a-better-model&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model&quot; aria-label=&quot;Anchor link for: a-better-model&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;trade-offs&quot;&gt;Trade-offs&lt;a class=&quot;zola-anchor&quot; href=&quot;#trade-offs&quot; aria-label=&quot;Anchor link for: trade-offs&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-important&quot;&gt;
&lt;p&gt;Something the reader should not miss.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-problem-1&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem-1&quot; aria-label=&quot;Anchor link for: the-problem-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;first-attempt-1&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt-1&quot; aria-label=&quot;Anchor link for: first-attempt-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;a-better-model-1&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model-1&quot; aria-label=&quot;Anchor link for: a-better-model-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: tokio, a socket loop, and the pieces you&#39;d otherwise take for granted compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Slicing features so each PR is reviewable in 20 minutes</title>
		<published>2026-01-31T00:00:00+00:00</published>
		<updated>2026-01-31T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/slicing-features-so-each-pr-is-reviewable-in-20-minutes/"/>
		<id>https://blog.kaushalrijal.com.np/posts/slicing-features-so-each-pr-is-reviewable-in-20-minutes/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/slicing-features-so-each-pr-is-reviewable-in-20-minutes/">&lt;p&gt;Vertical slices, feature flags, and reviews that catch things.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h2 id=&quot;a-short-history&quot;&gt;A short history&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-short-history&quot; aria-label=&quot;Anchor link for: a-short-history&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-design&quot;&gt;The design&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-design&quot; aria-label=&quot;Anchor link for: the-design&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: vertical slices, feature flags, and reviews that catch things is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Async Python is not a silver bullet</title>
		<published>2026-01-11T00:00:00+00:00</published>
		<updated>2026-01-11T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/async-python-is-not-a-silver-bullet/"/>
		<id>https://blog.kaushalrijal.com.np/posts/async-python-is-not-a-silver-bullet/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/async-python-is-not-a-silver-bullet/">&lt;p&gt;Where asyncio shines, where it hurts, and when threads were the right answer.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;a-better-model&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model&quot; aria-label=&quot;Anchor link for: a-better-model&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;trade-offs&quot;&gt;Trade-offs&lt;a class=&quot;zola-anchor&quot; href=&quot;#trade-offs&quot; aria-label=&quot;Anchor link for: trade-offs&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-problem-1&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem-1&quot; aria-label=&quot;Anchor link for: the-problem-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; INDEX&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; CONCURRENTLY&lt;/span&gt;&lt;span&gt; idx_orders_created_at&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    ON&lt;/span&gt;&lt;span&gt; orders (created_at &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;DESC&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    WHERE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; status&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;first-attempt-1&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt-1&quot; aria-label=&quot;Anchor link for: first-attempt-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;a-better-model-1&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model-1&quot; aria-label=&quot;Anchor link for: a-better-model-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: where asyncio shines, where it hurts, and when threads were the right answer compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Why I write design docs before code</title>
		<published>2025-12-21T00:00:00+00:00</published>
		<updated>2025-12-21T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/why-i-write-design-docs-before-code/"/>
		<id>https://blog.kaushalrijal.com.np/posts/why-i-write-design-docs-before-code/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/why-i-write-design-docs-before-code/">&lt;p&gt;One page, three sections, and the arguments it saves a month later.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: one page, three sections, and the arguments it saves a month later is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Performance budgets for people who ship</title>
		<published>2025-11-30T00:00:00+00:00</published>
		<updated>2025-11-30T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/performance-budgets-for-people-who-ship/"/>
		<id>https://blog.kaushalrijal.com.np/posts/performance-budgets-for-people-who-ship/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/performance-budgets-for-people-who-ship/">&lt;p&gt;A budget you can enforce in CI beats a wish you revisit never.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;h2 id=&quot;context&quot;&gt;Context&lt;a class=&quot;zola-anchor&quot; href=&quot;#context&quot; aria-label=&quot;Anchor link for: context&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-plan&quot;&gt;The plan&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-plan&quot; aria-label=&quot;Anchor link for: the-plan&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: a budget you can enforce in ci beats a wish you revisit never is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>The long tail of accessibility fixes nobody assigns</title>
		<published>2025-11-10T00:00:00+00:00</published>
		<updated>2025-11-10T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/the-long-tail-of-accessibility-fixes-nobody-assigns/"/>
		<id>https://blog.kaushalrijal.com.np/posts/the-long-tail-of-accessibility-fixes-nobody-assigns/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/the-long-tail-of-accessibility-fixes-nobody-assigns/">&lt;p&gt;Focus rings, labels, and the audit checklist that fits in an afternoon.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; rebuild only what changed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; build&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-cache-from&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:latest&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-tag&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;{&lt;/span&gt;&lt;span&gt;GIT_SHA&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;  .&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;a-better-model&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model&quot; aria-label=&quot;Anchor link for: a-better-model&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Webhooks done right: retries, signatures, and idempotency</title>
		<published>2025-10-20T00:00:00+00:00</published>
		<updated>2025-10-20T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/webhooks-done-right-retries-signatures-and-idempotency/"/>
		<id>https://blog.kaushalrijal.com.np/posts/webhooks-done-right-retries-signatures-and-idempotency/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/webhooks-done-right-retries-signatures-and-idempotency/">&lt;p&gt;The three properties that separate webhooks that just work from ones you fear.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;context&quot;&gt;Context&lt;a class=&quot;zola-anchor&quot; href=&quot;#context&quot; aria-label=&quot;Anchor link for: context&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;the-plan&quot;&gt;The plan&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-plan&quot; aria-label=&quot;Anchor link for: the-plan&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-shipped&quot;&gt;What shipped&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-shipped&quot; aria-label=&quot;Anchor link for: what-shipped&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;follow-ups&quot;&gt;Follow-ups&lt;a class=&quot;zola-anchor&quot; href=&quot;#follow-ups&quot; aria-label=&quot;Anchor link for: follow-ups&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;context-1&quot;&gt;Context&lt;a class=&quot;zola-anchor&quot; href=&quot;#context-1&quot; aria-label=&quot;Anchor link for: context-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-plan-1&quot;&gt;The plan&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-plan-1&quot; aria-label=&quot;Anchor link for: the-plan-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-shipped-1&quot;&gt;What shipped&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-shipped-1&quot; aria-label=&quot;Anchor link for: what-shipped-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;follow-ups-1&quot;&gt;Follow-ups&lt;a class=&quot;zola-anchor&quot; href=&quot;#follow-ups-1&quot; aria-label=&quot;Anchor link for: follow-ups-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: the three properties that separate webhooks that just work from ones you fear compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Terminal workflows: the tools I refuse to give up</title>
		<published>2025-09-29T00:00:00+00:00</published>
		<updated>2025-09-29T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/terminal-workflows-the-tools-i-refuse-to-give-up/"/>
		<id>https://blog.kaushalrijal.com.np/posts/terminal-workflows-the-tools-i-refuse-to-give-up/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/terminal-workflows-the-tools-i-refuse-to-give-up/">&lt;p&gt;The small utilities that quietly save an hour a day.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background&quot; aria-label=&quot;Anchor link for: background&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; rebuild only what changed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; build&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-cache-from&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:latest&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-tag&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;{&lt;/span&gt;&lt;span&gt;GIT_SHA&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;  .&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;how-it-works&quot;&gt;How it works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-it-works&quot; aria-label=&quot;Anchor link for: how-it-works&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-warning&quot;&gt;
&lt;p&gt;A risky operation or a likely mistake.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;in-practice&quot;&gt;In practice&lt;a class=&quot;zola-anchor&quot; href=&quot;#in-practice&quot; aria-label=&quot;Anchor link for: in-practice&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;edge-cases&quot;&gt;Edge cases&lt;a class=&quot;zola-anchor&quot; href=&quot;#edge-cases&quot; aria-label=&quot;Anchor link for: edge-cases&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>How I keep a learning journal that I actually reread</title>
		<published>2025-09-09T00:00:00+00:00</published>
		<updated>2025-09-09T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/how-i-keep-a-learning-journal-that-i-actually-reread/"/>
		<id>https://blog.kaushalrijal.com.np/posts/how-i-keep-a-learning-journal-that-i-actually-reread/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/how-i-keep-a-learning-journal-that-i-actually-reread/">&lt;p&gt;A flat file, five questions, and a weekly review that survives real life.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: a flat file, five questions, and a weekly review that survives real life is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>SQLite is all you need (until it isn&#39;t)</title>
		<published>2025-08-19T00:00:00+00:00</published>
		<updated>2025-08-19T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/sqlite-is-all-you-need-until-it-isn-t/"/>
		<id>https://blog.kaushalrijal.com.np/posts/sqlite-is-all-you-need-until-it-isn-t/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/sqlite-is-all-you-need-until-it-isn-t/">&lt;p&gt;Where a single-file database wins outright, and the exact line where it stops.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;the-story-so-far&quot;&gt;The story so far&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-story-so-far&quot; aria-label=&quot;Anchor link for: the-story-so-far&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; rebuild only what changed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; build&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-cache-from&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:latest&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-tag&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;{&lt;/span&gt;&lt;span&gt;GIT_SHA&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;  .&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-measurement&quot;&gt;The measurement&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-measurement&quot; aria-label=&quot;Anchor link for: the-measurement&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-caution&quot;&gt;
&lt;p&gt;A destructive or irreversible operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-change&quot;&gt;The change&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-change&quot; aria-label=&quot;Anchor link for: the-change&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;numbers&quot;&gt;Numbers&lt;a class=&quot;zola-anchor&quot; href=&quot;#numbers&quot; aria-label=&quot;Anchor link for: numbers&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>From monolith to modules without the microservices tax</title>
		<published>2025-07-29T00:00:00+00:00</published>
		<updated>2025-07-29T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/from-monolith-to-modules-without-the-microservices-tax/"/>
		<id>https://blog.kaushalrijal.com.np/posts/from-monolith-to-modules-without-the-microservices-tax/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/from-monolith-to-modules-without-the-microservices-tax/">&lt;p&gt;Boundaries, dependency rules, and extracting a service only when the metrics say so.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background&quot; aria-label=&quot;Anchor link for: background&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot;&gt;How it works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-it-works&quot; aria-label=&quot;Anchor link for: how-it-works&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;in-practice&quot;&gt;In practice&lt;a class=&quot;zola-anchor&quot; href=&quot;#in-practice&quot; aria-label=&quot;Anchor link for: in-practice&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;edge-cases&quot;&gt;Edge cases&lt;a class=&quot;zola-anchor&quot; href=&quot;#edge-cases&quot; aria-label=&quot;Anchor link for: edge-cases&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;alternatives-considered&quot;&gt;Alternatives considered&lt;a class=&quot;zola-anchor&quot; href=&quot;#alternatives-considered&quot; aria-label=&quot;Anchor link for: alternatives-considered&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-caution&quot;&gt;
&lt;p&gt;A destructive or irreversible operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;background-1&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background-1&quot; aria-label=&quot;Anchor link for: background-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;how-it-works-1&quot;&gt;How it works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-it-works-1&quot; aria-label=&quot;Anchor link for: how-it-works-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;in-practice-1&quot;&gt;In practice&lt;a class=&quot;zola-anchor&quot; href=&quot;#in-practice-1&quot; aria-label=&quot;Anchor link for: in-practice-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: boundaries, dependency rules, and extracting a service only when the metrics say so compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Reading the standard library for fun</title>
		<published>2025-07-09T00:00:00+00:00</published>
		<updated>2025-07-09T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/reading-the-standard-library-for-fun/"/>
		<id>https://blog.kaushalrijal.com.np/posts/reading-the-standard-library-for-fun/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/reading-the-standard-library-for-fun/">&lt;p&gt;What you learn about a language by reading the code everyone else already trusts.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;a-short-history&quot;&gt;A short history&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-short-history&quot; aria-label=&quot;Anchor link for: a-short-history&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-design&quot;&gt;The design&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-design&quot; aria-label=&quot;Anchor link for: the-design&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: what you learn about a language by reading the code everyone else already trusts is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>CSS container queries changed how I build components</title>
		<published>2025-06-18T00:00:00+00:00</published>
		<updated>2025-06-18T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/css-container-queries-changed-how-i-build-components/"/>
		<id>https://blog.kaushalrijal.com.np/posts/css-container-queries-changed-how-i-build-components/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/css-container-queries-changed-how-i-build-components/">&lt;p&gt;Components that know their own width, and the layout code that disappeared.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-important&quot;&gt;
&lt;p&gt;Something the reader should not miss.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;a-better-model&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model&quot; aria-label=&quot;Anchor link for: a-better-model&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>The deployment pipeline that broke in prod (and how I fixed it)</title>
		<published>2025-05-28T00:00:00+00:00</published>
		<updated>2025-05-28T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/the-deployment-pipeline-that-broke-in-prod-and-how-i-fixed-it/"/>
		<id>https://blog.kaushalrijal.com.np/posts/the-deployment-pipeline-that-broke-in-prod-and-how-i-fixed-it/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/the-deployment-pipeline-that-broke-in-prod-and-how-i-fixed-it/">&lt;p&gt;A green build, a broken release, and the missing piece between them.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-scene&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene&quot; aria-label=&quot;Anchor link for: setting-the-scene&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;the-naive-approach&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach&quot; aria-label=&quot;Anchor link for: the-naive-approach&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-the-profiler-said&quot;&gt;What the profiler said&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-the-profiler-said&quot; aria-label=&quot;Anchor link for: what-the-profiler-said&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-rewrite&quot;&gt;The rewrite&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-rewrite&quot; aria-label=&quot;Anchor link for: the-rewrite&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;lessons&quot;&gt;Lessons&lt;a class=&quot;zola-anchor&quot; href=&quot;#lessons&quot; aria-label=&quot;Anchor link for: lessons&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-warning&quot;&gt;
&lt;p&gt;A risky operation or a likely mistake.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;setting-the-scene-1&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene-1&quot; aria-label=&quot;Anchor link for: setting-the-scene-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-naive-approach-1&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach-1&quot; aria-label=&quot;Anchor link for: the-naive-approach-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-the-profiler-said-1&quot;&gt;What the profiler said&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-the-profiler-said-1&quot; aria-label=&quot;Anchor link for: what-the-profiler-said-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: a green build, a broken release, and the missing piece between them compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Rust ownership explained with a library book checkout counter</title>
		<published>2025-05-07T00:00:00+00:00</published>
		<updated>2025-05-07T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/rust-ownership-explained-with-a-library-book-checkout-counter/"/>
		<id>https://blog.kaushalrijal.com.np/posts/rust-ownership-explained-with-a-library-book-checkout-counter/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/rust-ownership-explained-with-a-library-book-checkout-counter/">&lt;p&gt;Borrowing, moves, and lifetimes through one analogy that finally stuck.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;context&quot;&gt;Context&lt;a class=&quot;zola-anchor&quot; href=&quot;#context&quot; aria-label=&quot;Anchor link for: context&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; load_config&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; dict&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    with&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; encoding&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        return&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                (&lt;/span&gt;&lt;span&gt;line&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-plan&quot;&gt;The plan&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-plan&quot; aria-label=&quot;Anchor link for: the-plan&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-shipped&quot;&gt;What shipped&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-shipped&quot; aria-label=&quot;Anchor link for: what-shipped&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;follow-ups&quot;&gt;Follow-ups&lt;a class=&quot;zola-anchor&quot; href=&quot;#follow-ups&quot; aria-label=&quot;Anchor link for: follow-ups&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Making friends with the Linux OOM killer</title>
		<published>2025-04-17T00:00:00+00:00</published>
		<updated>2025-04-17T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/making-friends-with-the-linux-oom-killer/"/>
		<id>https://blog.kaushalrijal.com.np/posts/making-friends-with-the-linux-oom-killer/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/making-friends-with-the-linux-oom-killer/">&lt;p&gt;Reading dmesg, understanding overcommit, and choosing sane memory limits.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;context&quot;&gt;Context&lt;a class=&quot;zola-anchor&quot; href=&quot;#context&quot; aria-label=&quot;Anchor link for: context&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; load_config&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; dict&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    with&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; encoding&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        return&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                (&lt;/span&gt;&lt;span&gt;line&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-plan&quot;&gt;The plan&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-plan&quot; aria-label=&quot;Anchor link for: the-plan&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-caution&quot;&gt;
&lt;p&gt;A destructive or irreversible operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-shipped&quot;&gt;What shipped&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-shipped&quot; aria-label=&quot;Anchor link for: what-shipped&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;follow-ups&quot;&gt;Follow-ups&lt;a class=&quot;zola-anchor&quot; href=&quot;#follow-ups&quot; aria-label=&quot;Anchor link for: follow-ups&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Prompt engineering is just interface design</title>
		<published>2025-03-27T00:00:00+00:00</published>
		<updated>2025-03-27T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/prompt-engineering-is-just-interface-design/"/>
		<id>https://blog.kaushalrijal.com.np/posts/prompt-engineering-is-just-interface-design/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/prompt-engineering-is-just-interface-design/">&lt;p&gt;Treating prompts as APIs — versions, contracts, and tests included.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: treating prompts as apis is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>An honest review of my AI agent architecture after six months</title>
		<published>2025-03-06T00:00:00+00:00</published>
		<updated>2025-03-06T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/an-honest-review-of-my-ai-agent-architecture-after-six-months/"/>
		<id>https://blog.kaushalrijal.com.np/posts/an-honest-review-of-my-ai-agent-architecture-after-six-months/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/an-honest-review-of-my-ai-agent-architecture-after-six-months/">&lt;p&gt;What held up, what I ripped out, and where the token bills went.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background&quot; aria-label=&quot;Anchor link for: background&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h2 id=&quot;how-it-works&quot;&gt;How it works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-it-works&quot; aria-label=&quot;Anchor link for: how-it-works&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;in-practice&quot;&gt;In practice&lt;a class=&quot;zola-anchor&quot; href=&quot;#in-practice&quot; aria-label=&quot;Anchor link for: in-practice&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;edge-cases&quot;&gt;Edge cases&lt;a class=&quot;zola-anchor&quot; href=&quot;#edge-cases&quot; aria-label=&quot;Anchor link for: edge-cases&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;alternatives-considered&quot;&gt;Alternatives considered&lt;a class=&quot;zola-anchor&quot; href=&quot;#alternatives-considered&quot; aria-label=&quot;Anchor link for: alternatives-considered&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-important&quot;&gt;
&lt;p&gt;Something the reader should not miss.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;background-1&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background-1&quot; aria-label=&quot;Anchor link for: background-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; rebuild only what changed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; build&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-cache-from&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:latest&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-tag&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;{&lt;/span&gt;&lt;span&gt;GIT_SHA&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;  .&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;how-it-works-1&quot;&gt;How it works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-it-works-1&quot; aria-label=&quot;Anchor link for: how-it-works-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;in-practice-1&quot;&gt;In practice&lt;a class=&quot;zola-anchor&quot; href=&quot;#in-practice-1&quot; aria-label=&quot;Anchor link for: in-practice-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: what held up, what i ripped out, and where the token bills went compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Connection pooling in five minutes</title>
		<published>2025-02-14T00:00:00+00:00</published>
		<updated>2025-02-14T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/connection-pooling-in-five-minutes/"/>
		<id>https://blog.kaushalrijal.com.np/posts/connection-pooling-in-five-minutes/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/connection-pooling-in-five-minutes/">&lt;p&gt;What pgbouncer actually pools, and the two settings that matter most.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-scene&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene&quot; aria-label=&quot;Anchor link for: setting-the-scene&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-naive-approach&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach&quot; aria-label=&quot;Anchor link for: the-naive-approach&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: what pgbouncer actually pools, and the two settings that matter most is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Why your background jobs keep failing at 3am</title>
		<published>2025-01-24T00:00:00+00:00</published>
		<updated>2025-01-24T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/why-your-background-jobs-keep-failing-at-3am/"/>
		<id>https://blog.kaushalrijal.com.np/posts/why-your-background-jobs-keep-failing-at-3am/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/why-your-background-jobs-keep-failing-at-3am/">&lt;p&gt;Retries, idempotency, and the quiet ways outboxes fall out of sync.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;a-better-model&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model&quot; aria-label=&quot;Anchor link for: a-better-model&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Observability for side projects: logs, traces, and one dashboard</title>
		<published>2025-01-03T00:00:00+00:00</published>
		<updated>2025-01-03T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/observability-for-side-projects-logs-traces-and-one-dashboard/"/>
		<id>https://blog.kaushalrijal.com.np/posts/observability-for-side-projects-logs-traces-and-one-dashboard/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/observability-for-side-projects-logs-traces-and-one-dashboard/">&lt;p&gt;The minimum instrumentation that answers &#39;what happened&#39; at 3am.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-scene&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene&quot; aria-label=&quot;Anchor link for: setting-the-scene&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;the-naive-approach&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach&quot; aria-label=&quot;Anchor link for: the-naive-approach&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-the-profiler-said&quot;&gt;What the profiler said&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-the-profiler-said&quot; aria-label=&quot;Anchor link for: what-the-profiler-said&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-rewrite&quot;&gt;The rewrite&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-rewrite&quot; aria-label=&quot;Anchor link for: the-rewrite&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;lessons&quot;&gt;Lessons&lt;a class=&quot;zola-anchor&quot; href=&quot;#lessons&quot; aria-label=&quot;Anchor link for: lessons&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;setting-the-scene-1&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene-1&quot; aria-label=&quot;Anchor link for: setting-the-scene-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-naive-approach-1&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach-1&quot; aria-label=&quot;Anchor link for: the-naive-approach-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;what-the-profiler-said-1&quot;&gt;What the profiler said&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-the-profiler-said-1&quot; aria-label=&quot;Anchor link for: what-the-profiler-said-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: the minimum instrumentation that answers &#39;what happened&#39; at 3am compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Writing tests for code you&#39;re afraid to touch</title>
		<published>2024-12-14T00:00:00+00:00</published>
		<updated>2024-12-14T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/writing-tests-for-code-you-re-afraid-to-touch/"/>
		<id>https://blog.kaushalrijal.com.np/posts/writing-tests-for-code-you-re-afraid-to-touch/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/writing-tests-for-code-you-re-afraid-to-touch/">&lt;p&gt;A characterization-testing recipe for legacy code with no safety net.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background&quot; aria-label=&quot;Anchor link for: background&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; load_config&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; dict&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    with&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; encoding&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        return&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                (&lt;/span&gt;&lt;span&gt;line&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;how-it-works&quot;&gt;How it works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-it-works&quot; aria-label=&quot;Anchor link for: how-it-works&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;in-practice&quot;&gt;In practice&lt;a class=&quot;zola-anchor&quot; href=&quot;#in-practice&quot; aria-label=&quot;Anchor link for: in-practice&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases&quot;&gt;Edge cases&lt;a class=&quot;zola-anchor&quot; href=&quot;#edge-cases&quot; aria-label=&quot;Anchor link for: edge-cases&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>CI pipelines that finish before the coffee does</title>
		<published>2024-11-23T00:00:00+00:00</published>
		<updated>2024-11-23T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/ci-pipelines-that-finish-before-the-coffee-does/"/>
		<id>https://blog.kaushalrijal.com.np/posts/ci-pipelines-that-finish-before-the-coffee-does/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/ci-pipelines-that-finish-before-the-coffee-does/">&lt;p&gt;Caching, matrix builds, and the discipline of a pipeline under four minutes.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-warning&quot;&gt;
&lt;p&gt;A risky operation or a likely mistake.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-fix&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix&quot; aria-label=&quot;Anchor link for: the-fix&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-i-d-do-differently&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>What happens when you type a URL into a browser</title>
		<published>2024-11-02T00:00:00+00:00</published>
		<updated>2024-11-02T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/what-happens-when-you-type-a-url-into-a-browser/"/>
		<id>https://blog.kaushalrijal.com.np/posts/what-happens-when-you-type-a-url-into-a-browser/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/what-happens-when-you-type-a-url-into-a-browser/">&lt;p&gt;DNS, TCP, TLS, and rendering — the full trip, told once, properly.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;a-better-model&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model&quot; aria-label=&quot;Anchor link for: a-better-model&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;trade-offs&quot;&gt;Trade-offs&lt;a class=&quot;zola-anchor&quot; href=&quot;#trade-offs&quot; aria-label=&quot;Anchor link for: trade-offs&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-problem-1&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem-1&quot; aria-label=&quot;Anchor link for: the-problem-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;first-attempt-1&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt-1&quot; aria-label=&quot;Anchor link for: first-attempt-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;a-better-model-1&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model-1&quot; aria-label=&quot;Anchor link for: a-better-model-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: dns, tcp, tls, and rendering compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>React state management in 2026: the boring answer</title>
		<published>2024-10-13T00:00:00+00:00</published>
		<updated>2024-10-13T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/react-state-management-in-2026-the-boring-answer/"/>
		<id>https://blog.kaushalrijal.com.np/posts/react-state-management-in-2026-the-boring-answer/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/react-state-management-in-2026-the-boring-answer/">&lt;p&gt;Most apps need less state than they have, and a store is rarely the missing piece.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h2 id=&quot;context&quot;&gt;Context&lt;a class=&quot;zola-anchor&quot; href=&quot;#context&quot; aria-label=&quot;Anchor link for: context&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-plan&quot;&gt;The plan&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-plan&quot; aria-label=&quot;Anchor link for: the-plan&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-caution&quot;&gt;
&lt;p&gt;A destructive or irreversible operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-shipped&quot;&gt;What shipped&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-shipped&quot; aria-label=&quot;Anchor link for: what-shipped&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;follow-ups&quot;&gt;Follow-ups&lt;a class=&quot;zola-anchor&quot; href=&quot;#follow-ups&quot; aria-label=&quot;Anchor link for: follow-ups&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>TypeScript types are a programming language</title>
		<published>2024-09-22T00:00:00+00:00</published>
		<updated>2024-09-22T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/typescript-types-are-a-programming-language/"/>
		<id>https://blog.kaushalrijal.com.np/posts/typescript-types-are-a-programming-language/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/typescript-types-are-a-programming-language/">&lt;p&gt;Discriminated unions, branded types, and the point where types start computing.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;context&quot;&gt;Context&lt;a class=&quot;zola-anchor&quot; href=&quot;#context&quot; aria-label=&quot;Anchor link for: context&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;h2 id=&quot;the-plan&quot;&gt;The plan&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-plan&quot; aria-label=&quot;Anchor link for: the-plan&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; INDEX&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; CONCURRENTLY&lt;/span&gt;&lt;span&gt; idx_orders_created_at&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    ON&lt;/span&gt;&lt;span&gt; orders (created_at &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;DESC&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    WHERE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; status&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-shipped&quot;&gt;What shipped&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-shipped&quot; aria-label=&quot;Anchor link for: what-shipped&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;follow-ups&quot;&gt;Follow-ups&lt;a class=&quot;zola-anchor&quot; href=&quot;#follow-ups&quot; aria-label=&quot;Anchor link for: follow-ups&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;context-1&quot;&gt;Context&lt;a class=&quot;zola-anchor&quot; href=&quot;#context-1&quot; aria-label=&quot;Anchor link for: context-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-caution&quot;&gt;
&lt;p&gt;A destructive or irreversible operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-plan-1&quot;&gt;The plan&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-plan-1&quot; aria-label=&quot;Anchor link for: the-plan-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-shipped-1&quot;&gt;What shipped&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-shipped-1&quot; aria-label=&quot;Anchor link for: what-shipped-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;follow-ups-1&quot;&gt;Follow-ups&lt;a class=&quot;zola-anchor&quot; href=&quot;#follow-ups-1&quot; aria-label=&quot;Anchor link for: follow-ups-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: discriminated unions, branded types, and the point where types start computing compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Rate limiting from scratch: token bucket in 40 lines</title>
		<published>2024-09-01T00:00:00+00:00</published>
		<updated>2024-09-01T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/rate-limiting-from-scratch-token-bucket-in-40-lines/"/>
		<id>https://blog.kaushalrijal.com.np/posts/rate-limiting-from-scratch-token-bucket-in-40-lines/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/rate-limiting-from-scratch-token-bucket-in-40-lines/">&lt;p&gt;A small, correct token bucket, and the edge cases that make it interesting.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-important&quot;&gt;
&lt;p&gt;Something the reader should not miss.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-fix&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix&quot; aria-label=&quot;Anchor link for: the-fix&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Capture the current behavior before touching the code&lt;/li&gt;
&lt;li&gt;Make the smallest change that preserves it&lt;/li&gt;
&lt;li&gt;Delete the workaround you were sure you&#39;d need&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&quot;what-i-d-do-differently&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>The cost of a cache: measuring before optimizing</title>
		<published>2024-08-12T00:00:00+00:00</published>
		<updated>2024-09-29T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/the-cost-of-a-cache-measuring-before-optimizing/"/>
		<id>https://blog.kaushalrijal.com.np/posts/the-cost-of-a-cache-measuring-before-optimizing/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/the-cost-of-a-cache-measuring-before-optimizing/">&lt;p&gt;Hit rates, eviction, and the latency numbers behind a cache that made things worse.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-fix&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix&quot; aria-label=&quot;Anchor link for: the-fix&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-i-d-do-differently&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;where-i-started-1&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started-1&quot; aria-label=&quot;Anchor link for: where-i-started-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-warning&quot;&gt;
&lt;p&gt;A risky operation or a likely mistake.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-went-wrong-1&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong-1&quot; aria-label=&quot;Anchor link for: what-went-wrong-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; load_config&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; dict&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    with&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; encoding&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        return&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                (&lt;/span&gt;&lt;span&gt;line&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-fix-1&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix-1&quot; aria-label=&quot;Anchor link for: the-fix-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-i-d-do-differently-1&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently-1&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: hit rates, eviction, and the latency numbers behind a cache that made things worse compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Git bisect saved me four hours</title>
		<published>2024-07-22T00:00:00+00:00</published>
		<updated>2024-07-22T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/git-bisect-saved-me-four-hours/"/>
		<id>https://blog.kaushalrijal.com.np/posts/git-bisect-saved-me-four-hours/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/git-bisect-saved-me-four-hours/">&lt;p&gt;How a two-minute ritual turned a mysterious regression into a single bad commit.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: how a two-minute ritual turned a mysterious regression into a single bad commit is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Docker images 60% smaller: multi-stage builds in practice</title>
		<published>2024-07-01T00:00:00+00:00</published>
		<updated>2024-07-01T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/docker-images-60-smaller-multi-stage-builds-in-practice/"/>
		<id>https://blog.kaushalrijal.com.np/posts/docker-images-60-smaller-multi-stage-builds-in-practice/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/docker-images-60-smaller-multi-stage-builds-in-practice/">&lt;p&gt;A practical walkthrough from a 1.2GB image to a 460MB one without changing app code.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-scene&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene&quot; aria-label=&quot;Anchor link for: setting-the-scene&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; INDEX&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; CONCURRENTLY&lt;/span&gt;&lt;span&gt; idx_orders_created_at&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    ON&lt;/span&gt;&lt;span&gt; orders (created_at &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;DESC&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    WHERE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; status&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-naive-approach&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach&quot; aria-label=&quot;Anchor link for: the-naive-approach&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-the-profiler-said&quot;&gt;What the profiler said&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-the-profiler-said&quot; aria-label=&quot;Anchor link for: what-the-profiler-said&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-rewrite&quot;&gt;The rewrite&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-rewrite&quot; aria-label=&quot;Anchor link for: the-rewrite&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Building a retrieval pipeline that doesn&#39;t lie to you</title>
		<published>2024-06-11T00:00:00+00:00</published>
		<updated>2024-06-11T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/building-a-retrieval-pipeline-that-doesn-t-lie-to-you/"/>
		<id>https://blog.kaushalrijal.com.np/posts/building-a-retrieval-pipeline-that-doesn-t-lie-to-you/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/building-a-retrieval-pipeline-that-doesn-t-lie-to-you/">&lt;p&gt;Chunking, reranking, and evaluation for a RAG system that admits when it doesn&#39;t know.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;h2 id=&quot;a-short-history&quot;&gt;A short history&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-short-history&quot; aria-label=&quot;Anchor link for: a-short-history&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;h2 id=&quot;the-design&quot;&gt;The design&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-design&quot; aria-label=&quot;Anchor link for: the-design&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;sql&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;CREATE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; INDEX&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; CONCURRENTLY&lt;/span&gt;&lt;span&gt; idx_orders_created_at&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    ON&lt;/span&gt;&lt;span&gt; orders (created_at &lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;DESC&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    WHERE&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; status&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;#39;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;#39;&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;implementation-notes&quot;&gt;Implementation notes&lt;a class=&quot;zola-anchor&quot; href=&quot;#implementation-notes&quot; aria-label=&quot;Anchor link for: implementation-notes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;failure-modes&quot;&gt;Failure modes&lt;a class=&quot;zola-anchor&quot; href=&quot;#failure-modes&quot; aria-label=&quot;Anchor link for: failure-modes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;when-not-to-use-this&quot;&gt;When not to use this&lt;a class=&quot;zola-anchor&quot; href=&quot;#when-not-to-use-this&quot; aria-label=&quot;Anchor link for: when-not-to-use-this&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-important&quot;&gt;
&lt;p&gt;Something the reader should not miss.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;further-reading&quot;&gt;Further reading&lt;a class=&quot;zola-anchor&quot; href=&quot;#further-reading&quot; aria-label=&quot;Anchor link for: further-reading&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; rebuild only what changed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; build&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-cache-from&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:latest&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-tag&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;{&lt;/span&gt;&lt;span&gt;GIT_SHA&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;  .&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;a-short-history-1&quot;&gt;A short history&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-short-history-1&quot; aria-label=&quot;Anchor link for: a-short-history-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-design-1&quot;&gt;The design&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-design-1&quot; aria-label=&quot;Anchor link for: the-design-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: chunking, reranking, and evaluation for a rag system that admits when it doesn&#39;t know compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Understanding embeddings without the math degree</title>
		<published>2024-05-21T00:00:00+00:00</published>
		<updated>2024-05-21T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/understanding-embeddings-without-the-math-degree/"/>
		<id>https://blog.kaushalrijal.com.np/posts/understanding-embeddings-without-the-math-degree/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/understanding-embeddings-without-the-math-degree/">&lt;p&gt;Vectors, similarity, and why your search results suddenly got better.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;background&quot;&gt;Background&lt;a class=&quot;zola-anchor&quot; href=&quot;#background&quot; aria-label=&quot;Anchor link for: background&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;how-it-works&quot;&gt;How it works&lt;a class=&quot;zola-anchor&quot; href=&quot;#how-it-works&quot; aria-label=&quot;Anchor link for: how-it-works&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;in-practice&quot;&gt;In practice&lt;a class=&quot;zola-anchor&quot; href=&quot;#in-practice&quot; aria-label=&quot;Anchor link for: in-practice&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;edge-cases&quot;&gt;Edge cases&lt;a class=&quot;zola-anchor&quot; href=&quot;#edge-cases&quot; aria-label=&quot;Anchor link for: edge-cases&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Shipping a side project in 30 days: what actually mattered</title>
		<published>2024-04-30T00:00:00+00:00</published>
		<updated>2024-04-30T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/shipping-a-side-project-in-30-days-what-actually-mattered/"/>
		<id>https://blog.kaushalrijal.com.np/posts/shipping-a-side-project-in-30-days-what-actually-mattered/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/shipping-a-side-project-in-30-days-what-actually-mattered/">&lt;p&gt;Scope, deadlines, and the one weekly ritual that kept the project alive.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h2 id=&quot;setting-the-scene&quot;&gt;Setting the scene&lt;a class=&quot;zola-anchor&quot; href=&quot;#setting-the-scene&quot; aria-label=&quot;Anchor link for: setting-the-scene&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-naive-approach&quot;&gt;The naive approach&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-naive-approach&quot; aria-label=&quot;Anchor link for: the-naive-approach&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-warning&quot;&gt;
&lt;p&gt;A risky operation or a likely mistake.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-the-profiler-said&quot;&gt;What the profiler said&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-the-profiler-said&quot; aria-label=&quot;Anchor link for: what-the-profiler-said&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;the-rewrite&quot;&gt;The rewrite&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-rewrite&quot; aria-label=&quot;Anchor link for: the-rewrite&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Things I wish someone told me before my first internship</title>
		<published>2024-04-10T00:00:00+00:00</published>
		<updated>2024-04-10T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/things-i-wish-someone-told-me-before-my-first-internship/"/>
		<id>https://blog.kaushalrijal.com.np/posts/things-i-wish-someone-told-me-before-my-first-internship/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/things-i-wish-someone-told-me-before-my-first-internship/">&lt;p&gt;Nobody expects you to know the codebase. They expect you to ask good questions.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;A second point, kept short on purpose&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;Everything above is the short version. The full write-up of how this played out is a story for another day — for now, the takeaway is simple: nobody expects you to know the codebase. they expect you to ask good questions is a decision you make once and revisit deliberately.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Debugging a memory leak with nothing but /proc</title>
		<published>2024-03-20T00:00:00+00:00</published>
		<updated>2024-03-20T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/debugging-a-memory-leak-with-nothing-but-proc/"/>
		<id>https://blog.kaushalrijal.com.np/posts/debugging-a-memory-leak-with-nothing-but-proc/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/debugging-a-memory-leak-with-nothing-but-proc/">&lt;p&gt;A weekend incident, a growing RSS number, and no profiler available on the box.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;python&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;def&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; load_config&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; str&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; dict&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    with&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; open&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;path&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; encoding&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;utf-8&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; as&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        return&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;span&gt;k&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;:&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;strip&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; k&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; v&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;                (&lt;/span&gt;&lt;span&gt;line&lt;/span&gt;&lt;span&gt;.&lt;/span&gt;&lt;span&gt;split&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; for&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; if&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span&gt; line&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-caution&quot;&gt;
&lt;p&gt;A destructive or irreversible operation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-fix&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix&quot; aria-label=&quot;Anchor link for: the-fix&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read the error message twice before changing anything&lt;/li&gt;
&lt;li&gt;Reproduce it with the smallest input you can&lt;/li&gt;
&lt;li&gt;Write the failing test first, even if it feels ceremonial&lt;/li&gt;
&lt;li&gt;Only then reach for the fix&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-i-d-do-differently&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Postgres indexes: the only guide I wish I had</title>
		<published>2024-02-28T00:00:00+00:00</published>
		<updated>2024-05-06T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/postgres-indexes-the-only-guide-i-wish-i-had/"/>
		<id>https://blog.kaushalrijal.com.np/posts/postgres-indexes-the-only-guide-i-wish-i-had/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/postgres-indexes-the-only-guide-i-wish-i-had/">&lt;p&gt;B-tree, partial, covering, and GIN indexes with the queries that motivated each one.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;the-problem&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem&quot; aria-label=&quot;Anchor link for: the-problem&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;h2 id=&quot;first-attempt&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt&quot; aria-label=&quot;Anchor link for: first-attempt&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;rust&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; retry&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;mut&lt;/span&gt;&lt;span&gt; f&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; impl&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; FnMut&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; times&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; u32&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; -&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Result&lt;/span&gt;&lt;span&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;T&lt;/span&gt;&lt;span&gt;&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    let&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; mut&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; None&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;    for&lt;/span&gt;&lt;span&gt; _&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; in&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 0&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;..&lt;/span&gt;&lt;span&gt;times&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;        match&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; f&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; return&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Ok&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;v&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;            Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; Some&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;e&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;        }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    }&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    Err&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;last&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;unwrap&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;a-better-model&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model&quot; aria-label=&quot;Anchor link for: a-better-model&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;results&quot;&gt;Results&lt;a class=&quot;zola-anchor&quot; href=&quot;#results&quot; aria-label=&quot;Anchor link for: results&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;trade-offs&quot;&gt;Trade-offs&lt;a class=&quot;zola-anchor&quot; href=&quot;#trade-offs&quot; aria-label=&quot;Anchor link for: trade-offs&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;the-problem-1&quot;&gt;The problem&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-problem-1&quot; aria-label=&quot;Anchor link for: the-problem-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;first-attempt-1&quot;&gt;First attempt&lt;a class=&quot;zola-anchor&quot; href=&quot;#first-attempt-1&quot; aria-label=&quot;Anchor link for: first-attempt-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;a-better-model-1&quot;&gt;A better model&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-better-model-1&quot; aria-label=&quot;Anchor link for: a-better-model-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: b-tree, partial, covering, and gin indexes with the queries that motivated each one compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>A gentle introduction to async Rust for people who know sync Python</title>
		<published>2024-02-08T00:00:00+00:00</published>
		<updated>2024-02-08T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/a-gentle-introduction-to-async-rust-for-people-who-know-sync-python/"/>
		<id>https://blog.kaushalrijal.com.np/posts/a-gentle-introduction-to-async-rust-for-people-who-know-sync-python/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/a-gentle-introduction-to-async-rust-for-people-who-know-sync-python/">&lt;p&gt;Futures, executors, and await, explained against the backdrop of Python&#39;s asyncio.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;where-i-started&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started&quot; aria-label=&quot;Anchor link for: where-i-started&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;The numbers below are from my own machine and my own workload. Treat them as a method, not a benchmark: the point is how the measurement was taken, not the exact figures it produced.&lt;/p&gt;
&lt;h2 id=&quot;what-went-wrong&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong&quot; aria-label=&quot;Anchor link for: what-went-wrong&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;toml&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;[&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;deploy&lt;/span&gt;&lt;span&gt;]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;strategy&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;rolling&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;healthcheck&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;/healthz&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;max_unavailable&lt;/span&gt;&lt;span&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-fix&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix&quot; aria-label=&quot;Anchor link for: the-fix&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;The best engineering advice I&#39;ve received is unglamorous: make it measurable, make it reversible, and only then make it fast.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-i-d-do-differently&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;table&gt;&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Approach&lt;/th&gt;&lt;th&gt;Best for&lt;/th&gt;&lt;th&gt;Watch out for&lt;/th&gt;&lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
&lt;tr&gt;&lt;td&gt;Baseline&lt;/td&gt;&lt;td&gt;Quick comparisons&lt;/td&gt;&lt;td&gt;No tail visibility&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Instrumented&lt;/td&gt;&lt;td&gt;Finding the real hotspot&lt;/td&gt;&lt;td&gt;Overhead of the probes&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;Production&lt;/td&gt;&lt;td&gt;Truthful numbers&lt;/td&gt;&lt;td&gt;Harder to reproduce&lt;/td&gt;&lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;
&lt;h2 id=&quot;where-i-started-1&quot;&gt;Where I started&lt;a class=&quot;zola-anchor&quot; href=&quot;#where-i-started-1&quot; aria-label=&quot;Anchor link for: where-i-started-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-note&quot;&gt;
&lt;p&gt;A note for context that helps the reader.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;what-went-wrong-1&quot;&gt;What went wrong&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-went-wrong-1&quot; aria-label=&quot;Anchor link for: what-went-wrong-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;const&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; debounce&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;fn&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt; ms&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; 200&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  let&lt;/span&gt;&lt;span&gt; t&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;  return&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;z-l-9 z-d-12&quot;&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span&gt; {&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;    clearTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;t&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;    t&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; setTimeout&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt; =&amp;gt;&lt;/span&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt; fn&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span class=&quot;z-l-8 z-d-10&quot;&gt;...&lt;/span&gt;&lt;span&gt;args&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;span&gt; ms&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;  }&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span&gt;}&lt;/span&gt;&lt;span&gt;;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-fix-1&quot;&gt;The fix&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-fix-1&quot; aria-label=&quot;Anchor link for: the-fix-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;what-i-d-do-differently-1&quot;&gt;What I&#39;d do differently&lt;a class=&quot;zola-anchor&quot; href=&quot;#what-i-d-do-differently-1&quot; aria-label=&quot;Anchor link for: what-i-d-do-differently-1&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I want to be honest about the trade-offs here. The approach I settled on solves the problem I had, not every problem of this shape, and there is a clear point where you should reach for something more heavy-duty.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;h3 id=&quot;wrap-up&quot;&gt;Wrap-up&lt;a class=&quot;zola-anchor&quot; href=&quot;#wrap-up&quot; aria-label=&quot;Anchor link for: wrap-up&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h3&gt;
&lt;p&gt;If you remember one thing, make it this: futures, executors, and await, explained against the backdrop of python&#39;s asyncio compounds. The cost of getting it right early is a afternoon; the cost of getting it late is a migration.&lt;/p&gt;
</content>
	</entry>
	<entry xml:lang="en">
		<title>Why I stopped fighting CSS specificity and started nesting</title>
		<published>2024-01-18T00:00:00+00:00</published>
		<updated>2024-01-18T00:00:00+00:00</updated>
		<link rel="alternate" type="text/html" href="https://blog.kaushalrijal.com.np/posts/why-i-stopped-fighting-css-specificity-and-started-nesting/"/>
		<id>https://blog.kaushalrijal.com.np/posts/why-i-stopped-fighting-css-specificity-and-started-nesting/</id>
    
		<content type="html" xml:base="https://blog.kaushalrijal.com.np/posts/why-i-stopped-fighting-css-specificity-and-started-nesting/">&lt;p&gt;Specificity wars are a symptom of structure, not selectors — nesting with layers fixed it for me.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
&lt;h2 id=&quot;a-short-history&quot;&gt;A short history&lt;a class=&quot;zola-anchor&quot; href=&quot;#a-short-history&quot; aria-label=&quot;Anchor link for: a-short-history&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;p&gt;By the end of this post you should be able to reproduce the whole thing yourself in under an hour, including the parts I got wrong the first time — those are marked so you can skip them if you&#39;re in a hurry.&lt;/p&gt;
&lt;pre class=&quot;giallo z-l-code z-d-code&quot; &gt;&lt;code data-lang=&quot;shellscript&quot;&gt;&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt;#&lt;/span&gt;&lt;span class=&quot;z-l-5 z-d-3&quot;&gt; rebuild only what changed&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-6 z-d-7&quot;&gt;docker&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; build&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-cache-from&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:latest&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;  -&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt;-tag&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt; &amp;quot;&lt;/span&gt;&lt;span&gt;$&lt;/span&gt;&lt;span&gt;IMAGE&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;{&lt;/span&gt;&lt;span&gt;GIT_SHA&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;z-l-1 z-d-4&quot;&gt; \&lt;/span&gt;&lt;/span&gt;
&lt;span class=&quot;giallo-l&quot;&gt;&lt;span class=&quot;z-l-2 z-d-6&quot;&gt;  .&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&quot;the-design&quot;&gt;The design&lt;a class=&quot;zola-anchor&quot; href=&quot;#the-design&quot; aria-label=&quot;Anchor link for: the-design&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;Tools matter less than the feedback loop they enable. A fast, boring loop beat every sophisticated setup I tried, and I&#39;ve kept it ever since, even as the rest of the stack changed twice over.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;blockquote class=&quot;markdown-alert-tip&quot;&gt;
&lt;p&gt;A tip for a practical recommendation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h2 id=&quot;implementation-notes&quot;&gt;Implementation notes&lt;a class=&quot;zola-anchor&quot; href=&quot;#implementation-notes&quot; aria-label=&quot;Anchor link for: implementation-notes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;p&gt;I kept a log of every decision during this project, and reading it back a month later was humbling: the choices that aged well were the boring ones, and the clever ones all came with a footnote I hadn&#39;t written yet.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Latency at p50, because most users live there&lt;/li&gt;
&lt;li&gt;Latency at p99, because someone always lives there&lt;/li&gt;
&lt;li&gt;Error rate, because a fast failure is still a failure&lt;/li&gt;
&lt;li&gt;Saturation, because averages hide the cliff&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&quot;failure-modes&quot;&gt;Failure modes&lt;a class=&quot;zola-anchor&quot; href=&quot;#failure-modes&quot; aria-label=&quot;Anchor link for: failure-modes&quot; style=&quot;visibility: hidden;&quot;&gt;&lt;/a&gt;
&lt;/h2&gt;
&lt;p&gt;The first version worked, which is exactly why it was hard to see how wrong it was. Everything looked fine in the demo, and everything looked fine until traffic arrived on a Tuesday afternoon and the graph started doing something I&#39;d never seen before.&lt;/p&gt;
&lt;p&gt;There is a version of this article that opens with theory. I decided against it, because the theory is easy to find and the motivation is not — so let&#39;s start with the thing that actually broke.&lt;/p&gt;
&lt;p&gt;What surprised me most was how small the final change was. Most of the work was understanding the problem precisely enough that the fix became obvious, and that understanding took far longer than the fix itself.&lt;/p&gt;
</content>
	</entry>
</feed>
