<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>Blog on Prateek Sharma</title>
		<link>https://prateeksharma.me/blog/</link>
		<description>Recent content in Blog on Prateek Sharma</description>
		<generator>Hugo</generator>
		<language>en-us</language>
		
		
		
		
			<lastBuildDate>Thu, 27 Aug 2026 00:00:00 +0000</lastBuildDate>
		
			<atom:link href="https://prateeksharma.me/blog/index.xml" rel="self" type="application/rss+xml" />
			<item>
				<title>Two-sided membership needs one lock, not two</title>
				<link>https://prateeksharma.me/blog/atomic-membership-in-a-concurrent-go-library/</link>
				<pubDate>Thu, 27 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/blog/atomic-membership-in-a-concurrent-go-library/</guid>
				<description>&lt;p&gt;&lt;a href=&#34;https://prateeksharma.me/projects/goroomlib/&#34;&gt;Goroomlib&lt;/a&gt;&#xA; models a relationship that points both ways: a&#xA;&lt;code&gt;Room&lt;/code&gt; holds a map of its users, and each &lt;code&gt;User&lt;/code&gt; holds a list of the rooms it&amp;rsquo;s&#xA;in. That redundancy is deliberate — both lookups need to be O(1) — but it&amp;rsquo;s also&#xA;the whole bug surface.&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-first-version&#34;&gt;The first version&lt;/h2&gt;&#xA;&lt;p&gt;&lt;code&gt;AddUserToRoom&lt;/code&gt; did the obvious thing:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#e6edf3;background-color:#0d1117;-moz-tab-size:2;-o-tab-size:2;tab-size:2;-webkit-text-size-adjust:none;&#34;&gt;&lt;code class=&#34;language-go&#34; data-lang=&#34;go&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#ff7b72&#34;&gt;func&lt;/span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;(s&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72;font-weight:bold&#34;&gt;*&lt;/span&gt;RoomService)&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#d2a8ff;font-weight:bold&#34;&gt;AddUserToRoom&lt;/span&gt;(roomName&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72&#34;&gt;string&lt;/span&gt;,&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;user&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72;font-weight:bold&#34;&gt;*&lt;/span&gt;User)&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;{&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;    &lt;/span&gt;room&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;&lt;span style=&#34;color:#ff7b72;font-weight:bold&#34;&gt;:=&lt;/span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;s.rooms[roomName]&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;    &lt;/span&gt;room.mu.&lt;span style=&#34;color:#d2a8ff;font-weight:bold&#34;&gt;Lock&lt;/span&gt;()&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;    &lt;/span&gt;room.users[user.ID]&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;=&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;user&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;    &lt;/span&gt;room.mu.&lt;span style=&#34;color:#d2a8ff;font-weight:bold&#34;&gt;Unlock&lt;/span&gt;()&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;    &lt;/span&gt;user.mu.&lt;span style=&#34;color:#d2a8ff;font-weight:bold&#34;&gt;Lock&lt;/span&gt;()&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;    &lt;/span&gt;user.joinedRooms&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;=&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;append(user.joinedRooms,&lt;span style=&#34;color:#6e7681&#34;&gt; &lt;/span&gt;roomName)&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#6e7681&#34;&gt;    &lt;/span&gt;user.mu.&lt;span style=&#34;color:#d2a8ff;font-weight:bold&#34;&gt;Unlock&lt;/span&gt;()&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;}&lt;span style=&#34;color:#6e7681&#34;&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Each side is individually locked, so &lt;code&gt;go vet&lt;/code&gt; and the race detector on a simple&#xA;test are both happy. But there&amp;rsquo;s a window between the two critical sections where&#xA;the room says &amp;ldquo;user is here&amp;rdquo; and the user says &amp;ldquo;I&amp;rsquo;m not in that room.&amp;rdquo; Anything&#xA;that reads both — say, a disconnect handler that walks &lt;code&gt;user.joinedRooms&lt;/code&gt; to&#xA;remove the user from each — can run in that window and leak the membership.&lt;/p&gt;</description>
			</item>
			<item>
				<title>Endpoint maps over hand-rolled methods</title>
				<link>https://prateeksharma.me/blog/endpoint-maps-over-hand-rolled-methods/</link>
				<pubDate>Tue, 25 Aug 2026 00:00:00 +0000</pubDate>
				<guid>https://prateeksharma.me/blog/endpoint-maps-over-hand-rolled-methods/</guid>
				<description>&lt;p&gt;I&amp;rsquo;ve now written two client libraries for the same exchange API — one in&#xA;&lt;a href=&#34;https://prateeksharma.me/projects/wazirx-connector-go/&#34;&gt;Go&lt;/a&gt;&#xA;, one in&#xA;&lt;a href=&#34;https://prateeksharma.me/projects/wazirx-connector-java/&#34;&gt;Java&lt;/a&gt;&#xA; — and the thing I&amp;rsquo;d keep from both is&#xA;the same: don&amp;rsquo;t write a method per endpoint. Describe the endpoints as data and&#xA;dispatch through one function.&lt;/p&gt;&#xA;&lt;h2 id=&#34;the-shape-of-the-problem&#34;&gt;The shape of the problem&lt;/h2&gt;&#xA;&lt;p&gt;The API has roughly two dozen endpoints. They differ in four ways:&lt;/p&gt;&#xA;&lt;ul&gt;&#xA;&lt;li&gt;HTTP verb (&lt;code&gt;GET&lt;/code&gt;, &lt;code&gt;POST&lt;/code&gt;, &lt;code&gt;DELETE&lt;/code&gt;)&lt;/li&gt;&#xA;&lt;li&gt;path&lt;/li&gt;&#xA;&lt;li&gt;whether the request must be signed&lt;/li&gt;&#xA;&lt;li&gt;the response body&lt;/li&gt;&#xA;&lt;/ul&gt;&#xA;&lt;p&gt;Everything else — building query params, adding a signature, choosing the verb&#xA;handler, parsing the response — is identical. Writing a hand-rolled method per&#xA;endpoint means writing that identical body 25 times, and then maintaining 25&#xA;copies of it when the signing scheme or the base URL handling changes.&lt;/p&gt;</description>
			</item>
	</channel>
</rss>
