<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sawastik Bhullar</title>
    <description>The latest articles on DEV Community by Sawastik Bhullar (@sawastik_bhullar).</description>
    <link>https://dev.to/sawastik_bhullar</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4029046%2F3f36bddc-7a45-4a38-b346-ea280f8ee847.jpg</url>
      <title>DEV Community: Sawastik Bhullar</title>
      <link>https://dev.to/sawastik_bhullar</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sawastik_bhullar"/>
    <language>en</language>
    <item>
      <title>How I Built a Distributed API Gateway with Rate Limiting, BullMQ Queues, and Real-Time Analytics — From Scratch</title>
      <dc:creator>Sawastik Bhullar</dc:creator>
      <pubDate>Tue, 14 Jul 2026 16:56:30 +0000</pubDate>
      <link>https://dev.to/sawastik_bhullar/how-i-built-a-distributed-api-gateway-with-rate-limiting-bullmq-queues-and-real-time-analytics--53dm</link>
      <guid>https://dev.to/sawastik_bhullar/how-i-built-a-distributed-api-gateway-with-rate-limiting-bullmq-queues-and-real-time-analytics--53dm</guid>
      <description>&lt;p&gt;I'm a CS undergrad and I wanted to build something that wasn't &lt;br&gt;
a tutorial clone. So I built a 7-phase distributed API gateway &lt;br&gt;
from scratch with Node.js — here's everything I learned.&lt;/p&gt;
&lt;h2&gt;
  
  
  What I Built
&lt;/h2&gt;

&lt;p&gt;A production-grade API gateway that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Routes requests to multiple upstream microservices&lt;/li&gt;
&lt;li&gt;Enforces per-client rate limiting using Redis token-bucket algorithm&lt;/li&gt;
&lt;li&gt;Logs analytics asynchronously via BullMQ worker queues&lt;/li&gt;
&lt;li&gt;Streams live traffic metrics to a React dashboard via Socket.io&lt;/li&gt;
&lt;li&gt;Secures all routes with JWT authentication&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;GitHub: &lt;/p&gt;
&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://github.com/sawastik7-bit" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Favatars.githubusercontent.com%2Fu%2F247727860%3Fv%3D4%3Fs%3D400" height="420" class="m-0" width="420"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://github.com/sawastik7-bit" rel="noopener noreferrer" class="c-link"&gt;
            sawastik7-bit (Sawastik Bhullar) · GitHub
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            sawastik7-bit has 28 repositories available. Follow their code on GitHub.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.githubassets.com%2Ffavicons%2Ffavicon.svg" width="32" height="32"&gt;
          github.com
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;


&lt;h2&gt;
  
  
  Phase Breakdown
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Phase 1 — Reverse Proxy&lt;/strong&gt;&lt;br&gt;
Used http-proxy-middleware to forward requests to upstream services.&lt;br&gt;
Hit a nasty bug: Express strips the mount path before passing &lt;br&gt;
to the proxy, so /api/users was reaching upstream as /users &lt;br&gt;
instead of /api/users. Fixed it with pathRewrite to prepend &lt;br&gt;
the path back.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 2 — JWT Auth Middleware&lt;/strong&gt;&lt;br&gt;
Standard but important. Every request hits the auth middleware &lt;br&gt;
before reaching the proxy. Invalid token = 401, no forwarding.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 3 — Redis Rate Limiting (Token Bucket)&lt;/strong&gt;&lt;br&gt;
Each client gets a bucket. Every request costs 1 token. &lt;br&gt;
Tokens refill at a fixed rate. If bucket is empty = 429.&lt;br&gt;
Why token bucket over fixed window? It handles burst traffic &lt;br&gt;
gracefully instead of hard-cutting requests at the window boundary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 4 — Async Analytics with BullMQ&lt;/strong&gt;&lt;br&gt;
This was the most interesting part. Logging every request &lt;br&gt;
synchronously would add latency to every single API call. &lt;br&gt;
Instead, I push a job to a BullMQ queue and return the response &lt;br&gt;
immediately. A separate worker picks up the job and writes to MongoDB.&lt;br&gt;
Result: 35% latency reduction on the critical path.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 5 — Socket.io Worker&lt;/strong&gt;&lt;br&gt;
The BullMQ worker doesn't just write to DB — it also emits &lt;br&gt;
events via Socket.io so the dashboard updates in real time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 6 — React Dashboard&lt;/strong&gt;&lt;br&gt;
Built with Vite + Recharts. Shows live request rate, &lt;br&gt;
rate-limit hits, latency percentiles. Updates sub-200ms.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Phase 7 — ES Modules Throughout&lt;/strong&gt;&lt;br&gt;
Kept the entire codebase on ESM. Painful to set up with &lt;br&gt;
some packages but worth it for consistency.&lt;/p&gt;
&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Never do sync I/O on the request path. Ever.&lt;/li&gt;
&lt;li&gt;Redis is not just a cache — it's a coordination primitive.&lt;/li&gt;
&lt;li&gt;BullMQ is criminally underrated for background jobs.&lt;/li&gt;
&lt;li&gt;pathRewrite in http-proxy-middleware will save your life.&lt;/li&gt;
&lt;li&gt;Socket.io namespaces are the right abstraction for 
multi-tenant real-time features.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Stack
&lt;/h2&gt;

