<?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 juniordcoder on Medium]]></title>
        <description><![CDATA[Stories by juniordcoder on Medium]]></description>
        <link>https://medium.com/@foryoungjuniorngu?source=rss-433f49b9591a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*gOI5bv4X93XEePpF</url>
            <title>Stories by juniordcoder on Medium</title>
            <link>https://medium.com/@foryoungjuniorngu?source=rss-433f49b9591a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 19:49:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@foryoungjuniorngu/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[ How ORM Lazy Loading Almost Killed Performance in my Project]]></title>
            <link>https://medium.com/@foryoungjuniorngu/how-orm-lazy-loading-almost-killed-performance-in-my-project-57a8615c82b3?source=rss-433f49b9591a------2</link>
            <guid isPermaLink="false">https://medium.com/p/57a8615c82b3</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[juniordcoder]]></dc:creator>
            <pubDate>Fri, 03 Oct 2025 21:23:03 GMT</pubDate>
            <atom:updated>2025-10-03T21:23:03.798Z</atom:updated>
            <content:encoded><![CDATA[<p>When building AsapChop (<a href="https://asapchop.com/">https://asapchop.com</a>) — our food ordering platform — I ran into one of the sneakiest backend traps I’ve ever seen.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w-Odj3K58WKcHACKR9AhgA.png" /></figure><p>Locally, everything worked fine. Pages were snappy. APIs responded in milliseconds.<br> But when we launched to production… some pages took <strong>8–12 seconds</strong> to load.</p><p>The strangest part? The database server was barely sweating. CPU and memory were fine. Queries looked “simple.”</p><p>That was the day I learned (the hard way) about <strong>Laravel ORM (Eloquent) + Lazy Loading + the N+1 query problem</strong>.</p><h3>The Setup</h3><p>One of the core features of AsapChop is the <strong>meals listing</strong>.</p><p>A meal can have:</p><ul><li>Multiple <strong>ingredients</strong></li><li>Belong to a <strong>category</strong></li><li>Come from a <strong>restaurant</strong></li><li>And have <strong>reviews</strong></li></ul><p>On the backend, in Laravel Eloquent, that translated into relations like:</p><pre>class Meal extends Model {<br>    public function ingredients() {<br>        return $this-&gt;hasMany(Ingredient::class);<br>    }<br>    public function category() {<br>        return $this-&gt;belongsTo(Category::class);<br>    }<br>    public function restaurant() {<br>        return $this-&gt;belongsTo(Restaurant::class);<br>    }<br>}</pre><p>When I first built the meals endpoint, I simply wrote:</p><pre>$meals = Meal::all();<br><br>foreach ($meals as $meal) {<br>    $meal-&gt;ingredients;<br>    $meal-&gt;category;<br>    $meal-&gt;restaurant;<br>}</pre><p>Locally, with 10–20 meals in my dev database, it was blazing fast. No problems.<br> So I shipped it.</p><h3>The Disaster in Production 🚨</h3><p>Once the production DB had <strong>hundreds of meals</strong> (and each meal had several ingredients, reviews, etc.), that same code turned into a nightmare.</p><p>What happened under the hood:</p><ol><li>Fetch meals:</li></ol><pre>SELECT * FROM meals;</pre><p>2. For each meal (say 50 meals), Laravel fired:</p><pre>SELECT * FROM ingredients WHERE meal_id = 1;<br>SELECT * FROM ingredients WHERE meal_id = 2;<br>...<br>SELECT * FROM ingredients WHERE meal_id = 50;</pre><p>3. Same thing for categories, restaurants, reviews…</p><p>End result? <strong>Dozens or even hundreds of queries for a single page.</strong></p><p>That’s the classic <strong>N+1 Query Problem</strong>:</p><ul><li>1 query to fetch meals</li><li>N queries to fetch related records for each meal</li><li>Stack more relations = exponential slowdown</li></ul><p>So even though the database was “idle,” latency from <strong>all those tiny queries</strong> stacked up to 8–12 seconds of waiting time.</p><h3>Diagnosing the Problem 🔍</h3><p>The “aha” moment came when I enabled <strong>query logging in Laravel</strong>:</p><pre>\DB::listen(function($query) {<br>    logger($query-&gt;sql);<br>});</pre><p>The logs showed <strong>the same query running over and over again</strong> for each meal.</p><p>Then I tried loading a staging DB with real meal/ingredient data, and I could instantly reproduce the slowdown.</p><h3>The Fix: Eager Loading</h3><p>Laravel has a built-in fix: <strong>eager loading</strong>. Instead of fetching related records meal-by-meal, you fetch everything in one go.</p><p>So I changed my code from this:</p><pre>$meals = Meal::all();</pre><p>To this:</p><pre>$meals = Meal::with([&#39;ingredients&#39;, &#39;category&#39;, &#39;restaurant&#39;])-&gt;get();</pre><p>Now Laravel runs just a few queries:</p><pre>SELECT * FROM meals;<br>SELECT * FROM ingredients WHERE meal_id IN (1,2,3,...,50);<br>SELECT * FROM categories WHERE id IN (...);<br>SELECT * FROM restaurants WHERE id IN (...);</pre><p>That’s it. No more N+1 madness.</p><h3>The Results 🚀</h3><p>After switching to eager loading:</p><ul><li>Queries dropped from <strong>hundreds → ~4–5</strong></li><li>API response time dropped from <strong>8–12s → under 500ms</strong></li><li>Database stayed healthy, even with realistic production load</li></ul><p>The difference was night and day.</p><h3>Lessons Learned</h3><ul><li><strong>Lazy loading feels magical but dangerous</strong> — $meal-&gt;ingredients looks harmless, but can silently cause N+1.</li><li><strong>Small dev datasets lie</strong> — you won’t notice issues until you hit production-scale data.</li><li><strong>Always use eager loading (</strong><strong>with())</strong> for relations you know you’ll need.</li><li><strong>Log queries in staging/production</strong> to spot inefficiencies.</li><li><strong>Be intentional</strong>: don’t over-fetch — only load relations and columns you actually need.</li></ul><h3>Final Takeaway</h3><p>Building AsapChop taught me a painful but valuable lesson:<br> <strong>An ORM doesn’t remove the need to think about SQL.</strong></p><p>If you’re using Laravel (or any ORM), always keep an eye on what’s really happening under the hood. Because what feels “clean” in dev can quietly destroy your app in production.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57a8615c82b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ UUIDs in Backends: The Hidden Cons Nobody Talks About]]></title>
            <link>https://medium.com/@foryoungjuniorngu/uuids-in-backends-the-hidden-cons-nobody-talks-about-2bf9a26d64a0?source=rss-433f49b9591a------2</link>
            <guid isPermaLink="false">https://medium.com/p/2bf9a26d64a0</guid>
            <category><![CDATA[database-optimization]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[uuid]]></category>
            <dc:creator><![CDATA[juniordcoder]]></dc:creator>
            <pubDate>Wed, 01 Oct 2025 12:03:10 GMT</pubDate>
            <atom:updated>2025-10-01T12:03:10.570Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PpV94ITys62ctC3oSmzllw.png" /></figure><p>Most backend devs (myself included, at some point 😅) grab UUIDs because:<br> ✔️ They’re unique<br> ✔️ They work great in distributed systems<br> ✔️ No central authority is needed for ID generation</p><p>…but here’s the thing 👇 UUIDs come with <em>trade-offs</em> that might be silently slowing down your app.</p><h3>🔴 The Cons of UUIDs</h3><p>1️⃣ <strong>Storage Overhead</strong></p><ul><li>UUID = 128 bits (16 bytes)</li><li>INT = 4 bytes, BIGINT = 8 bytes<br> 👉 On huge tables, that adds up.</li></ul><p>2️⃣ <strong>Indexing Pain</strong></p><ul><li>Random UUIDs break the natural order of DB indexes.</li><li>More fragmentation → slower inserts &amp; bigger indexes.</li></ul><p>3️⃣ <strong>Not Human-Friendly</strong></p><ul><li>Debugging c56a4180-65aa-42ec-a945-5fd21dec0538 vs 12345?</li><li>Guess which one your 3AM-brain prefers 😅</li></ul><p>4️⃣ <strong>Network &amp; Logging Weight</strong></p><ul><li>Every API response, every log line, every message queue entry → heavier with UUIDs.</li></ul><p>5️⃣ <strong>Possible Collisions (Bad RNG)</strong></p><ul><li>Rare, but with poor implementations, collisions can creep in.</li></ul><p>6️⃣ <strong>Compatibility Issues</strong></p><ul><li>Some legacy systems just don’t play nice with UUIDs.</li></ul><h3>How to Make UUIDs Work Better</h3><ul><li>Use <strong>UUIDv7</strong> (time-ordered) → reduces index fragmentation.</li><li>Store in <strong>BINARY(16)</strong> instead of CHAR(36) → space saver.</li><li>Check out <strong>ULIDs</strong> or <strong>KSUIDs</strong> → sortable + more human-friendly.</li><li>Mix &amp; match:</li><li><strong>Internal DB IDs?</strong> Integers.</li><li><strong>Public IDs in URLs?</strong> UUIDs (harder to guess).</li></ul><h3>💡 Takeaway</h3><p>UUIDs are awesome… but not always the silver bullet.<br> Next time you’re designing your backend, ask yourself:</p><p>👉 Do I need <em>global uniqueness</em> across distributed systems?<br> 👉 Or is a good old auto-increment INT just fine (and faster)?</p><p>💬 What’s your take? Have UUIDs bitten you in production before? Or are you team INT forever? Let’s hear your stories 👇</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2bf9a26d64a0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>