<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://eozsahin1993.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://eozsahin1993.github.io/" rel="alternate" type="text/html" /><updated>2026-07-19T13:39:02+00:00</updated><id>https://eozsahin1993.github.io/feed.xml</id><title type="html">Emre Ozsahin</title><subtitle>Software Engineer with a passion for mobile and web development.</subtitle><author><name>Emre Ozsahin</name></author><entry><title type="html">Goroutines and channels</title><link href="https://eozsahin1993.github.io/posts/2026/07/17/goroutines-and-channels.html" rel="alternate" type="text/html" title="Goroutines and channels" /><published>2026-07-17T00:00:00+00:00</published><updated>2026-07-17T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2026/07/17/goroutines-and-channels</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2026/07/17/goroutines-and-channels.html"><![CDATA[<p>While building <a href="www.ragpack.dev">RagPack</a>, I needed a file worker that would parse file chunks and write them into LanceDB, an embedded columnar vector database. This would have been fiddly to get right in most languages, but Go’s concurrency primitives made it simple without any major architectural shift. Here’s how goroutines, channels, and <code class="language-plaintext highlighter-rouge">sync.WaitGroup</code> work together in the ingestion pipeline.</p>

<h3 id="what-are-goroutines">What are goroutines?</h3>

<p>Goroutines, just like coroutines in Kotlin, are lightweight concurrency units managed by the Go runtime. The runtime multiplexes many goroutines onto a much smaller number of OS threads, so spawning thousands of them is cheap.</p>

<p>Launching one is one line:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">go</span> <span class="k">func</span><span class="p">()</span> <span class="p">{}()</span>
</code></pre></div></div>

<p>In my case, I spawn a fixed number of worker goroutines based on the configured worker count:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for</span> <span class="n">i</span> <span class="o">:=</span> <span class="m">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">workers</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span> <span class="p">{</span>
  <span class="n">wp</span><span class="o">.</span><span class="n">waitGroup</span><span class="o">.</span><span class="n">Add</span><span class="p">(</span><span class="m">1</span><span class="p">)</span>
  <span class="k">go</span> <span class="n">wp</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">ctx</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Since each goroutine runs independently, something has to coordinate handing off work between them and knowing when they’re actually done. That’s where channels and <code class="language-plaintext highlighter-rouge">WaitGroup</code> come in, and they solve two completely different problems.</p>

<h3 id="channels-move-the-work">Channels move the work</h3>

<p>A channel is the communication layer between concurrent goroutines, where each can send and receive values safely, without explicit locks or race conditions.</p>

<p>In my case, workers pull queued items off a shared channel:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">type</span> <span class="n">queueItem</span> <span class="k">struct</span> <span class="p">{</span>
	<span class="n">job</span>    <span class="n">meta</span><span class="o">.</span><span class="n">Job</span>
	<span class="n">reader</span> <span class="n">io</span><span class="o">.</span><span class="n">ReadCloser</span>
<span class="p">}</span>

<span class="n">queue</span> <span class="o">:=</span> <span class="nb">make</span><span class="p">(</span><span class="k">chan</span> <span class="n">queueItem</span><span class="p">,</span> <span class="n">workers</span><span class="o">*</span><span class="m">10</span><span class="p">)</span>
</code></pre></div></div>

<p>Data flows through the <code class="language-plaintext highlighter-rouge">&lt;-</code> operator:</p>

<ul>
  <li>Send to a channel: <code class="language-plaintext highlighter-rouge">ch &lt;- item</code></li>
  <li>Receive from a channel: <code class="language-plaintext highlighter-rouge">item := &lt;-ch</code></li>
</ul>

<p>There are two flavors, and they behave differently based on capacity:</p>

<p><strong>Unbuffered channels</strong> have no capacity to hold data. A send blocks the sender until a receiver is ready, and a receiver blocks until a sender sends. This synchronizes the two goroutines directly.</p>

<p><strong>Buffered channels</strong> are created with a fixed capacity, like <code class="language-plaintext highlighter-rouge">make(chan queueItem, 10)</code>. Sending only blocks once the buffer is full, receiving only blocks once it’s empty. That decouples the timing of sender and receiver, which is why my queue channel above is buffered at <code class="language-plaintext highlighter-rouge">workers*10</code>, it lets jobs pile up a bit without forcing whoever’s submitting them to wait on a free worker.</p>

<p>Sending on an unbuffered channel with nobody reading deadlocks the whole program:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">func</span> <span class="n">main</span><span class="p">()</span> <span class="p">{</span>
	<span class="n">ch</span> <span class="o">:=</span> <span class="nb">make</span><span class="p">(</span><span class="k">chan</span> <span class="n">queueItem</span><span class="p">)</span>
	<span class="n">ch</span> <span class="o">&lt;-</span> <span class="n">queueItem</span><span class="p">{}</span> <span class="c">// ERROR: deadlock, nothing is ever reading from ch</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Each worker in my pool avoids this by always being ready to receive, looping on a <code class="language-plaintext highlighter-rouge">select</code> that watches both the queue and cancellation:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">func</span> <span class="p">(</span><span class="n">wp</span> <span class="o">*</span><span class="n">WorkerPool</span><span class="p">)</span> <span class="n">run</span><span class="p">(</span><span class="n">ctx</span> <span class="n">context</span><span class="o">.</span><span class="n">Context</span><span class="p">)</span> <span class="p">{</span>
	<span class="k">defer</span> <span class="n">wp</span><span class="o">.</span><span class="n">waitGroup</span><span class="o">.</span><span class="n">Done</span><span class="p">()</span>
	<span class="k">for</span> <span class="p">{</span>
		<span class="k">select</span> <span class="p">{</span>
		<span class="k">case</span> <span class="o">&lt;-</span><span class="n">ctx</span><span class="o">.</span><span class="n">Done</span><span class="p">()</span><span class="o">:</span>
			<span class="k">return</span>
		<span class="k">case</span> <span class="n">item</span> <span class="o">:=</span> <span class="o">&lt;-</span><span class="n">wp</span><span class="o">.</span><span class="n">queue</span><span class="o">:</span>
			<span class="k">if</span> <span class="n">err</span> <span class="o">:=</span> <span class="n">wp</span><span class="o">.</span><span class="n">processJob</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">item</span><span class="p">);</span> <span class="n">err</span> <span class="o">!=</span> <span class="no">nil</span> <span class="p">{</span>
				<span class="n">log</span><span class="o">.</span><span class="n">Printf</span><span class="p">(</span><span class="s">"ingester: job %s failed: %v"</span><span class="p">,</span> <span class="n">item</span><span class="o">.</span><span class="n">job</span><span class="o">.</span><span class="n">ID</span><span class="p">,</span> <span class="n">err</span><span class="p">)</span>
			<span class="p">}</span>
		<span class="p">}</span>
	<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>This is what makes the producer/consumer pattern so easy in Go. There’s no thread pool to manage and no lock to take, just a channel read in a loop.</p>

<h3 id="waitgroup-answers-a-different-question">WaitGroup answers a different question</h3>

<p>I initially assumed WaitGroup was somehow gating the channel, blocking new work until a slot opened up. It isn’t, and it has no idea what a channel even is. It’s a plain counter with three methods:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">Add(n)</code>: increments the counter by <code class="language-plaintext highlighter-rouge">n</code>, called before spawning the goroutines you want tracked</li>
  <li><code class="language-plaintext highlighter-rouge">Done()</code>: decrements the counter by one, called by each goroutine when it finishes, usually via <code class="language-plaintext highlighter-rouge">defer</code></li>
  <li><code class="language-plaintext highlighter-rouge">Wait()</code>: blocks the calling goroutine until the counter hits zero</li>
</ul>

<p>What it actually answers is: “have all the goroutines I started actually finished?” Canceling <code class="language-plaintext highlighter-rouge">ctx</code> tells workers to stop picking up <em>new</em> jobs, but it says nothing about a job already in progress. A worker could be mid-write to LanceDB the instant <code class="language-plaintext highlighter-rouge">ctx</code> is canceled, and if the process exits right then, that write is lost.</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">func</span> <span class="p">(</span><span class="n">wp</span> <span class="o">*</span><span class="n">WorkerPool</span><span class="p">)</span> <span class="n">Stop</span><span class="p">()</span> <span class="p">{</span>
	<span class="n">wp</span><span class="o">.</span><span class="n">waitGroup</span><span class="o">.</span><span class="n">Wait</span><span class="p">()</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">Stop()</code> is called after the context is canceled, and it blocks until every worker’s deferred <code class="language-plaintext highlighter-rouge">wp.waitGroup.Done()</code> has actually run, meaning every in-flight job finished processing first. Skip this and shutdown becomes a race: clean most of the time, but occasionally losing the tail end of whatever a worker was writing.</p>

<h3 id="putting-it-together">Putting it together</h3>

<p><code class="language-plaintext highlighter-rouge">run</code> and <code class="language-plaintext highlighter-rouge">Stop</code> above are two of the three moving pieces. The dispatcher ties them together:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">func</span> <span class="p">(</span><span class="n">wp</span> <span class="o">*</span><span class="n">WorkerPool</span><span class="p">)</span> <span class="n">Start</span><span class="p">(</span><span class="n">ctx</span> <span class="n">context</span><span class="o">.</span><span class="n">Context</span><span class="p">,</span> <span class="n">workers</span> <span class="kt">int</span><span class="p">)</span> <span class="p">{</span>
	<span class="k">go</span> <span class="n">wp</span><span class="o">.</span><span class="n">loop</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">workers</span><span class="p">)</span>
<span class="p">}</span>

