<?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 Nnakwe Anslem on Medium]]></title>
        <description><![CDATA[Stories by Nnakwe Anslem on Medium]]></description>
        <link>https://medium.com/@javanslem?source=rss-52104c59ad9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*wqN26LKRseSwTGHk.jpg</url>
            <title>Stories by Nnakwe Anslem on Medium</title>
            <link>https://medium.com/@javanslem?source=rss-52104c59ad9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 18:43:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@javanslem/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[Stopping API Abuse: Building a High-Performance Rate Limiter with Redis & Fastify]]></title>
            <link>https://medium.com/@javanslem/stopping-api-abuse-building-a-high-performance-rate-limiter-with-redis-fastify-30b4b2ed9f92?source=rss-52104c59ad9------2</link>
            <guid isPermaLink="false">https://medium.com/p/30b4b2ed9f92</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[redis]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[backend-development]]></category>
            <dc:creator><![CDATA[Nnakwe Anslem]]></dc:creator>
            <pubDate>Sat, 21 Mar 2026 11:29:16 GMT</pubDate>
            <atom:updated>2026-03-28T11:24:19.278Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Stopping API Abuse: Building a High-Performance Rate Limiter with Redis &amp; Fastify</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-LSy8F2fN5zIFXEP_Y_ZAA.png" /><figcaption>Cover image generated with Gemini</figcaption></figure><p>Imagine it’s 2:00 AM on a Tuesday. Your monitoring system goes off — the main database is crawling, response times have spiked to over 5 seconds, and memory alerts are everywhere.</p><p>You groggily open the logs, expecting to find a bad deployment or a missing index. Instead, you see a single IP address hammering one of your public search endpoints with hundreds of requests per second. It isn’t a sophisticated attack — just a poorly written scraper tearing through your pagination like a bulldozer.</p><p>You quickly cobble together an NGINX rule to block the IP, but it gets you thinking. Rate limiting is universally acknowledged as a best practice, but surprisingly few developers build it out robustly until <em>*after*</em> they get burned. And even when they do, the configuration is usually buried in code, making it a nightmare to manage or dynamically adjust per client without deploying new code.</p><p>I decided I didn’t just want to use a generic middleware library. I wanted to build a standalone, lightning-fast Rate Limiter service from scratch. And more importantly, I wanted a way to visualize and control it easily.</p><p>So, I built precisely that using <strong>Node.js, Fastify, Redis, and PostgreSQL</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AOF-Rt_XNwJBRCX8nZYNcg.png" /><figcaption><em>The ‘Clients’ Dashboard View showing the registered clients and their limits</em></figcaption></figure><p><strong>The Technical Foundation</strong></p><p>To build a rate limiter that doesn’t become the bottleneck itself, you need absolute speed.</p><p>1. <strong>Fastify:</strong> I chose Fastify over Express. Fastify is built explicitly for high throughput and low latency, handling upwards of 30,000 requests per second out of the box. Every millisecond counts when you sit in front of the actual application servers.</p><p>2. <strong>PostgreSQL:</strong> Postgres serves as the persistent source of truth. It holds the client configurations: uniquely identifying clients, assigning them one of the available rate-limiting algorithms, and specifying their exact limits (e.g., 100 requests every 60,000 milliseconds).</p><p>3. <strong>Redis:</strong> Redis is the engine. Because rate limiting requires distributed, lightning-fast atomic operations (like increments, sets, and expirations), using an in-memory datastore is mandatory.</p><p><strong>Implementing the Algorithms</strong></p><p>I didn’t want a one-size-fits-all approach. Different endpoints require different throttling behaviors. I implemented three core algorithms:</p><p><strong>1. Fixed Window</strong></p><p>The simplest approach. We track requests in a discrete time bucket (e.g., 9:00:00 to 9:01:00). Redis handles this elegantly using atomic `INCR` commands coupled with `EXPIRE`. It’s highly efficient but suffers from the “burst effect” at the edges of the window.</p><p><strong>2. Sliding Window</strong></p><p>To fix the burst effect, I implemented a sliding window approach using Redis Sorted Sets (`<em>ZSET`</em>). Every request is added to a sorted set with a timestamp score. By using `<em>ZREMRANGEBYSCORE</em>` to cull timestamps older than the window limits, and `<em>ZCARD</em>` to count the remaining requests, we guarantee a perfectly rolling window.</p><p><strong>3. Token Bucket</strong></p><p>Perfect for APIs that need to handle smooth, constant traffic while allowing controlled bursts. Every client has a “bucket” of tokens that continuously refills at a set rate.</p><p><strong>Why I Built a Dashboard (and the Burst Tester)</strong></p><p>The biggest pain point with rate limiting is testing it. You usually end up writing bash loops with `curl` to see if your middleware blocks the 101st request.</p><p>I wanted the developer experience to be flawless. So, I built a dashboard served statically by the Fastify server.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OLtLtYQ7TcXLylagjNMYBA.png" /><figcaption><em>The ‘Register’ form showing the dynamic inputs based on the selected algorithm</em></figcaption></figure><p>From the dashboard, you can register new clients and instantly apply dynamic limits without touching the database directly.</p><p>But my favorite feature is the <strong>Burst Traffic Simulator</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Py7o2BWis2S5-HGMkIvKvA.png" /><figcaption><em>The ‘Burst Test’ tab showing the scrolling log of Allowed and Blocked requests</em></figcaption></figure><p>If you want to test how the Sliding Window algorithm behaves under stress, you open the Burst Tester. You tell the dashboard to send 50 requests with a 50ms delay.</p><p>You literally watch the live log scroll by. The first 20 requests flash green (`ALLOWED` — Remaining: 10, 9, 8…). Then, exactly at the limit boundary, the UI shifts to red (`BLOCKED` — Rate limit exceeded). It gives you immediate, visual validation that your algorithmic logic in Redis is executing perfectly under pressure.</p><p><strong>The Source Code</strong></p><p>I’ve open-sourced the entire project. It comes with a Docker Compose file so you can spin up the Postgres and Redis instances immediately, and the Fastify server is ready to go out of the box.</p><p>🔗 <a href="https://github.com/ansman58/rate-limiter"><strong>Check out the code on GitHub</strong></a></p><p>🔗 <a href="https://rate-limiter-phi.vercel.app/"><strong>Live Demo</strong></a></p><p>If backend architecture, Redis optimization, or building specialized microservices interests you, I’d love to hear your thoughts or answer any questions about the implementation!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30b4b2ed9f92" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let me share a quick back story with you: Last year, while working on a project that involved HTML…]]></title>
            <link>https://medium.com/@javanslem/let-me-share-a-quick-back-story-with-you-last-year-while-working-on-a-project-that-involved-html-eaa8e99eaaea?source=rss-52104c59ad9------2</link>
            <guid isPermaLink="false">https://medium.com/p/eaa8e99eaaea</guid>
            <dc:creator><![CDATA[Nnakwe Anslem]]></dc:creator>
            <pubDate>Fri, 07 Apr 2023 20:47:23 GMT</pubDate>
            <atom:updated>2023-04-07T20:47:23.616Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong>JAVASCRIPT WEB COMPONENTS. THE END OF JAVASCRIPT FRAMEWORKS?</strong></blockquote><p>Let me share a quick back story with you: Last year, while working on a project that involved HTML, CSS, and vanilla JS, I stumbled upon JavaScript web components. I needed to reuse the header and footer across different pages, without the repetitive and tedious copy-pasting. As we all know, we must always follow the DRY (Don’t Repeat Yourself) principle. I searched high and low, flipping through endless pages and exploring countless YouTube videos until finally, I found my breakthrough: JavaScript web components. And let me tell you, I’ve never looked back since.</p><p><strong><em>So what are JavaScript Web Components, you may ask:</em></strong></p><p>JavaScript Web Components are a set of APIs that allow developers to create and use custom, reusable HTML elements in web applications. This technology has been gaining popularity in recent years, leading some to question if it could signal the end of JavaScript frameworks. Today, we will explore what JavaScript Web Components are, their advantages and limitations, and their impact on the future of JavaScript frameworks.</p><p>There are four main APIs that make up Web Components:</p><p>A. <strong>Custom Elements</strong>: allow developers to create new HTML tags in a declarative manner, defining their own reusable custom elements. This API enables developers to encapsulate the behavior and styles of their custom elements, preventing global scope collisions.</p><p>B. <strong>Shadow DOM</strong>: provides a way to encapsulate the styles and HTML structure of the custom element, preventing the global scope style and class collisions. This API allows developers to define local styles for their custom elements, which are not visible outside of the element and don’t interfere with the rest of the page.</p><p>C. <strong>HTML Templates</strong>: this API allows developers to define templates that can be used to create instances of custom elements. Templates can contain HTML markup, including other custom elements, and can be defined either inline in an HTML file or in a separate file. Templates are used to create new instances of custom elements using the document.importNode() method.</p><p>D. <strong>HTML Imports</strong>: provides a way to include HTML, CSS, and JavaScript files as dependencies for custom elements, allowing developers to create reusable components that can be easily shared and reused across different web applications. HTML imports are included using the &lt;link&gt; element with a rel=”import” attribute.</p><p>And what is even more beautiful about web components is that it can be used with other JS frameworks.</p><p><strong><em>So, what are the advantages?</em></strong></p><p>There are several advantages to using JavaScript Web Components:</p><ol><li><strong>Reusability</strong>: Web Components can be used across different web applications, making it easier to maintain and update them.</li><li><strong>Encapsulation</strong>: Shadow DOM provides encapsulation for DOM and CSS, allowing components to be isolated from the rest of the page. This can prevent conflicts between different parts of the application.</li><li><strong>Flexibility</strong>: Web Components can be used with any JavaScript framework, or even without any framework at all. This can give developers more flexibility in choosing the tools they use.</li><li><strong>Standardization</strong>: Web Components are built on standards, making them more interoperable and future-proof. This can help ensure that components will work correctly across different browsers and platforms.</li></ol><p>Here’s an example code for creating a simple custom element:</p><pre>class MyElement extends HTMLElement {<br> constructor() {<br>  super();<br><br>  const shadow = this.attachShadow({ mode: &#39;open&#39; });<br><br>  const div = document.createElement(&#39;div&#39;);<br>  div.setAttribute(&#39;class&#39;, &#39;container&#39;);<br><br>  const h1 = document.createElement(&#39;h1&#39;);<br>  h1.textContent = &#39;Hello World!&#39;;<br>  div.appendChild(h1);<br><br>  shadow.appendChild(div);<br><br> }<br>}<br><br>customElements.define(&#39;my-element&#39;, MyElement);</pre><p>In this example, we create a new class called <strong>MyElement</strong> that extends <strong>HTMLElement</strong>. In the constructor, we attach a shadow root to the custom element and create a <strong>div</strong> element with a class of “container”. We then create an <strong>h1</strong> element with the text “Hello World!” and append it to the <strong>div</strong>. Finally, we append the <strong>div</strong> to the shadow root.</p><p><strong><em>Are there limitations?</em></strong></p><p>Yes, while JavaScript Web Components offer many advantages, there are also some limitations:</p><p><strong>Browser support</strong>: not all browsers support Web Components, which can limit their adoption. This means that developers may need to use polyfills or fallbacks to ensure that their components work correctly across different browsers.</p><p><strong>Complexity</strong>: creating Web Components can be more complex than using existing JavaScript frameworks. This may require more time and effort to learn and master, especially for developers who are new to web development.</p><p><strong>Lack of tooling</strong>: there is currently a lack of tooling and libraries for building and testing Web Components, which can make development more difficult.</p><p><strong><em>So will they replace JavaScript frameworks?</em></strong></p><p>While JavaScript Web Components offer many advantages, it is unlikely that they will completely replace JavaScript frameworks. Instead, they are more likely to be used in combination with frameworks, allowing developers to create reusable components.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=eaa8e99eaaea" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>