&lt;p&gt;Node.js, Express, Redis (ioredis), BullMQ, Socket.io, &lt;br&gt;
JWT, React, Vite, Recharts, MongoDB, ES Modules&lt;/p&gt;
&lt;h2&gt;
  
  
  Repo
&lt;/h2&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://assets.dev.to/assets/github-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/sawastik7-bit" rel="noopener noreferrer"&gt;
        sawastik7-bit
      &lt;/a&gt; / &lt;a href="https://github.com/sawastik7-bit/distributed-api-gateway-analytics" rel="noopener noreferrer"&gt;
        distributed-api-gateway-analytics
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      A custom API Gateway built with Node.js featuring  reverse proxy, Redis rate limiting, JWT auth,  async logging with BullMQ, and a real-time  analytics dashboard using React and Socket.io
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Distributed API Gateway &amp;amp; Analytics Engine&lt;/h1&gt;
&lt;/div&gt;
&lt;p&gt;A production-grade API Gateway built with Node.js featuring reverse proxy, Redis rate limiting, JWT authentication, async logging with BullMQ, and a real-time analytics dashboard.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Architecture&lt;/h2&gt;
&lt;/div&gt;
&lt;div class="snippet-clipboard-content notranslate position-relative overflow-auto"&gt;&lt;pre class="notranslate"&gt;&lt;code&gt;Client Request
      ↓
API Gateway (Port 3000)
  → Rate Limiter (Redis)
  → JWT Auth
  → Reverse Proxy
      ↓
Microservices
  → Service A - Users (Port 4001)
  → Service B - Products (Port 4002)
      ↓
Logger → BullMQ Queue → Worker → MongoDB
                                    ↓
                          React Dashboard (Port 5173)
                          via Socket.io (Port 4003)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Features&lt;/h2&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Reverse proxy routing to microservices&lt;/li&gt;
&lt;li&gt;Redis rate limiting (10 requests/minute per IP)&lt;/li&gt;
&lt;li&gt;JWT authentication at gateway level&lt;/li&gt;
&lt;li&gt;Async request logging via BullMQ message queue&lt;/li&gt;
&lt;li&gt;Real time analytics dashboard with live charts&lt;/li&gt;
&lt;li&gt;Request metrics: total requests, requests per minute, average response time, error rate&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Tech Stack&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Backend:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Node.js, Express.js&lt;/li&gt;
&lt;li&gt;Redis (Memurai on Windows)&lt;/li&gt;
&lt;li&gt;BullMQ (message queue)&lt;/li&gt;
&lt;li&gt;MongoDB with Mongoose&lt;/li&gt;
&lt;li&gt;Socket.io&lt;/li&gt;
&lt;li&gt;JSON Web Tokens&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Frontend:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;React (Vite)&lt;/li&gt;
&lt;li&gt;Recharts&lt;/li&gt;
&lt;li&gt;Socket.io…&lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/sawastik7-bit/distributed-api-gateway-analytics" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;Would love feedback on the architecture — especially around &lt;br&gt;
the queue worker design and rate limiting strategy.&lt;/p&gt;

</description>
      <category>api</category>
      <category>node</category>
      <category>showdev</category>
      <category>systemdesign</category>
    </item>
  </channel>
</rss>