<span class="k">func</span> <span class="p">(</span><span class="n">wp</span> <span class="o">*</span><span class="n">WorkerPool</span><span class="p">)</span> <span class="n">loop</span><span class="p">(</span><span class="n">ctx</span> <span class="n">context</span><span class="o">.</span><span class="n">Context</span><span class="p">,</span> <span class="n">workers</span> <span class="kt">int</span><span class="p">)</span> <span class="p">{</span>
	<span class="k">for</span> <span class="n">i</span> <span class="o">:=</span> <span class="m">0</span><span class="p">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="n">workers</span><span class="p">;</span> <span class="n">i</span><span class="o">++</span> <span class="p">{</span>
		<span class="n">wp</span><span class="o">.</span><span class="n">waitGroup</span><span class="o">.</span><span class="n">Add</span><span class="p">(</span><span class="m">1</span><span class="p">)</span>
		<span class="k">go</span> <span class="n">wp</span><span class="o">.</span><span class="n">run</span><span class="p">(</span><span class="n">ctx</span><span class="p">)</span>
	<span class="p">}</span>

	<span class="k">for</span> <span class="p">{</span>
		<span class="k">select</span> <span class="p">{</span>
		<span class="k">case</span> <span class="o">&lt;-</span><span class="n">ctx</span><span class="o">.</span><span class="n">Done</span><span class="p">()</span><span class="o">:</span>
			<span class="k">return</span>
		<span class="p">}</span>
	<span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">Start</code> kicks off the dispatcher in its own goroutine. The dispatcher spawns the fixed pool of workers, each incrementing the shared WaitGroup before it starts. Every worker pulls from the same queue channel until the context is canceled. <code class="language-plaintext highlighter-rouge">Stop</code> is the only place that actually confirms shutdown is done, not when the context is canceled, but when the last worker’s Done call lands.</p>

<p>Three primitives, three separate jobs: goroutines run the work, the channel distributes it, <code class="language-plaintext highlighter-rouge">WaitGroup</code> confirms it’s finished.</p>

<p>Happy coding!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="Golang" /><category term="Go" /><category term="concurrency" /><summary type="html"><![CDATA[While building RagPack, I needed a file worker that would parse file chunks and write them into LanceDB, an embedded columnar vector database. This would have been fiddly to get right in most languages, but Go’s concurrency primitives made it simple without any major architectural shift. Here’s how goroutines, channels, and sync.WaitGroup work together in the ingestion pipeline.]]></summary></entry><entry><title type="html">Publishing to the VS Code Marketplace with CI</title><link href="https://eozsahin1993.github.io/posts/2026/07/10/vscode-marketplace-managed-identity.html" rel="alternate" type="text/html" title="Publishing to the VS Code Marketplace with CI" /><published>2026-07-10T00:00:00+00:00</published><updated>2026-07-10T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2026/07/10/vscode-marketplace-managed-identity</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2026/07/10/vscode-marketplace-managed-identity.html"><![CDATA[<p>While setting up CI for <a href="https://marketplace.visualstudio.com/items?itemName=EmreOzsahin.lancedb-explorer">LanceDB Explorer</a>, a VS Code extension I built for browsing LanceDB databases, I wanted <code class="language-plaintext highlighter-rouge">git tag vX.Y.Z &amp;&amp; git push</code> to publish straight to the VS Code Marketplace.</p>

<p>The obvious way is a Personal Access Token: generate one in Azure DevOps, drop it in a GitHub secret, done. But global Azure DevOps PATs are being retired on December 1, 2026, and Microsoft’s <a href="https://code.visualstudio.com/api/working-with-extensions/publishing-extension">own publishing docs</a> now point everyone toward Entra ID instead: OIDC through a managed identity, a federated credential, and one undocumented API call to find the right ID. That page covers the Azure Pipelines version. I spent way more time than I expected getting this to actually work, mostly guessing at IDs the Marketplace would not recognize. This is the GitHub Actions version, spelled out the way I wish I had it going in.</p>

<h3 id="requirements">Requirements</h3>

<ul>
  <li>An Azure account with an active subscription. A free tier subscription is enough, a managed identity is a real Azure resource so it needs somewhere to live.</li>
  <li>A GitHub repo with Actions enabled, and permission to add repo secrets.</li>
  <li>A publisher created on <code class="language-plaintext highlighter-rouge">marketplace.visualstudio.com/manage</code> (sign in with a Microsoft account, <strong>+ Create publisher</strong>, pick an ID). Nothing else in this post works without this, the managed identity you set up later gets authorized against this specific publisher. Put its ID in your extension’s <code class="language-plaintext highlighter-rouge">publisher</code> field in <code class="language-plaintext highlighter-rouge">package.json</code>.</li>
  <li>The Azure CLI (<code class="language-plaintext highlighter-rouge">az</code>) if you want to run the identity lookup in step 4 locally instead of as a throwaway GitHub Actions job.</li>
</ul>

<h3 id="step-1-create-a-user-assigned-managed-identity-not-an-app-registration">Step 1: create a user-assigned managed identity, not an App Registration</h3>

<p>Use a managed identity, not an App Registration. An App Registration is free and needs no subscription, so it looks like the right choice, but it authenticates fine and then fails at the actual publish step with <code class="language-plaintext highlighter-rouge">InvalidAccessException: The requested operation is not allowed</code>. Only a managed identity works here.</p>

<ol>
  <li>Go to <code class="language-plaintext highlighter-rouge">portal.azure.com</code> and sign in.</li>
  <li>In the search bar at the top, type <strong>Managed Identities</strong> and click the matching result. Do not use the generic “Create a resource” button, it buries this under a category picker.</li>
  <li>Click <strong>+ Create</strong>.</li>
  <li>Fill in: your subscription, a resource group (create a new one if you do not have one already), a region (any region is fine), and a name for the identity (for example <code class="language-plaintext highlighter-rouge">vscode-publisher</code>).</li>
  <li>Click <strong>Review + create</strong>, then <strong>Create</strong>. Wait for the deployment to finish, then click <strong>Go to resource</strong>.</li>
</ol>

<h3 id="step-2-add-a-federated-credential-for-github-actions">Step 2: add a federated credential for GitHub Actions</h3>

<p>This step tells Azure to trust GitHub Actions, so it can hand out short-lived tokens without you storing a password anywhere.</p>

<ol>
  <li>On the same managed identity resource, in the left menu click <strong>Settings</strong>, then <strong>Federated credentials</strong>.</li>
  <li>Click <strong>+ Add credential</strong>.</li>
  <li>Under <strong>Federated credential scenario</strong>, choose <strong>GitHub Actions deploying Azure resources</strong>.</li>
  <li>Fill in:
    <ul>
      <li><strong>Organization</strong>: your GitHub username or org name</li>
      <li><strong>Repository</strong>: the name of your repo (just the repo name, not the full URL)</li>
      <li><strong>Entity type</strong>: choose <strong>Environment</strong></li>
      <li><strong>GitHub environment name</strong>: type a name for this, for example <code class="language-plaintext highlighter-rouge">marketplace-publish</code>. Write this down exactly, you will type it again later in your workflow file.</li>
    </ul>
  </li>
  <li>Give the credential a <strong>Name</strong> (any label works, for example <code class="language-plaintext highlighter-rouge">github-actions</code>) and click <strong>Add</strong>.</li>
</ol>

<p>Use <strong>Environment</strong> here, not <strong>Branch</strong> or <strong>Tag</strong>. If you pick Tag, the trust only matches one exact tag name, and it breaks the moment you push a second release.</p>

<h3 id="step-3-add-the-github-actions-secrets">Step 3: add the GitHub Actions secrets</h3>

<p>First grab the two values you need. On the managed identity resource, in the left menu click <strong>Settings</strong>, then <strong>Properties</strong>. Copy the values labeled <strong>Client ID</strong> and <strong>Tenant ID</strong>.</p>

<p>Then:</p>

<ol>
  <li>Open your repo on GitHub in a browser.</li>
  <li>Click the <strong>Settings</strong> tab (top of the repo page, not your account settings).</li>
  <li>In the left menu, click <strong>Secrets and variables</strong>, then <strong>Actions</strong>.</li>
  <li>Click <strong>New repository secret</strong>.</li>
  <li>Name it <code class="language-plaintext highlighter-rouge">AZURE_CLIENT_ID</code>, paste the Client ID, click <strong>Add secret</strong>.</li>
  <li>Click <strong>New repository secret</strong> again. Name it <code class="language-plaintext highlighter-rouge">AZURE_TENANT_ID</code>, paste the Tenant ID, click <strong>Add secret</strong>.</li>
</ol>

<p>Every <code class="language-plaintext highlighter-rouge">azure/login</code> step later in this post reads these two secrets by these exact names, so they need to exist before anything else here will work.</p>

<h3 id="step-4-find-the-id-the-marketplace-actually-wants">Step 4: find the ID the Marketplace actually wants</h3>

<p>This is the part that is not documented anywhere I could find. The VS Code Marketplace runs on Azure DevOps under the hood, and Azure DevOps keeps its own internal identity record, separate from both the managed identity’s ARM resource ID and its Entra Object ID. A managed identity that has never talked to Azure DevOps before does not have a profile there yet, so trying to add it to your publisher by either of those IDs will just come back “not found.”</p>

<p>The fix is one API call, made once, while authenticated as the identity:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>az rest <span class="nt">-u</span> https://app.vssps.visualstudio.com/_apis/profile/profiles/me <span class="se">\</span>
  <span class="nt">--resource</span> 499b84ac-1321-427f-aa17-267ca6975798
</code></pre></div></div>

<p>That GUID is Azure DevOps’s well-known app ID in Microsoft Entra, <a href="https://learn.microsoft.com/en-us/azure/devops/cli/entra-tokens?view=azure-devops">documented here</a> as the resource ID to use when requesting Entra tokens for Azure DevOps. It is the same for every organization, not something specific to your setup. Calling this endpoint registers the identity with Azure DevOps and returns its ID in Azure DevOps’s own terms:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"displayName"</span><span class="p">:</span><span class="w"> </span><span class="s2">"...</span><span class="se">\\</span><span class="s2">&lt;entra-object-id&gt;"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"&lt;the ID that actually works&gt;"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"publicAlias"</span><span class="p">:</span><span class="w"> </span><span class="s2">"&lt;same as id&gt;"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>The easiest way to run this once is a throwaway <code class="language-plaintext highlighter-rouge">workflow_dispatch</code> job:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">name</span><span class="pi">:</span> <span class="s">Debug Identity</span>
<span class="na">on</span><span class="pi">:</span> <span class="s">workflow_dispatch</span>
<span class="na">permissions</span><span class="pi">:</span>
  <span class="na">id-token</span><span class="pi">:</span> <span class="s">write</span>
  <span class="na">contents</span><span class="pi">:</span> <span class="s">read</span>
<span class="na">jobs</span><span class="pi">:</span>
  <span class="na">debug</span><span class="pi">:</span>
    <span class="na">runs-on</span><span class="pi">:</span> <span class="s">ubuntu-latest</span>
    <span class="na">environment</span><span class="pi">:</span> <span class="s">marketplace-publish</span>
    <span class="na">steps</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">uses</span><span class="pi">:</span> <span class="s">azure/login@v2</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">client-id</span><span class="pi">:</span> <span class="s">$</span>
          <span class="na">tenant-id</span><span class="pi">:</span> <span class="s">$</span>
          <span class="na">allow-no-subscriptions</span><span class="pi">:</span> <span class="kc">true</span>
      <span class="pi">-</span> <span class="na">run</span><span class="pi">:</span> <span class="s">az rest -u https://app.vssps.visualstudio.com/_apis/profile/profiles/me --resource 499b84ac-1321-427f-aa17-267ca6975798</span>
</code></pre></div></div>

<p>To run it:</p>

<ol>
  <li>Save that YAML as a new file, for example <code class="language-plaintext highlighter-rouge">.github/workflows/debug-identity.yml</code>, commit it, and push.</li>
  <li>On GitHub, click the <strong>Actions</strong> tab of your repo.</li>
  <li>In the left list of workflows, click <strong>Debug Identity</strong>.</li>
  <li>Click the <strong>Run workflow</strong> button, then confirm.</li>
  <li>Wait a few seconds, then click into the run that appears, then click the <strong>debug</strong> job.</li>
  <li>Expand the last step in the log. You will see a block of JSON, find the line that says <code class="language-plaintext highlighter-rouge">"id": "..."</code> and copy that value.</li>
  <li>Delete the workflow file and push again, you only need it this once.</li>
</ol>

<h3 id="step-5-authorize-the-identity-on-your-publisher">Step 5: authorize the identity on your publisher</h3>

<ol>
  <li>Go to <code class="language-plaintext highlighter-rouge">marketplace.visualstudio.com/manage</code>, sign in, and select your publisher.</li>
  <li>Look for a <strong>Members</strong> section (in some views this is under a settings or gear icon near the publisher name).</li>
  <li>Click <strong>Add</strong> (or the equivalent button to add a member).</li>
  <li>Paste the <code class="language-plaintext highlighter-rouge">id</code> value from step 4 into the search or ID field. Use that value specifically, not the managed identity’s Client ID, Tenant ID, or Resource ID, none of those are recognized here.</li>
  <li>Set the role to <strong>Contributor</strong> and save.</li>
</ol>

<p>If this does not find the identity, you likely pasted the wrong value. The only ID this search recognizes is the one from step 4’s API call.</p>

<h3 id="step-6-the-actual-publish-workflow">Step 6: the actual publish workflow</h3>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">permissions</span><span class="pi">:</span>
  <span class="na">id-token</span><span class="pi">:</span> <span class="s">write</span>
  <span class="na">contents</span><span class="pi">:</span> <span class="s">read</span>

<span class="na">jobs</span><span class="pi">:</span>
  <span class="na">publish</span><span class="pi">:</span>
    <span class="na">runs-on</span><span class="pi">:</span> <span class="s">ubuntu-latest</span>
    <span class="na">environment</span><span class="pi">:</span> <span class="s">marketplace-publish</span>
    <span class="na">steps</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/checkout@v4</span>
      <span class="pi">-</span> <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/setup-node@v4</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">node-version</span><span class="pi">:</span> <span class="m">20</span>
      <span class="pi">-</span> <span class="na">run</span><span class="pi">:</span> <span class="s">npm ci</span>
      <span class="pi">-</span> <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/download-artifact@v4</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">path</span><span class="pi">:</span> <span class="s">artifacts</span>
          <span class="na">merge-multiple</span><span class="pi">:</span> <span class="kc">true</span>
      <span class="pi">-</span> <span class="na">uses</span><span class="pi">:</span> <span class="s">azure/login@v2</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">client-id</span><span class="pi">:</span> <span class="s">$</span>
          <span class="na">tenant-id</span><span class="pi">:</span> <span class="s">$</span>
          <span class="na">allow-no-subscriptions</span><span class="pi">:</span> <span class="kc">true</span>
      <span class="pi">-</span> <span class="na">run</span><span class="pi">:</span> <span class="s">npx vsce publish --packagePath artifacts/*.vsix --skip-duplicate --azure-credential</span>
</code></pre></div></div>

<p>No <code class="language-plaintext highlighter-rouge">VSCE_PAT</code>, no client secret, nothing to rotate or expire. For the full CI/CD workflow, including the build matrix that produces <code class="language-plaintext highlighter-rouge">artifacts/*.vsix</code> in the first place, see <a href="https://github.com/eozsahin1993/lancedb-explorer/blob/main/.github/workflows/release.yml"><code class="language-plaintext highlighter-rouge">release.yml</code> in the LanceDB Explorer repo</a>.</p>

<h3 id="resources">Resources</h3>

<ul>
  <li><a href="https://code.visualstudio.com/api/working-with-extensions/publishing-extension">Publishing Extensions - VS Code API docs</a></li>
  <li><a href="https://learn.microsoft.com/en-us/rest/api/azure/devops/profile/profiles/get">Azure DevOps Profile REST API</a></li>
  <li><a href="https://learn.microsoft.com/en-us/azure/devops/cli/entra-tokens?view=azure-devops">Issue Entra tokens with Azure CLI - Azure DevOps</a></li>
  <li><a href="https://github.com/marketplace/actions/azure-login">azure/login GitHub Action</a></li>
</ul>

<p>Happy coding!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="DevOps" /><category term="Azure" /><category term="VS Code" /><category term="LanceDB" /><category term="VS Code Extension" /><summary type="html"><![CDATA[While setting up CI for LanceDB Explorer, a VS Code extension I built for browsing LanceDB databases, I wanted git tag vX.Y.Z &amp;&amp; git push to publish straight to the VS Code Marketplace.]]></summary></entry><entry><title type="html">Cutting Vercel Fluid CPU with Next.js Server-Side Caching</title><link href="https://eozsahin1993.github.io/posts/2026/07/06/vercel-fluid-cpu-nextjs-caching.html" rel="alternate" type="text/html" title="Cutting Vercel Fluid CPU with Next.js Server-Side Caching" /><published>2026-07-06T00:00:00+00:00</published><updated>2026-07-06T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2026/07/06/vercel-fluid-cpu-nextjs-caching</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2026/07/06/vercel-fluid-cpu-nextjs-caching.html"><![CDATA[<p>Got an email from Vercel about reaching limits and checked to see Fluid Active CPU spiking for <a href="https://www.worldcuppicks.co">worldcuppicks.co</a>. Obviously I don’t want to go to premium, so I implemented certain measures to bring it down. We are in the knockout rounds now, so I wanted to get it sorted before things got worse.</p>

<h3 id="first-identification">First identification</h3>

<p>Going to the Vercel Observability tab, I was able to see which page was causing the heavy load. The home page function was clocking nearly 3 minutes of active CPU time per billing window while every other route measured in seconds. That pointed me straight at the problem: the home page was doing two full database fetches on every single visit, for every user, with no caching in between.</p>

<div class="language-ts highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// This ran on every page visit, for every user</span>
<span class="kd">const</span> <span class="p">[</span><span class="nx">matches</span><span class="p">,</span> <span class="nx">predictions</span><span class="p">]</span> <span class="o">=</span> <span class="k">await</span> <span class="nb">Promise</span><span class="p">.</span><span class="nf">all</span><span class="p">([</span>
  <span class="nf">getAllMatches</span><span class="p">(),</span>
  <span class="nf">getAllMatchPredictions</span><span class="p">(),</span>
<span class="p">]);</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">getAllMatches</code> joins across three tables. <code class="language-plaintext highlighter-rouge">getAllMatchPredictions</code> pulls aggregate pick stats. Both were uncached, so every visit hit the database from scratch.</p>

<p>The second culprit was Sentry. I had it configured with a <code class="language-plaintext highlighter-rouge">tunnelRoute</code> that proxies Sentry events through a Vercel function at <code class="language-plaintext highlighter-rouge">/monitoring</code>. Every page load was generating an extra function invocation. I disabled Sentry entirely for now and that brought the baseline down.</p>

<h3 id="the-fix-unstable_cache">The fix: unstable_cache</h3>

<p>Next.js ships a function called <code class="language-plaintext highlighter-rouge">unstable_cache</code> that wraps any async function with a server-side cache. The result is shared across all users and all requests, not per session. The first request after a cache miss hits the database, and every subsequent request gets the cached result.</p>

<p>For matches I set <code class="language-plaintext highlighter-rouge">revalidate: false</code>, meaning the cache never expires on a timer:</p>

<div class="language-ts highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="kd">const</span> <span class="nx">getAllMatches</span> <span class="o">=</span> <span class="nf">unstable_cache</span><span class="p">(</span>
  <span class="k">async </span><span class="p">():</span> <span class="nb">Promise</span><span class="o">&lt;</span><span class="nx">Match</span><span class="p">[]</span><span class="o">&gt;</span> <span class="o">=&gt;</span> <span class="p">{</span>
    <span class="kd">const</span> <span class="nx">supabase</span> <span class="o">=</span> <span class="nf">getOrCreateAdminClient</span><span class="p">();</span>
    <span class="kd">const</span> <span class="p">{</span> <span class="nx">data</span> <span class="p">}</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">supabase</span>
      <span class="p">.</span><span class="k">from</span><span class="p">(</span><span class="dl">"</span><span class="s2">matches</span><span class="dl">"</span><span class="p">)</span>
      <span class="p">.</span><span class="nf">select</span><span class="p">(</span><span class="s2">`*, home_team:teams!home_team_id(...), away_team:teams!away_team_id(...)`</span><span class="p">)</span>
      <span class="p">.</span><span class="nf">order</span><span class="p">(</span><span class="dl">"</span><span class="s2">match_date</span><span class="dl">"</span><span class="p">,</span> <span class="p">{</span> <span class="na">ascending</span><span class="p">:</span> <span class="kc">true</span> <span class="p">});</span>
    <span class="k">return </span><span class="p">(</span><span class="nx">data</span> <span class="kd">as </span><span class="nx">Match</span><span class="p">[])</span> <span class="o">??</span> <span class="p">[];</span>
  <span class="p">},</span>
  <span class="p">[</span><span class="dl">"</span><span class="s2">all-matches</span><span class="dl">"</span><span class="p">],</span>
  <span class="p">{</span> <span class="na">revalidate</span><span class="p">:</span> <span class="kc">false</span><span class="p">,</span> <span class="na">tags</span><span class="p">:</span> <span class="p">[</span><span class="dl">"</span><span class="s2">matches</span><span class="dl">"</span><span class="p">]</span> <span class="p">}</span>
<span class="p">);</span>
</code></pre></div></div>

<p>Match data only changes when I update it from the admin panel, so a time-based TTL adds nothing. The admin server action calls <code class="language-plaintext highlighter-rouge">revalidateTag("matches")</code> the moment a match is saved, which busts the cache immediately:</p>

<div class="language-ts highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="p">{</span> <span class="nx">error</span> <span class="p">}</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">supabase</span><span class="p">.</span><span class="k">from</span><span class="p">(</span><span class="dl">"</span><span class="s2">matches</span><span class="dl">"</span><span class="p">).</span><span class="nf">update</span><span class="p">(</span><span class="nx">update</span><span class="p">).</span><span class="nf">eq</span><span class="p">(</span><span class="dl">"</span><span class="s2">id</span><span class="dl">"</span><span class="p">,</span> <span class="nx">matchId</span><span class="p">);</span>
<span class="k">if </span><span class="p">(</span><span class="nx">error</span><span class="p">)</span> <span class="k">throw</span> <span class="k">new</span> <span class="nc">Error</span><span class="p">(</span><span class="dl">"</span><span class="s2">Failed to update match</span><span class="dl">"</span><span class="p">);</span>
<span class="nf">revalidatePath</span><span class="p">(</span><span class="dl">"</span><span class="s2">/admin</span><span class="dl">"</span><span class="p">);</span>
<span class="nf">revalidateTag</span><span class="p">(</span><span class="dl">"</span><span class="s2">matches</span><span class="dl">"</span><span class="p">);</span>
<span class="nf">revalidateTag</span><span class="p">(</span><span class="dl">"</span><span class="s2">predictions</span><span class="dl">"</span><span class="p">);</span>
</code></pre></div></div>

<p>For prediction stats I went with a one-hour TTL as a fallback:</p>

<div class="language-ts highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="kd">const</span> <span class="nx">getAllMatchPredictions</span> <span class="o">=</span> <span class="nf">unstable_cache</span><span class="p">(</span>
  <span class="k">async </span><span class="p">():</span> <span class="nb">Promise</span><span class="o">&lt;</span><span class="nx">MatchPredictionStats</span><span class="p">[]</span><span class="o">&gt;</span> <span class="o">=&gt;</span> <span class="p">{</span>
    <span class="kd">const</span> <span class="nx">supabase</span> <span class="o">=</span> <span class="nf">getOrCreateAdminClient</span><span class="p">();</span>
    <span class="kd">const</span> <span class="p">{</span> <span class="nx">data</span> <span class="p">}</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">supabase</span><span class="p">.</span><span class="k">from</span><span class="p">(</span><span class="dl">"</span><span class="s2">match_predictions</span><span class="dl">"</span><span class="p">).</span><span class="nf">select</span><span class="p">(</span><span class="dl">"</span><span class="s2">*</span><span class="dl">"</span><span class="p">);</span>
    <span class="k">return </span><span class="p">(</span><span class="nx">data</span> <span class="o">??</span> <span class="p">[])</span> <span class="kd">as </span><span class="nx">MatchPredictionStats</span><span class="p">[];</span>
  <span class="p">},</span>
  <span class="p">[</span><span class="dl">"</span><span class="s2">all-match-predictions</span><span class="dl">"</span><span class="p">],</span>
  <span class="p">{</span> <span class="na">revalidate</span><span class="p">:</span> <span class="mi">3600</span><span class="p">,</span> <span class="na">tags</span><span class="p">:</span> <span class="p">[</span><span class="dl">"</span><span class="s2">predictions</span><span class="dl">"</span><span class="p">]</span> <span class="p">}</span>
<span class="p">);</span>
</code></pre></div></div>

<h3 id="why-stale-prediction-stats-are-fine">Why stale prediction stats are fine</h3>

<p>The obvious concern is that cached prediction percentages go stale. Won’t someone loading the page see wrong crowd percentages?</p>

<p>But the crowd percentage bar uses a Supabase realtime subscription on the client. The moment a pick is submitted, Supabase pushes the updated row to every connected browser over a WebSocket. The cached server data is only used for the initial SSR render. Within milliseconds of hydration, realtime takes over.</p>

<p>The user’s own pick is handled via optimistic local state, so it’s instant regardless:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">async</span> <span class="kd">function</span> <span class="nf">handlePick</span><span class="p">(</span><span class="nx">newPick</span><span class="p">:</span> <span class="nb">Pick</span><span class="p">)</span> <span class="p">{</span>
  <span class="nf">setPick</span><span class="p">(</span><span class="nx">newPick</span><span class="p">);</span> <span class="c1">// instant, before the server action returns</span>
  <span class="k">await</span> <span class="nf">submitPrediction</span><span class="p">(</span><span class="nx">matchId</span><span class="p">,</span> <span class="nx">newPick</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<h3 id="the-key-insight">The key insight</h3>

<p><code class="language-plaintext highlighter-rouge">unstable_cache</code> is shared across all requests on the server, not per session. Without it, every page visit queries the database for the exact same data. With it, it’s one query until the cache is busted. For match data that only changes when I update it from the admin panel, that’s the right trade.</p>

<p>Happy coding!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="Next.js" /><category term="Vercel" /><category term="Web" /><summary type="html"><![CDATA[Got an email from Vercel about reaching limits and checked to see Fluid Active CPU spiking for worldcuppicks.co. Obviously I don’t want to go to premium, so I implemented certain measures to bring it down. We are in the knockout rounds now, so I wanted to get it sorted before things got worse.]]></summary></entry><entry><title type="html">TIL: Streaming Data in Go with iter and yield</title><link href="https://eozsahin1993.github.io/posts/2026/07/03/go-iter-yield.html" rel="alternate" type="text/html" title="TIL: Streaming Data in Go with iter and yield" /><published>2026-07-03T00:00:00+00:00</published><updated>2026-07-03T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2026/07/03/go-iter-yield</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2026/07/03/go-iter-yield.html"><![CDATA[<p>While building <a href="https://github.com/eozsahin1993/ragpack">RagPack</a>, a library that chunks files for embedding, I needed a common way to stream parsed content from multiple file formats. RagPack supports CSV, PDF, DOCX, HTML, XLSX, Markdown, JSON and more. Each format has its own parser, but the ingester that consumes them should not care which one it is talking to. I needed a shared contract. In Java I would have reached for an <code class="language-plaintext highlighter-rouge">Iterator&lt;T&gt;</code> or an <code class="language-plaintext highlighter-rouge">InputStream</code>, but in Go the answer turned out to be the <code class="language-plaintext highlighter-rouge">iter</code> package, introduced in Go 1.23.</p>

<h3 id="the-parser-interface">The Parser interface</h3>

<p>The <code class="language-plaintext highlighter-rouge">iter</code> package introduces two types. <code class="language-plaintext highlighter-rouge">Seq[V]</code> yields a single value at a time, and <code class="language-plaintext highlighter-rouge">Seq2[K, V]</code> yields a pair:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">type</span> <span class="n">Seq</span><span class="p">[</span><span class="n">V</span> <span class="n">any</span><span class="p">]</span>     <span class="k">func</span><span class="p">(</span><span class="n">yield</span> <span class="k">func</span><span class="p">(</span><span class="n">V</span><span class="p">)</span> <span class="kt">bool</span><span class="p">)</span>
<span class="k">type</span> <span class="n">Seq2</span><span class="p">[</span><span class="n">K</span><span class="p">,</span> <span class="n">V</span> <span class="n">any</span><span class="p">]</span> <span class="k">func</span><span class="p">(</span><span class="n">yield</span> <span class="k">func</span><span class="p">(</span><span class="n">K</span><span class="p">,</span> <span class="n">V</span><span class="p">)</span> <span class="kt">bool</span><span class="p">)</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">Seq2</code> is the right fit here because each iteration naturally produces two things: a parsed unit and any read error. This matches Go’s standard <code class="language-plaintext highlighter-rouge">(value, error)</code> convention and lets the caller handle errors inline without wrapping them in a struct.</p>

<p>That made <code class="language-plaintext highlighter-rouge">iter.Seq2[Unit, error]</code> a natural return type for the <code class="language-plaintext highlighter-rouge">Parser</code> interface:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">type</span> <span class="n">Parser</span> <span class="k">interface</span> <span class="p">{</span>
    <span class="n">Parse</span><span class="p">(</span><span class="n">ctx</span> <span class="n">context</span><span class="o">.</span><span class="n">Context</span><span class="p">,</span> <span class="n">r</span> <span class="n">io</span><span class="o">.</span><span class="n">ReadCloser</span><span class="p">)</span> <span class="n">iter</span><span class="o">.</span><span class="n">Seq2</span><span class="p">[</span><span class="n">Unit</span><span class="p">,</span> <span class="kt">error</span><span class="p">]</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Every sub-parser, <code class="language-plaintext highlighter-rouge">CSVParser</code>, <code class="language-plaintext highlighter-rouge">PDFParser</code>, <code class="language-plaintext highlighter-rouge">DocxParser</code>, <code class="language-plaintext highlighter-rouge">HTMLParser</code> and so on, implements this one method. The ingester does not need to know which format it is dealing with.</p>

<h3 id="implementing-a-parser">Implementing a parser</h3>

<p>Here is what a parser implementation looks like:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">func</span> <span class="p">(</span><span class="n">p</span> <span class="o">*</span><span class="n">Parser</span><span class="p">)</span> <span class="n">Parse</span><span class="p">(</span><span class="n">_</span> <span class="n">context</span><span class="o">.</span><span class="n">Context</span><span class="p">,</span> <span class="n">r</span> <span class="n">io</span><span class="o">.</span><span class="n">ReadCloser</span><span class="p">)</span> <span class="n">iter</span><span class="o">.</span><span class="n">Seq2</span><span class="p">[</span><span class="n">Unit</span><span class="p">,</span> <span class="kt">error</span><span class="p">]</span> <span class="p">{</span>
    <span class="k">return</span> <span class="k">func</span><span class="p">(</span><span class="n">yield</span> <span class="k">func</span><span class="p">(</span><span class="n">Unit</span><span class="p">,</span> <span class="kt">error</span><span class="p">)</span> <span class="kt">bool</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">defer</span> <span class="n">r</span><span class="o">.</span><span class="n">Close</span><span class="p">()</span>

        <span class="n">reader</span> <span class="o">:=</span> <span class="n">bufio</span><span class="o">.</span><span class="n">NewReader</span><span class="p">(</span><span class="n">r</span><span class="p">)</span>
        <span class="k">for</span> <span class="p">{</span>
            <span class="n">line</span><span class="p">,</span> <span class="n">err</span> <span class="o">:=</span> <span class="n">reader</span><span class="o">.</span><span class="n">ReadString</span><span class="p">(</span><span class="sc">'\n'</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">err</span> <span class="o">==</span> <span class="n">io</span><span class="o">.</span><span class="n">EOF</span> <span class="p">{</span>
                <span class="k">break</span>
            <span class="p">}</span>
            <span class="k">if</span> <span class="n">err</span> <span class="o">!=</span> <span class="no">nil</span> <span class="p">{</span>
                <span class="n">yield</span><span class="p">(</span><span class="n">Unit</span><span class="p">{},</span> <span class="n">err</span><span class="p">)</span>
                <span class="k">return</span>
            <span class="p">}</span>
            <span class="k">if</span> <span class="o">!</span><span class="n">yield</span><span class="p">(</span><span class="n">Unit</span><span class="p">{</span><span class="n">Text</span><span class="o">:</span> <span class="n">strings</span><span class="o">.</span><span class="n">TrimRight</span><span class="p">(</span><span class="n">line</span><span class="p">,</span> <span class="s">"</span><span class="se">\n</span><span class="s">"</span><span class="p">)},</span> <span class="no">nil</span><span class="p">)</span> <span class="p">{</span>
                <span class="k">return</span>
            <span class="p">}</span>
        <span class="p">}</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">if !yield(...) { return }</code> part is the key. If the caller breaks out of the loop early, <code class="language-plaintext highlighter-rouge">yield</code> returns <code class="language-plaintext highlighter-rouge">false</code> and we stop reading. No wasted work.</p>

<h3 id="using-it-with-range">Using it with range</h3>

<p>Because all parsers return the same type, the ingester ranges over any of them the same way:</p>

<div class="language-go highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">for</span> <span class="n">unit</span><span class="p">,</span> <span class="n">err</span> <span class="o">:=</span> <span class="k">range</span> <span class="n">parser</span><span class="o">.</span><span class="n">Parse</span><span class="p">(</span><span class="n">ctx</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span> <span class="p">{</span>
    <span class="k">if</span> <span class="n">err</span> <span class="o">!=</span> <span class="no">nil</span> <span class="p">{</span>
        <span class="c">// handle error</span>
    <span class="p">}</span>
    <span class="n">embed</span><span class="p">(</span><span class="n">unit</span><span class="p">)</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Swap in a different parser and the loop does not change. That is one big win. Memory was also in our minds when designing this. For streaming formats like CSV, JSON, or plain text, yielding one unit at a time keeps the footprint flat no matter how large the file is. For formats like PDF it is a bit more nuanced since the underlying parser has to load the full file first to parse it.</p>

<p>Happy coding!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="Today I learned" /><category term="Go" /><summary type="html"><![CDATA[While building RagPack, a library that chunks files for embedding, I needed a common way to stream parsed content from multiple file formats. RagPack supports CSV, PDF, DOCX, HTML, XLSX, Markdown, JSON and more. Each format has its own parser, but the ingester that consumes them should not care which one it is talking to. I needed a shared contract. In Java I would have reached for an Iterator&lt;T&gt; or an InputStream, but in Go the answer turned out to be the iter package, introduced in Go 1.23.]]></summary></entry><entry><title type="html">Publishing to npm Without Storing a Token</title><link href="https://eozsahin1993.github.io/posts/2026/06/26/npm-trusted-publishing.html" rel="alternate" type="text/html" title="Publishing to npm Without Storing a Token" /><published>2026-06-26T00:00:00+00:00</published><updated>2026-06-26T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2026/06/26/npm-trusted-publishing</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2026/06/26/npm-trusted-publishing.html"><![CDATA[<p>When setting up CI/CD for <a href="https://github.com/eozsahin1993/ragpack">RagPack</a>, I wanted to publish to npm from GitHub Actions without storing a long-lived token as a secret. Tokens are annoying: they expire, need rotating, and if they leak you have a problem.</p>

<p>Turns out there is already a feature in npm called <strong>trusted publishing</strong>, and it uses OIDC to let GitHub Actions authenticate directly with npm, no <code class="language-plaintext highlighter-rouge">NPM_TOKEN</code> required.</p>

<p>Here’s what the setup actually looks like, including a few things the docs gloss over.</p>

<h3 id="how-it-works">How it works</h3>

<p>Instead of a static token, GitHub Actions gets a short-lived OIDC token for each run. npm verifies that token came from the specific repo and workflow you authorized, then allows the publish. The token is scoped to that single job and can’t be extracted or reused.</p>

<h3 id="requirements">Requirements</h3>

<ul>
  <li>npm CLI <strong>11.5.1</strong> or later</li>
  <li>Node <strong>24</strong> or later (Node 22 is not sufficient — use 24)</li>
  <li><code class="language-plaintext highlighter-rouge">actions/setup-node</code> <strong>v6</strong> or later</li>
</ul>

<p>If you pin an older Node version or an older version of <code class="language-plaintext highlighter-rouge">setup-node</code>, it won’t work.</p>

<h3 id="step-1-configure-trusted-publishers-on-npmjscom">Step 1: Configure trusted publishers on npmjs.com</h3>

<p>This is the step the docs bury. You need to do this <strong>per package</strong>, on the package’s own settings page, not in your account settings.</p>

<p>Go to <code class="language-plaintext highlighter-rouge">npmjs.com/package/&lt;your-package&gt;</code>, click the <strong>Settings</strong> tab, find <strong>Publishing access</strong>, and add a trusted publisher. For GitHub Actions:</p>

<ul>
  <li><strong>Owner:</strong> your GitHub username or org</li>
  <li><strong>Repository:</strong> the repo name</li>
  <li><strong>Workflow:</strong> the filename of your workflow (e.g. <code class="language-plaintext highlighter-rouge">publish-cli.yml</code>)</li>
  <li><strong>Environment:</strong> leave blank unless you use GitHub environments</li>
</ul>

<p>If you have multiple packages in the same monorepo (like I do, a CLI and a JS SDK), you repeat this for each package but point to the respective workflow file.</p>

<h3 id="step-2-update-your-workflow">Step 2: Update your workflow</h3>

<p>You need <code class="language-plaintext highlighter-rouge">id-token: write</code> permission so the job can request an OIDC token. Then just run <code class="language-plaintext highlighter-rouge">npm publish --access public</code>, no <code class="language-plaintext highlighter-rouge">NODE_AUTH_TOKEN</code>, no secrets.</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">name</span><span class="pi">:</span> <span class="s">Publish CLI</span>

<span class="na">on</span><span class="pi">:</span>
  <span class="na">push</span><span class="pi">:</span>
    <span class="na">tags</span><span class="pi">:</span> <span class="pi">[</span><span class="s1">'</span><span class="s">cli/v*.*.*'</span><span class="pi">]</span>

<span class="na">permissions</span><span class="pi">:</span>
  <span class="na">id-token</span><span class="pi">:</span> <span class="s">write</span>
  <span class="na">contents</span><span class="pi">:</span> <span class="s">write</span>

<span class="na">jobs</span><span class="pi">:</span>
  <span class="na">publish</span><span class="pi">:</span>
    <span class="na">runs-on</span><span class="pi">:</span> <span class="s">ubuntu-latest</span>
    <span class="na">defaults</span><span class="pi">:</span>
      <span class="na">run</span><span class="pi">:</span>
        <span class="na">working-directory</span><span class="pi">:</span> <span class="s">cli</span>

    <span class="na">steps</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/checkout@v6</span>

      <span class="pi">-</span> <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/setup-node@v6</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">node-version</span><span class="pi">:</span> <span class="s1">'</span><span class="s">24'</span>
          <span class="na">registry-url</span><span class="pi">:</span> <span class="s1">'</span><span class="s">https://registry.npmjs.org'</span>
          <span class="na">package-manager-cache</span><span class="pi">:</span> <span class="kc">false</span>

      <span class="pi">-</span> <span class="na">run</span><span class="pi">:</span> <span class="s">npm ci</span>

      <span class="pi">-</span> <span class="na">run</span><span class="pi">:</span> <span class="s">npm publish --access public</span>
</code></pre></div></div>

<p>That’s it. No secrets to manage.</p>

<h3 id="keeping-tags-in-sync-with-packagejson">Keeping tags in sync with package.json</h3>

<p>One gotcha with tag-triggered workflows: the tag is just a trigger. Nothing enforces that <code class="language-plaintext highlighter-rouge">cli/v0.2.0</code> matches <code class="language-plaintext highlighter-rouge">"version": "0.2.0"</code> in <code class="language-plaintext highlighter-rouge">package.json</code>. They can silently drift.</p>

<p>I added a version check step that fails the job early if they don’t match:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Verify version matches tag</span>
  <span class="na">run</span><span class="pi">:</span> <span class="pi">|</span>
    <span class="s">PKG_VERSION="v$(node -p "require('./package.json').version")"</span>
    <span class="s">TAG_VERSION="${GITHUB_REF_NAME#cli/}"</span>
    <span class="s">if [ "$PKG_VERSION" != "$TAG_VERSION" ]; then</span>
      <span class="s">echo "Version mismatch: package.json=$PKG_VERSION tag=$TAG_VERSION"</span>
      <span class="s">exit 1</span>
    <span class="s">fi</span>
</code></pre></div></div>

<p>The release process then becomes: bump the version in <code class="language-plaintext highlighter-rouge">package.json</code>, commit, push, tag. If the version and tag don’t match you get a clear error instead of publishing the wrong version silently.</p>

<h3 id="first-publish">First publish</h3>

<p>One thing worth knowing: trusted publishing works for subsequent publishes but the package still needs to exist on npm first. For a brand new package, do a one-time manual publish from your machine:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>npm login
npm publish <span class="nt">--access</span> public
</code></pre></div></div>

<p>After that, the CI workflow handles everything.</p>

<h3 id="the-result">The result</h3>

<p>The packages page on npm now shows a provenance badge. Users can see exactly which commit and GitHub Actions run produced each version. And there are no tokens to rotate, expire, or accidentally commit.</p>

<p>Happy coding!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="npm" /><category term="DevOps" /><summary type="html"><![CDATA[When setting up CI/CD for RagPack, I wanted to publish to npm from GitHub Actions without storing a long-lived token as a secret. Tokens are annoying: they expire, need rotating, and if they leak you have a problem.]]></summary></entry><entry><title type="html">Using pg_cron for Match Notifications</title><link href="https://eozsahin1993.github.io/posts/2026/06/16/postgres-extensions.html" rel="alternate" type="text/html" title="Using pg_cron for Match Notifications" /><published>2026-06-16T00:00:00+00:00</published><updated>2026-06-16T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2026/06/16/postgres-extensions</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2026/06/16/postgres-extensions.html"><![CDATA[<p>While working on my side project, <a href="https://www.worldcuppicks.co">worldcuppicks.co</a> (a site where you predict World Cup games), I needed to add web push notifications. To build this, I used a Postgres extension I’d been wanting to try: <code class="language-plaintext highlighter-rouge">pg_cron</code>. It ended up doing more than I expected, so I wanted to write about it.</p>

<p><code class="language-plaintext highlighter-rouge">pg_cron</code> lets you schedule cron jobs directly inside the database. World Cup matches kick off on a fixed schedule, and I wanted a notification to fire 10 minutes before each one. I could have wired this up externally, with something like AWS EventBridge, but doing it inside Postgres turned out to be much simpler.</p>

<h3 id="why-pg_cron">Why pg_cron?</h3>

<p>Deciding whether to fire a notification, and what to put in it, depends entirely on the match schedule, which already lives in the database. An external scheduler would just turn around and hit an API to ask the database the same question. So instead of standing up a separate service for that, it only takes a few lines of SQL:</p>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">CREATE</span> <span class="n">EXTENSION</span> <span class="n">IF</span> <span class="k">NOT</span> <span class="k">EXISTS</span> <span class="n">pg_cron</span><span class="p">;</span>

<span class="k">SELECT</span> <span class="n">cron</span><span class="p">.</span><span class="n">schedule</span><span class="p">(</span>
  <span class="s1">'notify-upcoming-matches'</span><span class="p">,</span>
  <span class="s1">'50 * * * *'</span><span class="p">,</span>
  <span class="err">$$</span>
    <span class="k">INSERT</span> <span class="k">INTO</span> <span class="n">match_notifications</span> <span class="p">(</span><span class="n">match_id</span><span class="p">,</span> <span class="n">status</span><span class="p">,</span> <span class="n">scheduled_at</span><span class="p">)</span>
    <span class="k">SELECT</span>
      <span class="n">id</span><span class="p">,</span> <span class="s1">'scheduled'</span><span class="p">,</span> <span class="n">now</span><span class="p">()</span>
    <span class="k">FROM</span> <span class="n">matches</span>
    <span class="k">WHERE</span>
      <span class="n">match_date</span> <span class="k">BETWEEN</span> <span class="n">now</span><span class="p">()</span> <span class="k">AND</span> <span class="n">now</span><span class="p">()</span> <span class="o">+</span> <span class="n">interval</span> <span class="s1">'20 minutes'</span>
      <span class="k">AND</span> <span class="n">id</span> <span class="k">NOT</span> <span class="k">IN</span> <span class="p">(</span><span class="k">SELECT</span> <span class="n">match_id</span> <span class="k">FROM</span> <span class="n">match_notifications</span><span class="p">)</span>
    <span class="k">ON</span> <span class="n">CONFLICT</span> <span class="k">DO</span> <span class="k">NOTHING</span><span class="p">;</span>
  <span class="err">$$</span>
<span class="p">);</span>
</code></pre></div></div>

<p>This job fires at exactly the 50th minute of every hour and inserts a row into <code class="language-plaintext highlighter-rouge">match_notifications</code> for each match that’s about to kick off and hasn’t been notified yet. From there, all you need is a database webhook on INSERTs to that table, which calls a lambda/edge function to actually send the push notification.</p>

<p>Normally, scheduling something like this needs separate infrastructure, but with pg_cron it lives entirely inside Postgres. Happy coding!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="Postgres" /><summary type="html"><![CDATA[While working on my side project, worldcuppicks.co (a site where you predict World Cup games), I needed to add web push notifications. To build this, I used a Postgres extension I’d been wanting to try: pg_cron. It ended up doing more than I expected, so I wanted to write about it.]]></summary></entry><entry><title type="html">TIL: Server vs Client Components in Next.js</title><link href="https://eozsahin1993.github.io/posts/2026/06/08/nextjs-server-client-components.html" rel="alternate" type="text/html" title="TIL: Server vs Client Components in Next.js" /><published>2026-06-08T00:00:00+00:00</published><updated>2026-06-08T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2026/06/08/nextjs-server-client-components</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2026/06/08/nextjs-server-client-components.html"><![CDATA[<p>For <a href="https://www.worldcuppicks.co">worldcuppicks.co</a>, my World Cup prediction site, I used Next.js for the frontend. It comes with file based routing and built in image optimization, and the App Router makes data fetching simple. What I didn’t realize until I started building real pages was how much of the app could ship with zero client side JavaScript, because of how Server and Client Components work.</p>

<p>Coming from a React background where everything renders in the browser, my first instinct was to add <code class="language-plaintext highlighter-rouge">"use client"</code> to every file out of habit. Today I learned that’s the wrong default, so I wanted to write about why, using a couple of components from the app.</p>

<h3 id="server-components-by-default">Server Components by default</h3>

<p>Here’s the page that lists a user’s picks:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="k">default</span> <span class="k">async</span> <span class="kd">function</span> <span class="nf">PicksPage</span><span class="p">()</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="p">[</span><span class="nx">translate</span><span class="p">,</span> <span class="nx">user</span><span class="p">]</span> <span class="o">=</span> <span class="k">await</span> <span class="nb">Promise</span><span class="p">.</span><span class="nf">all</span><span class="p">([</span><span class="nf">getTranslations</span><span class="p">(</span><span class="dl">"</span><span class="s2">picks</span><span class="dl">"</span><span class="p">),</span> <span class="nf">getUser</span><span class="p">()]);</span>
  <span class="k">if </span><span class="p">(</span><span class="o">!</span><span class="nx">user</span><span class="p">)</span> <span class="nf">redirect</span><span class="p">(</span><span class="dl">"</span><span class="s2">/</span><span class="dl">"</span><span class="p">);</span>

  <span class="kd">const</span> <span class="p">[</span><span class="nx">predictions</span><span class="p">,</span> <span class="nx">completedMatchCount</span><span class="p">]</span> <span class="o">=</span> <span class="k">await</span> <span class="nb">Promise</span><span class="p">.</span><span class="nf">all</span><span class="p">([</span>
    <span class="nf">getUserPredictions</span><span class="p">(</span><span class="nx">user</span><span class="p">.</span><span class="nx">userId</span><span class="p">),</span>
    <span class="nf">getCompletedMatchCount</span><span class="p">(),</span>
  <span class="p">]);</span>

  <span class="c1">// ...compute stats from predictions...</span>

  <span class="k">return </span><span class="p">(</span>
    <span class="p">&lt;</span><span class="nt">div</span><span class="p">&gt;</span>
      <span class="p">&lt;</span><span class="nc">Heading</span><span class="p">&gt;</span><span class="si">{</span><span class="nf">translate</span><span class="p">(</span><span class="dl">"</span><span class="s2">heading</span><span class="dl">"</span><span class="p">)</span><span class="si">}</span><span class="p">&lt;/</span><span class="nc">Heading</span><span class="p">&gt;</span>
      <span class="p">&lt;</span><span class="nc">PicksStatsBanner</span> <span class="na">stats</span><span class="p">=</span><span class="si">{</span><span class="nx">stats</span><span class="si">}</span> <span class="p">/&gt;</span>
      <span class="p">&lt;</span><span class="nc">PredictionList</span> <span class="na">predictions</span><span class="p">=</span><span class="si">{</span><span class="nx">upcoming</span><span class="si">}</span> <span class="p">/&gt;</span>
    <span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
  <span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>No <code class="language-plaintext highlighter-rouge">useEffect</code>, no loading state, no client side data fetching library. It’s an <code class="language-plaintext highlighter-rouge">async</code> function that awaits the data it needs and renders. This is the default for every component in the App Router unless you say otherwise. It runs on the server, and none of this code gets sent to the browser at all.</p>

<h3 id="only-the-interactive-part-needs-to-be-a-client-component">Only the interactive part needs to be a Client Component</h3>

<p>The match card is where this really clicked for me. A card shows team flags, localized names, the score, and a voting widget. Only one of those things is actually interactive: the voting widget needs to hold state for the current pick and listen for live score updates.</p>

<p>So <code class="language-plaintext highlighter-rouge">MatchCard</code> stays a Server Component. It resolves translations, locale, and country names, then renders the static shell:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="k">default</span> <span class="k">async</span> <span class="kd">function</span> <span class="nf">MatchCard</span><span class="p">(</span><span class="nx">props</span><span class="p">:</span> <span class="nx">MatchCardModel</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="p">[</span><span class="nx">t</span><span class="p">,</span> <span class="nx">locale</span><span class="p">,</span> <span class="nx">localizedRound</span><span class="p">]</span> <span class="o">=</span> <span class="k">await</span> <span class="nb">Promise</span><span class="p">.</span><span class="nf">all</span><span class="p">([</span>
    <span class="nf">getTranslations</span><span class="p">(</span><span class="dl">"</span><span class="s2">matchCard</span><span class="dl">"</span><span class="p">),</span>
    <span class="nf">getLocale</span><span class="p">(),</span>
    <span class="nf">localizeRound</span><span class="p">(</span><span class="nx">props</span><span class="p">.</span><span class="nx">round</span><span class="p">),</span>
  <span class="p">]);</span>

  <span class="k">return </span><span class="p">(</span>
    <span class="p">&lt;</span><span class="nt">div</span><span class="p">&gt;</span>
      <span class="p">&lt;</span><span class="nc">TeamDisplay</span> <span class="na">team</span><span class="p">=</span><span class="si">{</span><span class="nx">props</span><span class="p">.</span><span class="nx">homeTeam</span><span class="si">}</span> <span class="err">...</span> <span class="p">/&gt;</span>
      <span class="p">&lt;</span><span class="nc">MatchCardScoreClient</span> <span class="na">matchId</span><span class="p">=</span><span class="si">{</span><span class="nx">props</span><span class="p">.</span><span class="nx">matchId</span><span class="si">}</span> <span class="err">...</span> <span class="p">/&gt;</span>
      <span class="p">&lt;</span><span class="nc">TeamDisplay</span> <span class="na">team</span><span class="p">=</span><span class="si">{</span><span class="nx">props</span><span class="p">.</span><span class="nx">awayTeam</span><span class="si">}</span> <span class="err">...</span> <span class="p">/&gt;</span>
      <span class="p">&lt;</span><span class="nc">MatchCardClient</span> <span class="na">matchId</span><span class="p">=</span><span class="si">{</span><span class="nx">props</span><span class="p">.</span><span class="nx">matchId</span><span class="si">}</span> <span class="err">...</span> <span class="p">/&gt;</span>
    <span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
  <span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>And <code class="language-plaintext highlighter-rouge">MatchCardClient</code> only owns the part that actually needs to run in the browser: local state for the pick, a realtime subscription for live score updates, and the click handlers:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="dl">"</span><span class="s2">use client</span><span class="dl">"</span><span class="p">;</span>

<span class="k">export</span> <span class="k">default</span> <span class="kd">function</span> <span class="nf">MatchCardClient</span><span class="p">({</span> <span class="nx">matchId</span><span class="p">,</span> <span class="nx">homeTeam</span><span class="p">,</span> <span class="nx">awayTeam</span><span class="p">,</span> <span class="nx">initialPick</span><span class="p">,</span> <span class="p">...</span> <span class="p">}:</span> <span class="nx">Props</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="p">[</span><span class="nx">pick</span><span class="p">,</span> <span class="nx">setPick</span><span class="p">]</span> <span class="o">=</span> <span class="nx">useState</span><span class="o">&lt;</span><span class="nb">Pick</span> <span class="o">|</span> <span class="kc">null</span><span class="o">&gt;</span><span class="p">(</span><span class="nx">initialPick</span><span class="p">);</span>
  <span class="kd">const</span> <span class="p">{</span> <span class="nx">status</span><span class="p">,</span> <span class="nx">home_points</span><span class="p">,</span> <span class="nx">draw_points</span><span class="p">,</span> <span class="nx">away_points</span> <span class="p">}</span> <span class="o">=</span> <span class="nf">useMatchesRealtime</span><span class="p">(</span><span class="nx">matchId</span><span class="p">,</span> <span class="p">{</span> <span class="p">...</span> <span class="p">});</span>

  <span class="k">async</span> <span class="kd">function</span> <span class="nf">handlePick</span><span class="p">(</span><span class="nx">newPick</span><span class="p">:</span> <span class="nb">Pick</span><span class="p">)</span> <span class="p">{</span>
    <span class="nf">setPick</span><span class="p">(</span><span class="nx">newPick</span><span class="p">);</span>
    <span class="k">await</span> <span class="nf">submitPrediction</span><span class="p">(</span><span class="nx">matchId</span><span class="p">,</span> <span class="nx">newPick</span><span class="p">);</span>
  <span class="p">}</span>

  <span class="k">return</span> <span class="nx">votingOpen</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">pick</span>
    <span class="p">?</span> <span class="p">&lt;</span><span class="nc">VotingSelector</span> <span class="na">onPick</span><span class="p">=</span><span class="si">{</span><span class="nx">handlePick</span><span class="si">}</span> <span class="err">...</span> <span class="p">/&gt;</span>
    <span class="p">:</span> <span class="p">&lt;</span><span class="nc">VotingSummary</span> <span class="na">pick</span><span class="p">=</span><span class="si">{</span><span class="nx">pick</span><span class="si">}</span> <span class="err">...</span> <span class="p">/&gt;;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Everything above the <code class="language-plaintext highlighter-rouge">MatchCardClient</code> part (the flags, the translated team names, the round label) gets rendered to HTML on the server and never needs to be re run or hydrated as JavaScript. Only the voting widget ships JS to the browser.</p>

<h3 id="why-this-matters">Why this matters</h3>

<p>A few things became obvious once I started thinking about this split instead of defaulting to client everywhere:</p>

<ul>
  <li><strong>Less JS shipped.</strong> A page full of match cards mostly ships HTML, and the JS bundle only includes the bits that actually need interactivity. Since Server Component code never goes to the client, its dependencies don’t get bundled either.</li>
  <li><strong>No hydration cost.</strong> Client Components have to be downloaded, parsed, executed, and hydrated before they’re interactive. Server Components skip all of that since they’re already just HTML by the time they reach the browser.</li>
  <li><strong>Simpler data fetching.</strong> Server Components can just await your data layer directly, so there’s no loading spinners or client side fetch waterfalls for content that doesn’t change per interaction.</li>
  <li><strong>Real content for crawlers.</strong> The match cards and picks are real HTML in the response, not something that only shows up after JS runs, which is better for SEO and link previews.</li>
  <li><strong>Caching.</strong> Server rendered output can be cached at the route level or at the CDN, so repeat visits don’t redo the same data fetch and render every time.</li>
</ul>

<p>For every component, I now ask whether it actually needs to run in the browser instead of assuming it does. Translations, formatting, and static markup almost never do.</p>

<p>Happy coding!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="Today I learned" /><category term="Next.js" /><category term="React" /><summary type="html"><![CDATA[For worldcuppicks.co, my World Cup prediction site, I used Next.js for the frontend. It comes with file based routing and built in image optimization, and the App Router makes data fetching simple. What I didn’t realize until I started building real pages was how much of the app could ship with zero client side JavaScript, because of how Server and Client Components work.]]></summary></entry><entry><title type="html">TIL: Finding the Buggy Commit with Git Bisect</title><link href="https://eozsahin1993.github.io/posts/2025/07/03/finding-the-bad-commit.html" rel="alternate" type="text/html" title="TIL: Finding the Buggy Commit with Git Bisect" /><published>2025-07-03T00:00:00+00:00</published><updated>2025-07-03T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2025/07/03/finding-the-bad-commit</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2025/07/03/finding-the-bad-commit.html"><![CDATA[<p>On a Thursday night right before the 4th of July, I was going through PRs when I suddenly realized that our standard charts had their top padding completely missing. Usually, this would be easy to spot, but our web code is pretty complicated, so in the first 15 minutes, we couldn’t figure out the problem.</p>

<p>I thought, there must be an easier way to spot this issue than going through commits one by one. That’s when I discovered the magical tool called <code class="language-plaintext highlighter-rouge">git bisect</code>.</p>

<h3 id="git-bisect">Git Bisect</h3>

<p>How <code class="language-plaintext highlighter-rouge">git bisect</code> works is brilliant, and it probably saved me at least an hour. You start by identifying a commit in the history where everything was working correctly, and a bad commit (usually the current one) where the problem exists. Internally, it uses a binary search to find the faulty commit, so you don’t have to check each commit individually.</p>

<p>For the geeks out there, binary search has a runtime complexity of <strong>O(log n)</strong> instead of the linear <strong>O(n)</strong> you’d get going commit by commit. So if I had 100 commits, with binary search, it would take me around <strong>log₂(100) ≈ 6.6</strong> attempts to find the culprit — pretty awesome!</p>

<h3 id="in-action">In action</h3>

<p>Start the git bisect process:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git bisect start
</code></pre></div></div>

<p>Mark the current commit as bad:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git bisect bad
</code></pre></div></div>

<p>Mark a known good commit in history (for me, this was a commit from 4 days ago):</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git bisect good &lt;commit-hash&gt;
</code></pre></div></div>

<p>Git will now check out a commit halfway between the good and bad commits and ask you to test it.</p>

<p>After testing, tell git whether this commit is good or bad:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git bisect good &lt;commit-hash&gt;
</code></pre></div></div>
<p>or</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git bisect bad &lt;commit-hash&gt;
</code></pre></div></div>

<p>Repeat this process until git finds the exact commit that introduced the issue.</p>

<p>In my case, I had 33 commits to check, and it took only 5 attempts to find the bad one — much faster than testing all commits one by one!</p>

<p>That’s all for today. Happy coding!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="Today I learned" /><category term="Git" /><summary type="html"><![CDATA[On a Thursday night right before the 4th of July, I was going through PRs when I suddenly realized that our standard charts had their top padding completely missing. Usually, this would be easy to spot, but our web code is pretty complicated, so in the first 15 minutes, we couldn’t figure out the problem.]]></summary></entry><entry><title type="html">TIL: React Class vs Function Components</title><link href="https://eozsahin1993.github.io/posts/2025/03/14/react-class-vs-fun-component.html" rel="alternate" type="text/html" title="TIL: React Class vs Function Components" /><published>2025-03-14T00:00:00+00:00</published><updated>2025-03-14T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2025/03/14/react-class-vs-fun-component</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2025/03/14/react-class-vs-fun-component.html"><![CDATA[<p>Today, I was updating one of the existing React components in our Kustomer web codebase to prefetch saved search graph data upon a property change. Our existing React component appeared to be a class component like below:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="kd">class</span> <span class="nc">SearchLayout</span> <span class="kd">extends</span> <span class="nc">React</span><span class="p">.</span><span class="nx">Component</span><span class="o">&lt;</span><span class="nx">React</span><span class="p">.</span><span class="nx">PropsWithChildren</span><span class="o">&lt;</span><span class="nx">SearchLayoutProps</span><span class="o">&gt;&gt;</span> <span class="p">{</span>
    <span class="nf">componentDidMount</span><span class="p">()</span> <span class="p">{</span>
        <span class="c1">// Component logic...</span>
    <span class="p">}</span>

    <span class="nf">componentDidUpdate</span><span class="p">()</span> <span class="p">{</span>
        <span class="c1">// Component logic..</span>
    <span class="p">}</span>

    <span class="nf">render</span><span class="p">()</span> <span class="p">{</span>
        <span class="o">&lt;</span><span class="nx">div</span><span class="o">&gt;</span>
            <span class="p">{</span> <span class="cm">/* Render component */</span> <span class="p">}</span>
        <span class="p">&lt;</span><span class="err">/</span><span class="na">div</span><span class="p">&gt;</span>
    }

}
</code></pre></div></div>

