<?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 Atmaram Dhuri on Medium]]></title>
        <description><![CDATA[Stories by Atmaram Dhuri on Medium]]></description>
        <link>https://medium.com/@addmin.blaze?source=rss-220dbaa80ad1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*mBuXhW9cGKy9PsqV</url>
            <title>Stories by Atmaram Dhuri on Medium</title>
            <link>https://medium.com/@addmin.blaze?source=rss-220dbaa80ad1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 00:32:19 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@addmin.blaze/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[We Thought MongoDB Was Fast. Then Our Queries Told Us Otherwise!]]></title>
            <link>https://medium.com/@addmin.blaze/we-thought-mongodb-was-fast-then-our-queries-told-us-otherwise-64258cc53fa7?source=rss-220dbaa80ad1------2</link>
            <guid isPermaLink="false">https://medium.com/p/64258cc53fa7</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Atmaram Dhuri]]></dc:creator>
            <pubDate>Sun, 30 Aug 2026 13:32:36 GMT</pubDate>
            <atom:updated>2026-08-30T13:32:36.723Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="We Thought MongoDB Was Fast. Then Our Queries Told Us Otherwise" src="https://cdn-images-1.medium.com/max/1024/1*qic19_6ovpV187VWYVFIyw.png" /></figure><p><strong>What we learned while migrating from CouchDB to MongoDB</strong></p><p>As a newbie, we had many questions about database performance and optimization. We had worked on CouchDB (Cloudant), but there are some fundamental differences in how CouchDB and MongoDB work.</p><p>I’ll explain how we went from <strong>zero to hero</strong> while optimizing MongoDB performance.</p><p>We were all new to MongoDB, and we had a big CouchDB-to-MongoDB migration activity ahead of us.</p><p>So what did we do?</p><p>Like everyone else, we started with Google.</p><p>We read articles, tried different approaches, ran queries, checked results, changed things and tried again. That’s how most of us learn, right?</p><p><strong>Everything Looked Fast in Development<br></strong>We got a reasonably powerful development instance to learn MongoDB and perform our trials. And initially, everything looked great.</p><p>We ran queries. The responses came quickly.</p><p>Everyone was impressed with the performance MongoDB was delivering.</p><p>But it didn’t take too long to realize that our development environment wasn’t telling us the whole story.</p><p>We pushed some of our transactional data into MongoDB and started trying different queries.</p><p>Some queries were very fast. Some were average. Some were slower than what we expected.</p><p>So we started asking:<br><strong>Was something wrong with our queries?</strong></p><p>There was at least one pattern we could see. Queries involving the _id field were comparatively faster. That made sense because MongoDB automatically creates a <strong>unique index on _id</strong>.</p><p>But what about our other frequently queried fields? That’s where our learning really started.</p><p><strong>Creating Indexes</strong></p><p>NoSQL databases provide different mechanisms for indexing data, and each database has its own characteristics. We had already worked with CouchDB and Cassandra, so our first instinct was to apply what we already knew, but that didn’t work exactly the same way in MongoDB.</p><p>For example, in Cassandra, query design is closely tied to the partition key and clustering columns. You can’t simply create arbitrary indexes and expect Cassandra to behave like a traditional relational database.</p><p>CouchDB was different again.</p><p>CouchDB <strong>views </strong>are essentially indexed query definitions based on map/reduce functions. The view index is maintained separately from the original documents, which makes certain query patterns very efficient.</p><p>Then came MongoDB.</p><p>Our first approach was simple. We looked at the fields present in the WHERE-like conditions of our queries and created indexes on those fields.</p><p>We thought: “The query is filtering on these fields, so let’s create an index containing these fields.”</p><p>Seems logical.</p><p>But compound indexes in MongoDB require more thought. That’s when we came across something that became very important for us:</p><p><strong>The ESR Rule</strong></p><p>Yes, the title says it all.</p><p>The basic guideline is:</p><p><strong>E → Equality<br>S → Sort<br>R → Range</strong></p><p>For many compound-index query patterns, equality fields come first, followed by sort fields, followed by range fields.</p><p>For example, imagine a query like:</p><p>Find transactions</p><pre>WHERE accountId = ?<br>AND status = ?<br>AND transactionDate BETWEEN ? AND ?<br>ORDER BY transactionDate</pre><p>Instead of blindly putting fields into an index, we need to think about the way the query actually accesses the data.</p><p>The important lesson for us was:</p><p><strong>Creating an index is not enough. The index needs to match the way the query searches and sorts the data. </strong>MongoDB’s documentation itself describes ESR as a guideline rather than an absolute rule, so query selectivity and the actual query shape still need to be considered.</p><p><strong>But Our Problems Didn’t End With Indexes</strong></p><p>At this point, we thought:</p><p>“Okay, we created the right indexes. Now our queries should be fast.”</p><p>Technically, we were moving in the right direction. But there were still queries that weren’t performing as expected.</p><p>And then we found another important difference between our old CouchDB data and the way MongoDB was querying it.</p><p><strong>Everything Was a String</strong></p><p>Since we were migrating from CouchDB, a lot of our existing data was stored as strings.</p><p>Including dates. For example:</p><p>“25–08–2026”<br>“10–01–2025”<br>“05–12–2024”</p><p>At first, this didn’t look like a big problem.</p><p>After all, a date is just a value. But it isn’t.</p><p>A date stored as a string behaves differently from a date stored as a proper date datatype. Consider:</p><p>“25–08–2026”<br>“10–01–2025”</p><p>When these are compared as strings, MongoDB is comparing characters rather than understanding that these values represent calendar dates.</p><p>The same problem becomes much more obvious when you perform range queries.</p><p>For example:</p><p>transactionDate &gt;= startDate<br>transactionDate &lt;= endDate</p><p>If the underlying value is a string in dd-MM-yyyy format, the comparison doesn’t represent chronological ordering.</p><p>That’s when we realized, <strong>The datatype matters just as much as the index.</strong></p><p><strong>CouchDB and MongoDB Were Doing Different Things</strong></p><p>This was one of the most interesting parts of our migration. In CouchDB, we were using views for our query patterns. The view index was generated and maintained separately from the original documents.</p><p>So the database had already done part of the work required for those query patterns. MongoDB works differently.</p><p>MongoDB can use indexes to efficiently locate matching documents, but the query still needs to be designed around the available indexes and data types. Our assumption that:</p><p>“The same query worked well in CouchDB, so it should behave similarly in MongoDB.”</p><p>was simply wrong.</p><p>Different databases have different internal mechanisms. That was probably one of the biggest lessons from the migration.</p><p><strong>The Date Conversion</strong></p><p>We had two options. We could keep converting the string into a date during query execution or we could fix the data model.</p><p>We chose the second option.</p><p>MongoDB supports proper date datatypes, so we started storing dates as BSON Date values instead of strings. That changed the way the database could work with those values.</p><p>Now we could perform proper date comparisons and range operations without treating dates as arbitrary strings.</p><p>For example:</p><p>transactionDate &gt;= startDate<br>transactionDate &lt;= endDate</p><p>became a much more natural operation for the database. And the performance improvement was noticeable. This was another important lesson:</p><p><strong>Don’t try to optimize the query while ignoring the datatype of the data being queried.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qf3qnIWWZ0J2etG514tkag.png" /></figure><p><strong>Then We Found Another Query Problem</strong></p><p>We still had some queries involving status conditions. For example, we had logic similar to:</p><p>status NOT IN (<br>“approved”,<br>“initiated”,<br>“pending” <br>)</p><p>We initially thought: “Why don’t we convert this into an IN query?”</p><p>But here we had to be careful.</p><p>$nin and $ne are generally not very selective. MongoDB’s documentation specifically notes that $nin and $ne can match a large portion of a collection and therefore may not benefit significantly from an index.</p><p>So the actual optimization wasn’t simply:</p><p><strong>“Always replace NOT IN with IN.”</strong></p><p>That would be wrong. The important part was to understand what values we actually wanted.</p><p>For example, if the business requirement was:</p><p>Return only transactions whose status is rejected, in-progress, or null then we could express that directly:</p><p>status IN (<br>“rejected”,<br>“in-progress”,<br>null<br>)</p><p>This is a positive match against a known set of values. And $in is treated as a series of equality matches when used by itself.</p><p>The lesson here was not:</p><p>“IN is always faster than NOT IN.”</p><p>The real lesson was: <strong>Write the query based on what you actually want to retrieve, and pay attention to selectivity. </strong>That distinction matters.</p><p><strong>We Thought We Were Done</strong></p><p>By this point we had:</p><ul><li>Reviewed our indexes</li><li>Applied the ESR guideline where appropriate</li><li>Corrected our date datatypes</li><li>Reviewed our query conditions</li><li>Improved query selectivity</li></ul><p>We thought:</p><p>“Now we should get the best performance from MongoDB.” But then we tested the application during peak load and that’s when we found another problem.</p><p>The problem wasn’t necessarily an individual query anymore. It was <strong>the number of queries hitting the database at the same time</strong>.</p><p><strong>The Real Problem: Read and Write Load</strong></p><p>During peak hours, we had:</p><ul><li>Lakhs of read requests</li><li>Thousands of write requests</li></ul><p>hitting MongoDB. Our database was working hard.</p><p>At that point, optimizing an individual query could only take us so far. We started looking at the MongoDB deployment itself. That’s when replica sets and <strong>read preference</strong> became important.</p><p><strong>Read Preference and Secondary Reads</strong></p><p>We had a MongoDB replica set with:</p><p>1 Primary</p><p>3 Secondaries</p><p>The primary handled writes and also served reads by default.</p><p>The secondaries replicated data from the primary.</p><p>Our question was simple:</p><p><strong>If the secondaries are available, why should every read request go to the primary?</strong></p><p>MongoDB clients normally use the primary for reads by default, but read preference can be configured to direct reads to secondary members.</p><p>So we identified read operations where slightly stale data was acceptable and configured the appropriate read preference.</p><p>Conceptually, the architecture became:</p><pre>Application<br>     |<br>MongoDB Driver<br>     |<br>Read Preference<br>   /     \<br>Write    Read<br>  |       |<br>  ▼       ▼<br>Primary Secondaries<br>           / | \<br>          S1 S2 S3</pre><p>The idea was simple. Writes continued going to the primary, eligible reads could be served by secondary members. This reduced the amount of read traffic hitting the primary.</p><p><strong>But There Is an Important Catch</strong></p><p>This is something I would definitely mention if you’re writing about this from a production perspective. Secondary reads are <strong>not free performance</strong>.</p><p>MongoDB replication between primary and secondaries is asynchronous. That means a secondary can temporarily be behind the primary. So a read from a secondary may return <strong>stale data</strong>.</p><p>Therefore, we couldn’t simply say: “Move all reads to secondary.”</p><p>We had to identify which reads could tolerate that consistency model. For example, some reporting or historical queries may tolerate slightly stale data.</p><p>But a read immediately following a critical transaction may need to observe the latest state and therefore may need primary read preference. This was an important architectural decision.</p><p><strong>One More Thing We Learned</strong></p><p>Initially, we thought:</p><p>More nodes + More reads = More performance</p><p>But it’s not that simple, indexes have a cost. Every additional index can increase storage requirements and can add work to writes because indexes need to be maintained when documents change. MongoDB explicitly notes that indexes improve query performance but have a negative impact on write operations.</p><p>Similarly, sending reads to secondaries introduces a consistency trade-off. So database optimization is rarely about finding one magic configuration. It’s about understanding the workload.</p><p><strong>What Actually Helped Us?</strong></p><p>Looking back at our migration, the improvements didn’t come from one particular trick. They came from understanding the system layer by layer.</p><p><strong>1. Understand the query<br></strong>Don’t create indexes blindly. Understand: Equality, Sort, Range, Selectivity and Projection</p><p><strong>2. Understand your datatypes<br></strong>A date stored as a string is not the same as a database date. A datatype isn’t just a storage decision. It affects how the database can query the data.</p><p><strong>3. Understand your query operators<br></strong>$nin, $ne, $in, range operators, sorting and other predicates have different implications for index usage and selectivity.</p><p><strong>4. Understand your workload<br></strong>A query that performs perfectly with 100 requests may behave very differently with millions of reads.</p><p><strong>5. Understand your architecture<br></strong>Indexes optimize query execution. Replica sets can provide redundancy and allow non-primary read preferences for appropriate workloads.</p><p>But neither should be treated as a universal solution.</p><p>To Conclude I would say,</p><p>Our MongoDB journey started with a very simple assumption: <strong>“MongoDB is fast.” </strong>Then we learned something more useful. MongoDB isn’t simply fast or slow.</p><p><strong>The way we model data, design queries, create indexes, choose datatypes, distribute reads and writes, and understand consistency all affect the final performance.</strong></p><p>Coming from CouchDB made the learning even more interesting.</p><p>The same data, the same business requirements, sometimes even the same query idea, but completely different database internals.</p><p>And that’s probably the biggest lesson I took from the migration:</p><p><strong>Database optimization isn’t about memorizing which database is faster.</strong></p><p><strong>It’s about understanding how your database works and making your application work with it — not against it.</strong></p><p>When you understand what’s happening underneath the query, performance optimization becomes much less about trial and error and much more about engineering.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=64258cc53fa7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Think System.out.println() Is Harmless? Think Again]]></title>
            <link>https://medium.com/@addmin.blaze/think-system-out-println-is-harmless-think-again-37ae84162cb2?source=rss-220dbaa80ad1------2</link>
            <guid isPermaLink="false">https://medium.com/p/37ae84162cb2</guid>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[jvm]]></category>
            <dc:creator><![CDATA[Atmaram Dhuri]]></dc:creator>
            <pubDate>Sat, 25 Jul 2026 19:58:11 GMT</pubDate>
            <atom:updated>2026-07-25T19:58:11.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iLe2Vbc0WPgErCERXi4O3g.png" /></figure><p>I was reviewing a pull request from one of the junior developers on my team when something caught my attention.</p><p>The code was filled with System.out.println() statements.</p><p>As a fresher, he was using them to understand how the application was flowing instead of stepping through the code with a debugger. Honestly, we’ve all done that at some point in our careers, so there was nothing unusual about it. I simply explained why it works for quick experiments but isn’t something we should rely on in the long run.</p><p>A few days later, I noticed something interesting.</p><p>It wasn’t just junior developers.</p><p>Even experienced developers occasionally leave System.out.println() statements scattered across the codebase because they&#39;re quick, convenient, and easy to add while debugging.</p><p>We’ve all been there.</p><p><em>“Let me just print this value once…”</em></p><p><em>“I’ll remove it before committing.”</em></p><p>Sometimes we do.</p><p>Sometimes we forget.</p><p>Over the years, I’ve had the same conversation with many developers, which made me realize there’s a common misconception. Most people know they should remove System.out.println() before merging their code, but very few actually know <strong>why</strong>.</p><p>Is it just about keeping the code clean?</p><p>Or is there a technical reason behind it?</p><p>The answer is much more interesting than it seems.</p><p>In every programming language, input/output (I/O) operations are significantly slower than working with data in memory. Reading from files, writing to databases, or making network calls is often unavoidable. But writing to the console is usually meant only for temporary debugging. Every System.out.println() introduces an I/O operation, and when used repeatedly—especially inside loops or high-throughput applications—it can become a surprisingly expensive operation.</p><p>So what actually happens when we write just one line?</p><pre>System.out.println(&quot;Reached here&quot;);</pre><p>At first glance, it looks like Java simply prints a string to the console.</p><p>In reality, that single line starts a much longer journey through the JVM and the operating system than most developers realize.</p><p>Let’s find out.</p><p><strong>It Isn’t Just Printing Text</strong></p><p>When we write:</p><p>System.out.println(“Hello World”);</p><p>it feels like Java simply writes some text to the console. In reality, that single line triggers a surprisingly long chain of events.</p><pre>System.out.println()<br><br>↓<br><br>PrintStream.println()<br><br>↓<br><br>synchronized<br><br>↓<br><br>print()<br><br>↓<br><br>write()<br><br>↓<br><br>OutputStream<br><br>↓<br><br>FileDescriptor.out<br><br>↓<br><br>Native write()<br><br>↓<br><br>Kernel<br><br>↓<br><br>Console Buffer<br><br>↓<br><br>Terminal<br><br>↓<br><br>GPU<br><br>↓<br><br>Screen</pre><p>By the time “Hello World” appears on your monitor, it has travelled through multiple software layers — and each layer adds a little work.</p><p><strong>Java Finds System.out</strong></p><p>System.out isn’t a keyword. It’s actually a static object.</p><pre>public static final PrintStream out;</pre><p>So when you call:</p><p>System.out.println(…)</p><p>you’re really calling a method on a PrintStream. Nothing has been printed yet. Java has simply entered another method.</p><p><strong>The JVM Locks the Stream</strong></p><p>Here’s something many developers don’t know.</p><p>println() is thread-safe.</p><p>Internally, only one thread is allowed to print at a time. PrintStream synchronizes its write operations, ensuring that multiple threads don’t interleave their output. This makes console printing thread-safe, but it also means only one thread can write to the stream at a time.</p><pre>public void println(String x) {<br>    synchronized (this) {<br>        print(x);<br>        newLine();<br>    }<br>}</pre><p>Imagine a web application handling 200 requests simultaneously.</p><p>If every request executes:</p><p>System.out.println(“Processing request”);</p><p>only one thread gets access to the console and remaining 199 threads wait. Not because they’re doing useful work, they’re simply waiting for someone else to finish printing.</p><p>That waiting time can become surprisingly expensive.</p><p><strong>Your String Isn’t Ready Yet</strong></p><p>Computers don’t understand Java Strings, they understand bytes.</p><p>Before your text leaves the JVM, Java must convert:</p><p>“Hello World”</p><p>into something the operating system can write.</p><p>That means:</p><ul><li>Character encoding (The text is converted into a sequence of bytes using the output stream’s configured character encoding.)</li><li>Buffer management</li><li>Preparing bytes for output</li></ul><p>Again…</p><p>None of this has reached your screen yet.</p><p><strong>Java Asks the Operating System for Help</strong></p><p>At this point, Java has done everything it can, now it needs the operating system. The JVM performs a native system call.</p><p>Think of it as saying:</p><p>“Operating System, please write these bytes to the console.”</p><p>This transition — from user space to kernel space — is much more expensive than an ordinary Java method call. It involves crossing the boundary between the JVM and the operating system.</p><p><strong>The Console Is Surprisingly Slow</strong></p><p>Modern CPUs execute billions of instructions every second.</p><p>Your terminal doesn’t.</p><p>Every line must be:</p><ul><li>Written to the console buffer</li><li>Processed by the terminal</li><li>Rendered on the screen</li><li>Scrolled if necessary</li></ul><p>Compared to CPU speed, the console is incredibly slow. Your processor may finish calculating millions of numbers before the terminal has finished drawing the previous thousand lines.</p><p><strong>Now Imagine a Million Prints</strong></p><p>Consider this loop.</p><pre>for (int i = 0; i &lt; 1_000_000; i++) {<br>  System.out.println(i);<br>}</pre><p>Most developers assume the loop is slow because it executes one million iterations.</p><p>It isn’t.</p><p>The loop itself is extremely fast.</p><p>The expensive part is asking the operating system to print one million lines.</p><p>In many cases, Your application thread spends far more time waiting for I/O than executing Java instructions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oisaZKd8ciqjryMb-oTr9w.png" /><figcaption>code execution, with and without sysout statements</figcaption></figure><p>Above output shows time in micro-seconds, with sysout statement, it took around 94 mill seconds and without near 0 mill seconds.</p><p><strong>Why Logging Frameworks Perform Better</strong></p><p>If System.out.println() is so slow, why don’t enterprise applications suffer from the same problem?</p><p>Because most production systems don’t print directly to the console.</p><p>Frameworks like Logback and Log4j work differently.</p><p>Instead of blocking your application thread every time you log a message, they often:</p><ul><li>Buffer log events</li><li>Queue them in memory</li><li>Use dedicated background threads</li><li>Supports asynchronous appenders</li></ul><p>Your business logic keeps running while another thread handles the expensive I/O operations. That’s one reason production logging scales much better than thousands of System.out.println() calls.</p><p><strong>The Real Bottleneck Isn’t Java</strong></p><p>Many developers blame the JVM, but the JVM is rarely the slow part here.</p><p>The real bottleneck is I/O.</p><p>Printing text requires coordination between:</p><ul><li>The JVM</li><li>Thread synchronization</li><li>Character encoding</li><li>Native operating system calls</li><li>Terminal rendering</li><li>Screen updates</li></ul><p>Your Java code finishes long before your monitor displays the text.</p><p><strong>Final Verdict</strong></p><p>The next time you write:</p><pre>System.out.println(&quot;Debug&quot;);</pre><p>remember that you’re not just printing a string.</p><p>You’re asking the JVM to synchronize access to a shared stream, convert characters into bytes, cross into the operating system through a native call, write data to a terminal, and wait for the console to render it on your screen.</p><p>It’s one of the simplest lines of Java you’ll ever write, but behind it lies an entire journey through the JVM and the operating system. And that’s why a single line of text can become one of the slowest operations in your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=37ae84162cb2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Caching Isn’t Always Faster: The Trade-offs Every Backend Engineer Should Know]]></title>
            <link>https://medium.com/@addmin.blaze/why-caching-isnt-always-faster-the-trade-offs-every-backend-engineer-should-know-dba8a3d47ff0?source=rss-220dbaa80ad1------2</link>
            <guid isPermaLink="false">https://medium.com/p/dba8a3d47ff0</guid>
            <category><![CDATA[cache]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[backend-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[performance]]></category>
            <dc:creator><![CDATA[Atmaram Dhuri]]></dc:creator>
            <pubDate>Sat, 18 Jul 2026 17:48:06 GMT</pubDate>
            <atom:updated>2026-07-18T17:48:06.996Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*um05njDi3kQtX_1BDytJHQ.png" /></figure><p><strong>Every Backend Engineer Learns How to Cache. Very Few Learn When <em>Not</em> To.</strong></p><p>If you’ve spent enough time building backend applications, you’ve probably heard this suggestion more times than you can count:</p><p>“This API is slow. Let’s cache it.”</p><p>It almost feels like the default solution whenever performance becomes a discussion.</p><p>And honestly, it makes sense.</p><p>Memory is significantly faster than disk. Database calls involve network latency, query execution, object mapping, and serialization. So if we can avoid repeated database calls by storing data in memory, why wouldn’t we?</p><p>But over time, I realized something interesting.</p><p>The question isn’t <strong>“Can we cache this?”</strong></p><p>The real question is <strong>“Should we cache this?”</strong></p><p>Caching is one of the most powerful optimizations available to us, but it’s also one of the most misunderstood. Like every optimization, it comes with trade-offs. Sometimes it improves performance dramatically, and sometimes it simply moves the bottleneck somewhere else.</p><p><strong>We’ve Been Solving This Problem for Decades</strong></p><p>One thing I enjoy about Computer Science is that many “modern” software problems aren’t actually new. We’ve been solving the same problems for decades, just at different layers of the system.</p><p>Take the CPU, for example.</p><p>Imagine you’re preparing for an exam. Your textbook is on a shelf across the room. Every few minutes you walk to the shelf, open the book, read one formula, come back, solve a problem, and then repeat the process.</p><p>Eventually you’ll finish studying.</p><p>But you’ll waste a lot of time walking back and forth.</p><p>Now imagine writing the formulas you use most often on a sticky note and keeping it beside your notebook.</p><p>You haven’t replaced the textbook. You’ve simply kept the information you access repeatedly closer to you.</p><p>That’s exactly why CPUs introduced L1, L2 and L3 caches. The processor isn’t replacing RAM. It’s simply reducing the time spent fetching frequently used data. The key idea is <strong>locality of reference</strong> — if data is accessed repeatedly, keeping it closer improves performance.</p><p>Application caching follows the same philosophy. Instead of asking the database for the same information repeatedly, we temporarily keep frequently accessed data closer to the application.</p><p>The idea sounds simple. The difficult part is deciding <strong>what deserves that sticky note</strong>.</p><p><strong>Just Because You Can Cache It Doesn’t Mean You Should</strong></p><p>One pattern I’ve noticed is that once Redis becomes part of a project, almost everything starts looking like a caching candidate.</p><p>Configuration? Cache it.</p><p>Product catalogue? Cache it.</p><p>User profile? Cache it.</p><p>Transactions? Why not cache those as well?</p><p>Before long, every new feature starts with the same question:</p><p>“Can we cache this?”</p><p>Instead, I prefer asking another question.</p><p><strong>Will this data be requested again often enough to justify occupying memory?</strong></p><p>Think about a grocery store. The products that sell hundreds of times a day are placed where customers can access them quickly. Products that are purchased once every few months aren’t kept near the entrance.</p><p>Not because they’re unimportant, because shelf space is limited.</p><p>Memory works exactly the same way, every cached object occupies valuable memory.</p><p>If nobody asks for it again, that memory could have been used more effectively elsewhere.</p><p><strong>Fast Memory Doesn’t Mean a Faster Application</strong></p><p>One statement we hear quite often is:</p><p>Memory is faster than a database.</p><p>That’s absolutely true, but it’s only part of the story.</p><p>Fetching data from Redis isn’t simply reading bytes from RAM.</p><p>The application still has to:</p><ul><li>Serialize the object</li><li>Send a network request</li><li>Receive the response</li><li>Deserialize it back into an object</li></ul><p>Meanwhile, your database may already have the same data in its own buffer cache.</p><pre>Application<br><br>↓<br><br>Hash lookup<br><br>↓<br><br>Network<br><br>↓<br><br>Redis<br><br>↓<br><br>Network<br><br>↓<br><br>Deserialize<br><br>↓<br><br>GC allocation</pre><p>If a query already returns in <strong>2–3 milliseconds</strong>, introducing Redis might actually increase the total response time instead of reducing it.</p><p>Before optimizing, it’s always worth asking:</p><p><strong>Are we solving the real bottleneck?</strong></p><p><strong>The Most Expensive Cache Is the One Nobody Uses</strong></p><p>Imagine caching transaction history for every customer.</p><p>Customer A requests it once.</p><p>Customer B requests different data.</p><p>Customer C requests something else.</p><p>None of those responses are reused.</p><p>Now imagine doing this for a million customers. You’ve filled your cache with data that nobody is asking for again. It’s similar to a library where every visitor borrows a different book exactly once. Keeping every borrowed book on the front desk “just in case” doesn’t help anyone.</p><p>The front desk eventually becomes cluttered, while the books that people actually borrow every day become harder to access. A cache only creates value when the same data is reused.</p><p>Without reuse, it’s simply another copy of your database consuming memory.</p><p><strong>Cache Invalidation — The Hard Part</strong></p><p>Storing data in memory is easy.</p><p>Knowing <strong>when that data becomes invalid</strong> is much harder.</p><p>Imagine an e-commerce application.</p><p>A laptop is listed at ₹80,000.</p><p>A promotional campaign starts, and the price changes to ₹75,000. The database is updated immediately, but the cache still serves the old value.</p><p>Nothing crashes.</p><p>No exception is thrown.</p><p>The application is running perfectly.</p><p>Yet every customer sees incorrect information. This is why cache invalidation is considered one of the hardest problems in software engineering.</p><p>Caching doesn’t just improve performance.</p><p>It introduces another responsibility: <strong>keeping data consistent.</strong></p><p><strong>Cache Stampede</strong></p><p>Suppose one cached value expires.</p><p>Suddenly:</p><p>10,000 users request it simultaneously.</p><p>All requests miss the cache. Instead of one database query, your system suddenly generates thousands of identical queries for the same data.</p><p>Instead of reducing load, your cache causes a database spike.</p><p>This is called a <strong>Cache Stampede</strong>.</p><p>Solutions include:</p><ul><li>Request coalescing</li><li>Distributed locks</li><li>Early refresh</li><li>Stale-while-revalidate</li></ul><p><strong>Different Data Has Different Behavior</strong></p><p>Not every piece of data changes at the same rate.</p><p>A country’s list of states rarely changes.</p><p>Currency exchange rates change throughout the day.</p><p>An account balance can change every few seconds.</p><p>Treating all of them with the same caching strategy is like storing vegetables, frozen food, and fresh milk under identical conditions.</p><p>They’re all food, but they don’t all have the same shelf life. Similarly, different data requires different cache expiration strategies.</p><p><strong>Sometimes the Database Isn’t the Problem</strong></p><p>One mistake I’ve seen repeatedly is using a cache to compensate for an inefficient database query.</p><p>Imagine your room feels unusually warm.</p><p>Instead of checking why the fan is running slowly, you open another window.</p><p>The room becomes slightly cooler, the discomfort reduces, but the fan is still faulty.</p><p>Caching often works the same way.</p><p>If a query is slow because of:</p><ul><li>Missing indexes</li><li>Poor query design</li><li>Unnecessary joins</li><li>Fetching excessive data</li></ul><p>Adding Redis may improve response times, but the underlying issue still exists.</p><p>Caching should enhance a well-designed system — not become a substitute for fixing it.</p><p><strong>The Questions I Ask Before Adding a Cache</strong></p><p>Before introducing a cache, I usually ask myself a few simple questions:</p><ul><li>Is this data requested frequently?</li><li>Will multiple users access the same information?</li><li>Is generating this data expensive?</li><li>Can the business tolerate slightly stale data?</li><li>Is the complexity of maintaining a cache justified?</li></ul><p>If the answer to most of these questions is <strong>yes</strong>, caching is probably a good idea.</p><p>If not, I’d rather spend time improving the database query or redesigning the API.</p><p><strong>Local Cache vs Distributed Cache</strong></p><p>Many developers immediately think about Redis when they hear the word “cache.”</p><p>But Redis isn’t the only option.</p><p>Suppose your application frequently reads:</p><ul><li>Country codes</li><li>Currency symbols</li><li>Application configuration</li><li>Feature flags</li></ul><p>These values rarely change.</p><p>Using a local in-memory cache such as <strong>Caffeine</strong> might actually be faster than making a network call to Redis.</p><p>Local caches eliminate:</p><ul><li>Network latency</li><li>Serialization overhead</li><li>External infrastructure dependency</li></ul><p>Distributed caches like Redis become valuable when multiple application instances need to share the same cached data.</p><p>Choosing between a local and distributed cache is another architectural decision — not just a technical one.</p><p><strong>Final Thoughts</strong></p><p>Caching is one of the most powerful tools available to backend engineers, but it’s not a shortcut to better performance.</p><p><em>Every cache is a promise. A promise that the data you’re serving is still valid, still relevant, and worth the memory it occupies. Breaking that promise leads to stale data, wasted memory, and systems that become harder to reason about.</em></p><p><em>Another synchronization challenge.<br>Another operational responsibility.<br>The goal isn’t to eliminate every database call.</em></p><p>The goal is to make thoughtful engineering decisions based on trade-offs.</p><p>Sometimes the right answer is Redis.</p><p>Sometimes it’s a better SQL query.</p><p>And sometimes…</p><p>the best optimization is realizing that <strong>the data never needed to be cached in the first place.</strong></p><h3>References</h3><p>While writing this article, I revisited concepts from operating system memory hierarchies, CPU cache design, Redis and Caffeine documentation, and discussions across the Java backend community. This article reflects my understanding of those concepts, combined with practical experience building backend applications</p><p>I enjoy exploring the computer science principles behind modern backend systems. If you’re interested in Java, system design, and software architecture beyond the framework level, follow along for more articles.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dba8a3d47ff0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL vs NoSQL — A Real, Practical Decision Framework]]></title>
            <link>https://medium.com/@addmin.blaze/sql-vs-nosql-a-real-practical-decision-framework-52e55609bbea?source=rss-220dbaa80ad1------2</link>
            <guid isPermaLink="false">https://medium.com/p/52e55609bbea</guid>
            <category><![CDATA[database-design]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Atmaram Dhuri]]></dc:creator>
            <pubDate>Sun, 08 Mar 2026 18:45:05 GMT</pubDate>
            <atom:updated>2026-03-08T18:45:05.356Z</atom:updated>
            <content:encoded><![CDATA[<p>When most developers think about SQL and NoSQL, the conversation usually sounds like:</p><p>“SQL is structured and rigid…”<br>“NoSQL is flexible and scalable…”</p><p>That kind of comparison is everywhere, but it’s missing something crucial:</p><p>Real systems don’t make decisions based on bullet points — they make decisions based on <strong>trade-offs and real requirements.</strong></p><p>After building backend systems where both SQL and NoSQL play important roles, I realized that database choice is not about <em>which one is better</em>. It’s about <strong>what problem you are solving today, and what problems you need to solve in the future</strong>.</p><p>I thought of putting some light on this topic without writing down just comparisons.</p><p><strong>Start With the Nature of Your Data</strong></p><p>The first question we need to ask is:</p><p><strong>How relational is your data?</strong></p><p>When your data naturally has strong connections — like:<br>Order → Customer → Payment → Invoice</p><p>…a relational database often feels right because it was built for that model.</p><p>SQL databases excel when:</p><ul><li>You have many relationships between entities</li><li>You rely on joins</li><li>You need integrity constraints</li></ul><p>Examples:</p><ul><li>Banking systems</li><li>Order management</li><li>Inventory control</li></ul><p>These are naturally relational systems.</p><p><strong>Look at How You Query the Data<br></strong>Too many teams pick a database first and figure out queries later. That’s backwards.</p><p>Ask yourself:</p><ul><li>Will I run complex filters?</li><li>Do I need ad-hoc reporting?</li><li>Will I join data from multiple sources?</li></ul><p><strong>SQL wins</strong> when you have:</p><ul><li>Complex queries</li><li>Reporting requirements</li><li>Multi-table joins</li></ul><p><strong>NoSQL shines</strong> when:</p><ul><li>You access data with simple, predictable queries</li><li>You fetch complete documents</li><li>You don’t need joins</li></ul><p>For example:<br> Fetching analytics logs → simple, no joins → NoSQL<br> Generating business reports → multiple table joins → SQL</p><p>It’s not about flexibility vs rigidity — it’s about <strong>querying patterns</strong>.</p><p><strong>Consistency Needs Come First</strong></p><p>This is where theory and real systems part ways.</p><p>Many teams say “We can handle eventual consistency.”<br>But when money, finance, or billing is involved… eventual consistency suddenly becomes a liability.</p><p>SQL is strong when:</p><ul><li>You need strict ACID guarantees</li><li>You must rollback multi-entity changes</li><li>You cannot have partial failures</li></ul><p>NoSQL becomes useful when:</p><ul><li>Slight delays in data propagation are acceptable</li><li>Availability is more critical than immediate consistency</li><li>You can tolerate temporary data staleness</li></ul><p>For example:<br> ✔ Payment processing → consistent and transactional → SQL<br> ✔ User activity tracking → eventual consistency acceptable → NoSQL</p><p>Being honest about consistency needs changes everything.</p><p><strong>Understand Data Modeling Choices</strong></p><p>This is where I see teams trip up.</p><p>SQL expects:</p><ul><li>Normalized data</li><li>Clear relationships</li><li>Avoided duplication</li></ul><p>NoSQL encourages:</p><ul><li>Embedding related data</li><li>Intentional duplication to optimize reads</li><li>Schema-less documents</li></ul><p>This flexibility with NoSQL isn’t free — it often pushes complexity into your application logic.</p><p>I’ve seen teams choose NoSQL because it “feels easier” — only to rebuild relationships manually in code.</p><p>Always consider whether you are simply moving complexity from database to application.</p><p>Another cost appears during object mapping.</p><p>When working with document databases like MongoDB, JSON/BSON documents must be serialized and deserialized into application objects. Large documents can increase memory usage and processing overhead.</p><p><strong>Scalability Is Not a Binary Choice</strong></p><p>A common Internet myth is:</p><p>NoSQL scales, SQL doesn’t.</p><p>That’s outdated.</p><p>Today, both ecosystems support scaling — but they do it differently.</p><p><strong>SQL:</strong></p><ul><li>Vertical scaling first</li><li>Read replicas</li><li>Eventual sharding</li></ul><p><strong>NoSQL:</strong></p><ul><li>Horizontal scaling by design</li><li>Natural partitioning</li><li>Distributed by default</li></ul><p>What matters more in real systems is <strong>operational stability</strong>, not theoretical scalability. A poorly designed distributed system will fail just as badly as a poorly indexed relational one.</p><p>NoSQL databases were built with horizontal scaling in mind, which is why they are often considered more scalable. However, modern SQL databases have evolved significantly. Technologies like Oracle’s CDB-PDB architecture and PostgreSQL’s replication and read replicas allow relational systems to handle large-scale workloads as well. The real difference today lies in scaling strategies and trade-offs, not the ability to scale.</p><p><strong>When NoSQL Gets Misused</strong></p><p>In my experience, NoSQL can fail when:</p><ul><li>Documents grow unpredictably large</li><li>Indexes are missing or inefficient</li><li>Aggregation pipelines get abused</li><li>Schema drift happens without discipline</li></ul><p>NoSQL isn’t a silver bullet — it’s a powerful tool that must be used with intent.</p><p><strong>When SQL Becomes a Bottleneck</strong></p><p>Relational systems can struggle too:</p><ul><li>Lock contention</li><li>Long transactions</li><li>Deadlocks</li><li>Poor indexing</li></ul><p>These aren’t “SQL problems” — they’re data modelling and query planning issues.</p><p>A poorly designed database is slow in any paradigm.</p><p><strong>Most Real Systems Don’t Choose Just One</strong></p><p>In enterprise environments, the pattern is usually:</p><ul><li><strong>SQL</strong> for transactional data</li><li><strong>NoSQL</strong> for logs, sessions, and flexible documents</li><li><strong>Kafka</strong> for event streaming</li><li><strong>Redis</strong> for caching</li></ul><p>This is called <strong>polyglot persistence</strong> — using the right storage for the right job.</p><p>Think of building a house.</p><p>You wouldn’t use <strong>only a hammer</strong> for everything.</p><ul><li>A <strong>hammer</strong> is great for nails</li><li>A <strong>screwdriver</strong> is better for screws</li><li>A <strong>wrench</strong> is needed for bolts</li></ul><p>Each tool is designed for a specific job.</p><p>Using a hammer for everything would make the work harder and less efficient.</p><p>Polyglot persistence works the same way.</p><p>And this is where strong backend engineers differentiate themselves.</p><p><strong>Practical Decision Snapshot</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2R7klYcdGZtqJcsaYKSx5A.png" /><figcaption>SQL vs NoSQL decision framework</figcaption></figure><p>Use this as guidance — not a checklist.</p><p>Don’t pick a database because it’s popular.</p><p>Don’t pick one because a benchmark told you to.</p><p>Pick the one that fits your <strong>data shape, query patterns, consistency needs, operational maturity</strong>, and <strong>team expertise</strong>.</p><p>The SQL vs NoSQL debate often misses the bigger point.</p><p>Great systems are rarely built on a single storage model. They combine multiple tools based on the nature of the data, the query patterns, and the consistency guarantees required.</p><p>Great backend engineers don’t pick databases based on trends. They design systems based on trade-offs.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=52e55609bbea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java — Pass by Value or Pass by Reference?]]></title>
            <link>https://medium.com/@addmin.blaze/java-pass-by-value-or-pass-by-reference-865b4d9fe5a5?source=rss-220dbaa80ad1------2</link>
            <guid isPermaLink="false">https://medium.com/p/865b4d9fe5a5</guid>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[pass-by-value]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[pass-by-reference]]></category>
            <dc:creator><![CDATA[Atmaram Dhuri]]></dc:creator>
            <pubDate>Sat, 28 Feb 2026 19:41:00 GMT</pubDate>
            <atom:updated>2026-02-28T19:41:00.443Z</atom:updated>
            <content:encoded><![CDATA[<p>On a warm afternoon, one of my colleagues was revisiting Java fundamentals. He showed me a small piece of code and asked:</p><p>“Is Java pass-by-value or pass-by-reference?” It sounds like a beginner question.</p><p>It isn’t.</p><p>Even experienced developers sometimes hesitate. Some say “value,” some say “reference,” and some say, “It depends.” Let’s settle this properly — calmly, logically, and without myths.</p><p><strong>What Is Pass-By-Reference?</strong></p><p>The idea mostly comes from languages like C++.</p><p>In C++, you can write:</p><pre>void change(int&amp; x) {<br>    x = 20;<br>}</pre><p>Here, x is a reference to the original variable. When you modify x, you modify the caller’s variable directly.</p><p>No copy.<br>No indirection.<br>That is true pass-by-reference.</p><p>Here, x is a reference to the original variable. When you modify x, you modify the caller’s variable directly. So, passing reference does make the change on actual variables but does this apply to Java as well?</p><p>To avoid security concerns and memory mismanagement, Java does not allow direct pointer manipulation, hence Java does not actually modify memory. So, does java use pass by value? Let’s understand if it’s true.</p><p><strong>What Is Pass-By-Value?</strong></p><p>Pass-by-value means:<br>A copy of the variable’s value is passed to the method.<br>If you modify it inside the method, the original remains unchanged.</p><p>Simple Java example:</p><pre>void change(int x) {<br>    x = 20;<br>}<br><br>int a = 10;<br>change(a);<br>System.out.println(a);</pre><pre><strong>Output:</strong><br>10</pre><p>Because x received a copy of a.<br>So far, everything is simple.<br>Let’s step away from code for a moment and understand it in layman’s terms.</p><p>Imagine you created a Word document and saved it on your laptop. There are two ways you can share it with a colleague.</p><p><strong>Case 1: You Email a Copy</strong></p><p>You send the document as an attachment.<br>Now:</p><ul><li>You have your original file.</li><li>Your colleague has a separate copy.</li></ul><p>If your colleague edits their version, your file does not change.<br>That is pass-by-value.<br>Each person works on their own copy.</p><p><strong>Case 2: You Share a Cloud Link</strong></p><p>Instead of sending a copy, you share a Google Drive link.<br>Now:</p><ul><li>Both of you are looking at the same document.</li><li>If your colleague edits it, you see the changes.</li></ul><p>That feels like pass-by-reference.</p><p><strong>Now the Real Question — What Does Java Do?</strong></p><p>Here is the precise answer:</p><p><strong>Java is always pass-by-value.</strong></p><p>Always.<br>Even for objects.</p><p>Now let’s see why this statement causes confusion</p><p><strong>Example 1 — Primitives (The Swap That Fails)</strong></p><pre>void swap(int x, int y) {<br>    int temp = x;<br>    x = y;<br>    y = temp;<br>}<br><br>int a = 10;<br>int b = 20;<br>swap(a, b);<br>System.out.println(&quot;a -&gt; &quot; + a + &quot; b -&gt; &quot; + b);</pre><p>Output:</p><pre><strong>Output:</strong><br>a -&gt; 10 b -&gt; 20</pre><p>Why didn’t it swap?</p><p>Because x and y are copies.<br>You swapped the copies — not the originals.<br>Clear case of pass-by-value.</p><p><strong>Example 2 — Objects (The Confusing Part)</strong></p><pre>class A {<br>    int value;<br>    A(int value) {<br>        this.value = value;<br>    }<br>}<br><br>void modify(A obj) {<br>    obj.value = 50;<br>}<br><br>A a = new A(10);<br>modify(a);<br>System.out.println(a.value);</pre><pre><strong>Output:</strong><br>50</pre><p>Now it feels like pass-by-reference.<br>The object changed! So what’s going on?</p><p><strong>Understanding What Is Really Being Passed</strong></p><p>When you create an object:</p><p>A a = new A(10);</p><p>Memory looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/834/1*E239puqc7fekJ9kwQ8wiTw.png" /><figcaption>Memory Structure after creation of reference “a”</figcaption></figure><p>The variable a does not store the object.<br> It stores a <strong>reference</strong> to the object.</p><p>When you call: modify(a);</p><p>Java copies the value stored in a. What is that value?</p><p>The reference. So now:</p><p>Stack looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*lNCVxIQ3Iydsk0R-OHK4vg.png" /><figcaption>Memory Structure after Reference obj reffered in method</figcaption></figure><p>Two variables. Same reference value. Same object in heap.<br>So when you modify:</p><p>obj.value = 50;</p><p>You’re modifying the object both references point to. That’s why the change is visible.</p><p><strong>The Final Proof — Reassignment</strong></p><p>If Java were pass-by-reference, this would work:</p><pre>void reassign(A obj) {<br>    obj = new A(100);<br>}<br>A a = new A(10);<br>reassign(a);<br>System.out.println(a.value);</pre><pre><strong>Output:</strong><br>10</pre><p>The original object did not change.</p><p>Because the method only received a copy of the reference.</p><p>When you reassigned obj, you changed what the local copy points to — not the caller’s variable.</p><p>This proves Java is not pass-by-reference.</p><p><strong>What Java Actually Does</strong></p><p>Java does something subtle. It does NOT send the actual document.<br> It does NOT give control over your original file.</p><p>Instead:<br>It copies the <strong>link</strong> to the document. <br>Now both of you hold the same link.</p><p>If one person edits the document, the changes are visible — because the document is shared. But if someone throws away the link and creates a new document, that does not affect the other person’s link.</p><p>That is exactly what happens with object references in Java.</p><p>Java copies the link (reference), not the document (object).</p><p><strong>Why It Feels Confusing</strong></p><p>Because developers mix up three things:</p><ol><li>The variable</li><li>The reference stored in the variable</li><li>The object in memory</li></ol><p>Java always copies the variable’s value. Sometimes that value is:</p><ul><li>A number</li><li>A reference (a link)</li></ul><p>But it is always copied.</p><p>Never shared.</p><p><strong>You can:</strong></p><ul><li>Modify the object through the reference.</li><li>See changes reflected elsewhere if the object is shared.</li></ul><p><strong>You cannot:</strong></p><ul><li>Change what the caller’s reference points to.</li><li>Swap two objects using a method.</li><li>Reassign the caller’s variable from inside a method.</li></ul><p><strong>Final Conclusion</strong></p><p>Java is not “sometimes value, sometimes reference.”</p><p>Java is always <strong>pass-by-value</strong>.</p><p>The only reason it feels different for objects is because the value being copied is itself a reference.</p><p>Once you separate:</p><ul><li>Variable</li><li>Reference</li><li>Object</li></ul><p>The confusion disappears.</p><p>And once the confusion disappears, you start reasoning about Java memory much more clearly.</p><pre><strong>Note: </strong>This topic has been extensively discussed on platforms like <br>Stack Overflow and Medium. I referred to several discussions while <br>researching this post to ensure technical correctness.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=865b4d9fe5a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>