<?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 Samwel Wilson on Medium]]></title>
        <description><![CDATA[Stories by Samwel Wilson on Medium]]></description>
        <link>https://medium.com/@samwel141?source=rss-a5f80052d63d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*pS8KcDeApvcM2CaZ</url>
            <title>Stories by Samwel Wilson on Medium</title>
            <link>https://medium.com/@samwel141?source=rss-a5f80052d63d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:45:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samwel141/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[A microservices scaling time bomb: an N+1 hiding in the message queue]]></title>
            <link>https://medium.com/@samwel141/a-microservices-scaling-time-bomb-an-n-1-hiding-in-the-message-queue-cf0ad5b43c13?source=rss-a5f80052d63d------2</link>
            <guid isPermaLink="false">https://medium.com/p/cf0ad5b43c13</guid>
            <dc:creator><![CDATA[Samwel Wilson]]></dc:creator>
            <pubDate>Mon, 17 Aug 2026 11:11:43 GMT</pubDate>
            <atom:updated>2026-08-17T11:11:43.463Z</atom:updated>
            <content:encoded><![CDATA[<p>How one dashboard page froze login over RabbitMQ for 40 minutes at a time, while the logs said 200 OK</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MZhJRiJPPCHr9xiBa6AdXw.png" /></figure><p>In microservices system, two services that never call each other can still take each other down. Here is how a single admin dashboard page froze our login endpoint, over RabbitMQ, for 40 minutes at a time, while the logs cheerfully reported 200 OK</p><p><strong>The symptom</strong><br>This code shipped and ran fine for months. Nobody touched it. Then the user base grew, request volume climbed, and one day login started timing out. The bug was there the whole time; it only had to wait for enough data to show itself</p><p>It started the usual way: “login is slow,” then “login is broken.” Users waited and got a 504 Gateway Time-out. So we opened the logs expecting stack traces, and found this instead:</p><blockquote>Req: POST /login <br>Res: 200, 2,326,751 ms</blockquote><p>Two hundred OK. In 2,326,751 milliseconds, which is 38 minutes. The next one took longer. And the next. Every login was “succeeding,” each slower than the last, while the person who typed their password had left half an hour ago.</p><p>Two facts refused to agree. The user saw failure (their browser and nginx gave up at 60 seconds). The backend saw success (it finished eventually and logged 200). A 200 OK that arrives 40 minutes late is not a success. It is a receipt for a meal the customer already left without eating.</p><p><strong>The map</strong><br>Two services matter. Auth owns login and roles (roles live in its database but are served from a Redis cache). Users owns profiles. They talk over RabbitMQ using NestJS message patterns (request and reply), and two calls matter:</p><blockquote>// Login lives in Auth and asks Users for a profile usersClient.send(‘get_user_profile’, { userNumber });</blockquote><blockquote>// The salespeople page lives in Users and asks Auth for roles authClient.send(‘get_user_roles’, { userNumber });</blockquote><p>Notice the shape: login runs inside Auth, and the salespeople page hammers Auth from the outside. They meet in the same place. Keep one thing in mind, because it is the whole plot: each service is one Node.js process with one RabbitMQ consumer and one database pool. Login and the salespeople storm both run through Auth.</p><p><strong>What it was not</strong><br>We spent an hour here, so you don’t have to. RabbitMQ was healthy: no alarms, memory and disk fine, and every queue showed a connected consumer with zero backlog. The queue names were correct. The nginx 60-second timeout was only where the 504 surfaced, not why. When the broker looks perfectly idle but everything still hangs, stop blaming the broker and start looking at what the services do with the messages.</p><p><strong>The trigger: an N+1 hiding in a message queue</strong><br>You know N+1 from databases: one query for a list, then one more query per row. We had the same shape, but over a message queue.</p><p>An admin opened the “salespeople” page. To decide who is a salesperson, the code loaded every user, then asked Auth for each user’s roles, one message at a time:</p><blockquote>// The bug: one message PER user const users = await repo.find(); // ~600 rows await Promise.all( users.map((u) =&gt; authClient.send(‘get_user_roles’, { userNumber: u.userNumber }) ) ); // ~600 messages, all at once</blockquote><p>One page load became 600 RabbitMQ requests. The “+1” is the list. The “N” is one call per row, and N grows with your data: fine with 10 users in testing, a flood with 600 in production</p><p>The fix is to make N disappear. Ask one set-based question instead of many:</p><blockquote>// One message for everyone const salespeople = await authClient.send( ‘get_users_by_permission’, { permission: ‘VIEW_OWN_TARGET’ } );</blockquote><p><strong>Why it detonated: three multipliers</strong><br>An N+1 alone is slow. Three defaults turned slow into an outage:</p><ol><li>Unlimited prefetch. NestJS does not set a prefetchCount, and RabbitMQ’s default is unlimited. So Auth’s single consumer grabbed all 600 messages at once instead of draining them a few at a time, and its one event loop had no room left for anything else.</li><li>A small pool. Auth runs on about 10 database connections. Cache misses and login’s own user lookup all draw from those ten, so once the process was saturated there was no headroom for login to authenticate.</li><li>Aggressive retries. Each cross-service call retried up to 10 times at 10 seconds each. One slow spell became a 100-second hold per request.</li></ol><p><strong>The twist: why login died<br></strong>Login and the salespeople page are different endpoints, on different queues. So why did one freeze the other?</p><p>Because they run through the same Auth process. The 600 role requests landed on Auth’s single RabbitMQ consumer, which, with unlimited prefetch, pulled them all in at once and pegged the one event loop serving them. Redis caching made each role lookup cheap, but 600 arriving together still saturate a single consumer, and login lives in that same process. Its own database check then queued behind the flood. Different queue, shared fate. This is the part most people miss: in microservices, the coupling that hurts you is often not a direct call, it is a shared process or pool that two independent paths quietly contend for</p><p><strong>The collapse: retry storms and ghost successes</strong><br>Now the feedback loop. The backend took longer to finish a login than the client would wait. So the client timed out at 60 seconds and the user retried, which added another login to a queue that was already minutes deep. More waiting caused more timeouts, which caused more retries. The backlog grew to 40 minutes and kept growing, which is exactly why each logged duration was larger than the last.</p><p>And the backend never dropped the abandoned work. It finished each request long after the client had gone and logged 200 OK. Those were ghost successes: green in the logs, a failure for every human. If you only alert on error rates, this outage is invisible.</p><p><strong>The fix</strong><br>Stopgap: restart the two services. That throws away the 40-minute backlog and login returns in about two seconds. It buys minutes, not a cure, because the cause is still in the code.</p><p>Real fixes, in order of impact:</p><ul><li>600 messages for one page (N+1) → one batched call (get_users_by_permission)</li><li>Unlimited prefetch → set prefetchCount so a burst drains gradually</li><li>~10 DB connections → right-size the pool, index the hot queries</li><li>Retry 10× at 10s → fewer, shorter retries with backoff and a cap</li><li>Load all rows, then .slice() → paginate in the database</li></ul><p><strong>Takeaways</strong><br><strong>Five rules that travel to any queue-based system, NestJS or not:</strong></p><ol><li>Grep for .map(x =&gt; send(…)) and its cousins. A loop that sends one message per item is an N+1 in disguise. Batch it</li><li>Always set a prefetch count. “Unlimited” is a default, not a decision</li><li>Watch shared resources, not just shared calls. One process and one connection pool couple endpoints that look independent</li><li>Cap and back off your retries. Ten retries do not add resilience, they add a queue</li><li>Alert on latency, not only errors. A 200 OK that takes 40 minutes will never trip an error alarm</li></ol><p>The bug was one innocent line: fetch a list, then ask about each item. Over a database it would have been merely slow. Over a message queue, on a shared pool, behind a retry loop, it took down login for users who were never anywhere near that page</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cf0ad5b43c13" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[You’ve built a beautiful, fast, and functional website.]]></title>
            <link>https://medium.com/@samwel141/youve-built-a-beautiful-fast-and-functional-website-ac5b724a3818?source=rss-a5f80052d63d------2</link>
            <guid isPermaLink="false">https://medium.com/p/ac5b724a3818</guid>
            <dc:creator><![CDATA[Samwel Wilson]]></dc:creator>
            <pubDate>Fri, 26 Sep 2025 06:35:27 GMT</pubDate>
            <atom:updated>2025-09-26T06:45:42.129Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>Demystifying SEO: A Developer’s &amp; Content Creator’s Guide to Being Found Online</strong></blockquote><p>You’ve built a beautiful, fast, and functional website. It’s your digital masterpiece. But there’s a problem: if you launch it in a forest and no one is around to see it, does it make an impact?</p><p>This is where Search Engine Optimization (SEO) comes in. SEO isn’t about tricking search engines; it’s about speaking their language. It’s the art and science of making your website so clear, relevant, and authoritative that search engines like Google can’t help but recommend it to users.</p><p>Let’s break down the core components of technical and on-page SEO in a way you can immediately apply.</p><figure><img alt="An image of google bot crawling through the web pages" src="https://cdn-images-1.medium.com/max/1024/1*ME2TnwdWqpL-9yTgLuHNxQ.png" /></figure><p><strong>Part 1: The Foundation — How Search Engines See Your Site<br></strong>Before we talk code, you need to understand the basic process. Think of search engines as incredibly diligent librarians.</p><ol><li>Crawling: The librarian (a “crawler” or “spider” like Googlebot) explores the library (the internet) by following links (aisles and signs). It discovers new books (web pages) and updated editions.</li><li>Indexing: The librarian then reads each book and creates a massive, detailed index card for it. This card notes the title, chapter headings, key topics, and references. This index is the database Google searches when a user asks a question.</li><li>Ranking: When you ask the librarian a question, they don’t scan every book. They quickly consult their index and rank the most relevant, authoritative, and helpful books for you.</li></ol><p>Your Goal: Make crawling and indexing as easy as possible.</p><p><strong>Part 2: The Blueprint — Crucial Code in Your HTML </strong><strong>&lt;head&gt;<br></strong>The &lt;head&gt; section of your HTML is like a confidential memo to the search engine. It’s packed with meta-information that doesn&#39;t display on the page but is critical for understanding.</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>    &lt;!-- Character Set --&gt;<br>    &lt;meta charset=&quot;UTF-8&quot;&gt;<br>    &lt;!-- Viewport for Mobile-First Indexing --&gt;<br>    &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;    &lt;!-- THE SEO TRIFECTA --&gt;<br>    &lt;!-- Page Title - The Single Most Important Tag --&gt;<br>    &lt;title&gt;Precise, Engaging Page Title (under 60 characters) | Brand Name&lt;/title&gt;<br>    &lt;!-- Meta Description - Your Ad Copy --&gt;<br>    &lt;meta name=&quot;description&quot; content=&quot;A compelling summary of this specific page (around 150-160 characters). This is what appears in search results. Make people want to click!&quot;&gt;<br>    &lt;!-- Canonical URL - Solving Duplicate Content --&gt;<br>    &lt;link rel=&quot;canonical&quot; href=&quot;https://www.yoursite.com/definitive-page-url/&quot; /&gt;   &lt;!-- Open Graph Tags for Social Media (Especially Facebook/LinkedIn) --&gt;<br>    &lt;meta property=&quot;og:title&quot; content=&quot;Your Shareable Title&quot;&gt;<br>    &lt;meta property=&quot;og:description&quot; content=&quot;Your shareable description.&quot;&gt;<br>    &lt;meta property=&quot;og:image&quot; content=&quot;https://yoursite.com/image.jpg&quot;&gt;<br>    &lt;meta property=&quot;og:url&quot; content=&quot;https://www.yoursite.com/page-url&quot;&gt; &lt;!-- Twitter Card Tags --&gt;<br> &lt;meta name=&quot;twitter:card&quot; content=&quot;summary_large_image&quot;&gt;<br>    &lt;meta name=&quot;twitter:title&quot; content=&quot;Your Twitter Title&quot;&gt;<br>    &lt;meta name=&quot;twitter:description&quot; content=&quot;Your Twitter description.&quot;&gt;<br>    &lt;meta name=&quot;twitter:image&quot; content=&quot;https://yoursite.com/twitter-image.jpg&quot;&gt;&lt;!-- Structured Data (Schema.org) - Advanced Clarity --&gt;<br>    &lt;script type=&quot;application/ld+json&quot;&gt;<br>    {<br>      &quot;@context&quot;: &quot;https://schema.org&quot;,<br>      &quot;@type&quot;: &quot;Article&quot;,<br>      &quot;headline&quot;: &quot;Article Headline&quot;,<br>      &quot;author&quot;: &quot;Author Name&quot;,<br>      &quot;datePublished&quot;: &quot;2023-10-27&quot;<br>    }<br>    &lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;</pre><p>Why this matters:</p><ul><li>Title &amp; Description: Directly influence your click-through rate from search results.</li><li>Canonical Tag: Tells Google, “Hey, this is the main version of this page,” even if the same content is accessible via multiple URLs. This prevents duplicate content penalties.</li><li>OG &amp; Twitter Tags: Control how your content looks when shared, increasing engagement.</li><li>Structured Data: Provides explicit clues about the page’s content (e.g., this is a <em>Recipe</em>, with a <em>cookTime</em> and 5-star <em>rating</em>), helping you earn rich snippets — those enhanced results in search.</li></ul><p><strong>Part 3: The Architecture — Structuring Your Page Content (HTML Tags)<br></strong>Your page’s HTML structure tells a story. Using tags correctly is like using proper grammar and headings in a book.</p><p>The Hierarchy of Importance:</p><ol><li>&lt;h2&gt; to &lt;h6&gt; Tags: The chapters and sub-chapters. Use them in a logical hierarchy to break down your content. H2 sections support the H1, H3 sections support the H2, and so on.</li><li>&lt;p&gt; Tags: The body of your text. Write for humans first, but naturally include relevant keywords.</li><li>&lt;img&gt; Tags: Always use the alt attribute. alt=&quot;A person happily using a laptop in a cafe&quot; is far better than alt=&quot;IMG_3295.jpg&quot;. Alt text improves accessibility and provides context for image search.</li><li>&lt;div&gt; and &lt;span&gt; Tags: These are for layout and styling. They have no SEO weight on their own. Their job is to help you arrange the important elements (headings, paragraphs) in a user-friendly way. A common mistake is putting a headline inside a &lt;div&gt; with a class like &quot;title&quot; instead of using the proper &lt;h1&gt; tag.</li></ol><p>Example of Good Structure:</p><pre>&lt;body&gt;<br>  &lt;header&gt;...&lt;/header&gt;<br>  &lt;main&gt;<br>    &lt;article&gt;<br>      &lt;h1&gt;The Ultimate Guide to Baking Sourdough Bread&lt;/h1&gt; &lt;!-- Main Topic --&gt;<br>      &lt;p&gt;A brief introduction to the art of sourdough.&lt;/p&gt;&lt;h2&gt;What You&#39;ll Need&lt;/h2&gt; &lt;!-- Supporting Section --&gt;<br>      &lt;h3&gt;Ingredients&lt;/h3&gt;      &lt;!-- Sub-section --&gt;<br>      &lt;p&gt;Flour, water, salt, starter...&lt;/p&gt;<br>      &lt;h3&gt;Equipment&lt;/h3&gt;        &lt;!-- Sub-section --&gt;<br>      &lt;p&gt;A Dutch oven, scale, etc...&lt;/p&gt;&lt;h2&gt;The Step-by-Step Process&lt;/h2&gt; &lt;!-- Another Supporting Section --&gt;<br>      &lt;img src=&quot;kneading-dough.jpg&quot; alt=&quot;Hands kneading sourdough dough on a wooden countertop&quot;&gt;<br>      &lt;p&gt;Start by mixing your ingredients...&lt;/p&gt;<br>    &lt;/article&gt;<br>  &lt;/main&gt;<br>  &lt;footer&gt;...&lt;/footer&gt;<br>&lt;/body&gt;</pre><p><strong>Part 4: Beyond the Code — Other Critical SEO Scopes</strong></p><p>SEO doesn’t stop at the code. Here are other vital areas:</p><ul><li>Site Speed &amp; Core Web Vitals: Google prioritizes user experience. A slow site hurts rankings. Use tools like Google PageSpeed Insights and aim for good scores on Largest Contentful Paint (LCP), Interaction to Next Paint (INP), and Cumulative Layout Shift (CLS).</li><li>Mobile-First Design: Google predominantly uses the mobile version of your site for indexing and ranking. Your site must be fully responsive.</li><li>Internal Linking: Link to other relevant pages on your site. This helps with crawling (showing the librarian more books) and establishes information hierarchy (showing which pages are most important).</li><li>High-Quality Content: This is king. Create content that is original, valuable, and answers the user’s search intent better than any other page.</li><li>Backlinks (Off-Page SEO): These are links from other websites to yours. They are like votes of confidence. A few high-quality backlinks from reputable sites are worth more than thousands of spammy ones.</li></ul><h3>Conclusion: SEO is a Marathon, Not a Sprint</h3><p>SEO isn’t a one-time task. It’s an ongoing process of creating great content, ensuring your site is technically sound, and building a reputation.</p><p>Start with the basics covered here:</p><ol><li>Audit your &lt;head&gt; tags. Are your titles and descriptions unique and compelling?</li><li>Check your page structure. Are you using heading tags logically?</li><li>Optimize your images. Do they all have descriptive alt text?</li><li>Focus on speed and mobile experience.</li></ol><p>By making your website a well-organized, valuable resource, you’re not just optimizing for search engines — you’re creating a better experience for your most important audience: your users. And that, ultimately, is what SEO is all about.</p><p><em>Happy Optimizing!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ac5b724a3818" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>