<p>Up until this point, I knew that you could create React components either by extending React.Component class or simply creating a function like below:</p>

<div class="language-tsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="k">default</span> <span class="kd">function</span> <span class="nf">SearchLayout</span><span class="p">(</span><span class="nx">props</span><span class="p">:</span> <span class="nx">SearchLayoutProps</span><span class="p">)</span> <span class="p">{</span>
    <span class="c1">// Component logic..</span>
    <span class="k">return </span><span class="p">(</span>
        <span class="p">&lt;</span><span class="nt">div</span><span class="p">&gt;</span>
            <span class="si">{</span> <span class="cm">/* Render component */</span> <span class="si">}</span>
        <span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
    <span class="p">);</span>
<span class="p">}</span> 
</code></pre></div></div>

<p>As someone still relatively new to web development, I immediately realized something was wrong when I tried adding the <code class="language-plaintext highlighter-rouge">useEffect()</code> hook to our class component. It turns out, this is not even supported with React class components and that’s what I learned today. I decided to do more research about the history and differences between two styles and share my findings..</p>

<h3 id="react-class-components">React Class Components</h3>

<p>An example Class Component in <a href="https://react.dev/reference/react/Component#defining-a-class-component">react.dev</a>:</p>
<div class="language-jsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">import</span> <span class="p">{</span> <span class="nx">Component</span> <span class="p">}</span> <span class="k">from</span> <span class="dl">'</span><span class="s1">react</span><span class="dl">'</span><span class="p">;</span>

