<?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 Sai Pranav Moluguri on Medium]]></title>
        <description><![CDATA[Stories by Sai Pranav Moluguri on Medium]]></description>
        <link>https://medium.com/@saipranavmoluguri2001?source=rss-707f9eb0d5da------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*QBhTzIwTMdUAnlt3</url>
            <title>Stories by Sai Pranav Moluguri on Medium</title>
            <link>https://medium.com/@saipranavmoluguri2001?source=rss-707f9eb0d5da------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:04:33 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@saipranavmoluguri2001/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[ 10/29/2026 — Rediscovering System Design: Understanding What Happens Behind Every Request]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/10-29-2026-rediscovering-system-design-understanding-what-happens-behind-every-request-5eab8a351142?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/5eab8a351142</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[design-systems]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Fri, 30 Oct 2026 03:50:18 GMT</pubDate>
            <atom:updated>2026-10-30T03:50:18.604Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>By Sai Pranav Moluguri</strong></p><h3>Back to the Fundamentals</h3><p>Today, October 29, 2026, I started learning System Design through a YouTube course by <strong>Telusko</strong>.</p><p>I already knew many of the concepts being discussed: servers, databases, APIs, load balancers, caching, and distributed systems.</p><p>But this time, I wanted to revisit them with a different mindset.</p><p>Instead of simply knowing what these components are, I wanted to understand <strong>why we need them, what problems they solve, and how they work together to build scalable software.</strong></p><p>And today’s session reminded me of something important.</p><p><strong>Every component in system design exists because there is a problem that needs to be solved.</strong></p><h3>It Starts With a Simple Problem</h3><p>Imagine building an application where multiple users interact with the same data.</p><p>One user updates some information, but another user still sees the old version.</p><p>Now we have a problem.</p><p><strong>Data discrepancy.</strong></p><p>The data is not synchronized.</p><p>One possible approach is to introduce a centralized database so different application servers access a shared source of truth.</p><p>That sounds simple.</p><p>But as the application grows, new challenges emerge.</p><p>What happens when thousands of users access the database simultaneously?</p><p>What if the database becomes slow?</p><p>What happens if the database server goes down?</p><p>Suddenly, a simple application becomes a system design problem.</p><p>I realized that centralizing data can solve certain consistency problems, but it also introduces questions about availability, scalability, and reliability.</p><h3>What Happens When the Application Becomes Slow?</h3><p>Another interesting concept I revisited today was application performance.</p><p>Suppose users start complaining that an application is responding slowly.</p><p>My first thought was that there could be inefficient code.</p><p>We can investigate the application and improve its performance using:</p><ul><li><strong>Data Structures and Algorithms (DSA)</strong> to optimize inefficient operations.</li><li><strong>Low-Level Design (LLD)</strong> to improve code structure and responsibilities.</li><li>Better database queries and application logic.</li></ul><p>But what if the code is already reasonably optimized?</p><p>What if the real problem is that the application receives more requests than its infrastructure can handle?</p><p>That’s where scaling enters the picture.</p><h3>Vertical Scaling vs. Horizontal Scaling</h3><p>I revisited two fundamental approaches to scaling.</p><p><strong>Vertical Scaling</strong></p><p>Upgrade an existing server by increasing its resources, such as CPU, RAM, or storage capacity.</p><p><strong>Horizontal Scaling</strong></p><p>Instead of relying on a single powerful server, introduce additional servers and distribute the workload.</p><p>This was an important reminder.</p><p>Improving code quality is only one part of performance engineering.</p><p>Sometimes the bottleneck is the infrastructure, database, network, or another service.</p><p>The challenge is identifying the actual bottleneck before deciding how to solve it.</p><h3>Why Do We Need a Load Balancer?</h3><p>Now imagine that an application runs on multiple servers.</p><p>A new question appears.</p><p><strong>How do incoming requests reach those servers?</strong></p><p>This is where a load balancer comes in.</p><p>Today, I revisited two important responsibilities of a load balancer:</p><ol><li><strong>Health Checks:</strong> Determine which backend servers are healthy and available.</li><li><strong>Traffic Distribution:</strong> Route incoming requests across available servers according to a balancing strategy.</li></ol><p>For example, if one server becomes unhealthy, a properly configured load balancer can stop sending new requests to that server.</p><p>It’s a simple concept on paper.</p><p>But when I think about applications handling millions of requests, I can see why traffic management matters so much.</p><h3>Rediscovering the Components of System Design</h3><p>Towards the end of today’s session, I reviewed seven components that frequently appear in system design.</p><h3>1. Databases</h3><p>Store and manage application data.</p><p>Depending on the application, this could include structured information, metadata, or references to images, videos, audio, and other files.</p><h3>2. Application Code and APIs</h3><p>The backend processes business logic and exposes endpoints through which clients and services communicate.</p><h3>3. Client Applications</h3><p>Websites, mobile applications, and other interfaces through which users interact with the system.</p><h3>4. Cache</h3><p>Temporarily stores frequently accessed or expensive-to-compute data so the application can respond faster without repeatedly performing the same work.</p><p>Cached data can be removed or refreshed based on expiration and invalidation policies.</p><h3>5. Load Balancer</h3><p>Distributes incoming traffic across servers and helps route requests away from unhealthy instances.</p><h3>6. Message Queue</h3><p>Allows parts of a system to communicate asynchronously.</p><p>Instead of requiring every operation to complete immediately, producers can place messages in a queue for consumers to process.</p><h3>7. Monitoring and Logging</h3><p>Help engineers understand what happens inside a running system.</p><p>Logs, metrics, and traces are especially important when investigating errors, latency, and unexpected behavior.</p><p>This immediately reminded me of my earlier exploration of the <strong>OpenTelemetry Astronomy Shop</strong> project.</p><p>That project introduced me to how multiple microservices communicate.</p><p>Today’s course helped me reconnect that discovery with the fundamental components supporting such applications.</p><h3>From Centralized Systems to Distributed Architecture</h3><p>Another concept I revisited was distributed data architecture.</p><p>A centralized database can be useful, but as systems grow, engineers may need replication, partitioning, distributed storage, or specialized databases.</p><p>And that introduces new problems.</p><p>What if two replicas contain different versions of the same data?</p><p>What if network communication fails?</p><p>What if one service is available but another is not?</p><p>How do we maintain consistency while keeping the application responsive?</p><p>These questions are exactly why I want to study distributed systems more deeply.</p><h3>My Biggest Takeaway</h3><p>On October 22, I learned that one application could contain multiple microservices written in different programming languages.</p><p>Today, October 29, I revisited something even more fundamental.</p><p><strong>Before understanding how large-scale distributed systems are built, I need to understand the problems that make those architectural decisions necessary.</strong></p><p>Why introduce caching?</p><p>Why distribute traffic?</p><p>Why scale horizontally?</p><p>Why use message queues?</p><p>Why replicate data?</p><p>And most importantly, what trade-offs come with each decision?</p><p>I already knew the terminology.</p><p>But today wasn’t about discovering seven completely new concepts.</p><p>It was about rediscovering familiar concepts with a stronger focus on engineering reasoning.</p><p>I’m still early in this journey, and there’s much more to explore.</p><p>But I want to move beyond memorizing system design components.</p><p>I want to understand how software behaves under real traffic, how systems fail, and how engineers investigate and resolve those failures.</p><p><strong>Because understanding a system means understanding not only how it works, but also why it was designed that way.</strong></p><p><strong>Forever Learning. Forever Growing.</strong></p><p>— Sai Pranav Moluguri</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5eab8a351142" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ 10/22/2026 — The Day I Realized How Big Tech Companies Like Amazon and Other FAANG Companies…]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/10-22-2026-the-day-i-realized-how-big-tech-companies-like-amazon-and-other-faang-companies-b7153a9b69f0?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/b7153a9b69f0</guid>
            <category><![CDATA[faang]]></category>
            <category><![CDATA[amazon-web-services]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 23:22:23 GMT</pubDate>
            <atom:updated>2026-10-22T23:22:23.887Z</atom:updated>
            <content:encoded><![CDATA[<h3>🧠 10/22/2026 — The Day I Realized How Big Tech Companies Like Amazon and Other FAANG Companies Really Work</h3><p><strong>By Sai Pranav Moluguri</strong></p><h3>One GitHub Repository Changed My Understanding</h3><p>I’ve worked with smaller local companies in Boca Raton, Florida, and back in India.</p><p>Most of my development experience has been with the <strong>MERN stack</strong> — MongoDB, Express.js, React, and Node.js.</p><p>Until recently, I had a simple assumption about big tech companies like Amazon, Google, and Netflix.</p><p>I thought their backend services were primarily built using <strong>Java and frameworks like Spring Boot</strong>.</p><p>But today, while exploring an existing distributed system, I realized something interesting.</p><h3>The Discovery</h3><p>I’ve recently started learning <strong>Microservices Architecture and Distributed Systems</strong>.</p><p>Instead of only reading theory, I wanted to explore an existing codebase and understand how multiple services work together.</p><p>That’s when I came across the <a href="https://github.com/open-telemetry/opentelemetry-demo">OpenTelemetry Astronomy Shop</a>.</p><p>It’s a demo e-commerce application built using multiple microservices.</p><p>While reading its documentation, I noticed something that genuinely surprised me.</p><p><strong>Different services were written in completely different programming languages.</strong></p><p>For example:</p><ul><li><strong>Ad Service</strong> — Java</li><li><strong>Recommendation Service</strong> — Python</li><li><strong>Checkout Service</strong> — Go</li><li><strong>Payment Service</strong> — JavaScript</li><li><strong>Fraud Detection Service</strong> — Kotlin</li><li><strong>Shipping Service</strong> — Rust</li><li><strong>Cart Service</strong> — .NET</li></ul><p>I stopped reading for a moment.</p><p>Wait.</p><p>One application. Multiple microservices. Different programming languages?</p><h3>That’s When It Clicked</h3><p>I realized that large technology companies don’t necessarily use one programming language or framework for every service.</p><p>Different engineering teams can own different services, each built using technologies suited to their requirements.</p><p>One service might use Java.</p><p>Another might use Python.</p><p>Another might use Go.</p><p>And these services communicate through APIs, messaging, or other communication mechanisms to function as one system.</p><p>Of course, OpenTelemetry intentionally uses multiple languages to demonstrate instrumentation across different ecosystems.</p><p>But the broader architectural principle applies to real-world distributed systems too.</p><p><strong>Microservices don’t have to share the same programming language to work together.</strong></p><h3>My Biggest Takeaway</h3><p>Until now, I was mostly thinking about software development in terms of a technology stack.</p><p>MERN stack.</p><p>Java Spring Boot.</p><p>Python Django.</p><p>But today, I started looking at software from a different perspective.</p><p><strong>Service ownership. Independent deployability. Communication between services. Distributed systems.</strong></p><p>It’s no longer just about which programming language an application uses.</p><p>It’s about how independently developed services coordinate to make an entire system work.</p><p>I’m still new to microservices and distributed systems, and I have a lot to learn.</p><p>But discoveries like this make the learning process genuinely exciting.</p><p>One repository. One documentation page. One realization that changed how I look at large-scale software engineering.</p><p><strong>Forever Learning. Forever Growing.</strong><br> — Sai Pranav Moluguri</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b7153a9b69f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ 10 Million Users, 400 Million Lookups: The Math That Made Scale Click for Me]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/10-million-users-400-million-lookups-the-math-that-made-scale-click-for-me-a5cdd0f6664f?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5cdd0f6664f</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[backend-engineering]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[design-systems]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Fri, 16 Oct 2026 18:35:43 GMT</pubDate>
            <atom:updated>2026-10-16T18:35:43.389Z</atom:updated>
            <content:encoded><![CDATA[<p>Sai Pranav Moluguri</p><h3>When a Simple Timeline Became a Systems Problem</h3><p>Recently, while reading a case study about a social network in the style of X, formerly Twitter, I came across a calculation that made large-scale systems feel much more real to me.</p><p>The feature sounded simple:</p><blockquote><em>“Show me the latest posts from the people I follow.”</em></blockquote><p>At first, that does not sound like a difficult problem.</p><p>A user follows some people.</p><p>Those people make posts.</p><p>When the user opens the app, show the newest posts.</p><p>Simple.</p><p>But once millions of users start doing that at the same time, the math becomes crazy very quickly.</p><p>That was the part that made scale click for me.</p><h3>The Setup</h3><p>The case study assumes that:</p><ul><li><strong>10 million users are online at the same time</strong></li><li>Each user follows around <strong>200 people</strong></li><li>The application checks for new timeline posts every <strong>5 seconds</strong></li></ul><p>That repeated checking is called polling.</p><p>So every five seconds, each online user is essentially asking:</p><blockquote><em>“Do I have any new posts to show?”</em></blockquote><p>The first calculation is:</p><blockquote><strong><em>10,000,000 users ÷ 5 seconds</em></strong></blockquote><p>That gives:</p><blockquote><strong><em>2,000,000 timeline requests per second</em></strong></blockquote><p>Two million.</p><p>Every second.</p><p>That number already felt huge.</p><p>But then came the next step.</p><h3>One Timeline Request Is Not Just One Small Lookup</h3><p>Each user follows around 200 people.</p><p>To build that user’s timeline, the system may need to look at recent posts from those followed accounts.</p><p>So one timeline request can involve looking across roughly:</p><blockquote><strong><em>200 followed accounts</em></strong></blockquote><p>Now combine that with the 2 million timeline requests happening every second.</p><p>The math becomes:</p><blockquote><strong><em>2,000,000 × 200</em></strong></blockquote><p>Which gives:</p><blockquote><strong><em>400,000,000 lookups per second</em></strong></blockquote><p>That was the moment I stopped reading for a second.</p><p>Four hundred million.</p><p>Every second.</p><p>All because users want to see recent posts from people they follow.</p><h3>The Mental Model That Helped Me</h3><p>I simplified it like this.</p><p>For one user:</p><blockquote><em>“Check recent posts from 200 people.”</em></blockquote><p>That does not sound difficult.</p><p>But now imagine:</p><blockquote><strong><em>2 million users asking for that every second</em></strong></blockquote><p>Each request may require work across:</p><blockquote><strong><em>200 followed accounts</em></strong></blockquote><p>So:</p><blockquote><strong><em>2 million × 200 = 400 million</em></strong></blockquote><p>The feature did not suddenly become more complicated.</p><p>The number of users made it complicated.</p><p>That distinction helped me.</p><h3>This Is What “Scale” Actually Means</h3><p>Before this example, I understood the word scale in a general way.</p><p>More users.</p><p>More traffic.</p><p>More servers.</p><p>But this example made it concrete.</p><p>A feature can be completely reasonable for:</p><blockquote><em>1 user</em></blockquote><p>Still easy for:</p><blockquote><em>100 users</em></blockquote><p>Maybe manageable for:</p><blockquote><em>10,000 users</em></blockquote><p>But once millions of users perform the same operation continuously, even a simple design can become extremely expensive.</p><p>That is what large-scale system design is really dealing with.</p><p>The problem is not always:</p><blockquote><em>“How do I implement this feature?”</em></blockquote><p>Sometimes the harder question is:</p><blockquote><em>“How do I implement this feature when millions of people use it at the same time?”</em></blockquote><h3>The Database Query Was Not the Part That Surprised Me</h3><p>The SQL itself was understandable.</p><p>Find the people I follow.</p><p>Find their recent posts.</p><p>Sort the posts by timestamp.</p><p>Return the newest ones.</p><p>The surprising part was how often that query would need to run.</p><p>If 10 million users are online and each application polls every five seconds:</p><blockquote><strong><em>2 million timeline requests hit the backend every second</em></strong></blockquote><p>And if every request needs to consider around 200 followed accounts:</p><blockquote><strong><em>400 million account/post lookups per second</em></strong></blockquote><p>That is the difference between thinking about code and thinking about systems.</p><h3>And That Is Only the Average Case</h3><p>The example assumes an average user follows around 200 people.</p><p>But not everyone follows 200 people.</p><p>Some users may follow thousands.</p><p>For those users, generating the timeline becomes even more expensive.</p><p>So the 400 million number is not even describing the worst case.</p><p>It is describing the average case under those assumptions.</p><p>That made the problem even more interesting.</p><h3>The Lesson I Took Away</h3><p>The biggest thing I learned was this:</p><blockquote><em>A simple operation repeated at massive scale becomes a systems problem.</em></blockquote><p>“Show me posts from people I follow” sounds almost trivial.</p><p>But:</p><blockquote><strong><em>10 million online users</em></strong><em><br></em><strong><em>polling every 5 seconds</em></strong><em><br></em><strong><em>following 200 people on average</em></strong></blockquote><p>turns into:</p><blockquote><strong><em>2 million timeline requests per second</em></strong></blockquote><p>and potentially:</p><blockquote><strong><em>400 million lookups per second</em></strong></blockquote><p>That is the kind of math that makes distributed systems feel less abstract.</p><p>Instead of just hearing words like scalability, throughput, and load, I could finally see where the pressure actually comes from.</p><p>Millions of people doing something simple.</p><p>At the same time.</p><h3>What I Want to Understand Next</h3><p>Now I have a new question.</p><p>If generating the home timeline this way is so expensive, how can the system avoid doing all of that work every time a user asks for their feed?</p><p>That is where the design becomes more interesting.</p><p>Instead of only asking:</p><blockquote><em>“How do I query the data?”</em></blockquote><p>I now want to ask:</p><blockquote><em>“Where should the work happen, and when should it happen?”</em></blockquote><p>That is the part I want to understand next.</p><p>First, the math had to scare me a little.</p><p>Now I understand why the architecture needs to change.</p><p><strong>Forever Learning. Forever Growing.</strong><br> — Sai Pranav Moluguri</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5cdd0f6664f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Inheritance vs. Interfaces: The Flying Duck Problem That Made Design Patterns Click for Me]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/inheritance-vs-interfaces-the-flying-duck-problem-that-made-design-patterns-click-for-me-cbb94486d07c?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbb94486d07c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Thu, 15 Oct 2026 16:44:23 GMT</pubDate>
            <atom:updated>2026-10-15T16:44:23.238Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Part 1 — Understanding the problem before learning the solution</em></p><p><strong>By Sai Pranav Moluguri</strong></p><p>Recently, I started reading <em>Head First Design Patterns</em>.</p><p>The book begins with a duck simulation game called SimUDuck. There is a Duck superclass, and the different duck types inherit from it.</p><p>Then the company wants a new feature.</p><p>The ducks should fly.</p><p>My first thought was straightforward:</p><blockquote><em>“Put a fly method in the superclass. Every duck subclass can reuse it.”</em></blockquote><p>Write the code once. Let the subclasses inherit it.</p><p>Then the book introduced the problem.</p><p>Rubber ducks started flying too.</p><p>That made me pause. I could follow the explanation, but I wanted to understand it well enough to explain it in simple words.</p><p>So I wrote the code myself.</p><h3>First, I Tried Inheritance</h3><p>I kept the names simple so I could focus on the relationship between the classes.</p><pre>class Duck:<br>    def fly(self):<br>        print(&quot;This is a flying duck&quot;)<br></pre><pre>class Ducky(Duck):<br>    pass<br></pre><pre>class Duckyy(Duck):<br>    pass<br></pre><pre>class Duckyyy(Duck):<br>    pass<br></pre><pre>duck1 = Ducky()<br>duck2 = Duckyy()<br>duck3 = Duckyyy()</pre><pre>duck1.fly()<br>duck2.fly()<br>duck3.fly()</pre><p>The output was:</p><pre>This is a flying duck<br>This is a flying duck<br>This is a flying duck</pre><p>Here, Duck is the superclass.</p><p>Ducky, Duckyy, and Duckyyy are subclasses.</p><p>I did not write a fly() method inside any of the subclasses. They inherited it from Duck.</p><p>That was the benefit I could see directly:</p><p><strong>I wrote the flying code once, and three subclasses reused it.</strong></p><h3>Then I Saw Why the Rubber Duck Was a Problem</h3><p>My code worked. Every duck could fly.</p><p>But what if one of those subclasses represented a rubber duck?</p><p>It would still inherit fly().</p><p>Inheritance would pass down the method because of the class relationship. It would not check whether flying made sense for that particular duck.</p><p>That was the problem Joe encountered in the book.</p><p>He changed one place: the Duck superclass.</p><p>But that change affected the subclasses too, including ducks that should never have received flying behavior.</p><p>I could finally explain the problem in one sentence:</p><blockquote><em>“Putting flying code in the shared superclass gives it to ducks that should not fly too.”</em></blockquote><p>Joe could override fly() in the rubber duck so that it did nothing.</p><p>But the product would keep changing. For every new duck subclass, someone would need to check whether the inherited flying and quacking behaviors were appropriate.</p><p>The concern was ongoing maintenance as requirements changed.</p><h3>Would an Interface Fix It?</h3><p>The book then considers Flyable and Quackable interfaces.</p><p>At first, that sounded like the answer.</p><p>Only ducks that should fly would implement Flyable. A rubber duck would not.</p><p>But I needed to understand what the interface actually provided.</p><p>The distinction that helped me was:</p><blockquote><em>“Flyable requires a flying method. In this example, it does not provide the instructions for flying.”</em></blockquote><p>To represent that approach in Python, I used an abstract base class:</p><pre>from abc import ABC, abstractmethod<br></pre><pre>class Flyable(ABC):<br>    @abstractmethod<br>    def fly(self):<br>        pass</pre><p>Python provides ABC, which stands for Abstract Base Class. The @abstractmethod decorator marks fly() as a method that concrete subclasses must implement.</p><p>Here, I am using an abstract base class as an interface. It contains no flying implementation.</p><p>I then created two duck classes that fly slowly and three that fly fast.</p><pre>class DuckA(Flyable):<br>    def fly(self):<br>        print(&quot;Flying slowly&quot;)<br></pre><pre>class DuckB(Flyable):<br>    def fly(self):<br>        print(&quot;Flying slowly&quot;)<br></pre><pre>class DuckC(Flyable):<br>    def fly(self):<br>        print(&quot;Flying fast&quot;)<br></pre><pre>class DuckD(Flyable):<br>    def fly(self):<br>        print(&quot;Flying fast&quot;)<br></pre><pre>class DuckE(Flyable):<br>    def fly(self):<br>        print(&quot;Flying fast&quot;)<br></pre><pre>duckA = DuckA()<br>duckB = DuckB()<br>duckC = DuckC()<br>duckD = DuckD()<br>duckE = DuckE()</pre><pre>duckA.fly()<br>duckB.fly()<br>duckC.fly()<br>duckD.fly()<br>duckE.fly()</pre><p>The output was:</p><pre>Flying slowly<br>Flying slowly<br>Flying fast<br>Flying fast<br>Flying fast</pre><p>Each class now supplies its own fly() implementation.</p><p>But look at what I repeated.</p><h3>I Fixed One Problem and Found Another</h3><p>DuckA and DuckB contain the same slow-flying code.</p><p>DuckC, DuckD, and DuckE contain the same fast-flying code.</p><p>Suppose I need to change how slow flying works.</p><p>I have to update both DuckA and DuckB.</p><p>If fast flying changes, I have three implementations to update.</p><p>Now imagine ten duck classes sharing one flying behavior and another three sharing a different behavior.</p><p>With this approach, I would maintain ten copies of the first implementation and three copies of the second.</p><p><strong>The interface requires the method, but it does not give those classes a shared implementation.</strong></p><p>That was the maintenance problem I had been missing.</p><p>The examples use tiny print statements, but the duplication is already visible.</p><h3>The Distinction I Was Looking For</h3><p>I could now describe both problems simply:</p><p>Approach in this exampleWhat I gainWhat goes wrongFlying code in the superclassOne implementation that subclasses reuseDucks that should not fly inherit it tooA Flyable interface with implementations in each duck classI choose which duck classes implement flyingDucks with identical flying behavior repeat the same code</p><p>One detail mattered to me: the interface example still uses inheritance in Python. Each duck class inherits from Flyable.</p><p>The difference is what it receives.</p><p>In the first example, the subclasses inherit working flying code.</p><p>In the second, the abstract base class requires a method, and each concrete subclass supplies the code.</p><p>So this is a problem with these particular designs. It does not mean inheritance or interfaces are always wrong.</p><h3>Why I Wanted to Understand the Problem First</h3><p>I did not want to jump straight to a design pattern while still wondering why the previous approaches were difficult to maintain.</p><p>Writing the examples helped.</p><p>I could see where the behavior came from.</p><p>I could see which ducks received it.</p><p>And I could see how many places I would need to change when the requirements changed.</p><p>That gave the next part of the book a clear purpose.</p><p><strong>How can I let the right ducks share flying behavior without putting that behavior into every duck or repeating the implementation?</strong></p><h3>Coming in Part 2</h3><p>The book introduces a design principle that guides the solution:</p><blockquote><em>Identify the aspects of your application that vary and separate them from what stays the same.</em></blockquote><p>In Part 2, I will explore what that means in the duck example and how it helps address the problems I encountered with inheritance and interfaces.</p><p>First, I needed to understand the problem.</p><p>Now I have a reason to learn the solution.</p><p>Forever Learning. Forever Growing.</p><p>— Sai Pranav Moluguri</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbb94486d07c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ LLD Chapter 2: Understanding State Machines and Factories]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/lld-chapter-2-understanding-state-machines-and-factories-8b4ee9434720?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/8b4ee9434720</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[state-machine]]></category>
            <category><![CDATA[object-oriented-design]]></category>
            <category><![CDATA[factory-pattern]]></category>
            <category><![CDATA[low-level-design]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Wed, 07 Oct 2026 18:38:25 GMT</pubDate>
            <atom:updated>2026-10-07T18:38:25.189Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>By Sai Pranav Moluguri</strong></p><h3>Then State Machine Clicked</h3><p>The next pattern I learned was State Machine.</p><p>My simple definition became:</p><p>State Machine = same object, different behavior depending on its current state.</p><p>The vending machine example made this very easy to understand.</p><p>The vending machine is still the same machine.</p><p>But it behaves differently depending on what state it is currently in.</p><p>For example:</p><p>Waiting for money</p><p>↓</p><p>Money inserted</p><p>↓</p><p>Item selected</p><p>↓</p><p>Dispensing</p><p>↓</p><p>Back to waiting</p><p>The object did not change.</p><p>The vending machine is still the vending machine.</p><p>What changed was its state.</p><p>And because the state changed, the behavior changed too.</p><p>If the machine is waiting for money:</p><p>select_item()</p><p>should not work yet.</p><p>If money has already been inserted:</p><p>select_item()</p><p>can now work.</p><p>If the machine is dispensing:</p><p>inserting more money might not be allowed.</p><p>That made the idea click for me.</p><p>The important question is:</p><p>What state is this object currently in?</p><p>And then:</p><p>What actions are allowed in this state?</p><p>So now my mental model is:</p><p>STATE MACHINE</p><p>SAME OBJECT</p><p>↓</p><p>CURRENT STATE CHANGES</p><p>↓</p><p>BEHAVIOR CHANGES</p><p>That’s State Machine.</p><h3>Then Factory Finally Made Sense</h3><p>Factory confused me at first because it looked very similar to Strategy.</p><p>Both can involve different types of objects.</p><p>For example:</p><p>Credit Card</p><p>PayPal</p><p>Apple Pay</p><p>So initially I thought:</p><p>Isn’t this just Strategy again?</p><p>Then the difference became clear.</p><p>Strategy is about:</p><p>How should I perform this task?</p><p>Factory is about:</p><p>Which object should I create?</p><p>That was the distinction.</p><p>Suppose I have:</p><p>PaymentFactory.create(“paypal”)</p><p>The factory checks the requested type and creates:</p><p>PayPalPayment</p><p>If I ask for:</p><p>PaymentFactory.create(“credit”)</p><p>it creates:</p><p>CreditCardPayment</p><p>So the factory is responsible for object creation.</p><p>Instead of different parts of my program doing:</p><p>PayPalPayment()</p><p>CreditCardPayment()</p><p>ApplePayPayment()</p><p>everywhere,</p><p>I have one place responsible for deciding what object gets created.</p><p>That gave me the simplest mental model:</p><p>Factory = one place creates different object types.</p><p>And the difference between Factory and Strategy became:</p><p>Factory creates it.</p><p>Strategy uses it.</p><p>For example:</p><p>Factory creates:</p><p>PayPalPayment</p><p>Then Strategy can use that object as the way to perform payment.</p><p>That separation finally made both patterns much clearer.</p><h3>State Machine vs Strategy vs Factory</h3><p>At this point, I had three patterns that sounded different but were now easy to separate.</p><p>Strategy:</p><p>Same task</p><p>↓</p><p>Different ways to do it</p><p>Example:</p><p>Regular pricing</p><p>Happy-hour pricing</p><p>Employee discount</p><p>State Machine:</p><p>Same object</p><p>↓</p><p>Different behavior depending on current state</p><p>Example:</p><p>Vending machine</p><p>Waiting</p><p>Money inserted</p><p>Dispensing</p><p>Factory:</p><p>One place</p><p>↓</p><p>Creates different object types</p><p>Example:</p><p>PaymentFactory</p><p>↓</p><p>CreditCardPayment</p><p>PayPalPayment</p><p>ApplePayPayment</p><p>And that gave me another useful summary:</p><p>Strategy = choose behavior</p><p>State Machine = behavior depends on state</p><p>Factory = choose what object to create</p><p>The more I learn these patterns, the more I realize they are not complicated ideas.</p><p>The names sound bigger than the concepts.</p><p>The real challenge is simply recognizing:</p><p>What kind of problem am I looking at?</p><p>If the same task can be performed in different ways:</p><p>Strategy.</p><p>If one event should trigger multiple reactions:</p><p>Observer.</p><p>If one object behaves differently depending on its current state:</p><p>State Machine.</p><p>If object creation is scattered everywhere:</p><p>Factory.</p><p>That is the level at which these patterns are starting to make sense to me.</p><p>Not as definitions to memorize.</p><p>But as problems I can recognize.</p><p>And once I can explain them simply, I feel like I actually understand them.</p><p>Forever Learning. Forever Growing.</p><p>— Sai Pranav Moluguri</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8b4ee9434720" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ LLD Started Making Sense When I Stopped Thinking About It as System Design]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/lld-started-making-sense-when-i-stopped-thinking-about-it-as-system-design-f7f87ae1681d?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7f87ae1681d</guid>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[low-level-design]]></category>
            <category><![CDATA[object-oriented-design]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[clean-code]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Wed, 07 Oct 2026 18:02:07 GMT</pubDate>
            <atom:updated>2026-10-07T18:02:07.196Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>By Sai Pranav Moluguri</strong></p><p>I’ve been doing DSA almost every day for a while.</p><p>Arrays. Graphs. DFS. BFS. Dynamic programming.</p><p>I enjoy problem solving, but after repeating the same cycle every day, I wanted to learn something different.</p><p>That’s when I started looking into Low-Level Design.</p><p>At first, “LLD” sounded like another huge software engineering topic.</p><p>But once I started learning it, I realized something surprisingly simple:</p><p>LLD is mostly about modeling things using objects.</p><p>You’re designing the internal structure of a single component, not a whole system.</p><p>That distinction made it much easier for me.</p><h3>The Mental Model That Made LLD Click</h3><p>I started reducing LLD into a few simple questions.</p><p>Class = Thing</p><p>Responsibility = Its job</p><p>Relationship = How it connects to other things</p><p>Method = What it can do</p><p>Flow = What happens step by step</p><p>Suppose I’m designing a library.</p><p>I might have:</p><p>Library</p><p>Book</p><p>BookCopy</p><p>Member</p><p>Loan</p><p>Then I ask:</p><p>What is each one responsible for?</p><p>A Book stores information about a book.</p><p>A BookCopy represents one actual copy.</p><p>A Member represents someone using the library.</p><p>A Loan represents a book being borrowed.</p><p>Then I connect them.</p><p>A Library has many BookCopies.</p><p>A Member can have many Loans.</p><p>A Loan connects a Member with one BookCopy.</p><p>Then methods become another simple question:</p><p>What can this thing do?</p><p>A Library might:</p><p>borrow_book()</p><p>return_book()</p><p>search_book()</p><p>A Loan might:</p><p>is_overdue()</p><p>A BookCopy might:</p><p>checkout()</p><p>return_copy()</p><p>Once I started thinking this way, LLD stopped feeling abstract.</p><p>It started feeling like translating real life into code.</p><h3>A Flow Is Just What Happens in Real Life</h3><p>Take borrowing a book.</p><p>In real life:</p><p>Member asks for a book</p><p>↓</p><p>Library finds an available copy</p><p>↓</p><p>The copy becomes unavailable</p><p>↓</p><p>A loan is created</p><p>↓</p><p>The loan is associated with the member</p><p>That is the flow.</p><p>The software classes are simply cooperating to represent something that already makes sense in the real world.</p><p>This was probably the biggest simplification for me.</p><p>Instead of immediately thinking about code, I can first ask:</p><p>What actually happens?</p><p>Then I model that behavior.</p><h3>Then I Learned Strategy</h3><p>The first design pattern that really clicked for me was Strategy.</p><p>My simple definition became:</p><p>Strategy = different ways of doing the same thing.</p><p>At first I confused this with simply changing a value.</p><p>For example, at Starbucks I can order a latte as:</p><p>Tall</p><p>Grande</p><p>Venti</p><p>But that is not really Strategy.</p><p>The behavior has not changed.</p><p>The size is simply different data.</p><p>Then pricing made Strategy much clearer.</p><p>Imagine the task is:</p><p>calculate_price()</p><p>There might be different ways to calculate that price:</p><p>Regular pricing</p><p>Happy-hour pricing</p><p>Employee discount</p><p>For example:</p><p>Regular:</p><p>price</p><p>Happy hour:</p><p>price × 0.8</p><p>Employee discount:</p><p>price × 0.7</p><p>The final result is still a number.</p><p>But the important thing is not that the number changes.</p><p>The rule used to produce the number changes.</p><p>That was the distinction I needed.</p><p>Different value = configuration/data</p><p>Different way of performing the task = Strategy</p><p>So now my mental model is:</p><p>TASK</p><p>Calculate price</p><p>↓</p><p>STRATEGIES</p><p>Regular</p><p>Happy Hour</p><p>Employee Discount</p><p>Same job.</p><p>Different logic.</p><p>That’s Strategy.</p><h3>Observer Clicked Because of Kindle</h3><p>The next pattern I learned was Observer.</p><p>My definition became:</p><p>Observer = one event happens, and multiple interested things react to it.</p><p>The example that made it concrete for me was buying a Kindle book.</p><p>Imagine I press:</p><p>Buy</p><p>That is one event.</p><p>But several things might happen because of that one event.</p><p>The purchase/licensing information gets updated.</p><p>I receive a confirmation email.</p><p>The book appears in my Kindle library.</p><p>Maybe analytics records the purchase too.</p><p>Conceptually:</p><p>BUY BOOK</p><p>↓</p><p>Purchase recorded</p><p>↓</p><p>Email sent</p><p>↓</p><p>Kindle library updated</p><p>↓</p><p>Analytics updated</p><p>One action triggered several independent reactions.</p><p>That is Observer.</p><p>The important part is that those components care about the event.</p><p>They are essentially saying:</p><p>“If a purchase happens, tell me.”</p><p>That gave me another easy mental model:</p><p>Observer = one event, many reactions.</p><h3>Strategy vs Observer</h3><p>These two patterns sounded similar to me at first because both involve multiple possibilities.</p><p>But they solve completely different problems.</p><p>Strategy asks:</p><p>How should I perform this task?</p><p>Example:</p><p>Calculate price using:</p><p>regular pricing</p><p>happy-hour pricing</p><p>employee pricing</p><p>Observer asks:</p><p>Who needs to react when this event happens?</p><p>Example:</p><p>Kindle book purchased:</p><p>update library</p><p>send email</p><p>update analytics</p><p>So now I remember them like this:</p><p>Strategy</p><p>ONE TASK</p><p>↓</p><p>DIFFERENT WAYS</p><p>Observer</p><p>ONE EVENT</p><p>↓</p><p>MULTIPLE REACTIONS</p><p>That distinction made both patterns much easier to recognize.</p><h3>The Bigger Thing I’m Learning About LLD</h3><p>The interesting part of LLD for me is that it isn’t really about creating as many classes as possible.</p><p>It’s almost the opposite.</p><p>The goal is to make responsibilities obvious.</p><p>If one class is doing five unrelated jobs, something probably feels wrong.</p><p>If adding one small feature forces me to modify everything, something probably feels wrong.</p><p>If I need ten design patterns for a tiny problem, I’m probably overengineering it.</p><p>The best designs I’ve seen so far seem simple when you explain them.</p><p>That connects to one sentence I really like:</p><p>A good design that you can’t explain is indistinguishable from a bad design.</p><p>So while learning LLD, I’m trying not to collect definitions.</p><p>I’m trying to build intuition.</p><p>When behavior can change:</p><p>Strategy.</p><p>When one event should notify several interested components:</p><p>Observer.</p><p>When I create a class:</p><p>What is its one responsibility?</p><p>When classes interact:</p><p>What is the relationship?</p><p>When I add a method:</p><p>What can this object actually do?</p><p>And before writing any of that:</p><p>What happens in the real world?</p><p>That last question is making LLD much more interesting to me than I expected.</p><p>I started learning it simply because I wanted a break from doing DSA repeatedly.</p><p>Now I’m beginning to see software differently.</p><p>Instead of only asking:</p><p>“How do I solve this algorithm?”</p><p>I’m also starting to ask:</p><p>“How should I model this?”</p><p>“How should these objects communicate?”</p><p>“Where should this responsibility live?”</p><p>“What happens if the requirements change?”</p><p>It feels like a different kind of problem solving.</p><p>And I’m enjoying that.</p><p>Forever Learning. Forever Growing.</p><p>— Sai Pranav Moluguri</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7f87ae1681d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ I Thought These Were Two Different Graph Problems.]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/i-thought-these-were-two-different-graph-problems-a9d187a7097b?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9d187a7097b</guid>
            <category><![CDATA[graph]]></category>
            <category><![CDATA[set]]></category>
            <category><![CDATA[dfs]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[dictionary]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Mon, 21 Sep 2026 15:43:23 GMT</pubDate>
            <atom:updated>2026-09-21T15:43:23.068Z</atom:updated>
            <content:encoded><![CDATA[<h3>🧠 I Thought These Were Two Different Graph Problems. Then I Realized the DFS Was the Same — Only the State Changed.</h3><p><strong>By Sai Pranav Moluguri</strong></p><p>Before getting into the graph problem, I want to write down a milestone that means a lot to me.</p><p>I have successfully written and published <strong>100 blogs on Medium</strong>.</p><p>And this is my <strong>101st blog</strong>.</p><p>When I started writing, I wasn’t trying to build some perfect collection of technical articles. I wanted a place to document the moments when something I was learning finally clicked in my head.</p><p>100 published blogs later, I’m still doing exactly that.</p><p>So here is <strong>#101</strong>.</p><p>And many more to go.</p><h3>Two Graph Problems Started Looking Suspiciously Similar</h3><p>I was revisiting two graph problems:</p><p><strong>Can Color</strong></p><p>and</p><p><strong>Rare Routing</strong></p><p>I had already solved both of them.</p><p>At first, I understood them as separate problems.</p><p>Can Color was about <strong>graph coloring</strong>.</p><p>Rare Routing was about determining whether an undirected graph had <strong>unique routes</strong>, which required detecting cycles and making sure the graph was connected.</p><p>But when I placed my two solutions next to each other, something caught my attention.</p><p>They looked remarkably similar.</p><p>Here was my Can Color DFS:</p><pre>def can_color(graph):  coloring = {}  for node in graph:    if node not in coloring:      if not valid(graph, node, coloring, True):        return False  return Truedef valid(graph, node, coloring, current_color):  if node in coloring:    return coloring[node] == current_color  coloring[node] = current_color  for nei in graph[node]:    if not valid(graph, nei, coloring, not current_color):      return False  return True</pre><p>And here was my Rare Routing DFS:</p><pre>def rare_routing(n, roads):  graph = {}  for i in range(n):    graph[i] = []  for i, j in roads:    graph[i].append(j)    graph[j].append(i)  visited = set()  valid = validate(graph, 0, visited, None)  return valid and len(visited) == ndef validate(graph, node, visited, parent):  if node in visited:    return False  visited.add(node)  for nei in graph[node]:    if nei != parent and not validate(graph, nei, visited, node):      return False  return True</pre><p>Looking at them together made me ask:</p><blockquote><strong><em>Wait. Aren’t these basically using the same DFS structure?</em></strong></blockquote><p>Yes.</p><p>But they are carrying <strong>different information through the DFS</strong>.</p><p>That was the realization.</p><h3>The DFS Wasn’t the Important Difference</h3><p>Both algorithms essentially do this:</p><pre>Visit node<br>    ↓<br>Record something about node<br>    ↓<br>Explore neighbors<br>    ↓<br>Pass some state into recursion<br>    ↓<br>Validate something</pre><p>The traversal mechanism is DFS in both.</p><p>What changes is:</p><blockquote><strong><em>What property am I trying to validate?</em></strong></blockquote><p>And because the property changes, the <strong>state I need to carry through DFS changes</strong>.</p><p>That made both algorithms much easier for me to understand.</p><h3>Can Color: The State I Care About Is Color</h3><p>The question behind Can Color is essentially:</p><blockquote><em>Can I separate the graph into two groups such that connected nodes belong to opposite groups?</em></blockquote><p>I don’t actually care about literal colors.</p><p>I can represent my two groups using:</p><pre>True<br>False</pre><p>So when DFS begins:</p><pre>valid(graph, node, coloring, True)</pre><p>I could have started with False too.</p><p>What matters is that neighboring nodes receive the opposite value.</p><p>So if:</p><pre>A = True</pre><p>then:</p><pre>B = False</pre><p>and B’s neighbor should be:</p><pre>C = True</pre><p>Conceptually:</p><pre>A(True)<br>   |<br>B(False)<br>   |<br>C(True)</pre><p>That’s why recursion contains:</p><pre>not current_color</pre><p>Every time I cross an edge, I expect the opposite color.</p><h3>Why Can Color Uses a Dictionary</h3><p>Another thing clicked here.</p><p>Why am I using:</p><pre>coloring = {}</pre><p>instead of:</p><pre>visited = set()</pre><p>Because knowing:</p><blockquote><em>“I have already visited this node.”</em></blockquote><p>isn’t enough.</p><p>I also need to know:</p><blockquote><strong><em>“What color did I give this node?”</em></strong></blockquote><p>So my dictionary gives me both pieces of information.</p><pre>node exists in coloring<br>        ↓<br>I&#39;ve already visited it</pre><pre>coloring[node]<br>        ↓<br>This is the color I assigned it</pre><p>That’s why this condition is powerful:</p><pre>if node in coloring:  return coloring[node] == current_color</pre><p>When DFS reaches an already-colored node, the revisit itself isn’t necessarily a problem.</p><p>I ask:</p><blockquote><strong><em>Does the color I expect this node to have match the color it already has?</em></strong></blockquote><p>If yes, continue.</p><p>If no, the coloring is inconsistent.</p><p>That means the problem isn’t:</p><pre>REVISITED NODE<br>      ↓<br>BAD</pre><p>It’s:</p><pre>REVISITED NODE<br>      ↓<br>Does existing color == expected color?<br>      ↓<br>YES → fine<br>NO  → conflict</pre><p>That distinction matters.</p><h3>Rare Routing Looked Similar — But I Needed Different State</h3><p>Then I looked at Rare Routing.</p><p>Again, I’m traversing an undirected graph with DFS.</p><p>But now I’m not asking:</p><blockquote><em>What color should this node have?</em></blockquote><p>I’m asking:</p><blockquote><strong><em>Did I reach a node I’ve already visited through another route?</em></strong></blockquote><p>Because that can indicate a cycle.</p><p>So I don’t need:</p><pre>coloring = {}</pre><p>I use:</p><pre>visited = set()</pre><p>Why?</p><p>Because now my question is mostly binary:</p><pre>Have I seen this node?</pre><pre>YES / NO</pre><p>I don’t need to retrieve a color associated with the node.</p><p>But there was one important complication.</p><h3>In an Undirected Graph, Seeing Your Parent Again Is Normal</h3><p>Imagine:</p><pre>A — B</pre><p>Because the graph is undirected, the adjacency list essentially contains:</p><pre>A → B<br>B → A</pre><p>Now DFS starts from A.</p><pre>A<br>↓<br>B</pre><p>When I’m standing at B, I see A again.</p><p>But that doesn’t mean:</p><blockquote><em>“I found a cycle!”</em></blockquote><p>A is simply <strong>where I came from</strong>.</p><p>That’s why Rare Routing carries another piece of state:</p><pre>parent</pre><p>Initially:</p><pre>validate(graph, 0, visited, None)</pre><p>The starting node has no parent.</p><p>So:</p><pre>parent = None</pre><p>But suppose I move:</p><pre>A → B</pre><p>When DFS enters B, I pass A as B’s parent.</p><p>That’s what this means:</p><pre>validate(graph, nei, visited, node)</pre><p>In my head, I now read that as:</p><blockquote><strong><em>“I’m moving to </em></strong><strong><em>nei, and the current </em></strong><strong><em>node becomes the parent of </em></strong><strong><em>nei.”</em></strong></blockquote><p>So if B looks at its neighbors and sees A:</p><pre>if nei != parent:</pre><p>prevents me from treating the edge I just came through as a cycle.</p><h3>That Was the Connection</h3><p>Once I put the two algorithms next to each other, I saw this:</p><pre>CAN COLOR                     RARE ROUTING</pre><pre>DFS                           DFS<br> ↓                             ↓<br>current_color                 parent<br> ↓                             ↓<br>visit node                    visit node<br> ↓                             ↓<br>store its color               mark visited<br> ↓                             ↓<br>explore neighbors             explore neighbors<br> ↓                             ↓<br>pass opposite color           pass current node as parent<br> ↓                             ↓<br>revisit?                      revisit?<br> ↓                             ↓<br>check expected color          cycle detected<br>                              except immediate parent</pre><p>Same traversal mechanism.</p><p>Different question.</p><p>Different state.</p><p>That was the part that clicked.</p><h3>A Revisit Means Different Things in Different Problems</h3><p>This might actually be my favorite realization from comparing these problems.</p><p>In <strong>Can Color</strong>, revisiting a node is not automatically failure.</p><p>I might legitimately arrive at the same node through another path.</p><p>I need to ask:</p><pre>Does its existing color<br>match the color I expect?</pre><p>So:</p><pre>if node in coloring:  return coloring[node] == current_color</pre><p>But in <strong>Rare Routing</strong>, an already-visited node means something different.</p><p>If I reach a previously visited node through something other than the immediate parent edge, I’ve discovered another route back into the explored graph.</p><p>That’s exactly what I’m trying to prevent.</p><p>So the same event:</p><pre>&quot;I&#39;ve seen this node before.&quot;</pre><p>has completely different meaning depending on the problem.</p><p>That taught me something deeper than either individual solution.</p><h3>The Data Structure Follows the Information I Need</h3><p>I used to look at code like this and think:</p><pre>This problem uses a set.</pre><pre>That problem uses a dictionary.</pre><p>Now I want to ask <strong>why</strong>.</p><p>Rare Routing needs:</p><pre>node → visited?</pre><p>That’s membership information.</p><p>A set is enough.</p><pre>visited = set()</pre><p>Can Color needs:</p><pre>node → assigned color</pre><p>That’s an association between a key and some information.</p><p>So I need a dictionary.</p><pre>coloring = {}</pre><p>This gives me a simple rule I want to carry forward:</p><blockquote><strong><em>Choose the data structure based on the information the algorithm needs to remember.</em></strong></blockquote><p>Not because I remember that “this particular graph problem uses a dictionary.”</p><h3>My New Way of Looking at DFS Problems</h3><p>This comparison changed how I want to approach future graph problems.</p><p>Instead of immediately trying to remember:</p><blockquote><em>“Which DFS template did I use for this?”</em></blockquote><p>I want to ask:</p><pre>What am I trying to validate?<br>        ↓<br>What information must survive<br>from one recursive call to the next?<br>        ↓<br>What state represents that information?<br>        ↓<br>What data structure should store it?</pre><p>For Can Color:</p><pre>PROPERTY<br>Can neighbors belong to opposite groups?<br>        ↓<br>STATE<br>current_color<br>        ↓<br>MEMORY<br>node → assigned color<br>        ↓<br>DATA STRUCTURE<br>dictionary</pre><p>For Rare Routing:</p><pre>PROPERTY<br>Is the undirected graph acyclic?<br>        ↓<br>STATE<br>parent<br>        ↓<br>MEMORY<br>Have I visited this node?<br>        ↓<br>DATA STRUCTURE<br>set</pre><p>The DFS itself didn’t fundamentally change.</p><p><strong>The meaning of the DFS changed.</strong></p><h3>This Is Why I Don’t Want to Memorize Graph Solutions</h3><p>This is also why solving variations of graph problems has started becoming much more interesting to me.</p><p>If I simply memorized:</p><pre>Can Color → use this code</pre><pre>Rare Routing → use this code</pre><p>then the moment an interviewer changed the story, I could get stuck.</p><p>Instead, I want to recognize the machinery underneath.</p><p>Strip away the story and ask:</p><blockquote><strong><em>What problem am I trying to solve, and which data structure or algorithm do I need underneath?</em></strong></blockquote><p>Then go one level deeper:</p><blockquote><strong><em>What information does my traversal need to carry in order to solve that problem?</em></strong></blockquote><p>That’s much more reusable.</p><h3>My Recipe Going Forward</h3><p>When I encounter another DFS graph problem, I want to think:</p><pre>GRAPH PROBLEM<br>      ↓<br>What property am I checking?<br>      ↓<br>What state do I need while traversing?<br>      ↓<br>What does revisiting a node mean HERE?<br>      ↓<br>Do I only need membership?<br>Or do I need information associated with each node?<br>      ↓<br>Choose set / dictionary / other state<br>      ↓<br>DFS</pre><p>Especially this question:</p><blockquote><strong><em>What does revisiting a node mean in this specific problem?</em></strong></blockquote><p>Because Can Color and Rare Routing showed me that there isn’t one universal answer.</p><h3>My Takeaway</h3><p>Today I didn’t learn a completely new DFS algorithm.</p><p>I realized something better.</p><p>Two problems that looked different were built on almost the <strong>same traversal skeleton</strong>.</p><p>The difference was the information being carried through that traversal.</p><p>For Can Color:</p><pre>DFS<br>↓<br>carry COLOR<br>↓<br>neighbors get opposite color<br>↓<br>revisit means:<br>verify expected color</pre><p>For Rare Routing:</p><pre>DFS<br>↓<br>carry PARENT<br>↓<br>current node becomes neighbor&#39;s parent<br>↓<br>revisit means:<br>cycle, unless it&#39;s the parent edge</pre><p>And that led me to the bigger idea I want to remember:</p><blockquote><strong><em>The DFS skeleton can stay the same. The state I carry and the condition I validate change according to the property the problem asks me to prove.</em></strong></blockquote><p>That’s the realization I want to take into the next graph problem.</p><p>And there’s something special about writing that sentence in this particular post.</p><p>I have now successfully written and published <strong>100 blogs on Medium</strong>.</p><p>This is <strong>blog #101</strong>.</p><p>Those 100 posts contain problems I struggled with, concepts that finally clicked, bugs that cost me time, books I learned from, and ideas I wanted my future self to remember.</p><p>I’m proud that I kept writing and reached 100.</p><p>But I don’t see #100 as the finish line.</p><p>This is #101.</p><p><strong>And there are many more to go.</strong></p><p><strong>Forever Learning. Forever Growing.</strong></p><p>— <strong>Sai Pranav Moluguri</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9d187a7097b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ I Stopped Starting BFS From One Cell. Then “Best Bridge” Taught Me Multi-Source BFS.]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/i-stopped-starting-bfs-from-one-cell-then-best-bridge-taught-me-multi-source-bfs-db330a2339e3?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/db330a2339e3</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[graphic-design]]></category>
            <category><![CDATA[dfs]]></category>
            <category><![CDATA[fb]]></category>
            <category><![CDATA[algorithms]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Fri, 18 Sep 2026 23:32:35 GMT</pubDate>
            <atom:updated>2026-09-18T23:32:35.422Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>By Sai Pranav Moluguri</strong></p><p>I was solving <strong>Best Bridge</strong>, a graph problem where I’m given a grid containing exactly two islands.</p><p>L represents land.</p><p>W represents water.</p><p>My job is to return the <strong>minimum bridge length needed to connect the two islands</strong>.</p><p>At first, I knew one thing immediately:</p><blockquote><em>Minimum distance? This is going to involve BFS.</em></blockquote><p>I had already used BFS for shortest-path problems before.</p><p>But this problem taught me something more interesting.</p><p>Usually, I was used to thinking:</p><pre>Choose one starting position<br>        ↓<br>Put it in the queue<br>        ↓<br>BFS outward<br>        ↓<br>Find the shortest path</pre><p>But here, an island isn’t one cell.</p><p>An island could be:</p><pre>L L<br>L L L<br>  L</pre><p>Every one of those land cells belongs to the <strong>same starting island</strong>.</p><p>That led me to the idea that made this problem click:</p><blockquote><strong><em>What if I start BFS from the entire first island at the same time?</em></strong></blockquote><p>That was my introduction — or really my practical recall — to <strong>multi-source BFS</strong>.</p><h3>First, I Needed to Find One Entire Island</h3><p>Before thinking about the bridge, I needed to know:</p><pre>Which cells belong to the first island?</pre><p>This part felt familiar.</p><p>An island is simply a collection of vertically or horizontally connected land cells.</p><p>So once I find one L, I can DFS from it and collect every connected L.</p><p>I created:</p><pre>current_island = set()</pre><p>Then I searched the grid for the first land cell:</p><pre>for r in range(len(grid)):<br>  if current_island:<br>    break<br>  for c in range(len(grid[0])):<br>    if grid[r][c] == &quot;L&quot;:<br>      dfs(grid, r, c, current_island)<br>      break</pre><p>Once DFS starts from that first L, it explores the entire connected island.</p><p>Conceptually:</p><pre>Find one L<br>    ↓<br>DFS<br>    ↓<br>Explore up/down/left/right<br>    ↓<br>Collect every connected L<br>    ↓<br>current_island = entire first island</pre><h3>The Nested break Bug That Cost Me Time</h3><p>This was one of those small Python details that caused a surprisingly large problem.</p><p>Originally, once I found the first L, I thought:</p><pre>break</pre><p>would stop my search.</p><p>But I had <strong>nested loops</strong>.</p><pre>for every row:<br>    for every column:</pre><p>And break only exits the loop it directly belongs to.</p><p>So breaking from the inner column loop does <strong>not</strong> automatically stop the outer row loop.</p><p>That meant I could continue scanning the grid and eventually DFS into the <strong>second island too</strong>.</p><p>Then:</p><pre>current_island</pre><p>would contain both islands.</p><p>That completely destroyed the distinction I needed later between:</p><pre>first island</pre><p>and:</p><pre>second island</pre><p>The fix in my code was simple:</p><pre>for r in range(len(grid)):<br>  if current_island:<br>    break</pre><p>Once current_island has been populated, I know I&#39;ve already captured my first island.</p><p>Stop searching.</p><p>That gave me a useful Python reminder:</p><blockquote><strong><em>break exits only the immediate loop. With nested loops, I need to deliberately control the outer loop too.</em></strong></blockquote><h3>My DFS for Capturing the First Island</h3><p>This is the DFS I wrote:</p><pre>def dfs(grid, r, c, visited):<br>  row_inbounds = 0 &lt;= r &lt; len(grid)<br>  col_inbounds = 0 &lt;= c &lt; len(grid[0])</pre><pre>  if not row_inbounds or not col_inbounds:<br>    return visited</pre><pre>  if grid[r][c] == &quot;W&quot;:<br>    return visited</pre><pre>  pos = (r,c)</pre><pre>  if pos in visited:<br>    return visited<br>  visited.add(pos)</pre><pre>  dfs(grid, r+1, c, visited)<br>  dfs(grid, r-1, c, visited)<br>  dfs(grid, r, c+1, visited)<br>  dfs(grid, r, c-1, visited)</pre><pre>  return visited</pre><p>The mental recipe is straightforward:</p><pre>Out of bounds?<br>→ stop</pre><pre>Water?<br>→ stop</pre><pre>Already visited?<br>→ stop</pre><pre>New land?<br>→ add it</pre><pre>Then explore:<br>down<br>up<br>right<br>left</pre><p>By the end:</p><pre>current_island = every coordinate belonging to Island 1</pre><p>Now came the interesting part.</p><h3>My First Thought: Where Should BFS Start?</h3><p>Normally, I would write something like:</p><pre>queue = [starting position]</pre><p>But what is the starting position here?</p><p>The first island might contain many cells.</p><p>Suppose:</p><pre>L L<br>L L</pre><p>If I arbitrarily start BFS from only one of those cells, I might be starting much farther away from the second island than another cell on the same island.</p><p>But all four cells are already part of my first island.</p><p>So why choose only one?</p><p>That was the click.</p><p>I put <strong>every cell of the first island into the queue</strong>:</p><pre>queue = deque([])</pre><pre>for r,c in current_island:<br>  queue.append((r,c,0))</pre><p>Now my queue conceptually starts like:</p><pre>[<br>  (island_cell_1, distance 0),<br>  (island_cell_2, distance 0),<br>  (island_cell_3, distance 0),<br>  ...<br>]</pre><p>Every cell begins at distance 0 because I&#39;m not building a bridge yet.</p><p>I’m already standing on the island.</p><p>This is <strong>multi-source BFS</strong>.</p><h3>The Mental Shift: One BFS, Many Starting Points</h3><p>This was the biggest takeaway from the problem.</p><p>Before this, my BFS mental model was mostly:</p><pre>ONE SOURCE<br>    ↓<br>BFS<br>    ↓<br>shortest path</pre><p>Best Bridge expanded that model:</p><pre>MULTIPLE SOURCES<br>       ↓<br>Put all of them into the queue initially<br>       ↓<br>BFS expands from all of them<br>       ↓<br>Find the closest destination to ANY source</pre><p>I don’t need to run:</p><pre>BFS from island cell 1<br>BFS from island cell 2<br>BFS from island cell 3<br>...</pre><p>Instead:</p><pre>All first-island cells<br>        ↓<br>same queue<br>        ↓<br>same BFS<br>        ↓<br>expand outward together</pre><p>That was the part I wanted to remember.</p><h3>Expanding the Bridge</h3><p>Once the queue is initialized, I begin normal BFS:</p><pre>while queue:<br>  (r,c,length) = queue.popleft()</pre><p>Then I generate the four neighboring positions:</p><pre>positions = [(r+1, c), (r-1, c), (r, c+1), (r, c-1)]</pre><p>And add valid positions:</p><pre>for i,j in positions:<br>  if bounds(grid, i, j):<br>    queue.append((i, j, length+1))</pre><p>My bounds helper is:</p><pre>def bounds(grid, r, c):<br>  row_inbounds = 0 &lt;= r &lt; len(grid)<br>  col_inbounds = 0 &lt;= c &lt; len(grid[0])</pre><pre>  if not row_inbounds or not col_inbounds:<br>    return False <br>  return True</pre><p>So BFS keeps expanding outward from the entire first island.</p><h3>Then I Hit Another Bug: BFS Needs Its Own visited</h3><p>My DFS already had a visited set.</p><p>But that visited set was being used to identify the first island.</p><p>My BFS is a different traversal.</p><p>Without protecting BFS from revisiting cells, I could get behavior like:</p><pre>A → B<br>↑   ↓<br>D ← C</pre><p>Cells could repeatedly put previously encountered positions back into the queue.</p><p>So I created another:</p><pre>visited = set()</pre><p>Then:</p><pre>if (r,c) in visited:<br>  continue </pre><pre>visited.add((r,c))</pre><p>That gave the BFS its own protection against repeatedly processing the same coordinate.</p><p>Another small lesson:</p><blockquote><strong><em>Different traversal phases can need different visited state because they are solving different jobs.</em></strong></blockquote><p>My DFS visited set identifies Island 1.</p><p>My BFS visited set controls the outward shortest-path search.</p><h3>How Do I Know I Reached the Second Island?</h3><p>This part caused another bug.</p><p>At first, I thought:</p><pre>If BFS reaches L<br>→ second island found</pre><p>But my queue initially contains land cells from the <strong>first island</strong>.</p><p>And while BFS expands, it can encounter those first-island land cells again.</p><p>So:</p><pre>grid[r][c] == &quot;L&quot;</pre><p>alone is not enough.</p><p>I need land that <strong>doesn’t belong to </strong><strong>current_island</strong>.</p><p>That’s why my condition became:</p><pre>if length != 0 and (r,c) not in current_island and grid[r][c] == &quot;L&quot;:<br>  return length-1</pre><p>Conceptually:</p><pre>Is this land?<br>        ↓<br>YES</pre><pre>Is it part of my original island?<br>        ↓<br>NO</pre><pre>Then I&#39;ve reached Island 2.</pre><p>That distinction was important.</p><p>My first island is already known:</p><pre>current_island</pre><p>So any L reached outside that set belongs to the other island.</p><h3>Why length - 1?</h3><p>This was another detail I had to reason through.</p><p>Imagine:</p><pre>Island 1 → W → W → Island 2</pre><p>My BFS distances look like:</p><pre>Island 1     distance 0<br>W            distance 1<br>W            distance 2<br>Island 2     distance 3</pre><p>But the bridge isn’t length 3.</p><p>I’m only converting the water cells:</p><pre>W → bridge<br>W → bridge</pre><p>That’s <strong>2 cells</strong>.</p><p>The second island itself isn’t part of the bridge.</p><p>So when BFS reaches Island 2 at:</p><pre>length = 3</pre><p>the actual bridge length is:</p><pre>length - 1</pre><p>which gives:</p><pre>2</pre><p>That made the return value click for me.</p><h3>My Solution</h3><p>This is the code I wrote:</p><pre>from collections import deque </pre><pre>def best_bridge(grid):<br>  current_island = set()<br>  for r in range(len(grid)):<br>    if current_island:<br>      break<br>    for c in range(len(grid[0])):<br>      if grid[r][c] == &quot;L&quot;:<br>        dfs(grid, r, c, current_island)<br>        break<br>  queue = deque([])<br>  visited = set()<br>  for r,c in current_island:<br>    queue.append((r,c,0))<br>  while queue:<br>    (r,c,length) = queue.popleft()<br>    if length != 0 and (r,c) not in current_island and grid[r][c] == &quot;L&quot;:<br>      return length-1<br>    if (r,c) in visited:<br>      continue <br>    visited.add((r,c))<br>    positions = [(r+1, c), (r-1, c), (r, c+1), (r, c-1)]<br>    for i,j in positions:<br>      if bounds(grid, i, j):<br>        queue.append((i, j, length+1))<br>    <br>    </pre><pre>def bounds(grid, r, c):<br>  row_inbounds = 0 &lt;= r &lt; len(grid)<br>  col_inbounds = 0 &lt;= c &lt; len(grid[0])</pre><pre>  if not row_inbounds or not col_inbounds:<br>    return False <br>  return True <br></pre><pre>def dfs(grid, r, c, visited):<br>  row_inbounds = 0 &lt;= r &lt; len(grid)<br>  col_inbounds = 0 &lt;= c &lt; len(grid[0])</pre><pre>  if not row_inbounds or not col_inbounds:<br>    return visited</pre><pre>  if grid[r][c] == &quot;W&quot;:<br>    return visited</pre><pre>  pos = (r,c)</pre><pre>  if pos in visited:<br>    return visited<br>  visited.add(pos)</pre><pre>  dfs(grid, r+1, c, visited)<br>  dfs(grid, r-1, c, visited)<br>  dfs(grid, r, c+1, visited)<br>  dfs(grid, r, c-1, visited)</pre><pre>  return visited</pre><p>The final code combines two graph traversals with two different responsibilities:</p><pre>DFS<br>↓<br>Identify the entire first island</pre><pre>BFS<br>↓<br>Expand outward from the entire first island</pre><pre>First land outside first island<br>↓<br>Second island reached</pre><pre>length - 1<br>↓<br>Minimum bridge</pre><h3>The Bigger Lesson: BFS Doesn’t Need Just One Source</h3><p>This is what I want to carry into future problems.</p><p>When I see a shortest-path problem, my first instinct is still:</p><pre>BFS</pre><p>But now I want to ask another question:</p><blockquote><strong><em>Do I actually have one starting point, or do I have multiple equally valid starting points?</em></strong></blockquote><p>If multiple positions are all distance 0 from the thing I&#39;m measuring, I don&#39;t necessarily need separate BFS runs.</p><p>I can potentially put all of them into the queue initially.</p><p>That transforms:</p><pre>source 1 → BFS<br>source 2 → BFS<br>source 3 → BFS</pre><p>into:</p><pre>source 1 ─┐<br>source 2 ─┼→ ONE BFS<br>source 3 ─┘</pre><p>That is the idea from Best Bridge that I want to remember.</p><h3>My Best Bridge Recipe</h3><pre>Find the first L<br>        ↓<br>DFS the entire connected island<br>        ↓<br>Store all first-island positions<br>        ↓<br>Put ALL of those positions into the BFS queue<br>with distance 0<br>        ↓<br>BFS outward in four directions<br>        ↓<br>Avoid processing coordinates repeatedly<br>        ↓<br>Reach an L that is NOT part of the first island<br>        ↓<br>Second island found<br>        ↓<br>return length - 1</pre><h3>My Takeaway</h3><p>Best Bridge wasn’t difficult because DFS or BFS were completely new to me.</p><p>I already knew both.</p><p>The interesting part was realizing <strong>how they fit together</strong>.</p><p>DFS answered:</p><blockquote><strong><em>What exactly is my first island?</em></strong></blockquote><p>Then multi-source BFS answered:</p><blockquote><strong><em>What is the shortest expansion from anywhere on this island to the other island?</em></strong></blockquote><p>And the bugs taught me just as much as the final algorithm:</p><pre>break only exits one loop</pre><pre>DFS visited and BFS visited have different jobs</pre><pre>&quot;L&quot; doesn&#39;t automatically mean second island</pre><pre>BFS can start from many positions simultaneously</pre><p>The biggest idea I want to remember is:</p><blockquote><strong>When multiple positions are equally valid starting points, I don’t always need to choose one. I can start BFS from all of them at once.</strong></blockquote><p>For this problem:</p><pre>GRID<br>↓<br>Find first island</pre><pre>DFS<br>↓<br>Capture every cell of Island 1</pre><pre>MULTI-SOURCE BFS<br>↓<br>Start from every Island 1 cell</pre><pre>EXPAND<br>↓<br>Cross water layer by layer</pre><pre>SECOND ISLAND<br>↓<br>First contact gives the minimum bridge</pre><p>That was the moment <strong>Best Bridge stopped looking like two islands separated by water and became a multi-source shortest-path problem.</strong></p><p><strong>Forever Learning. Forever Growing.</strong></p><p>— <strong>Sai Pranav Moluguri</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=db330a2339e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ I Stripped Away the Story. Then “Find the Town Judge” Became an Indegree–Outdegree Problem.]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/i-stripped-away-the-story-then-find-the-town-judge-became-an-indegree-outdegree-problem-b3e8d23f2d76?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/b3e8d23f2d76</guid>
            <category><![CDATA[data-structures]]></category>
            <category><![CDATA[neetcode-150]]></category>
            <category><![CDATA[algorithms]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[graphic-design]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Fri, 18 Sep 2026 16:12:40 GMT</pubDate>
            <atom:updated>2026-09-18T16:12:40.811Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>By Sai Pranav Moluguri</strong></p><p>I was solving <strong>Find the Town Judge</strong>, and the problem gave me a whole story.</p><p>There is a town.</p><p>There are n people.</p><p>One person might secretly be the town judge.</p><p>The judge trusts nobody.</p><p>Everybody else trusts the judge.</p><p>At first, it sounds like I need to think about people, trust, and judges.</p><p>Then I did something I’ve been trying to get better at with DSA problems:</p><blockquote><strong><em>Strip away the story and ask what problem you are trying to solve and which data structure or algorithm you have to use underneath.</em></strong></blockquote><p>Once I did that, the entire problem became much smaller.</p><p>That same shift — from the terminology of a problem to what it actually represents underneath — is something I’ve been noticing more in my recent graph practice. In my previous bipartite-graph problem, for example, “colors” became much easier to understand once I started seeing them as labels or groups instead.</p><h3>Forget the Town for a Moment</h3><p>The input gives me relationships like:</p><pre>[1, 3]</pre><p>This simply means:</p><pre>1 → 3</pre><p>Person 1 trusts person 3.</p><p>That is a <strong>directed edge</strong>.</p><p>Immediately, I can translate the story into graph terminology:</p><pre>A person trusts someone<br>        ↓<br>Outgoing edge</pre><pre>A person is trusted by someone<br>        ↓<br>Incoming edge</pre><p>Now the “town judge” stops being a mysterious person in a story.</p><p>The judge is just a node with a very specific degree pattern.</p><h3>What Does “The Judge Trusts Nobody” Actually Mean?</h3><p>The first condition says:</p><blockquote><em>The town judge trusts nobody.</em></blockquote><p>In graph terms, if the judge never points toward another node:</p><pre>Judge ──X──→ anyone</pre><p>then:</p><pre>outdegree = 0</pre><p>That takes care of the first condition.</p><h3>What Does “Everybody Trusts the Judge” Mean?</h3><p>The second condition says:</p><blockquote><em>Everybody except the judge trusts the judge.</em></blockquote><p>Suppose:</p><pre>n = 4</pre><p>and person 3 is the judge.</p><p>Then:</p><pre>1 → 3<br>2 → 3<br>4 → 3</pre><p>There are four people total, but the judge doesn’t need to trust himself.</p><p>So exactly:</p><pre>n - 1</pre><p>other people must point toward him.</p><p>Therefore:</p><pre>indegree = n - 1</pre><p>Now the entire story has collapsed into two conditions:</p><pre>Town Judge</pre><pre>indegree  = n - 1<br>outdegree = 0</pre><p>That was the moment the problem became simple for me.</p><h3>My Representation</h3><p>I decided to create a dictionary for every person.</p><p>Each value contains two numbers:</p><pre>[indegree, outdegree]</pre><p>So:</p><pre>num_parents[i] = [0,0]</pre><p>means initially:</p><pre>person i</pre><pre>indegree  = 0<br>outdegree = 0</pre><p>I initialize every person from 1 through n:</p><pre>for i in range(1, n+1):<br>    num_parents[i] = [0,0]</pre><p>This gives every person a place to store their degree information before I process the trust relationships.</p><h3>Processing i → j</h3><p>This part became mechanical.</p><p>For every:</p><pre>for i,j in trust:</pre><p>I mentally read it as:</p><pre>i → j</pre><p>That tells me two things simultaneously.</p><p>i trusts someone, so i gains an outgoing edge:</p><pre>num_parents[i][1] += 1</pre><p>And j is being trusted, so j gains an incoming edge:</p><pre>num_parents[j][0] += 1</pre><p>My representation was:</p><pre>index 0 → indegree<br>index 1 → outdegree</pre><p>So the updates line up directly with the graph:</p><pre>i → j</pre><pre>i:<br>outdegree + 1</pre><pre>j:<br>indegree + 1</pre><h3>What the Dictionary Eventually Tells Me</h3><p>Take:</p><pre>n = 4</pre><pre>trust = [<br>    [1,3],<br>    [4,3],<br>    [2,3]<br>]</pre><p>The graph is:</p><pre>1 ───→ 3<br>2 ───→ 3<br>4 ───→ 3</pre><p>Conceptually, my dictionary becomes:</p><pre>1 → [0, 1]<br>2 → [0, 1]<br>3 → [3, 0]<br>4 → [0, 1]</pre><p>And now person 3 immediately stands out:</p><pre>3 → [3, 0]</pre><p>Since:</p><pre>n = 4<br>n - 1 = 3</pre><p>person 3 has:</p><pre>indegree  = 3<br>outdegree = 0</pre><p>That’s the judge.</p><p>I don’t need DFS.</p><p>I don’t need BFS.</p><p>I don’t need to traverse paths through the graph.</p><p>I just need to count incoming and outgoing edges.</p><h3>My Solution</h3><p>This is the code I wrote:</p><pre>class Solution:<br>    def findJudge(self, n: int, trust: List[List[int]]) -&gt; int:<br>        num_parents = {}<br>        for i in range(1, n+1):<br>            num_parents[i] = [0,0]<br>        for i,j in trust:<br>            num_parents[i][1] += 1 <br>            num_parents[j][0] += 1 <br>        <br>        for ele, degree in num_parents.items():<br>            if degree[0] == n-1 and degree[1] == 0:<br>                return ele<br>        return -1</pre><p>The code is small.</p><p>But the part I want to remember isn’t the syntax.</p><p>It’s how I got there.</p><h3>.items() Was Another Small Recall</h3><p>While implementing it, I also had to recall a small Python detail.</p><p>If I iterate through a dictionary normally, I get its keys.</p><p>But here I wanted:</p><pre>person + degree information</pre><p>So:</p><pre>for ele, degree in num_parents.items():</pre><p>gives me:</p><pre>ele    → key<br>degree → value</pre><p>For example:</p><pre>ele = 3<br>degree = [3, 0]</pre><p>Then my judge condition becomes almost identical to my reasoning:</p><pre>if degree[0] == n-1 and degree[1] == 0:<br>    return ele</pre><p>That’s something I like about this solution.</p><p>Once the representation is right, the code almost reads like the definition of the problem.</p><h3>The Second Example Makes the Outdegree Condition Important</h3><p>Consider:</p><pre>n = 3</pre><pre>1 → 3<br>2 → 3<br>3 → 1<br>3 → 2</pre><p>Person 3 receives trust from both other people:</p><pre>indegree = 2 = n - 1</pre><p>But 3 also trusts other people:</p><pre>outdegree = 2</pre><p>So:</p><pre>[2, 2]</pre><p>doesn’t satisfy:</p><pre>[n - 1, 0]</pre><p>Therefore there is no judge.</p><p>That showed me why I need <strong>both conditions</strong>.</p><p>Having a high indegree isn’t enough.</p><p>The judge must simultaneously have:</p><pre>Everybody points to me<br>AND<br>I point to nobody</pre><h3>The Bigger Lesson: Strip Away the Story</h3><p>This is the part I want to carry into future problems.</p><p>A problem might tell me about:</p><pre>towns<br>people<br>trust<br>judges<br>rumors</pre><p>But underneath, I should ask:</p><pre>What are the entities?<br>        ↓<br>Nodes</pre><pre>What are the relationships?<br>        ↓<br>Directed edges</pre><pre>What property am I searching for?<br>        ↓<br>A specific indegree/outdegree pattern</pre><p>So my mental transformation was:</p><pre>STORY<br>↓<br>&quot;Everybody trusts the judge,<br>but the judge trusts nobody&quot;</pre><pre>GRAPH<br>↓<br>Everyone → Judge<br>Judge → Nobody</pre><pre>DEGREES<br>↓<br>indegree = n - 1<br>outdegree = 0</pre><p>And suddenly the problem is no longer about a town judge.</p><p>It’s a degree-counting problem.</p><h3>My Town Judge Recipe</h3><p>This is what I want to remember:</p><pre>Strip away the story<br>        ↓<br>Recognize directed relationships<br>        ↓<br>Represent every node as<br>[indegree, outdegree]<br>        ↓<br>For i → j:<br>i outdegree + 1<br>j indegree + 1<br>        ↓<br>Find:<br>indegree = n - 1<br>outdegree = 0<br>        ↓<br>Found → return person<br>Not found → return -1</pre><h3>My Takeaway</h3><p>The biggest thing I learned from this problem wasn’t how to find a town judge.</p><p>It was another reminder that <strong>DSA problems often hide familiar ideas behind unfamiliar stories</strong>.</p><p>I already knew directed graphs.</p><p>I already knew indegree and outdegree.</p><p>I already knew how to iterate through edges.</p><p>The challenge was recognizing that those were the concepts hiding underneath the story.</p><p>So this is the question I want to keep asking myself:</p><blockquote><strong><em>Strip away the story and ask what problem you are trying to solve and which data structure or algorithm you have to use underneath.</em></strong></blockquote><p>For this problem:</p><pre>Town Judge<br>      ↓<br>Special node<br>      ↓<br>Directed graph<br>      ↓<br>Indegree / Outdegree<br>      ↓<br>[n - 1, 0]</pre><p>Once I saw that, the story disappeared.</p><p>And the algorithm was already something I knew.</p><p><strong>Forever Learning. Forever Growing.</strong></p><p>— <strong>Sai Pranav Moluguri</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b3e8d23f2d76" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Agency vs. Autonomy: The Question That Made Agentic AI Click for Me]]></title>
            <link>https://medium.com/@saipranavmoluguri2001/agency-vs-autonomy-the-question-that-made-agentic-ai-click-for-me-5b3ff4a85103?source=rss-707f9eb0d5da------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b3ff4a85103</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[generative-ai]]></category>
            <category><![CDATA[agentic-ai]]></category>
            <category><![CDATA[ai-engineering]]></category>
            <category><![CDATA[ai-agent]]></category>
            <dc:creator><![CDATA[Sai Pranav Moluguri]]></dc:creator>
            <pubDate>Sun, 13 Sep 2026 00:30:46 GMT</pubDate>
            <atom:updated>2026-09-13T00:30:46.039Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>By Sai Pranav Moluguri</strong></p><p>Recently, I’ve been spending more time learning about <strong>Agentic AI</strong>.</p><p>And while reading about AI agents, I came across two terms:</p><p><strong>Agency.</strong></p><p><strong>Autonomy.</strong></p><p>At first, both sounded almost identical to me.</p><p>Agency was described as the capacity of a system to <strong>act, make decisions, and pursue goals</strong>.</p><p>Then I reached autonomy.</p><p>An autonomous agent can <strong>decide how to achieve a goal using the information and resources available to it, without step-by-step human control</strong>.</p><p>I stopped there.</p><p>My immediate thought was:</p><blockquote>“Wait. Aren’t both of these just decision-making?”</blockquote><p>If agency means an agent can decide and act, and autonomy also involves deciding and acting, why do we need two different words?</p><p>That question led to one of those small learning moments where a concept suddenly became much cleaner.</p><h3>First, I Needed to Separate the Two</h3><p>I started simplifying both concepts in my own words.</p><p>For <strong>agency</strong>, I asked:</p><blockquote><strong>Can the system decide and act toward a goal?</strong></blockquote><p>For <strong>autonomy</strong>, I asked:</p><blockquote><strong>How independently can the system make those decisions and act without a human directing every step?</strong></blockquote><p>That was the distinction I was missing.</p><p>Agency is about the <strong>capability to act and decide</strong>.</p><p>Autonomy is about the <strong>independence with which that capability is exercised</strong>.</p><p>Once I separated them that way, they stopped looking like duplicate concepts.</p><h3>An Agent Can Have Agency Without Complete Autonomy</h3><p>This was the example that made it stick for me.</p><p>Imagine an AI agent is given a goal:</p><pre>Resolve a customer&#39;s payment issue.</pre><p>The agent examines the situation and decides:</p><pre>I should check the payment status.</pre><p>Then:</p><pre>I should retry the failed transaction.</pre><p>Then:</p><pre>I should notify the customer.</pre><p>The system is reasoning about what actions should be taken.</p><p>That’s <strong>agency</strong>.</p><p>But imagine that before every action, it has to ask:</p><pre>Agent:<br>&quot;I want to check the payment system.&quot;</pre><pre>Human:<br>&quot;Approved.&quot;</pre><p>Then:</p><pre>Agent:<br>&quot;I want to retry the transaction.&quot;</pre><pre>Human:<br>&quot;Approved.&quot;</pre><p>The agent can determine what it wants to do.</p><p>But a human is still controlling whether it can proceed at every step.</p><p>So it has <strong>agency</strong>, but limited <strong>autonomy</strong>.</p><p>That distinction finally made sense to me.</p><h3>Now Increase the Autonomy</h3><p>Imagine I give the same agent:</p><pre>Goal:<br>Resolve the customer&#39;s failed payment.</pre><p>And the agent can independently:</p><pre>Inspect payment status<br>        ↓<br>Identify the problem<br>        ↓<br>Choose the appropriate tool<br>        ↓<br>Retry the payment<br>        ↓<br>Verify the result<br>        ↓<br>Notify the customer</pre><p>I didn’t tell it:</p><pre>First do this.<br>Then do this.<br>Now call this API.<br>Now check this.<br>Now send this.</pre><p>I gave it the <strong>goal</strong>.</p><p>The system determined how to pursue that goal using the information and resources available to it.</p><p>That’s where autonomy became much clearer to me.</p><p>The question isn’t simply:</p><blockquote><strong>Can this system make decisions?</strong></blockquote><p>It’s also:</p><blockquote><strong>How much human direction does it need while making and executing those decisions?</strong></blockquote><h3>The Mental Model I’m Keeping</h3><p>After going back and forth with these definitions, I ended up with something incredibly simple.</p><pre>AGENCY</pre><pre>Can I decide and act toward a goal?</pre><p>And:</p><pre>AUTONOMY</pre><pre>How independently can I decide and act<br>without step-by-step human direction?</pre><p>That’s it.</p><p>I don’t need a paragraph-long definition in my head anymore.</p><p><strong>Agency → ability.</strong></p><p><strong>Autonomy → independence.</strong></p><h3>Then Agentic AI Started Looking Different</h3><p>Before this, it was easy for me to think about AI applications mainly in terms of:</p><pre>User asks something<br>        ↓<br>Model generates something<br>        ↓<br>User receives response</pre><p>But agents introduce another dimension.</p><p>The system may have a <strong>goal</strong>.</p><p>It may have <strong>information about its environment</strong>.</p><p>It may have <strong>tools and resources available to it</strong>.</p><p>And instead of being explicitly told every intermediate step, it can determine what actions are appropriate.</p><p>That made me start thinking about an agent as:</p><pre>GOAL<br>  ↓<br>Observe available information<br>  ↓<br>Decide what to do<br>  ↓<br>Use available resources<br>  ↓<br>Take action<br>  ↓<br>Continue toward the goal</pre><p>And now the words agency and autonomy have specific responsibilities inside that picture.</p><p><strong>Agency asks whether the system can decide and act.</strong></p><p><strong>Autonomy asks how independently it can do so.</strong></p><h3>Why This Matters to Me as an Engineer</h3><p>One thing I’ve noticed throughout my learning journey is that I don’t feel satisfied simply knowing the definition of a term.</p><p>I keep asking:</p><blockquote>“Why does this concept exist?”</blockquote><blockquote>“What is different from the concept I just learned?”</blockquote><blockquote>“What responsibility does it have in the system?”</blockquote><p>That happened again with agency and autonomy.</p><p>At first:</p><pre>Agency → decision-making<br>Autonomy → decision-making</pre><pre>???</pre><p>After digging into the distinction:</p><pre>Agency<br>→ capability to decide and act</pre><pre>Autonomy<br>→ independence in deciding and acting</pre><p>Now they occupy two different places in my mental model.</p><p>And that’s much more useful to me than simply remembering two definitions.</p><h3>My Takeaway</h3><p>The biggest realization for me was that an AI system doesn’t suddenly become autonomous just because it can make a decision.</p><p>There are two separate questions:</p><blockquote><strong>Does the system have the capacity to make decisions and take actions toward a goal?</strong></blockquote><p>That’s <strong>agency</strong>.</p><p>And:</p><blockquote><strong>How independently can it exercise that capacity without humans directing every step?</strong></blockquote><p>That’s <strong>autonomy</strong>.</p><p>The distinction is small.</p><p>But once I understood it, Agentic AI became a little less abstract.</p><p>And that’s what I’ve been enjoying about learning this field.</p><p>A new term appears.</p><p>I question it.</p><p>I compare it with what I already understand.</p><p>I try to break it.</p><p>And eventually, I find a mental model simple enough that I could explain it without the book in front of me.</p><p>That’s when I feel like I’ve actually learned something.</p><blockquote><strong>Agency tells me whether the system can decide and act. Autonomy tells me how independently it can do it.</strong></blockquote><p><strong>Forever Learning. Forever Growing.</strong></p><p><strong>— Sai Pranav Moluguri</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b3ff4a85103" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>