<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title>Latency Slayer</title><link>https://madflojo.dev/</link><description>Latency Slayer is a blog about building resilient, scalable, and high-performance distributed systems. It is focused on practical advice built from real-world experience.</description><generator>Hugo -- gohugo.io</generator><language>en-us</language><copyright>Benjamin Cane</copyright><lastBuildDate>Mon, 12 Jan 2026 00:00:00 +0000</lastBuildDate><atom:link href="https://madflojo.dev/index.xml" rel="self" type="application/rss+xml"/><item><title>Are Atomic Operations Faster and Better Than a Mutex? It Depends</title><link>https://madflojo.dev/posts/are-atomic-operations-faster-than-a-mutex/</link><pubDate>Mon, 12 Jan 2026 00:00:00 +0000</pubDate><author>Benjamin Cane</author><guid>https://madflojo.dev/posts/are-atomic-operations-faster-than-a-mutex/</guid><description><![CDATA[<div class="featured-image">
                <img src="/images/atomics-v-rwmutex/atomics-v-rwmutex.png" referrerpolicy="no-referrer">
            </div><p>Recently, while reviewing a pull request, a discussion arose about using <code>sync/atomic</code> versus <code>sync.RWMutex</code>.</p>
<p>It’s a question that comes up often when writing concurrent Go code, so I thought it would make a great post.</p>
<h2 id="tldr">TL;DR</h2>
<p>For those in a hurry, here are the key takeaways:</p>
<ul>
<li><strong>Atomic Operations:</strong> Can be faster when updating a single shared value across multiple threads (or goroutines).</li>
<li><strong>Mutexes/RWMutexes:</strong> Add overhead, but are better for operations involving multiple steps or fields.</li>
<li><strong>Atomic Operations protect one instruction:</strong> They do not guarantee correctness across a sequence of operations (<em>read → logic → write</em>).</li>
<li><strong>Complexity grows:</strong> As logic grows (compare-and-swap (CAS) loops, retries, multi-field consistency), atomic operations become harder to reason about.</li>
<li><strong>Mental model:</strong>
<ul>
<li><strong>Mutex/RWMutex:</strong> Everything inside the lock is one unit.</li>
<li><strong>Atomic Operations:</strong> Only this one operation is protected.</li>
</ul>
</li>
<li><strong>Rule of thumb:</strong> Start with a mutex (RWMutex if read-heavy); switch to atomic operations as an optimization when performance requirements and use cases justify it.</li>
</ul>
<h2 id="introduction">Introduction</h2>
<p>In this article, we’ll explore atomic operations and mutexes, how they differ in both performance and behavior, and when each one is appropriate.</p>]]></description></item><item><title>Cell-based Architecture Explained (with Zombies)</title><link>https://madflojo.dev/posts/cell-based-architecture-explained-with-zombies/</link><pubDate>Thu, 01 Jan 2026 00:00:00 +0000</pubDate><author>Benjamin Cane</author><guid>https://madflojo.dev/posts/cell-based-architecture-explained-with-zombies/</guid></item></channel></rss>