<span class="kd">class</span> <span class="nc">Greeting</span> <span class="kd">extends</span> <span class="nc">Component</span> <span class="p">{</span>
  <span class="nf">render</span><span class="p">()</span> <span class="p">{</span>
    <span class="k">return</span> <span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Hello, <span class="si">{</span><span class="k">this</span><span class="p">.</span><span class="nx">props</span><span class="p">.</span><span class="nx">name</span><span class="si">}</span>!<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;;</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>According to the docs:</p>

<ol>
  <li>A <code class="language-plaintext highlighter-rouge">return() {}</code> has to be specified.</li>
  <li>The props can be accessed via <code class="language-plaintext highlighter-rouge">this.props</code>.</li>
  <li><code class="language-plaintext highlighter-rouge">React hooks</code> are not supported!</li>
  <li>Component state managed by internal <code class="language-plaintext highlighter-rouge">this.state</code> and <code class="language-plaintext highlighter-rouge">this.setState()</code>.</li>
  <li>Has lifecycle methods such as:
    <ul>
      <li><code class="language-plaintext highlighter-rouge">componentDidMount()</code>: Component is added to the screen</li>
      <li><code class="language-plaintext highlighter-rouge">componentDidUpdate()</code>: Component rerenders due to props or state changes</li>
      <li><code class="language-plaintext highlighter-rouge">componentWillUnmount()</code>: Component is removed from the screen</li>
      <li><code class="language-plaintext highlighter-rouge">componentDidCatch()</code>: Component threw an error</li>
    </ul>
  </li>
</ol>

<h3 id="react-function-component">React Function Component</h3>

<p>An example function component in <a href="https://react.dev/reference/react/Component#alternatives">react.dev</a></p>
<div class="language-jsx highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">function</span> <span class="nf">Greeting</span><span class="p">({</span> <span class="nx">name</span> <span class="p">})</span> <span class="p">{</span>
  <span class="k">return</span> <span class="p">&lt;</span><span class="nt">h1</span><span class="p">&gt;</span>Hello, <span class="si">{</span><span class="nx">name</span><span class="si">}</span>!<span class="p">&lt;/</span><span class="nt">h1</span><span class="p">&gt;;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>According to the docs:</p>
<ol>
  <li>Supports React Hooks like <code class="language-plaintext highlighter-rouge">useState()</code> and <code class="language-plaintext highlighter-rouge">useEffect()</code></li>
  <li>Properties (<code class="language-plaintext highlighter-rouge">props</code>) can be directly accessed via function parameters.</li>
  <li>State is managed via hooks such as <code class="language-plaintext highlighter-rouge">useState()</code> instead of <code class="language-plaintext highlighter-rouge">this.state</code>.</li>
  <li>Does not rely on traditional lifecycle methods. Instead, hooks like useEffect() handle side effects.</li>
</ol>

<h3 id="verdict">Verdict</h3>

<p>According to the official documentation, it is <strong>recommended</strong> to convert all class components into function components.</p>

<p>Before React hooks were introduced, if your component had a state or if you wanted utilize the lifecycle methods, you <strong>had</strong> to use a class component. Over time, different React hooks were added such as</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">useState()</code> which allowed you retain state in a function component.</li>
  <li><code class="language-plaintext highlighter-rouge">useEffect()</code> which changes the whole lifecycle methodology for the good. These changes were also similar to how Jetpack Compose (declarative UI library for Android) introduced new state changes. Essentially, <code class="language-plaintext highlighter-rouge">useEffect()</code> accepts a parameter and the lambda function is triggered when that state changes.</li>
  <li><code class="language-plaintext highlighter-rouge">useContext()</code> allows you to read and subscribe to context within your application.</li>
  <li>Creating custom hooks by both using <code class="language-plaintext highlighter-rouge">useState()</code> and <code class="language-plaintext highlighter-rouge">useEffect()</code></li>
</ul>

<p>React Hooks offer significantly more functionality and flexibility compared to class component lifecycle methods. They make components more extensible and adaptable to future updates, whereas class components are now considered legacy.Thus, we should strive to use function components going forward.</p>

<p>Stay tuned for more articles, happy coding!</p>

<h4 id="resources">Resources</h4>
<ul>
  <li><a href="https://react.dev/reference/react">https://react.dev/reference/react</a></li>
  <li><a href="https://ui.dev/why-react-hooks">https://ui.dev/why-react-hooks</a></li>
</ul>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="Today I learned" /><category term="React" /><category term="Web" /><summary type="html"><![CDATA[Today, I was updating one of the existing React components in our Kustomer web codebase to prefetch saved search graph data upon a property change. Our existing React component appeared to be a class component like below:]]></summary></entry><entry><title type="html">Hello everyone!</title><link href="https://eozsahin1993.github.io/posts/2025/02/07/first-post.html" rel="alternate" type="text/html" title="Hello everyone!" /><published>2025-02-07T00:00:00+00:00</published><updated>2025-02-07T00:00:00+00:00</updated><id>https://eozsahin1993.github.io/posts/2025/02/07/first-post</id><content type="html" xml:base="https://eozsahin1993.github.io/posts/2025/02/07/first-post.html"><![CDATA[<p>I am super excited to start sharing my learnings and experiences in my brand new website! This will be a space where I document my findings, tips and learnings– mostly technical, but occasionally personal as well.</p>

<h4 id="tech-articles">Tech articles</h4>

<p>I plan to share a variety of tech articles including but not limited to mobile development, web development and cloud technologies. One of my personal goals is to have a set of articles called <strong>‘Today I Learned’</strong> (TIL) where I will jot down my learnings for the day. My aim is to keep myself accountable and try to learn as much as I can. After all, consistent improvements add up over time, thanks to the power of compounding.</p>

<h4 id="announcements">Announcements</h4>

<p>Beyond tech articles, I’ll also be posting personal or tech related announcements as well. After all, I don’t use twitter (or X) and don’t have much of a desire to :)</p>

<p>To keep articles relatively organized, I will be heavily using tags. Stay tuned!</p>]]></content><author><name>Emre Ozsahin</name></author><category term="Posts" /><category term="announcement" /><summary type="html"><![CDATA[I am super excited to start sharing my learnings and experiences in my brand new website! This will be a space where I document my findings, tips and learnings– mostly technical, but occasionally personal as well.]]></summary></entry></feed>