<?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: Ship Stack</title>
    <description>The latest articles on DEV Community by Ship Stack (@shipstackai).</description>
    <link>https://dev.to/shipstackai</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%2F4272826%2F6fd82ca2-0133-49b3-8059-70ecc435e2ac.png</url>
      <title>DEV Community: Ship Stack</title>
      <link>https://dev.to/shipstackai</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shipstackai"/>
    <language>en</language>
    <item>
      <title>I Built a Rate Limiter in 13 Lines of Node, Then Load-Tested It</title>
      <dc:creator>Ship Stack</dc:creator>
      <pubDate>Sun, 29 Nov 2026 19:16:30 +0000</pubDate>
      <link>https://dev.to/shipstackai/i-built-a-rate-limiter-in-13-lines-of-node-then-load-tested-it-5cg6</link>
      <guid>https://dev.to/shipstackai/i-built-a-rate-limiter-in-13-lines-of-node-then-load-tested-it-5cg6</guid>
      <description>&lt;p&gt;I built a rate limiter in plain Node with zero packages, then load-tested it until it failed. Token bucket, 13 lines, no timers. Here is the code, the four tests, and the exact numbers.&lt;/p&gt;

&lt;h2&gt;
  
  
  The limiter
&lt;/h2&gt;

&lt;p&gt;A token bucket per client. Each client gets a bucket of 10 tokens, every request costs one token, and the bucket refills at 5 tokens per second. A client can burst, but it cannot keep going forever.&lt;/p&gt;

&lt;p&gt;The whole limiter is a function that takes a capacity and a refill rate, keeps a &lt;code&gt;Map&lt;/code&gt; of buckets keyed by client, refills based on elapsed time, and returns true or false. 13 lines, no timers, no dependencies.&lt;/p&gt;

&lt;p&gt;The server is tiny on purpose: it reads a client name from a header, asks the limiter, and returns &lt;strong&gt;429 with a Retry-After header&lt;/strong&gt; when the answer is no. Otherwise it says okay.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tests
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Test 1: the burst.&lt;/strong&gt; A client called Alice sends 100 requests at once.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;10 got a 200&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;90 got a 429&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Exactly the bucket size. Nothing else leaked through.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test 2: client isolation.&lt;/strong&gt; Right after Alice's burst, a different client, Bob, sends one request.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Bob gets a &lt;strong&gt;200&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One noisy client did not block the others, because each client has its own bucket.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test 3: the refill.&lt;/strong&gt; Wait one second, then Alice sends 10 more.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;5 got a 200&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;5 got a 429&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That matches the refill rate of 5 tokens per second. After one second, exactly 5 tokens had come back.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Test 4: under the limit.&lt;/strong&gt; Carol sends 20 requests at 4 per second.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All &lt;strong&gt;20 got a 200&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Under the refill rate, the limiter is invisible.&lt;/p&gt;

&lt;h2&gt;
  
  
  The limits
&lt;/h2&gt;

&lt;p&gt;This lives in memory, so it only works on one server. Behind a load balancer with multiple instances, each server gets its own copy of the buckets and the real limit becomes n times what you configured. For many servers you need shared storage, usually Redis.&lt;/p&gt;

&lt;p&gt;Also, this was a short run on my own machine, which is the honest scope of the result: the logic is verified, the performance at real production scale is not.&lt;/p&gt;

&lt;p&gt;The full build, the code, and all four test runs are in the video:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/9fCCbBhJc6M" rel="noopener noreferrer"&gt;https://youtu.be/9fCCbBhJc6M&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
    <item>
      <title>I Load-Tested My Node.js Cache and Watched Memory Grow to 200 MB</title>
      <dc:creator>Ship Stack</dc:creator>
      <pubDate>Sun, 29 Nov 2026 18:46:55 +0000</pubDate>
      <link>https://dev.to/shipstackai/i-load-tested-my-nodejs-cache-and-watched-memory-grow-to-200-mb-40d8</link>
      <guid>https://dev.to/shipstackai/i-load-tested-my-nodejs-cache-and-watched-memory-grow-to-200-mb-40d8</guid>
      <description>&lt;p&gt;I let our Node service cache HTTP responses in a Map with no size limit. Then I load-tested it and watched the RSS grow from 3.4 MB to 200.1 MB. Here is what happened and the fix that kept memory flat at 13.6 MB.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test setup
&lt;/h2&gt;

&lt;p&gt;The service was a small Node.js server with an in-memory response cache: a plain &lt;code&gt;Map&lt;/code&gt; keyed by request URL. Every request that came in got its response stored so repeat requests could skip the work. Simple, and completely unbounded.&lt;/p&gt;

&lt;p&gt;I hammered it with autocannon: 4,000 requests, each with a unique URL, so every single response got added to the cache and nothing was ever evicted.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the memory did
&lt;/h2&gt;

&lt;p&gt;The result was a textbook leak shape:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Start: &lt;strong&gt;3.4 MB&lt;/strong&gt; RSS&lt;/li&gt;
&lt;li&gt;After 4,000 requests: &lt;strong&gt;200.1 MB&lt;/strong&gt; RSS&lt;/li&gt;
&lt;li&gt;No plateau. Memory grew linearly with request count, because the Map never let anything go.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Every unique key was a permanent allocation. The garbage collector could not touch any of it because the Map was still reachable and still growing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fix
&lt;/h2&gt;

&lt;p&gt;Two changes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Bounded cache&lt;/strong&gt;: a size cap on the cache. Once it hits the limit, the oldest entries get evicted.&lt;/li&gt;
&lt;li&gt;Same 4,000-request autocannon run against the fixed version.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Result: RSS stayed &lt;strong&gt;flat at 13.6 MB&lt;/strong&gt; through the entire run. Same traffic, same throughput, no growth.&lt;/p&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;An unbounded in-memory cache is a memory leak with extra steps. It works fine in dev, passes tests, and then eats your server in production the first time real traffic shows up. If you cache in memory:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Set a hard size limit and an eviction policy (LRU is usually the default you want)&lt;/li&gt;
&lt;li&gt;Add a TTL if the data goes stale&lt;/li&gt;
&lt;li&gt;Load-test it with unique keys before you ship, not after your pod gets OOMKilled&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full experiment, with the code and the live test runs, is in the video:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://youtu.be/n520Ht4eQn8" rel="noopener noreferrer"&gt;https://youtu.be/n520Ht4eQn8&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
