<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Shilp Thapak on Medium]]></title>
        <description><![CDATA[Stories by Shilp Thapak on Medium]]></description>
        <link>https://medium.com/@shilp.thapak?source=rss-2e7d15432600------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FDkRwVBEURiIz3o6</url>
            <title>Stories by Shilp Thapak on Medium</title>
            <link>https://medium.com/@shilp.thapak?source=rss-2e7d15432600------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:54:26 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shilp.thapak/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[When Raft(Lab 3A) Passed Every Test — Until It Didn’t]]></title>
            <link>https://medium.com/@shilp.thapak/when-raft-lab-3a-passed-every-test-until-it-didnt-62158460af55?source=rss-2e7d15432600------2</link>
            <guid isPermaLink="false">https://medium.com/p/62158460af55</guid>
            <category><![CDATA[raft]]></category>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Shilp Thapak]]></dc:creator>
            <pubDate>Wed, 30 Sep 2026 04:48:16 GMT</pubDate>
            <atom:updated>2026-09-30T04:48:16.167Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Another checkpoint in my MIT 6.5840 distributed systems journey.</em></p><p>I thought I was done with Lab 3A(Raft).</p><p>I had implemented it. I had run the tests. They passed.</p><p>I ran them again.</p><p>They passed again.</p><p>And again.</p><p>At some point, I started thinking, <em>Okay, this is working. Maybe I can finally move on to the next lab.</em></p><p>Then, just before moving on, I decided to run the tests one more time.</p><p>They failed.</p><p>That one failure was enough to completely change how I was looking at my implementation.</p><h3>When “it passed” stopped being enough</h3><p>The frustrating part wasn’t just that a test failed.</p><p>It was that it had already passed multiple times.</p><p>I hadn’t changed the code. I hadn’t changed the configuration. As far as I could tell, everything was exactly the same.</p><p>So I started going through the code again.</p><p>Logs. Timers. Goroutines. State changes. RPCs.</p><p>I kept asking myself:</p><p><em>What changed?</em></p><p>The answer was: nothing.</p><p>And somehow, that was the problem.</p><p>If the same code can pass several times and then fail without any code changes, there is probably something deeper going on.</p><p>I spent hours looking at logs and trying to understand what was happening. Eventually, I had to accept something that was difficult to admit:</p><p><strong>My implementation was not as robust as I thought it was.</strong></p><p>It worked under some executions.</p><p>That didn’t necessarily mean it was correct.</p><p>And honestly, that realization hurt.</p><p>I had already spent a lot of time on the lab. I had even written a blog post about my Raft journey. In my head, I had already started treating this part as complete.</p><p>Now I was back to looking at the same code, wondering why it was failing.</p><h3>I needed to step away</h3><p>At some point, I became genuinely frustrated.</p><p>I started thinking:</p><p><em>How many more hours am I going to spend looking at logs?</em></p><p><em>How many weekends am I going to spend on this?</em></p><p><em>Maybe distributed systems is just much harder than I expected.</em></p><p>I decided to take some time away from it.</p><p>Not because I had given up on the lab, but because I wasn’t making much progress by repeatedly staring at the same implementation.</p><p>I needed some distance.</p><p>But even while I was away from Raft, the problem stayed somewhere in the back of my mind.</p><p>Why was this so difficult?</p><p>What was I missing?</p><p>Why could the same implementation behave differently across runs?</p><h3>Maybe the problem wasn’t Raft</h3><p>While casually thinking about it, I started wondering whether the problem was partly on my side.</p><p>Not necessarily my understanding of Raft itself, but my understanding of some of the Go concurrency primitives I was using to implement it.</p><p>When I first started learning Go, I deliberately chose not to learn the entire language before starting MIT 6.5840.</p><p>I didn’t want to spend weeks going through every feature of a programming language without knowing why those features mattered.</p><p>It felt a little like being given a toolbox and being asked to memorize every tool before being allowed to build anything.</p><p>I preferred learning by doing.</p><p>So I learned enough Go to start Lab 1.</p><p>Then enough to get through Lab 2.</p><p>And then I reached Raft.</p><p>That’s where the approach started exposing its limitations.</p><p>Raft requires you to reason about things like goroutines, mutexes, channels, timers, contexts, shared state, and concurrency.</p><p>I knew some of these things.</p><p>But I wasn’t comfortable with all of them.</p><p>And more importantly, I didn’t always know <strong>which tool was appropriate for which problem</strong>.</p><h3>So I went back to concurrency</h3><p>Instead of immediately going back to Raft, I decided to do something different.</p><p>I started solving Go concurrency challenges.</p><p>I came across <a href="https://github.com/loong/go-concurrency-exercises">Long Hoang’s Go Concurrency Exercises</a> and started working through them.</p><p>The repository takes a hands-on approach to learning Go concurrency through practical exercises, with tests that help verify the solutions.</p><p>And something interesting happened.</p><p>While solving those problems, I kept having moments like:</p><blockquote><em>“Wait. I could have used this in Raft.”</em></blockquote><p>Or:</p><blockquote><em>“Oh, this is why that approach would have been simpler.”</em></blockquote><p>Or:</p><blockquote><em>“I was trying to solve this problem manually when Go already has a primitive designed for it.”</em></blockquote><p>That was a very different feeling from simply learning Go syntax.</p><p>I wasn’t learning:</p><blockquote><em>“Here is what a channel is.”</em></blockquote><p>I was learning:</p><blockquote><em>“Oh. </em><strong><em>This is why I need a channel.</em></strong><em>”</em></blockquote><p>And that difference mattered.</p><h3>Learning a tool is different from understanding why you need it</h3><p>Looking back, I think this was the missing piece.</p><p>When you’re starting with a programming language, it’s easy to learn features as isolated concepts.</p><p>Goroutines.</p><p>Channels.</p><p>Mutexes.</p><p>Context.</p><p>Timers.</p><p>Select.</p><p>WaitGroups.</p><p>You can learn what each one does.</p><p>But knowing what something does is not the same as knowing <strong>when it is the right tool for the problem you’re solving</strong>.</p><p>I had deliberately skipped some of this learning because I didn’t want Go itself to become a blocker for starting distributed systems.</p><p>At the time, I still think that was the right decision.</p><p>But Raft eventually became the point where I needed more depth.</p><p>And now, after working through concurrency problems, I can see things differently.</p><p>I can look at some of my Raft code and think:</p><blockquote><em>“I could simplify this.”</em></blockquote><blockquote><em>“This is where a channel would make more sense.”</em></blockquote><blockquote><em>“This goroutine needs a clearer lifecycle.”</em></blockquote><blockquote><em>“This is where context could help.”</em></blockquote><blockquote><em>“I understand now why this concurrency pattern is dangerous.”</em></blockquote><p>That’s a completely different level of understanding than simply knowing that these features exist.</p><h3>The interesting part is that Raft taught me what I needed to learn</h3><p>This is probably the biggest lesson I’ve taken from this phase of the journey.</p><p>If I had decided to completely finish learning Go before starting MIT 6.5840, I would have encountered dozens of language features without knowing why they mattered.</p><p>Instead, I started building something.</p><p>Then I got stuck.</p><p>That struggle showed me what I was missing.</p><p>Then I went back and learned those concepts with a very specific problem already in my head.</p><p>And suddenly, those concepts became much more meaningful.</p><p>It’s almost like the direction of learning changed.</p><p>Earlier, it was:</p><p><strong>Learn Go → use Go to build Raft</strong></p><p>Now it feels more like:</p><p><strong>Build Raft → discover what I don’t understand → learn Go concurrency → return to Raft with a better mental model</strong></p><p>And I actually like the second approach much more.</p><h3>I’m not done with Raft yet</h3><p>I haven’t magically solved everything.</p><p>I’m still working through Go concurrency.</p><p>And I still need to go back to my Raft implementation.</p><p>But this time, I’m going back with a different mindset.</p><p>Previously, I was mostly asking:</p><blockquote><em>“Why is my Raft implementation failing?”</em></blockquote><p>Now I’m also asking:</p><blockquote><em>“Am I using the right concurrency primitives to implement this correctly?”</em></blockquote><p>That feels like a much better question.</p><p>I’m actually excited to go back and refactor Lab 3A.</p><p>Not because I know that everything will suddenly work, but because I now have a better understanding of the tools I was using.</p><p>And that’s probably the most encouraging part of this entire experience.</p><h3>Another checkpoint</h3><p>When I started MIT 6.5840, my goal was simply to learn distributed systems.</p><p>I didn’t expect the course to teach me this much about how I learn.</p><p>Sometimes progress looks like passing another test.</p><p>Sometimes it looks like finally understanding a difficult concept.</p><p>And sometimes it looks like realizing that something you thought was finished isn’t actually finished.</p><p>For me, this was one of those checkpoints.</p><p>Raft passed.</p><p>Then it failed.</p><p>That failure was frustrating, but it also exposed a gap that I probably needed to discover.</p><p>And now, after stepping away, learning more about Go concurrency, and looking back at my implementation, I feel much more confident about going back to it.</p><p>Maybe I wasn’t using the wrong language.</p><p>Maybe I wasn’t incapable of understanding Raft.</p><p><strong>Maybe I just didn’t have all the right tools yet.</strong></p><p>And sometimes, the best way to learn which tools you need is to start building something difficult enough to force you to find them.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62158460af55" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Distributed Systems: My Experience with MIT 6.5840 — Lab 3A]]></title>
            <link>https://medium.com/@shilp.thapak/learning-distributed-systems-my-experience-with-mit-6-5840-lab-3a-e317bb50bcad?source=rss-2e7d15432600------2</link>
            <guid isPermaLink="false">https://medium.com/p/e317bb50bcad</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[raft]]></category>
            <category><![CDATA[consensus-algorithm]]></category>
            <dc:creator><![CDATA[Shilp Thapak]]></dc:creator>
            <pubDate>Tue, 28 Jul 2026 06:23:40 GMT</pubDate>
            <atom:updated>2026-07-28T06:23:40.588Z</atom:updated>
            <content:encoded><![CDATA[<p>Around a year ago, I decided that I wanted to learn distributed systems from first principles. While working as a software engineer, I had interacted with distributed systems almost every day — databases, queues, retries, replication, caching — but I never truly understood what was happening underneath. I wanted to change that.</p><p>That’s when I came across <strong>MIT’s 6.5840 Distributed Systems</strong> course, and it has been one of the best learning experiences I’ve had so far.</p><p>In my previous blogs, I shared my journey through <strong>Lab 1 (MapReduce)</strong> and <strong>Lab 2 (Fault-Tolerant Key-Value Store)</strong>. Those labs introduced concepts like RPCs, concurrency, fault tolerance, and unreliable networks. They were challenging, but they also built a solid foundation for what comes next.</p><p>Now comes <strong>Lab 3</strong>, where we begin implementing <strong>Raft</strong>, one of the most popular consensus algorithms used in distributed systems.</p><p>Unlike the previous labs, Lab 3 is significantly larger and much more challenging. There are so many concepts to understand and implement that I decided not to wait until the entire lab was complete before writing about it. Instead, I’ll be documenting my progress in parts.</p><p>This article covers <strong>Lab 3A</strong>, where the focus is on implementing <strong>leader election</strong> and <strong>heartbeats</strong>.</p><p>There was also an unexpected gap of almost six months between my Lab 2 and Lab 3 articles. During that time, life got busy — I got married, spent time with my family, and naturally my focus shifted away from the course for a while.</p><p>Coming back after such a long break wasn’t easy. Before I could even think about writing code, I had to rebuild my understanding of how Raft actually works.</p><p>This article is about that journey — how I prepared, how I approached the implementation, the mistakes I made, and the lessons I learned while finally getting Lab 3A to pass.</p><h3>Before Writing a Single Line of Code</h3><p>If there’s one thing I learned before even starting this lab, it’s this:</p><p><strong>Raft is overwhelming when you first look at it.</strong></p><p>There are followers, candidates, leaders, election timeouts, heartbeats, terms, votes, network partitions, RPCs, and all of these things are happening simultaneously. Unlike the previous labs, this wasn’t something I could just start coding and figure out along the way.</p><p>One challenge I always face while learning something new is figuring out <strong>how to get started</strong>. Looking at the Raft paper for the first time, I honestly had no idea where to begin.</p><p>So instead of opening my editor immediately, I spent time understanding the algorithm itself.</p><p>Before writing any code, I:</p><ul><li>Watched the MIT lecture videos multiple times.</li><li>Read the Raft paper more than once.</li><li>Drew diagrams to understand different state transitions.</li><li>Simulated leader elections on paper.</li><li>Explored interactive visualizations to see how different failure scenarios play out.</li></ul><p>One resource that helped me a lot was the official Raft visualization:</p><p>&gt;&gt; <a href="https://raft.github.io/">The Secret Lives of Data — Interactive Raft Visualization</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nwww3E-TWR_ldNwOp-i_qg.png" /><figcaption>Raft visualization from raft.github.io</figcaption></figure><p>Being able to actually <em>see</em> leaders getting elected, followers timing out, and network partitions happening made the algorithm much easier to understand. It also helped me build a mental model of what should happen before I started implementing it myself.</p><p>I also spent quite a bit of time simply going through the starter code provided by MIT. I wasn’t trying to understand every line — I just wanted to know what helper functions were already available and where different pieces of logic would eventually fit.</p><p>In hindsight, I probably spent longer preparing than I needed to.</p><p>But I don’t regret it.</p><p>That preparation gave me the confidence to finally start writing code. More importantly, it meant that while implementing the algorithm, I wasn’t constantly asking myself <em>“What should happen next?”</em> Instead, I could focus on <em>“How do I implement what I already understand?”</em></p><h3>My Approach to Lab 3A</h3><p>Once I felt comfortable with the theory, it was finally time to start implementing Raft.</p><p>The very first thing I did was exactly what I had done in the previous labs — I ran the tests without writing a single line of code.</p><p>As expected…</p><p>Everything failed.</p><p>But that failure actually helped me decide where to start.</p><p>A newly created Raft cluster doesn’t have a leader. Without a leader, nothing else in the protocol can really happen. So instead of thinking about the entire implementation at once, I broke the problem into smaller milestones.</p><p>The first milestone was simple:</p><p><strong>Get the cluster to elect a leader.</strong></p><p>That meant implementing the <strong>election timeout</strong>.</p><p>Each follower waits for a random amount of time (roughly <strong>150–300 milliseconds</strong>). If it doesn’t receive a heartbeat from a leader within that period, it assumes the leader is unavailable and starts a new election by becoming a candidate.</p><p>One decision I made early on was to <strong>avoid goroutines initially</strong>.</p><p>I knew the final implementation would require concurrency, but since I was still trying to understand the flow of the algorithm, I deliberately wrote everything sequentially. My thinking was that linear code would be much easier to debug than dozens of goroutines running in parallel.</p><p>At the time, it felt like the right decision.</p><p>Later, I realised it would also become one of the biggest reasons my implementation behaved unpredictably.</p><h3>Checkpoint 1 — Starting from Zero</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HXrUQW0ydhoABAk12vAzxw.png" /><figcaption>Porcupine image — Failing test</figcaption></figure><p>When I first ran the MIT tests, absolutely nothing worked — which was completely expected. At this point, there wasn’t any Raft implementation yet, so the cluster couldn’t elect a leader or make any progress.</p><p>Although seeing every test fail wasn’t particularly encouraging, it gave me a very clear starting point. Instead of trying to implement the entire Raft protocol, I focused only on getting the cluster to elect a single leader. Breaking the problem into smaller milestones made the implementation feel much less overwhelming.</p><h3>When Things Started Falling Apart</h3><p>My sequential implementation got me through the initial stages, but as I started implementing more of the protocol, the tests became… strange.</p><p>Sometimes they passed.</p><p>Sometimes they failed.</p><p>And occasionally, I would rerun the exact same code without making any changes, and the outcome would be completely different.</p><p>At first, I assumed there was some bug in my election logic. But after spending some time debugging, I realised the problem wasn’t the logic itself — it was <strong>time</strong>.</p><p>Raft is an algorithm where timing matters a lot.</p><p>The election timeout is only a few hundred milliseconds, and heartbeats are sent frequently enough to assure followers that the leader is still alive. If there is even a small delay in sending or processing those RPCs, followers may incorrectly assume that the leader has failed and start a new election.</p><p>That was exactly what was happening in my implementation.</p><p>Because I had written everything sequentially, one RPC would block the next one. Those tiny delays were enough for followers to miss heartbeats and trigger unnecessary elections. Once that happened, multiple candidates would appear at the same time, terms would increase unexpectedly, and the tests became incredibly flaky.</p><p>Eventually, I accepted that concurrency wasn’t something I could postpone anymore.</p><p>I converted the RPCs into goroutines so they could execute in parallel instead of one after another. That single change made the implementation significantly more reliable and much closer to how a real distributed system behaves.</p><p>Looking back, my idea of “make it work first, then make it concurrent” wasn’t entirely wrong — it actually helped me understand the flow of the algorithm. But it also taught me that, in distributed systems, concurrency isn’t just an optimization. In many cases, it’s part of the algorithm itself.</p><h3>Logging Became My Best Debugging Tool</h3><p>One thing that saved me countless hours during this lab was logging.</p><p>Lots of logging.</p><p>In fact, my terminal became almost unusable because of the sheer number of log statements being printed every second. But despite all that noise, those logs became my primary debugging tool.</p><p>I tried to include three pieces of information in almost every log statement:</p><ul><li>The <strong>server ID</strong></li><li>The server’s <strong>current state</strong> (Follower, Candidate, or Leader)</li><li>The <strong>current term</strong></li></ul><p>Those three values alone made it much easier to follow what was happening.</p><p>Instead of seeing a generic message like:</p><blockquote><em>Received RequestVote RPC</em></blockquote><p>I could immediately tell:</p><blockquote><em>Server 2 (Candidate, Term 4) received a vote from Server 0.</em></blockquote><p>That context made an enormous difference.</p><pre>[S1][Follower][Term 0] Election timeout.<br>[S1][Candidate][Term 1] Starting election.<br>[S1][Candidate][Term 1] Sending RequestVote to S0.<br>[S0][Follower][Term 1] Vote granted to S1.<br>[S2][Follower][Term 1] Vote granted to S1.<br>[S1][Leader][Term 1] Received majority. Becoming leader.<br>[S1][Leader][Term 1] Sending heartbeats.<br>...<br>[S2][Follower][Term 2] Higher term discovered.<br>[S1][Leader][Term 1] Stepping down to follower.</pre><p>Distributed systems are difficult because multiple machines are doing different things at the same time. Without knowing <strong>which server</strong> is printing a log, <strong>what state it’s currently in</strong>, and <strong>which election term</strong> it’s belongs to, the logs quickly become impossible to follow.</p><p>There were definitely moments when I wished the logs were shorter, but every time I tried removing them, I ended up adding them back. They repeatedly helped me narrow down exactly where my implementation was going wrong.</p><h3>Following Figure 2, One Step at a Time</h3><p>One piece of advice I came across multiple times while reading about Raft was:</p><blockquote><strong><em>If you’re implementing Raft, follow Figure 2 exactly.</em></strong></blockquote><p>At first, I didn’t fully appreciate why people emphasized it so much.</p><p>Later, I understood.</p><p>Figure 2 isn’t just a diagram — it’s almost a complete implementation checklist.</p><p>Instead of trying to remember the entire algorithm from memory, I started treating each condition in Figure 2 as a small task to implement.</p><p>For example:</p><ul><li>If an RPC arrives with a lower term than the current server’s term, reject it.</li><li>If a server discovers a higher term, immediately step down to a follower.</li><li>Grant a vote only if the candidate satisfies the conditions mentioned in the paper.</li></ul><p>Implementing these rules one by one made the entire protocol much less intimidating.</p><p>One bug that took me some time to identify involved <strong>vote requests</strong>.</p><p>There were situations where I expected a follower to grant its vote, but it kept rejecting the candidate. Instead of trying to guess what was happening, I added logs for every rejected vote and printed the exact reason behind the rejection.</p><p>That immediately highlighted the cases I had misunderstood.</p><p>This became a recurring pattern throughout the lab. Whenever something didn’t behave the way I expected, I resisted the urge to start changing random pieces of code. Instead, I added enough logging to understand <strong>why</strong> the server had made a particular decision.</p><p>More often than not, the logs pointed directly to the missing condition or incorrect assumption.</p><h3>Checkpoint 2 — Chasing Flaky Elections</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3YH_3bYAwC-RPiz7V7vi6g.png" /><figcaption>Porcupine Test — failure during network partition</figcaption></figure><p>By this point, the implementation had started to resemble a real Raft cluster. Leaders were being elected, and most of the basic election logic was in place. However, the tests were still failing during later terms — around <strong>Term 4</strong> in my case.</p><p>At first, I assumed there was a major flaw in the election algorithm. But after carefully reading the logs and comparing them with the visualization, I realised most of these failures were actually caused by timing issues. Followers were missing heartbeats, starting unnecessary elections, and multiple candidates were competing for leadership at the same time.</p><p>This checkpoint was a reminder that distributed systems aren’t only about implementing the correct logic. They’re equally about making sure that logic executes at the right time. A few milliseconds of delay can completely change the behaviour of the entire cluster.</p><h3>The Tests Became the Teacher</h3><p>One thing I really appreciate about the MIT labs is that they don’t just verify whether your implementation works — they actively teach you what you’ve missed.</p><p>Every time I fixed one issue, the next test would fail for a completely different reason. Instead of feeling frustrating, it almost felt like the tests were guiding me through the Raft protocol one scenario at a time.</p><p>The first test was straightforward.</p><p>Could the cluster elect a leader when it started with no leader?</p><p>Once that passed, the tests became much more interesting.</p><p>They would simulate a <strong>network partition</strong>, separating the current leader from the majority of the cluster. Since the leader no longer had the support of the majority, the remaining servers had to elect a new leader among themselves.</p><p>Just when that started working, another test introduced an even more challenging scenario.</p><p>Each server was isolated into its own partition.</p><p>Since no server could obtain a majority of votes, <strong>no leader should be elected</strong>. Instead, the servers should repeatedly start elections, increase their terms, and continue waiting until communication was restored.</p><p>Finally, the partitions would heal.</p><p>The servers had to communicate again, outdated leaders had to recognise that they were no longer the leader, and the cluster had to converge back to a single, stable leader.</p><p>Watching these scenarios play out made me appreciate how much thought has gone into the Raft algorithm. Every edge case that initially felt confusing eventually made sense once I understood <em>why</em> the protocol behaved that way.</p><p>I didn’t solve all of these scenarios in one go.</p><p>Every failing test pointed to one missing behaviour, one incorrect assumption, or one condition I had overlooked.</p><p>Slowly, one fix at a time, the implementation became more complete.</p><h3>Checkpoint 3 — A Stable Cluster</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Pl072JiC-sUUxjGgmWy3ww.png" /></figure><p>By this point, the implementation had started behaving the way I had imagined when I first began reading the Raft paper.</p><p>Leader elections were stable, followers were receiving heartbeats consistently, and the cluster was behaving correctly across the different failure scenarios introduced by the MIT tests.</p><p>Looking back at this visualization alongside the very first checkpoint was incredibly satisfying. It showed that there wasn’t a single “magic fix” that suddenly made everything work. Instead, the implementation improved through dozens of small corrections — understanding one edge case, fixing one race condition, handling one more scenario, and repeating that process over and over again.</p><p>That gradual progress is probably what I enjoyed the most about this lab.</p><h3>What I Learned from Lab 3A</h3><p>Looking back, Lab 3A taught me much more than just how leader election works.</p><p>The biggest lesson was that spending time understanding the theory before writing code isn’t wasted effort. Initially, I felt guilty about spending so much time reading the Raft paper, watching lectures, and drawing diagrams instead of coding. But once I started implementing the algorithm, that preparation paid off because I already had a mental model of how the system should behave.</p><p>Another lesson was about <strong>concurrency</strong>.</p><p>Before this lab, I often thought of concurrency as something you add later to improve performance. Raft changed that perspective. Here, concurrency isn’t just about making the implementation faster — it is fundamental to making the protocol behave correctly. Delaying RPCs by even a few milliseconds can completely change the outcome of an election.</p><p>I also realised the importance of <strong>good logging</strong>.</p><p>Without detailed logs, debugging a distributed system is almost impossible. Every server is making independent decisions at the same time, and unless you know which server is speaking, what state it’s in, and which term it’s processing, the logs quickly become meaningless.</p><p>Finally, I learned the value of implementing complex systems incrementally.</p><p>There were many moments where Lab 3A felt overwhelming. Looking at the entire Raft protocol made it seem impossible to implement. Breaking it down into smaller milestones — first election timeout, then voting, then leader election, then heartbeats, then handling failures — made the problem much more manageable.</p><p>It’s a lesson I’ll probably carry into every future project as well.</p><h3>What’s Next?</h3><p>Completing Lab 3A feels like reaching the base camp rather than the summit.</p><p>Leader election is only the beginning of Raft.</p><p>The next part of the lab introduces <strong>log replication</strong>, arguably the most important part of the protocol. That’s where the real challenge begins — keeping multiple servers in sync while handling failures, crashes, and network partitions.</p><p>I’m looking forward to diving into it and, just like the previous labs, documenting everything I learn along the way.</p><p>If you’ve been following this series, I hope this article gives you a realistic picture of what it’s like to implement Raft for the first time. It isn’t a straight path, and it certainly isn’t easy, but that’s also what makes it such a rewarding learning experience.</p><p>See you in the next article, where I’ll continue the journey with <strong>MIT 6.5840 — Lab 3B</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e317bb50bcad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Rebuilding MapReduce in Go]]></title>
            <link>https://medium.com/@shilp.thapak/rebuilding-mapreduce-in-go-1fb8076148cb?source=rss-2e7d15432600------2</link>
            <guid isPermaLink="false">https://medium.com/p/1fb8076148cb</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[mapreduce]]></category>
            <dc:creator><![CDATA[Shilp Thapak]]></dc:creator>
            <pubDate>Wed, 24 Jun 2026 04:53:14 GMT</pubDate>
            <atom:updated>2026-06-24T04:53:14.089Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s been a while since I last wrote about my distributed systems learning journey.</p><p>Over the past few months, I completed the first two labs of MIT’s 6.824 Distributed Systems course: MapReduce and the Key-Value Store. I had planned to continue with the third lab, Raft, but life had other plans. With my marriage coming up and several personal commitments in between, I wasn’t able to continue the course at the pace I wanted.</p><p>Instead of leaving things unfinished, I decided to revisit the first lab and do something I had wanted to do for a long time: create my own MapReduce implementation that I could freely experiment with, modify, and share.</p><p>The result is here:</p><p>GitHub Repository: <a href="https://github.com/ShilpThapak/mr">https://github.com/ShilpThapak/mr</a></p><h3>Why Rebuild It?</h3><p>When I originally completed the MIT lab, the goal was to understand the concepts and pass the tests.</p><p>This time, I wanted to focus on building something that felt like my own project.</p><p>I wanted to organize the code the way I would normally structure an application, make the components easier to understand, and create a foundation that I could extend in the future.</p><h3>What I Learned</h3><p>The biggest takeaway wasn’t MapReduce itself. It was learning how distributed systems are built incrementally.</p><p>Some of the most valuable lessons were:</p><ul><li>Building fault-tolerant systems that can recover from worker failures.</li><li>Writing tests that validate failure scenarios rather than only happy paths.</li><li>Breaking a complex system into smaller, independently understandable components.</li><li>Understanding task scheduling and coordination between multiple processes.</li><li>Organizing Go projects with a cleaner file and package structure.</li></ul><p>The experience reinforced an important lesson: distributed systems become much less intimidating when you build them one feature at a time.</p><h3>How I Built It</h3><p>One mistake I often make when learning something new is trying to build the final version immediately.</p><p>This time I took a different approach.</p><h3>Step 1: Start With a Sequential Version</h3><p>The first thing I built was a simple sequential implementation.</p><p>One script handled the entire MapReduce flow from start to finish. No coordinator. No workers. No concurrency.</p><p>The goal was simply to make sure the Map and Reduce logic worked correctly.</p><h3>Step 2: Create a Better Structure</h3><p>Once the sequential version was working, I reorganized the code.</p><p>I separated the Map and Reduce handling into their own files and defined clear interfaces for how those functions should be executed.</p><p>This made it easier to evolve the project without constantly rewriting code.</p><h3>Step 3: Add Coordinator and Worker Processes</h3><p>After the foundation was ready, I introduced the Coordinator and Worker architecture.</p><p>The coordinator became responsible for assigning work, while workers focused only on executing tasks.</p><p>At this point, the system was distributed, but still relatively simple.</p><h3>Step 4: Add Features Incrementally</h3><p>Instead of implementing everything at once, I added one feature at a time.</p><p>First came support for temporary files and intermediate outputs.</p><p>Then support for multiple input files.</p><p>After that, support for multiple workers running in parallel.</p><p>Finally, I implemented fault tolerance by allowing tasks to be reassigned if a worker stopped responding.</p><p>Building features incrementally made debugging significantly easier and helped me understand exactly why each piece of the system existed.</p><h3>The Final Result</h3><p>The final implementation includes:</p><ul><li>Parallel task execution across multiple workers.</li><li>Dynamic task scheduling through a coordinator.</li><li>Automatic task reassignment when workers fail.</li><li>Support for multiple input files.</li><li>Reliable MapReduce processing using temporary intermediate files.</li></ul><p>More importantly, it gave me a much deeper understanding of how distributed systems are designed and how fault tolerance is achieved in practice.</p><h3>What’s Next?</h3><p>I still plan to return to MIT 6.824 and continue with the Raft lab.</p><p>But before moving forward, I wanted to take a step back and rebuild what I had already learned from scratch.</p><p>That exercise turned out to be one of the most valuable parts of the entire journey.</p><p>Sometimes the best way to understand a system is not just to complete it, but to rebuild it yourself.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1fb8076148cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Distributed Systems the Hard Way: My Experience with MIT 6.5840 — Lab 2]]></title>
            <link>https://medium.com/@shilp.thapak/learning-distributed-systems-the-hard-way-my-experience-with-mit-6-5840-lab-2-bc04d07e7d79?source=rss-2e7d15432600------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc04d07e7d79</guid>
            <category><![CDATA[golang]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[mit]]></category>
            <dc:creator><![CDATA[Shilp Thapak]]></dc:creator>
            <pubDate>Sun, 23 Nov 2025 17:41:10 GMT</pubDate>
            <atom:updated>2025-11-23T17:42:39.803Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning Distributed Systems: My Experience with MIT 6.5840 — Lab 2 (KV Server)</h3><p>After finishing Lab 1 of MIT’s 6.5840 (Distributed Systems), I walked into Lab 2 feeling a little more confident. Lab 1 introduced me to Go, goroutines, mutexes, and race conditions, and I thought I had finally reached a point where Go wouldn’t slow me down anymore.</p><p>But Lab 2 had different plans.</p><p>Even simple things — like converting an integer to a string — kept sending me back to Google. That was the moment I realized something important: if I keep struggling with Go’s syntax, I won’t have the mental energy left to actually enjoy the distributed-systems concepts.</p><p>So I made a small change. Every day, I solved one very easy LeetCode problem in Go — sorted by highest acceptance rate. No algorithmic pressure, just basic operations: array manipulation, loops, simple math. Most questions took 5 to 10 minutes, but they helped immensely. Within a few weeks, Go started feeling more natural, and I stopped getting stuck on basic syntax.</p><p>It made the entire lab much more enjoyable, even though the whole thing took me around 1.5 months.</p><p>Here’s how Lab 2 went for me, part by part.</p><h3>1. Basic GET and PUT (Reliable Network)</h3><p>The first part is about implementing a simple key-value store without worrying about dropped messages.</p><p>You implement:</p><ul><li>Put and Get on the server</li><li>The corresponding RPC calls in the client (the “clerk”)</li></ul><p>I used a simple map as the KV store. The lab spec for this part is very clear compared to Lab 1. It lists all the possible error types (rpc.OK, rpc.ErrNoKey, rpc.ErrVersion, rpc.ErrMaybe) and explains exactly which conditions should trigger which error.</p><p>What helped here:</p><ul><li>Reading the spec multiple times</li><li>Writing pseudocode for all the error conditions</li><li>Listing exactly when each error should be returned</li></ul><p>Once I had that mental model, implementing GET and PUT was straightforward.</p><h3>2. Implementing a Lock (Reliable Network)</h3><p>This is where Lab 2 becomes interesting.</p><p>The lock is stored inside the key-value store using a key like &quot;L&quot;. The value is the ID of whoever owns the lock. If no one owns it, the value is blank. To acquire the lock:</p><ul><li>If &quot;L&quot; is blank → set it to your random ID and succeed</li><li>If &quot;L&quot; is taken → keep retrying until it becomes free</li></ul><p>To release the lock:</p><ul><li>Check if you are the owner</li><li>If yes, set &quot;L&quot; back to blank</li></ul><p>This part was conceptually simple once I understood the goal. The only part that felt new was the idea that an <strong>acquire call must keep retrying until it succeeds</strong>. You’re essentially writing code that refuses to give up, which is a recurring theme in distributed systems.</p><p>At this point everything still assumed a reliable network. That changes in the next parts.</p><h3>3. GET and PUT on an Unreliable Network (Handling Dropped Messages)</h3><p>This part forces you to rethink PUT and GET when the network is unreliable.</p><h3>GET</h3><p>This one is straightforward:</p><ul><li>GET can only return two meaningful outcomes: OK or ErrNoKey</li><li>Any other unexpected error means the request likely failed in transit</li><li>So you simply retry until you get either OK or ErrNoKey</li></ul><p>Once you understand this rule, GET becomes easy to implement even under network failures.</p><h3>PUT</h3><p>PUT adds an extra twist: <strong>ErrMaybe</strong>.</p><p>ErrMaybe happens when:</p><ul><li>The server <strong>did</strong> process your PUT</li><li>But due to network issues, the client never received the response</li></ul><p>So the client is stuck in an ambiguous situation. It might have succeeded… or not.</p><p>The lab wants you to surface that ambiguity to the next layer. That’s why you return ErrMaybe instead of retrying blindly. It’s a realistic scenario: in distributed systems, you often can&#39;t tell if a write actually happened.</p><p>During this part, I didn’t really understand <em>why</em> we had to return ErrMaybe or how it would be used. That answer came in the next part.</p><h3>4. Building a Correct Lock Over an Unreliable Network</h3><p>This is where the whole puzzle clicks together.</p><p>In this part, you update your lock implementation to correctly handle the ambiguous ErrMaybe from PUT.</p><p>The logic is actually very clean:</p><ul><li>If Acquire() receives ErrMaybe, it means:</li><li>The PUT (claiming the lock) <em>may</em> have succeeded.</li><li>Or it may have failed.</li><li>To resolve this uncertainty:</li><li>Send a GET request for the lock.</li><li>If the stored owner ID matches your ID → you acquired the lock.</li><li>If it’s someone else → your attempt failed.</li><li>If it’s empty → also failed; retry normally.</li></ul><p>Once I understood this idea, implementing part 4 was straightforward.</p><p>But conceptually, this part was one of the best learning moments of the lab. It shows how unreliable networks force you into these ambiguous states, and how higher-level logic (like checking the current lock owner) can help resolve them safely.</p><h3>What I Learned</h3><p>Lab 2 taught me:</p><ul><li>How to design retry loops that make an operation “eventually succeed”</li><li>How to think about network reliability (or unreliability)</li><li>How ambiguity (ErrMaybe) is a real part of distributed systems</li><li>How to design code that can survive dropped requests</li><li>How higher-level protocols handle uncertainty by re-checking system state</li></ul><p>Overall, this lab gave me a better intuition for how distributed systems behave in real-world scenarios. When you can’t trust the network or the remote server, your only tools are:</p><ul><li>retries</li><li>validation</li><li>idempotent operations</li><li>clean, consistent semantics</li></ul><p>MIT’s labs are proving to be incredibly effective. Even with just 4–5 hours per week, I’ve been learning concepts that I wouldn’t have been exposed to otherwise.</p><p>Lab 2 was frustrating in places, but genuinely fun and deeply educational.<br> Looking forward to Lab 3, where things start getting even more real.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc04d07e7d79" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From “It Works” to “It Can’t Go Wrong”: My Mindset Shift into Systems Thinking]]></title>
            <link>https://medium.com/@shilp.thapak/from-it-works-to-it-cant-go-wrong-my-mindset-shift-into-systems-thinking-df8a9d982d83?source=rss-2e7d15432600------2</link>
            <guid isPermaLink="false">https://medium.com/p/df8a9d982d83</guid>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Shilp Thapak]]></dc:creator>
            <pubDate>Sat, 18 Oct 2025 21:03:41 GMT</pubDate>
            <atom:updated>2025-10-18T21:03:41.323Z</atom:updated>
            <content:encoded><![CDATA[<p>There was a time when I thought I really understood how to build software.<br> If it ran, if the tests passed, and if users weren’t complaining — I called it a good day.</p><p>But when I started learning distributed systems, everything I thought I knew about reliability and correctness began to fall apart.</p><p>I’d finish writing code, run the tests, see most of them pass — and feel satisfied.<br> Then a few “weird” ones would fail. Something about timing, or concurrency, or a retry. I’d look at the error and think, <em>this is such a minor detail, why does it even matter?</em></p><p>But that mindset didn’t survive for long. Because in distributed systems, those “minor details” are exactly what separate a correct system from a broken one.</p><h3>When “it works” isn’t enough</h3><p>In my earlier experience, the way we built software was very straightforward: move fast, fix later.<br> If something broke, we patched it quickly and shipped again.<br> The focus was on momentum — not perfection.</p><p>I got used to thinking that as long as the happy path worked, that was enough.<br> My instinct was to prove that my code <em>could work</em>, not that it <em>couldn’t fail</em>.</p><p>So when I began working on distributed systems labs, that old instinct started to clash with the new reality.<br> Here, the goal wasn’t to make the system work once — it was to make it behave correctly <em>every single time</em>, even when everything else went wrong.</p><p>And that felt painfully slow and meticulous at first.<br> It felt like the field cared too much about “edge cases.”<br> But over time, I realized those edge cases <em>are the system</em>. That’s where the true complexity lives.</p><h3>The moment it clicked</h3><p>It took me a while to understand what distributed systems are really testing.<br>Each failing test wasn’t nitpicking — it was exposing a possible real-world failure that I hadn’t accounted for.</p><p>That one flaky timing bug?<br>That’s what could cause data loss if two servers write simultaneously.</p><p>That single missing retry?<br>That’s how a user’s payment could go through twice.</p><p>That inconsistent read?<br>That’s what could crash a service under load.</p><p>Every tiny test failure was a story someone else had already lived — usually the hard way.<br>It stopped feeling like “academic overkill” and started feeling like wisdom encoded as code.</p><p>That’s when it hit me: distributed systems are not about building things that work. They’re about building things that <em>can’t go wrong</em>, even when chaos hits from every side.</p><h3>Unlearning old habits</h3><p>The hardest part of this journey wasn’t understanding the technical content.<br> It was unlearning my old mindset — the one that valued speed over rigor, progress over correctness.</p><p>I had to train myself to ask different kinds of questions:</p><ul><li>What if this server dies right now?</li><li>What if a client retries at the wrong moment?</li><li>What if two writes happen at the same time?</li><li>What assumptions am I silently depending on?</li></ul><p>At first, thinking like this felt unnatural. But once I started to see how these questions mapped directly to real failure scenarios, it began to make sense.<br> It wasn’t slowing me down anymore — it was deepening my understanding.</p><h3>Learning to think like a system</h3><p>I started keeping a short journal of every distributed bug I ran into.<br>For each one, I’d note what broke, what invariant was violated, and what I should have thought of earlier.</p><p>This small habit changed everything.<br>It forced me to see bugs not as random annoyances but as logical consequences of broken assumptions.<br>Eventually, I stopped debugging line by line and started debugging the <em>state</em> of the system — how it evolved, what invariants were supposed to hold, and what went wrong when they didn’t.</p><p>That’s when I realized: systems thinking isn’t about code. It’s about mental models.</p><h3>The value of paranoia</h3><p>Reading the source code of real-world systems like etcd or CockroachDB made me appreciate just how <em>paranoid</em> good systems are.<br> They’re full of safety nets — retries, heartbeats, version checks, leases, timeouts — layers of defense against every possible failure.</p><p>At first glance, it feels excessive.<br>But each of those lines of code exists because someone once ignored that exact edge case and paid the price.</p><p>It’s not paranoia. It’s experience, hardened into design.</p><h3>Balancing two mindsets</h3><p>I don’t think my old “ship fast” mindset was wrong. It was necessary for the kind of work I was doing back then.<br>But now I see that engineering requires two completely different modes of thinking.</p><p>The first is the <em>product mindset</em> — move fast, deliver value, and iterate.<br>The second is the <em>systems mindset</em> — move carefully, reason deeply, and defend correctness.</p><p>You need both.<br>One builds momentum, the other builds reliability.<br>The real skill is knowing when to switch between them.</p><h3>What this shift really taught me</h3><p>If you’re learning distributed systems and feeling like the tests are too picky or the details too small — that’s normal. I felt that too.<br>But every one of those small details represents a real-world failure waiting to happen.</p><p>Distributed systems teach you something deeper than concurrency or replication.<br>They teach you how to think about correctness — not as an afterthought, but as the foundation.</p><p>You stop asking, “does it work?”<br>And start asking, “can it <em>ever</em> go wrong?”</p><p>That’s the shift. That’s systems thinking.</p><h3>Final thought</h3><p>Product engineers say: <em>“It works.”</em><br> Systems engineers say: <em>“It can’t go wrong.”</em></p><p>Both are right — depending on the problem.<br>But when you start thinking in terms of invariants, failures, and guarantees, you realize that “it works” is just the beginning, not the goal.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=df8a9d982d83" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Distributed Systems the Hard Way: My Experience With MIT 6.5840 (Lab 1)]]></title>
            <link>https://medium.com/@shilp.thapak/learning-distributed-systems-the-hard-way-my-experience-with-mit-6-5840-lab-1-36ec8aadf2d4?source=rss-2e7d15432600------2</link>
            <guid isPermaLink="false">https://medium.com/p/36ec8aadf2d4</guid>
            <dc:creator><![CDATA[Shilp Thapak]]></dc:creator>
            <pubDate>Sat, 11 Oct 2025 13:32:38 GMT</pubDate>
            <atom:updated>2025-11-23T17:42:14.774Z</atom:updated>
            <content:encoded><![CDATA[<h3>Learning Distributed Systems: My Experience With MIT 6.5840 — Lab 1 (MapReduce)</h3><p>For a long time, I wanted to dive deep into distributed systems — not just by reading or watching videos, but by actually <em>building</em> something. I’ve always admired developers like Primagen, watching them build complex systems from scratch. One day I decided: instead of watching, I’ll do it myself.</p><p>That’s when I found <strong>MIT’s 6.5840 (Distributed Systems)</strong> course. It’s known for being challenging, but also one of the most practical and respected ways to learn the fundamentals. I didn’t know <strong>Go</strong> (the language used in the course), but that was part of the excitement — a chance to learn a new language <em>and</em> distributed systems at the same time.</p><h3>Balancing a Full-Time Job and a Side Learning Project</h3><p>I’m currently working full-time as a JavaScript (Node.js) developer, so finding time wasn’t easy. I decided to dedicate <strong>around 6 hours every weekend</strong>, mostly Saturdays, to make consistent progress.</p><p>Before touching the labs, I learned Go basics using <strong>Go Tour</strong> and by writing small scripts to get comfortable with concepts like structs, goroutines, and channels.</p><p>Once I felt ready, I started with <strong>Lab 1 — MapReduce</strong>, the first lab of the series. It took me <strong>around a month</strong> to finish, mainly because I wanted to understand <em>every line</em> instead of rushing to get the tests to pass.</p><h3>Setting Up and Understanding the Codebase</h3><p>MIT provides a skeleton repository with partial code. The files I had to modify were:</p><ul><li>coordinator.go</li><li>worker.go</li><li>rpc.go</li></ul><p>At first, the codebase felt overwhelming. There were many interconnected files like mrcoordinator.go and mrworker.go that used the functions I had to implement. It took time just to map out what called what.</p><p>The lab description itself was quite verbose, so I broke the requirements into <strong>smaller, actionable tasks</strong> and planned to first make the system work <em>sequentially</em>, and then make it <em>parallel</em> using goroutines.</p><h3>Building the Coordinator and Worker</h3><p>I started by focusing on the <strong>Coordinator</strong>. I created a Task struct and implemented an RPC function RequestTask that assigns tasks to workers. The coordinator tracks the status of all tasks (pending, in-progress, done) and sends a pending task whenever a worker requests one.</p><p>To initialize, the coordinator creates one map task for every input file, marking each as <em>pending</em>.</p><p>Next, I moved to the <strong>Worker</strong>. The worker continuously calls the RequestTask RPC in a loop, gets a task, performs it, and reports completion. I started with a single worker to simplify debugging before scaling up to multiple workers.</p><p>Once the map tasks worked correctly, I implemented the <strong>reduce phase</strong>. When all map tasks were done, the coordinator switched its phase to “reduce” and generated reduce tasks, which the workers then picked up.</p><h3>Introducing Parallelism and Locks</h3><p>This was the turning point — adding <strong>goroutines</strong> and ensuring concurrency safety.</p><p>To avoid race conditions, I used a single sync.Mutex for the entire coordinator. Each RPC handler would:</p><pre>mutex.Lock()<br>defer mutex.Unlock()</pre><p>This ensured that only one worker could modify shared state at a time. It wasn’t the most granular solution, but it worked reliably.</p><p>When I finally ran multiple workers in parallel and saw them coordinating tasks correctly — it felt like magic. The parallel version ran <em>10–20x faster</em> than the sequential one, completing in just a couple of seconds.</p><h3>Debugging Nightmares</h3><p>Debugging distributed systems, even small ones, is brutal. A few memorable bugs:</p><ul><li><strong>Race conditions:</strong> Two workers picking the same task because I forgot a continue statement after processing a wait task. That single missing line caused hours of confusion.</li><li><strong>Task reassignment:</strong> When a worker crashed, the coordinator had to detect it and reassign the task. Implementing that logic was tricky but rewarding.</li><li><strong>Test failures:</strong> MIT’s tests cover a lot — sequential execution, parallelism, and crash recovery. I initially passed some, but others (like mtiming) failed because my artificial time.Sleep(1 * time.Second) was too long. Reducing it fixed the issue.</li><li><strong>Hardcoded logic:</strong> My first version only worked for the “word count” app, not “indexer.” I had to refactor the code to make it more general.</li></ul><p>Each failed test taught me something new about fault tolerance and synchronization — things you don’t fully appreciate until you <em>see them break</em>.</p><h3>Lessons Learned</h3><p>After a month of late nights and debugging marathons, I finally passed all the tests. More importantly, I learned:</p><ul><li><strong>Go is perfect for systems programming</strong> — simple syntax, powerful concurrency model.</li><li><strong>Distributed systems are not just theory.</strong> You only really understand coordination, race conditions, and failure recovery by <em>implementing</em> them.</li><li><strong>Avoiding shortcuts matters.</strong> I didn’t use any LLMs or AI code generation, because I wanted to actually <em>learn</em>. That forced me to think deeply about every line.</li></ul><h3>What’s Next</h3><p>Lab 1 was just the start. The upcoming labs — especially the <strong>Raft</strong> implementation — are known to be much harder. But now I have the confidence and foundational understanding to take them on.</p><p>If you’re planning to learn distributed systems, I can’t recommend MIT’s 6.5840 course enough. It’s tough, but if you love building things from scratch, it’s worth every hour.</p><p>✳ <em>If you’re curious, I’ve shared my (beginner-level) Lab 1 code on GitHub </em><a href="https://github.com/ShilpThapak/mit-distributed-systems">https://github.com/ShilpThapak/mit-distributed-systems</a><em>. It’s not perfect, but it’s the product of many weekends of learning, frustration, and small eureka moments.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36ec8aadf2d4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>