<?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"><channel><title><![CDATA[Ship Stack]]></title><description><![CDATA[Ship Stack]]></description><link>https://shipstackai.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 22:39:43 GMT</lastBuildDate><atom:link href="https://shipstackai.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How Big Is a String in Bytes in Node?]]></title><description><![CDATA[A string's length and its size in bytes are not the same number, and confusing them breaks anything that counts bytes: upload limits, Content-Length…]]></description><link>https://shipstackai.hashnode.dev/how-big-is-a-string-in-bytes-in-node</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/how-big-is-a-string-in-bytes-in-node</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Fri, 04 Dec 2026 06:37:27 GMT</pubDate><content:encoded><![CDATA[<p>A string's length and its size in bytes are not the same number, and confusing them breaks anything that counts bytes: upload limits, Content-Length headers, payload budgets. I measured both with a real run in Node.js 22. Full run in this Short: <a href="https://youtu.be/Kc37nb6lQqE">https://youtu.be/Kc37nb6lQqE</a></p>
<h2>The test</h2>
<p>Two strings of a million characters each. The first is a million plain "a" letters. The second is a million accented "e" characters. Both report length 1,000,000.</p>
<h2>The numbers</h2>
<p>Put them in a Buffer and the sizes split. The plain "a" string: 1,000,000 bytes, one byte per character, exactly what length suggests. The accented "e" string: 2,000,000 bytes, two bytes per character. Same length, double the size.</p>
<p>The reason is encoding. Node counts UTF-16 code units for length, but a Buffer holds UTF-8. Plain ASCII characters take one byte in UTF-8; accented characters take two; emoji take more. Length never tells you which case you are in.</p>
<h2>The rule</h2>
<p>Never use string length where bytes are meant. If a limit is in bytes - and wire formats, storage quotas and HTTP headers all are - measure the bytes, for example with Buffer.byteLength. Not tested here: emoji and other 4-byte characters, other encodings, and very large strings, each of which widens the gap.</p>
<h2>Watch the run</h2>
<p>The real terminal output is in the Short: <a href="https://youtu.be/Kc37nb6lQqE">https://youtu.be/Kc37nb6lQqE</a> (narration is AI-generated; the output is from a real run in Node.js 22).</p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[Array Includes or Set Has: Which Is Faster?]]></title><description><![CDATA[Array.includes is the tool everyone reaches for. Set.has sits one refactor away and is almost never used. I benchmarked both with a real run in Node.js 22…]]></description><link>https://shipstackai.hashnode.dev/array-includes-or-set-has-which-is-faster</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/array-includes-or-set-has-which-is-faster</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Fri, 04 Dec 2026 03:38:13 GMT</pubDate><content:encoded><![CDATA[<p>Array.includes is the tool everyone reaches for. Set.has sits one refactor away and is almost never used. I benchmarked both with a real run in Node.js 22, and the gap is not subtle. Full run in this Short: <a href="https://youtu.be/r2CVLAdLe5U">https://youtu.be/r2CVLAdLe5U</a></p>
<h2>The test</h2>
<p>A list of 100,000 items, and 1,000 lookups for values near the end of it. That is the worst case for includes: every lookup scans almost the whole list before finding its target. Set.has answers the same questions through a hash table.</p>
<h2>The numbers</h2>
<p>Array.includes: 83.46 ms. Set.has: 0.03 ms. Same 1,000 lookups, same data, same machine. That is a difference you can feel in a request handler, not a micro-optimization footnote.</p>
<p>The reason is the data structure, not cleverness. includes walks the array element by element, so 1,000 lookups each scanning ~100,000 items means ~100 million comparisons. Set.has hashes the target and jumps straight to it, so each lookup costs roughly the same no matter how big the set is.</p>
<h2>The rule</h2>
<p>If you build the list once and look things up many times, use a Set. Keep the array for order and iteration; build the Set for membership checks. For a handful of lookups against a small list, includes is fine and simpler. Not tested here: the cost of building the Set itself, other list sizes, or lookups for values near the front, where includes wins by doing almost nothing.</p>
<h2>Watch the run</h2>
<p>The real terminal output is in the Short: <a href="https://youtu.be/r2CVLAdLe5U">https://youtu.be/r2CVLAdLe5U</a> (narration is AI-generated; the output is from a real run in Node.js 22).</p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[Retry Logic: 10 of 30 Calls OK, Then 30 of 30]]></title><description><![CDATA[Retries look like a free win: if a request fails, try again. I tested what they actually cost with a real Node.js run, and the bill is bigger than it…]]></description><link>https://shipstackai.hashnode.dev/retry-logic-10-of-30-calls-ok-then-30-of-30</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/retry-logic-10-of-30-calls-ok-then-30-of-30</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Thu, 03 Dec 2026 21:37:30 GMT</pubDate><content:encoded><![CDATA[<p>Retries look like a free win: if a request fails, try again. I tested what they actually cost with a real Node.js run, and the bill is bigger than it looks. Full run in this Short: <a href="https://youtu.be/Ck7Pm2pR_aY">https://youtu.be/Ck7Pm2pR_aY</a></p>
<h2>The setup</h2>
<p>A server that fails 2 of every 3 requests, and a client making 30 calls. First with plain fetch, no retries.</p>
<h2>Without retries</h2>
<p>30 plain fetch calls came back 10 ok, 20 failed. That matches the server's failure rate: with no retry logic, you inherit it. Two thirds of the calls simply fail.</p>
<h2>With 3 tries</h2>
<p>With up to 3 attempts per call, all 30 calls eventually succeeded: 30 of 30 ok. But the server saw 90 hits instead of 30, and the whole run took 4.6 seconds. Every retried call is another request the server has to absorb, and the wait between tries is time your caller spends blocked.</p>
<h2>The rule</h2>
<p>Retries trade reliability for load and latency. They fix the caller's view of the world while making the server's worse. If the server is failing because it is overloaded, blind retries push it further over. Use them with a cap, a delay, and a clear idea of which failures are worth retrying. Not tested here: backoff strategies, timeouts, and retrying against a recovering server, all of which change the numbers.</p>
<h2>Watch the run</h2>
<p>The real terminal output is in the Short: <a href="https://youtu.be/Ck7Pm2pR_aY">https://youtu.be/Ck7Pm2pR_aY</a> (narration is AI-generated; the test output is from a real run). The full video is here: <a href="https://youtu.be/vgoOmh39738">https://youtu.be/vgoOmh39738</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[1 of 5 Tests Passed: Splitting CSV on Commas]]></title><description><![CDATA[Splitting a CSV on newline and comma feels obvious. I built exactly that parser, then ran 5 test cases against it. Only 1 passed. Full run in this Short:]]></description><link>https://shipstackai.hashnode.dev/1-of-5-tests-passed-splitting-csv-on-commas</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/1-of-5-tests-passed-splitting-csv-on-commas</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Thu, 03 Dec 2026 03:35:06 GMT</pubDate><content:encoded><![CDATA[<p>Splitting a CSV on newline and comma feels obvious. I built exactly that parser, then ran 5 test cases against it. Only 1 passed. Full run in this Short: <a href="https://youtu.be/Mp89iYCmfGU">https://youtu.be/Mp89iYCmfGU</a></p>
<h2>What the naive split got wrong</h2>
<p>The split-on-comma parser handles the happy path: plain fields, no quotes, Unix line endings. Real CSV files are not like that. Four of the five test cases broke it:</p>
<ul>
<li>Quoted commas: a comma inside a quoted field is data, not a separator. The naive split cut the field in half.</li>
<li>Escaped quotes: a double quote inside a quoted field is written as two quotes. The naive split treated it as the end of the field.</li>
<li>Newlines inside a field: a quoted field can span lines. Splitting on newline shredded the record.</li>
<li>Windows line endings: CRLF left a stray carriage return glued to the last field of every row.</li>
</ul>
<h2>What passed instead</h2>
<p>A small state machine parser walked the input character by character, tracking whether it was inside quotes. It passed 8 of 8 tests, covering the four cases above plus the combinations of them. The rules of CSV are simple, but they are rules about state, not about splitting.</p>
<h2>The rule</h2>
<p>Never parse CSV with split. The format looks flat and is not. Not tested here: huge files and other encodings, both of which bring their own problems. Use a maintained CSV library.</p>
<h2>Watch the run</h2>
<p>The real terminal output is in the Short: <a href="https://youtu.be/Mp89iYCmfGU">https://youtu.be/Mp89iYCmfGU</a> (narration is AI-generated; the test output is from a real run). The full build, a 17-line parser, is here: <a href="https://youtu.be/zdCNzOnxUv4">https://youtu.be/zdCNzOnxUv4</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[Myth: If a JWT Decodes, It Is Safe]]></title><description><![CDATA[A JWT is three base64 parts, and decoding it is trivial. That convenience creates a dangerous shortcut: if the token decodes, treat it as valid. I tested…]]></description><link>https://shipstackai.hashnode.dev/myth-if-a-jwt-decodes-it-is-safe</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/myth-if-a-jwt-decodes-it-is-safe</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Thu, 03 Dec 2026 00:34:44 GMT</pubDate><content:encoded><![CDATA[<p>A JWT is three base64 parts, and decoding it is trivial. That convenience creates a dangerous shortcut: if the token decodes, treat it as valid. I tested that belief with a real run, and it failed twice. Full run in this Short: <a href="https://youtu.be/1aLXVqGiOZk">https://youtu.be/1aLXVqGiOZk</a></p>
<h2>What decode-only accepted</h2>
<p>I built a decode-only check in Node and fed it 6 tokens. It accepted an expired token and a token signed with the wrong key. Decoding only reads the payload; it never asks who signed it or whether it is still valid. To a decode-only check, both of those tokens look perfectly fine.</p>
<h2>What verify does instead</h2>
<p>Verification is ordered. First the signature: recompute it from the header and payload with your key and compare. A token signed with the wrong key fails here and nothing else about it matters. Then the time claims: exp (not after) and nbf (not before), checked against your clock. The expired token fails here. Only after both pass is the payload yours to trust.</p>
<p>The test used HS256 with Node's crypto module, a fixed demo clock, and 6 tokens. Verify rejected exactly the tokens decode accepted.</p>
<h2>The rule</h2>
<p>Decode is for reading; verify is for trusting. Never branch on a payload you have not verified. Not tested here: RS256, key rotation, clock skew, and revocation, all of which matter in production. Use a maintained JWT library.</p>
<h2>Watch the run</h2>
<p>The real terminal output is in the Short: <a href="https://youtu.be/1aLXVqGiOZk">https://youtu.be/1aLXVqGiOZk</a> (narration is AI-generated; the test output is from a real run). The full build, a 17-line demo file, is here: <a href="https://youtu.be/OGD-QY_qzy0">https://youtu.be/OGD-QY_qzy0</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[SQLite: 5,000 Inserts in 6 ms Instead of 1.2 s]]></title><description><![CDATA[I ran the same 5,000 SQLite inserts two ways in Node.js and the difference was not small. Full run in this Short: Inserting 5,000 rows one by one took…]]></description><link>https://shipstackai.hashnode.dev/sqlite-5-000-inserts-in-6-ms-instead-of-1-2-s</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/sqlite-5-000-inserts-in-6-ms-instead-of-1-2-s</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Wed, 02 Dec 2026 21:35:35 GMT</pubDate><content:encoded><![CDATA[<p>I ran the same 5,000 SQLite inserts two ways in Node.js and the difference was not small. Full run in this Short: <a href="https://youtu.be/-xqnLIvmZTQ">https://youtu.be/-xqnLIvmZTQ</a></p>
<h2>The numbers</h2>
<p>Inserting 5,000 rows one by one took 1,263 ms. Wrapping the same inserts in a single transaction took 6 ms. That is about 200x faster, from adding two words: BEGIN and COMMIT.</p>
<h2>Why a transaction is so much faster</h2>
<p>By default, SQLite treats every single insert as its own transaction, and every transaction ends with a commit that forces data to disk. So 5,000 inserts one by one means 5,000 separate commits, and the disk flush dominates everything else.</p>
<p>Wrap the batch in BEGIN and COMMIT and you get one commit for all 5,000 rows. The inserts themselves barely change; the 5,000 disk flushes become one. The work that survives is the work that was always fast.</p>
<h2>The rule of thumb</h2>
<p>Any time you insert, update, or delete more than a handful of rows, wrap the batch in a transaction. It costs two lines and it is often the single biggest SQLite speedup available. Inside the transaction, prepare the statement once and bind parameters per row, so SQLite skips re-parsing the SQL too.</p>
<h2>Watch the run</h2>
<p>The real benchmark output is in the Short: <a href="https://youtu.be/-xqnLIvmZTQ">https://youtu.be/-xqnLIvmZTQ</a> (narration is AI-generated; the test output is from a real run). The full build is here: <a href="https://youtu.be/vOOsCOFnxqU">https://youtu.be/vOOsCOFnxqU</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[Same File Size Does Not Mean Duplicate]]></title><description><![CDATA[Two files, same name, same size. Must be duplicates, right? I tested that assumption with a real Node.js run, and it failed. Full run in this Short:]]></description><link>https://shipstackai.hashnode.dev/same-file-size-does-not-mean-duplicate</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/same-file-size-does-not-mean-duplicate</guid><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Wed, 02 Dec 2026 03:34:09 GMT</pubDate><content:encoded><![CDATA[<p>Two files, same name, same size. Must be duplicates, right? I tested that assumption with a real Node.js run, and it failed. Full run in this Short: <a href="https://youtu.be/nrhOO58008Y">https://youtu.be/nrhOO58008Y</a></p>
<h2>The test</h2>
<p>I made two notes files with the same name and the same size: 1,920 bytes each. If size were a reliable duplicate check, these two would be the same file.</p>
<p>Then I hashed both with SHA-256 in Node.js. The hashes were different. Different hashes mean different content, so the files are not duplicates, even though the name and size match exactly.</p>
<h2>Why size is not enough</h2>
<p>Size is a count, not a fingerprint. Two files reach the same byte count in endless ways: swap two paragraphs, change a word for a longer one and trim elsewhere, or just have unrelated content that happens to add up the same. A hash reads every byte, so any change, anywhere, changes the result.</p>
<p>That is why real duplicate finders use size only as a first pass. Group files by size to skip the obvious non-duplicates cheaply, then hash only the groups that collide. Checking size first is fast; trusting size alone is wrong.</p>
<h2>Watch the run</h2>
<p>The real terminal output is in the Short: <a href="https://youtu.be/nrhOO58008Y">https://youtu.be/nrhOO58008Y</a> (narration is AI-generated; the test output is from a real run). The full duplicate-finder build is here: <a href="https://youtu.be/SFwkTAPenzw">https://youtu.be/SFwkTAPenzw</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[How Do You Put a Quote Inside a CSV Field?]]></title><description><![CDATA[A CSV field is wrapped in quotes to protect it. So what happens when the field itself contains a quote? I tested it with a real run, and the answer is one…]]></description><link>https://shipstackai.hashnode.dev/how-do-you-put-a-quote-inside-a-csv-field</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/how-do-you-put-a-quote-inside-a-csv-field</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Wed, 02 Dec 2026 00:29:46 GMT</pubDate><content:encoded><![CDATA[<p>A CSV field is wrapped in quotes to protect it. So what happens when the field itself contains a quote? I tested it with a real run, and the answer is one rule: write two quotes in a row. Full run in this Short: <a href="https://youtu.be/J_7vSa_Ir48">https://youtu.be/J_7vSa_Ir48</a></p>
<h2>Two quotes in a row mean one</h2>
<p>Inside a quoted field, a doubled quote is an escaped quote. This:</p>
<pre><code class="language-plaintext">"He said ""hi"""
</code></pre>
<p>is one field whose value is <code>He said "hi"</code>. The parser reads the two quotes as a single literal quote and keeps going.</p>
<h2>The unterminated quote is an error</h2>
<p>A quoted field that never closes is malformed, and the parser should say so. Mine throws an error on an unterminated quote instead of guessing where the field ends. Silently guessing is how bad data slips through.</p>
<p>Both behaviors come from the same small state machine as the comma-in-quotes case: track whether you are inside quotes, and treat a doubled quote as an escape.</p>
<h2>What I tested, and what I did not</h2>
<p>Tested with 8 real test cases, covering doubled quotes and unterminated quotes. Not tested: huge files and encodings other than UTF-8. For production, use a maintained library.</p>
<h2>Watch the run</h2>
<p>The real terminal output is in the Short: <a href="https://youtu.be/J_7vSa_Ir48">https://youtu.be/J_7vSa_Ir48</a> (narration is AI-generated; the test output is from a real run). The full build, a 17-line parser, is here: <a href="https://youtu.be/zdCNzOnxUv4">https://youtu.be/zdCNzOnxUv4</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[Myth: CSV Is Just Comma-Separated Values]]></title><description><![CDATA[The name says it: comma-separated values. So the parser is one line: split on commas. I tested that belief with a real run, and a single quoted field broke…]]></description><link>https://shipstackai.hashnode.dev/myth-csv-is-just-comma-separated-values</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/myth-csv-is-just-comma-separated-values</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[node]]></category><category><![CDATA[webdev]]></category><category><![CDATA[AI]]></category><category><![CDATA[AI]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Tue, 01 Dec 2026 21:36:07 GMT</pubDate><content:encoded><![CDATA[<p>The name says it: comma-separated values. So the parser is one line: split on commas. I tested that belief with a real run, and a single quoted field broke it. Full run in this Short: <a href="https://youtu.be/s4W4DtdlBCs">https://youtu.be/s4W4DtdlBCs</a></p>
<h2>The field that breaks the split</h2>
<p>Take a name field like this:</p>
<pre><code class="language-plaintext">"Smith, Jo"
</code></pre>
<p>That is one field containing a comma, wrapped in quotes to protect it. A naive <code>line.split(',')</code> has no notion of quotes, so it returns two fields: <code>"Smith</code> and <code>Jo"</code>. Every column after it shifts, and the row is silently corrupt.</p>
<h2>The one-flag fix</h2>
<p>The fix is a single piece of state: a flag that says whether you are inside quotes. While the flag is on, a comma is plain text, not a delimiter. Walk the field character by character, flip the flag on each unescaped quote, and only treat commas as separators when the flag is off.</p>
<p>That one flag is the entire difference between "CSV is trivial" and a parser that survives real files. It is also why every serious CSV library is a state machine under the hood.</p>
<h2>What I did not test</h2>
<p>Huge files and encodings other than UTF-8 are still open. For production, use a maintained library. But the myth itself costs nothing to check, and one quoted name is enough to break it.</p>
<h2>Watch the run</h2>
<p>The real terminal output is in the Short: <a href="https://youtu.be/s4W4DtdlBCs">https://youtu.be/s4W4DtdlBCs</a> (narration is AI-generated; the test output is from a real run).</p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[Debounce vs Throttle: An AI Agent Wrote Both, and One Ran 5 Times While One Ran Once]]></title><description><![CDATA[Debounce and throttle get treated as interchangeable synonyms for "slow this function down." They are not. I asked an AI agent to write both in Node.js and…]]></description><link>https://shipstackai.hashnode.dev/debounce-vs-throttle-an-ai-agent-wrote-both-and-one-ran-5-times-while-one-ran-once</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/debounce-vs-throttle-an-ai-agent-wrote-both-and-one-ran-5-times-while-one-ran-once</guid><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Tue, 01 Dec 2026 09:28:10 GMT</pubDate><content:encoded><![CDATA[<p>Debounce and throttle get treated as interchangeable synonyms for "slow this function down." They are not. I asked an AI agent to write both in Node.js and I ran them for real on a simulated clock. The full run is on video: <a href="https://youtu.be/GmsIIMlFATU">https://youtu.be/GmsIIMlFATU</a></p>
<h2>The test</h2>
<p>50 events arrive 20 ms apart, from t = 0 to t = 980 ms. The wait period is 200 ms. Think of it as a search box being typed into, or a scroll handler firing continuously for about a second.</p>
<h2>Throttle: 5 calls</h2>
<p>Throttle limits how often the function can run: at most once per 200 ms window. The calls landed at 0, 200, 400, 600 and 800 ms: 5 calls, evenly spaced, for the whole burst. The function keeps running at a steady drip while events keep coming.</p>
<h2>Debounce: 1 call</h2>
<p>Debounce waits for the events to stop. Every new event resets its 200 ms timer, so as long as events keep arriving 20 ms apart, the function never fires. It ran exactly once, at 1180 ms: 200 ms after the last event.</p>
<p>Same 50 events, same 200 ms wait: 5 calls versus 1. The rule of thumb from this test: debounce waits for events to stop, throttle limits how often they run. A resize handler that recalculates layout mid-drag wants throttle. A search box that should only query when you pause typing wants debounce.</p>
<h2>What I did not test</h2>
<p>Leading and trailing edge options, real timers, and real browser events are all still open. The clock is simulated, not wall time. In production, reach for a battle-tested utility. But if you have ever reached for one and meant the other, this run shows the difference in the starkest terms.</p>
<h2>Watch the run</h2>
<p>The code, the terminal output, and every call timestamp are in the video: <a href="https://youtu.be/GmsIIMlFATU">https://youtu.be/GmsIIMlFATU</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[Fixed Window vs Token Bucket: I Let an AI Agent Build Both and Broke One With 20 Requests]]></title><description><![CDATA[A rate limit of 10 requests per second sounds like it means 10 requests per second. I asked an AI agent to write two rate limiters in Node.js, a fixed…]]></description><link>https://shipstackai.hashnode.dev/fixed-window-vs-token-bucket-i-let-an-ai-agent-build-both-and-broke-one-with-20-requests</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/fixed-window-vs-token-bucket-i-let-an-ai-agent-build-both-and-broke-one-with-20-requests</guid><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Tue, 01 Dec 2026 03:29:17 GMT</pubDate><content:encoded><![CDATA[<p>A rate limit of 10 requests per second sounds like it means 10 requests per second. I asked an AI agent to write two rate limiters in Node.js, a fixed window counter and a token bucket, and I ran a boundary attack against both for real. The full run is on video: <a href="https://youtu.be/qP5apGGTbb0">https://youtu.be/qP5apGGTbb0</a></p>
<h2>The attack</h2>
<p>The test is simple. On a simulated clock, send 10 requests just before a second boundary, then 10 more just after it. Twenty requests, landing within 95 milliseconds of each other, against a limiter that should allow 10 per second.</p>
<h2>Fixed window: 20 of 20 allowed</h2>
<p>The fixed window limiter counts requests inside the current one-second window and resets the counter when the window rolls over. That reset is the whole problem: my 10 requests at the end of window one and 10 at the start of window two are legal in both windows, so the limiter allowed 20 of 20 within 95 ms. Twice the intended rate, right through the middle of the limit.</p>
<p>This is not a bug in the implementation. It is what fixed window means. The algorithm is honest about a per-window count and blind to anything that straddles the edge.</p>
<h2>Token bucket: 10 of 20 allowed</h2>
<p>The token bucket works differently: a bucket holds up to 10 tokens and refills at 10 tokens per second; each request spends one token, and an empty bucket means rejection. The first 10 requests drain the bucket. The boundary does not reset anything, because there is no window, only a balance. Refill over 95 ms adds less than one token, so the second burst gets rejected: 10 of 20 allowed, exactly the intended rate.</p>
<p>Same limit, same traffic, opposite outcomes. The difference is that the bucket remembers how recently you were allowed, while the window forgets everything at the boundary.</p>
<h2>What I did not test</h2>
<p>Multiple servers, shared storage like Redis, real network delay, and the sliding window log algorithm are all still open. The test clock is simulated, not wall time. For production, use a maintained limiter. But if your mental model of a rate limit is "10 per second means 10 per second," the fixed window boundary case is worth watching fail.</p>
<h2>Watch the run</h2>
<p>The code, the terminal output, and every allow/reject are in the video: <a href="https://youtu.be/qP5apGGTbb0">https://youtu.be/qP5apGGTbb0</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[An AI Agent Wrote JWT Checks in Node. Decode-Only Accepted All 6 Fake Tokens]]></title><description><![CDATA[I asked an AI agent to write JWT expiry checks in Node.js and I ran them for real: HS256 tokens, Node's built-in crypto, a fixed demo clock. The full run…]]></description><link>https://shipstackai.hashnode.dev/an-ai-agent-wrote-jwt-checks-in-node-decode-only-accepted-all-6-fake-tokens</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/an-ai-agent-wrote-jwt-checks-in-node-decode-only-accepted-all-6-fake-tokens</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Artificial Intelligence]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Tue, 01 Dec 2026 00:32:13 GMT</pubDate><content:encoded><![CDATA[<p>I asked an AI agent to write JWT expiry checks in Node.js and I ran them for real: HS256 tokens, Node's built-in crypto, a fixed demo clock. The full run is on video: <a href="https://youtu.be/OGD-QY_qzy0">https://youtu.be/OGD-QY_qzy0</a></p>
<h2>The decode-only version</h2>
<p>The tempting shortcut is to decode the payload and trust what it says:</p>
<pre><code class="language-js">const payload = JSON.parse(Buffer.from(token.split('.')[1], 'base64url').toString());
if (payload.exp &lt; now) throw new Error('expired');
</code></pre>
<p>This reads the claims without ever checking the signature. I built 6 fake tokens to probe it: an expired token, a not-yet-valid token, a token signed with the wrong key, and a token whose payload I tampered with to claim admin.</p>
<p>The decode-only check accepted all 6 of 6.</p>
<p>That includes the expired one, but far worse: the wrong-key token and the tampered admin token also sailed through, because nothing ever proved the payload came from someone holding the key. <code>exp</code> is data, and unauthenticated data is whatever the attacker wants it to be.</p>
<h2>The verify version</h2>
<p>The agent then produced a verify function (the whole demo file is 17 lines). The order matters:</p>
<ol>
<li>Verify the signature first, with a constant-time comparison.</li>
<li>Only then trust the claims: check expiry and not-before.</li>
</ol>
<p>I ran the same 6 fake tokens against it. It rejected 5 of 6, each with the correct reason. The sixth case is the interesting one: a token that expires exactly now. The verify function counts it as expired, which is the correct reading of the spec (<code>exp</code> is the time at or after which the token must not be accepted).</p>
<h2>What I did not test</h2>
<p>RS256 and other algorithms, key rotation, clock skew leeway, and token revocation are all still open. In production, use a maintained library like <code>jsonwebtoken</code> or <code>jose</code> rather than hand-rolled crypto. But the lesson of the run stands: signature first, claims second, and never trust a decoded payload you have not verified.</p>
<h2>Watch the run</h2>
<p>The code, the terminal output, and every accept/reject are in the video: <a href="https://youtu.be/OGD-QY_qzy0">https://youtu.be/OGD-QY_qzy0</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[An AI Agent Wrote a CSV Parser in Node. I Tested It With Real Inputs]]></title><description><![CDATA[I asked an AI agent to write a CSV parser in Node.js and then I tested it for real, first the version everyone writes by instinct, then the version that…]]></description><link>https://shipstackai.hashnode.dev/an-ai-agent-wrote-a-csv-parser-in-node-i-tested-it-with-real-inputs</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/an-ai-agent-wrote-a-csv-parser-in-node-i-tested-it-with-real-inputs</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Artificial Intelligence]]></category><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Mon, 30 Nov 2026 21:30:54 GMT</pubDate><content:encoded><![CDATA[<p>I asked an AI agent to write a CSV parser in Node.js and then I tested it for real, first the version everyone writes by instinct, then the version that actually survives. Everything below was run on my machine. The full run is on video: <a href="https://youtu.be/zdCNzOnxUv4">https://youtu.be/zdCNzOnxUv4</a></p>
<h2>The naive version</h2>
<p>Every one of us has written this:</p>
<pre><code class="language-js">const rows = text.split('\n').map(line =&gt; line.split(','));
</code></pre>
<p>Split on newline, split on comma, done. I ran it against 5 test cases drawn from real CSV files: quoted fields containing commas, escaped quotes inside a field, a newline inside a quoted field, and Windows line endings (CRLF).</p>
<p>It passed 1 of 5.</p>
<p>Quoted commas break the split because the comma inside quotes is not a delimiter. Escaped quotes (<code>"she said ""hi"""</code>) come out mangled. A newline inside a quoted field creates phantom rows. CRLF leaves a stray <code>\r</code> glued to every last column. Only the plainest comma-separated file survives.</p>
<h2>The state machine version</h2>
<p>The agent then produced a 17-line state machine parser. The idea is small: walk the text one character at a time and track whether you are inside quotes. A comma only ends a field when you are outside quotes; a quote only closes when it is not followed by another quote; anything else, including newlines, is just data.</p>
<p>I ran it against the full suite: all 5 cases from before plus extra edge cases, 8 tests in total. It passed 8 of 8, including correctly raising an error on an unterminated quote, which is the case most hand-rolled parsers silently swallow.</p>
<p>The difference between 1 of 5 and 8 of 8 is not cleverness. It is that CSV is a format with quoting rules, and quoting rules need state. <code>split(',')</code> has no state, so it cannot tell a delimiter from data.</p>
<h2>What I did not test</h2>
<p>Very large files, encodings other than UTF-8, and full RFC 4180 coverage are still open. For production, a battle-tested library like <code>csv-parse</code> or <code>papaparse</code> is still the right call. But as a demonstration of why the naive split fails, the test run is the whole point.</p>
<h2>Watch the run</h2>
<p>The code, the terminal output, and every pass/fail are in the video: <a href="https://youtu.be/zdCNzOnxUv4">https://youtu.be/zdCNzOnxUv4</a></p>
<p>Subscribe to Ship Stack AI on YouTube and tell me in the comments what to build and break next.</p>
]]></content:encoded></item><item><title><![CDATA[An AI Agent Wrote a Duplicate File Finder in Node. I Ran It on 11 Real Files.]]></title><description><![CDATA[You have a folder full of copies. Same report, three names, three places. So I had an AI agent write a duplicate file finder in Node, and I ran it on a…]]></description><link>https://shipstackai.hashnode.dev/an-ai-agent-wrote-a-duplicate-file-finder-in-node-i-ran-it-on-11-real-files</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/an-ai-agent-wrote-a-duplicate-file-finder-in-node-i-ran-it-on-11-real-files</guid><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Mon, 30 Nov 2026 15:29:28 GMT</pubDate><content:encoded><![CDATA[<p>You have a folder full of copies. Same report, three names, three places. So I had an AI agent write a duplicate file finder in Node, and I ran it on a real test folder. Here is what it built and what the run actually found.</p>
<h2>How it works</h2>
<p>Two files with the same content have the same hash. So the tool walks every folder and groups files by hash. But hashing every file is slow, so the agent added a shortcut first: files with a unique size cannot be duplicates, so they never get hashed at all.</p>
<h2>The test folder and the run</h2>
<p>The test folder has 11 files in three folders. Some are real copies, some only look similar.</p>
<ul>
<li>The tool scans 11 files and hashes nine. Two were skipped because their size was unique.</li>
<li>It finds two groups. The report exists three times under three different names. The photo file exists twice.</li>
<li>Total wasted space: 17,920 bytes. That is what you would get back by deleting the extra copies.</li>
</ul>
<h2>The tricky cases it got right</h2>
<p>This is the part I actually cared about, because "looks like a duplicate" and "is a duplicate" are different things:</p>
<ul>
<li><strong>Two notes files with the same name and the same size, but different content.</strong> They were hashed and correctly not flagged.</li>
<li><strong>A file with the same size as the report, but one changed character.</strong> Different hash, so not a duplicate.</li>
</ul>
<p>The size shortcut only skips hashing. It never decides a match on its own.</p>
<h2>What I did not test</h2>
<p>Huge files. This version reads each file fully into memory, so a multi-gigabyte file would be a problem. A streaming hash would fix that.</p>
<p>One deliberate choice worth copying: the tool never deletes anything. It only prints the groups. That is on purpose, because a delete bug is the worst kind of bug.</p>
<p>The full build and the real run are in the video:</p>
<p><a href="https://youtu.be/SFwkTAPenzw">https://youtu.be/SFwkTAPenzw</a></p>
<p>We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.</p>
]]></content:encoded></item><item><title><![CDATA[27 Lines of Callbacks Became 12 Lines of Async/Await. I Ran Both to Prove They Match.]]></title><description><![CDATA[A lot of real projects still run on callback code. So I took a 27-line callback file, had an AI agent refactor it to async/await, and then ran both…]]></description><link>https://shipstackai.hashnode.dev/27-lines-of-callbacks-became-12-lines-of-async-await-i-ran-both-to-prove-they-match</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/27-lines-of-callbacks-became-12-lines-of-async-await-i-ran-both-to-prove-they-match</guid><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Mon, 30 Nov 2026 06:34:00 GMT</pubDate><content:encoded><![CDATA[<p>A lot of real projects still run on callback code. So I took a 27-line callback file, had an AI agent refactor it to async/await, and then ran both versions side by side to check the answers match. Not a style review. A behavior test.</p>
<h2>The two versionsThe old version reads several JSON files one at a time, builds a report, and calls back with the result. It has a nested function, a manual counter, and an error check at every level.The new version is 12 lines. It reads all the files at the same time with Promise.all, flattens the rows, and returns the same report. Errors now come out as normal exceptions, so the repeated error checks are gone.</h2>
<h2>The test that mattersI ran both versions on the same four inputs: two good files, one file with broken JSON, and one file that does not exist.</h2>
<ul>
<li><strong>Good files.</strong> Both versions return five rows, top scored average 78.8. Same numbers.</li>
<li><strong>Broken JSON.</strong> Both fail with the same message.</li>
<li><strong>Missing file.</strong> Both fail with the same error code.</li>
</ul>
<p>All four results are identical. The refactor kept the behavior, including the failure behavior, which is the part rewrites usually get wrong.</p>
<h2>The one real differenceThe old code reads files one after another. The new code reads them in parallel. That is faster, but it cuts both ways: if you point it at thousands of files, you would want to limit the concurrency instead of opening them all at once.</h2>
<h2>The verdictShorter, safer, and provably the same output. "Provably" is doing the work here: I did not trust the diff, I ran both versions and compared what came out.</h2>
<p>The full refactor and every run are in the video:</p>
<p><a href="https://youtu.be/IwyDzuBQQlwWe">https://youtu.be/IwyDzuBQQlwWe</a> are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.</p>
]]></content:encoded></item><item><title><![CDATA[One Sentence to an AI Agent Got a Working Website. I Tested It.]]></title><description><![CDATA[I gave an AI agent one sentence of brief: a landing page for a to-do app with an email waitlist that saves to a file, no framework, no database. Then I…]]></description><link>https://shipstackai.hashnode.dev/one-sentence-to-an-ai-agent-got-a-working-website-i-tested-it</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/one-sentence-to-an-ai-agent-got-a-working-website-i-tested-it</guid><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Mon, 30 Nov 2026 03:35:20 GMT</pubDate><content:encoded><![CDATA[<p>I gave an AI agent one sentence of brief: a landing page for a to-do app with an email waitlist that saves to a file, no framework, no database. Then I tested what came back with real requests, on camera. Here is what it built, what passed, and the three corners it cut.</p>
<h2>What came back</h2>
<p>A plain Node server, three static files, and one API route. 61 lines total. The important part is the signup route: it takes the email, checks the format, lowercases it, and only then saves it. That lowercase step matters, and it got tested in a minute.</p>
<h2>The tests</h2>
<ul>
<li><strong>Not an email.</strong> I typed something that is not an email into the form. The server rejected it. From the command line, a bad email gets a 400.</li>
<li><strong>A real address.</strong> It saves and tells me I am number one on the list.</li>
<li><strong>Same address in capital letters.</strong> No duplicate created. The lowercase step doing exactly its job.</li>
</ul>
<p>Everything I threw at it behaved correctly. As a first draft, it works, it validates input, and it did not break in any of my tests.</p>
<h2>The honest part</h2>
<p>Three corners were cut, and all three matter before real traffic:</p>
<ul>
<li><strong>Storage is a plain JSON file.</strong> Fine for a demo, not for a launch.</li>
<li><strong>No rate limiting.</strong> Anyone could flood the list with signups.</li>
<li><strong>No confirmation email.</strong> Addresses are never verified, so the list fills with typos and other people's addresses.</li>
</ul>
<h2>The verdict</h2>
<p>One sentence produced a working, tested first draft. That is genuinely impressive for 61 lines. But "works in my tests" and "ready for strangers" are different states, and the distance between them is exactly those three fixes.</p>
<p>The full build and every test are in the video:</p>
<p><a href="https://youtu.be/49TNItqOlEA">https://youtu.be/49TNItqOlEA</a></p>
<p>We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.</p>
]]></content:encoded></item><item><title><![CDATA[100% Test Coverage and the App Still Had 2 Real Bugs]]></title><description><![CDATA[Everyone says check your test coverage. So I gave an AI agent a messy shopping cart API in Express, asked it to write tests, and measured the coverage. It…]]></description><link>https://shipstackai.hashnode.dev/100-test-coverage-and-the-app-still-had-2-real-bugs</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/100-test-coverage-and-the-app-still-had-2-real-bugs</guid><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Mon, 30 Nov 2026 00:46:02 GMT</pubDate><content:encoded><![CDATA[<p>Everyone says check your test coverage. So I gave an AI agent a messy shopping cart API in Express, asked it to write tests, and measured the coverage. It hit 100%. The app still had two real bugs. Here is what happened.</p>
<h2>The app</h2>
<p>A small Express cart API, 26 lines. You can add items, get a total with two coupon codes, and remove items. It looks fine at a glance. Nothing is validated except the item name.</p>
<h2>The happy paths</h2>
<p>The agent wrote tests for the happy paths: adding an item, the total, the 10% coupon, the half-price coupon that only works over $20, and deleting. All seven tests pass. Line coverage: 100%.</p>
<p>If you stopped here, you would ship it.</p>
<h2>The probing tests</h2>
<p>Then I added two tests that ask what should never be allowed.</p>
<ul>
<li><strong>Negative quantity.</strong> The server accepts it and answers 201.</li>
<li><strong>Text quantity.</strong> Send quantity "ABC" and the total comes back as NaN.</li>
</ul>
<p>Both are real bugs. 100% line coverage did not catch either one, because coverage only tells you which lines ran, not whether the answers were right.</p>
<h2>The fix</h2>
<p>One line of validation: if the quantity is not a finite number, or is zero or less, return a 400. Run the tests again: all nine pass. Coverage is still 100%, exactly where it started. The metric never moved; the app is meaningfully less broken.</p>
<h2>The takeaway</h2>
<p>Coverage is a floor check, not a correctness check. The tests that find real bugs are the ones that ask what should never be allowed: negative numbers, wrong types, empty strings, absurd sizes. Write a few of those for every endpoint before you trust the green checkmark.</p>
<p>The full run, with the code and every test on screen, is in the video:</p>
<p><a href="https://youtu.be/JqhsD936gD0">https://youtu.be/JqhsD936gD0</a></p>
<p>We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.</p>
]]></content:encoded></item><item><title><![CDATA[An AI Agent Wrote a URL Shortener in 17 Lines. I Tested It With Real Requests.]]></title><description><![CDATA[A URL shortener sounds like a weekend project, so I had an AI agent write one in plain Node with zero packages, then tested it with real requests. Here is…]]></description><link>https://shipstackai.hashnode.dev/an-ai-agent-wrote-a-url-shortener-in-17-lines-i-tested-it-with-real-requests</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/an-ai-agent-wrote-a-url-shortener-in-17-lines-i-tested-it-with-real-requests</guid><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Sun, 29 Nov 2026 21:35:02 GMT</pubDate><content:encoded><![CDATA[<p>A URL shortener sounds like a weekend project, so I had an AI agent write one in plain Node with zero packages, then tested it with real requests. Here is what works, what the tests caught, and what I would fix before putting it online.</p>
<h2>The build</h2>
<p>The whole server is 17 lines. One route takes a URL and returns a random 6-character code. Another route looks the code up and redirects. Codes use letters and numbers with the lookalike characters removed, and the server retries if a generated code already exists.</p>
<h2>The real requests</h2>
<p>I sent a normal link and got back a short code. Opening that code returned a <strong>302 redirect</strong> to the original page, and the stats route then reported <strong>one hit</strong>. So far, so good.</p>
<p>The part I care about most is validation. I sent a link that starts with <code>javascript:</code> and the server rejected it with a <strong>400</strong>. Only HTTP and HTTPS links are allowed. Without that check, a shortener becomes a tool for hiding harmful links behind a trusted-looking domain.</p>
<h2>The automated tests</h2>
<p>I ran the five automated tests that came with the build:</p>
<ul>
<li>Creating a code</li>
<li>Rejecting a bad link</li>
<li>Rejecting broken JSON</li>
<li>Redirecting and counting hits</li>
<li>An unknown code returning 404</li>
</ul>
<p>All five passed on the first run. Honest caveat: that is a small test suite, not proof the thing is production ready.</p>
<h2>What is missing</h2>
<ul>
<li><strong>Links live in memory.</strong> A restart erases every short link ever created. A database comes first for real use.</li>
<li><strong>No login and no rate limit.</strong> Anyone can create unlimited links.</li>
<li><strong>No custom names.</strong> You get the random code you are given.</li>
</ul>
<p>As a learning project it is solid. The validation being there at all, and actually working, puts it ahead of most weekend shorteners.</p>
<p>The full build, the code on screen, and all the test runs are in the video:</p>
<p><a href="https://youtu.be/PMs0w0sqKR0">https://youtu.be/PMs0w0sqKR0</a></p>
<p>We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.</p>
]]></content:encoded></item><item><title><![CDATA[I Built a Rate Limiter in 13 Lines of Node, Then Load-Tested It]]></title><description><![CDATA[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…]]></description><link>https://shipstackai.hashnode.dev/i-built-a-rate-limiter-in-13-lines-of-node-then-load-tested-it</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/i-built-a-rate-limiter-in-13-lines-of-node-then-load-tested-it</guid><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Sun, 29 Nov 2026 19:19:31 GMT</pubDate><content:encoded><![CDATA[<p>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.</p>
<h2>The limiter</h2>
<p>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.</p>
<p>The whole limiter is a function that takes a capacity and a refill rate, keeps a <code>Map</code> of buckets keyed by client, refills based on elapsed time, and returns true or false. 13 lines, no timers, no dependencies.</p>
<p>The server is tiny on purpose: it reads a client name from a header, asks the limiter, and returns <strong>429 with a Retry-After header</strong> when the answer is no. Otherwise it says okay.</p>
<h2>The tests</h2>
<p><strong>Test 1: the burst.</strong> A client called Alice sends 100 requests at once.</p>
<ul>
<li><strong>10 got a 200</strong></li>
<li>- <strong>90 got a 429</strong></li>
<li>Exactly the bucket size. Nothing else leaked through.</li>
</ul>
<p><strong>Test 2: client isolation.</strong> Right after Alice's burst, a different client, Bob, sends one request.</p>
<ul>
<li>Bob gets a <strong>200</strong></li>
</ul>
<p>One noisy client did not block the others, because each client has its own bucket.</p>
<p><strong>Test 3: the refill.</strong> Wait one second, then Alice sends 10 more.</p>
<ul>
<li><strong>5 got a 200</strong></li>
<li>- <strong>5 got a 429</strong></li>
</ul>
<p>That matches the refill rate of 5 tokens per second. After one second, exactly 5 tokens had come back.</p>
<p><strong>Test 4: under the limit.</strong> Carol sends 20 requests at 4 per second.</p>
<ul>
<li>All <strong>20 got a 200</strong></li>
</ul>
<p>Under the refill rate, the limiter is invisible.</p>
<h2>The limits</h2>
<p>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.</p>
<p>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.</p>
<p>The full build, the code, and all four test runs are in the video:</p>
<p><a href="https://youtu.be/9fCCbBhJc6M">https://youtu.be/9fCCbBhJc6M</a></p>
<p>We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.</p>
]]></content:encoded></item><item><title><![CDATA[I Load-Tested My Node.js Cache and Watched Memory Grow to 200 MB]]></title><description><![CDATA[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…]]></description><link>https://shipstackai.hashnode.dev/i-load-tested-my-node-js-cache-and-watched-memory-grow-to-200-mb</link><guid isPermaLink="true">https://shipstackai.hashnode.dev/i-load-tested-my-node-js-cache-and-watched-memory-grow-to-200-mb</guid><dc:creator><![CDATA[Ship Stack]]></dc:creator><pubDate>Sun, 29 Nov 2026 18:49:54 GMT</pubDate><content:encoded><![CDATA[<p>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.</p>
<h2>The test setup</h2>
<p>The service was a small Node.js server with an in-memory response cache: a plain <code>Map</code> keyed by request URL. Every request that came in got its response stored so repeat requests could skip the work. Simple, and completely unbounded.</p>
<p>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.</p>
<h2>What the memory did</h2>
<p>The result was a textbook leak shape:</p>
<ul>
<li>Start: <strong>3.4 MB</strong> RSS</li>
<li>- After 4,000 requests: <strong>200.1 MB</strong> RSS- No plateau. Memory grew linearly with request count, because the Map never let anything go.</li>
</ul>
<p>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.</p>
<h2>The fix</h2>
<p>Two changes:</p>
<ol>
<li><strong>Bounded cache</strong>: a size cap on the cache. Once it hits the limit, the oldest entries get evicted.</li>
<li>2. Same 4,000-request autocannon run against the fixed version.</li>
</ol>
<p>Result: RSS stayed <strong>flat at 13.6 MB</strong> through the entire run. Same traffic, same throughput, no growth.</p>
<h2>The takeaway</h2>
<p>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:</p>
<ul>
<li>Set a hard size limit and an eviction policy (LRU is usually the default you want)</li>
<li>Add a TTL if the data goes stale</li>
<li>Load-test it with unique keys before you ship, not after your pod gets OOMKilled</li>
</ul>
<p>The full experiment, with the code and the live test runs, is in the video:</p>
<p><a href="https://youtu.be/n520Ht4eQn8">https://youtu.be/n520Ht4eQn8</a></p>
<p>We are building Ship Stack: real experiments on real backends, with the actual numbers, no hand-waving. More of these are on the channel.</p>
]]></content:encoded></item></channel></rss>