<?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[Alok Verma]]></title><description><![CDATA[Alok Verma]]></description><link>https://alokvermaa.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Fri, 04 Dec 2026 23:40:34 GMT</lastBuildDate><atom:link href="https://alokvermaa.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How a “Harmless” 5-Line Pull Request Breaks 14 Modules — And How to Catch It Automatically]]></title><description><![CDATA[Inside PR Risk Analyzer: catch breaking PR using parse-only WASM static analysis reverse-dependency graphs idempotent webhooks and bounded LLM scoring]]></description><link>https://alokvermaa.hashnode.dev/how-a-harmless-5-line-pull-request-breaks-14-modules-and-how-to-catch-it-automatically</link><guid isPermaLink="true">https://alokvermaa.hashnode.dev/how-a-harmless-5-line-pull-request-breaks-14-modules-and-how-to-catch-it-automatically</guid><category><![CDATA[Software Engineering]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[GitHub]]></category><category><![CDATA[software architecture]]></category><category><![CDATA[Node.js]]></category><dc:creator><![CDATA[Alok Verma]]></dc:creator><pubDate>Wed, 02 Dec 2026 11:08:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ac92378224ea1b3deffccde/fd1872e8-dedc-4d6c-a847-877d2cbd17ec.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<p>Every engineering team has lived through the same post-mortem. Someone opens a five-line pull request — a subtle tweak to a helper function, a renamed field on an exported type, or an edge-case fallback in a shared utility. The diff looks clean. CI passes on the touched file. A reviewer glances at five lines of green and red, hits <strong>Approve</strong>, and merges.</p>
<p>Two hours later, three unrelated services fail in staging.</p>
<p>The problem isn’t careless reviewers. The problem is that <strong>a code diff only shows what changed — never what those changes can break.</strong> When you stare at GitHub’s “Files changed” tab under deadline pressure, three critical questions go unanswered:</p>
<ol>
<li><strong>Blast radius:</strong> Which other modules across the repository transitively import this code?</li>
<li><strong>Breaking changes:</strong> Did a public function signature, return shape, or exported type silently change?</li>
<li><strong>Test gaps:</strong> Is the modified logic actually exercised by any test — even indirectly?</li>
</ol>
<p>Generic “AI code review” bots haven’t solved this. Most of them just pipe the raw diff into an LLM and dump a wall of speculative prose onto the PR. Worse, they re-comment on every push, offer no visibility into token costs, and break under real-world webhook traffic.</p>
<p><img src="https://cdn-images-1.medium.com/max/2160/1*EXpNG2LAoOlhFytpGWb9kA.png" alt="The 5-Line Diff Illusion" /></p>
<p><strong>PR Risk Analyzer</strong> approaches automated review from a different premise: before an LLM ever scores a pull request, deterministic systems engineering and static analysis must map the true impact of the change.</p>
<hr />
<h2>Problem 1: Automated PR Review Breaks Before Reading a Single Line of Code</h2>
<p>In a toy demo, a GitHub bot receives a webhook, calls an API, and posts a comment. In production, webhooks are messy:</p>
<ul>
<li><strong>Duplicate deliveries:</strong> GitHub retries webhooks when networks hiccup, and maintainers click “Redeliver” during debugging.</li>
<li><strong>Force-push storms:</strong> A developer pushes three commits in 30 seconds, triggering overlapping analysis jobs where an older commit could finish last and overwrite newer results.</li>
<li><strong>Mid-job crashes:</strong> A worker process gets <code>SIGKILL</code>ed during a deploy right after claiming a job—or crashes in the narrow window between committing a database row and pushing a job to Redis.</li>
<li><strong>Hostile payloads:</strong> Anything inside a webhook or PR — titles, branch names, <code>diff_url</code> fields—is untrusted input.</li>
</ul>
<p>PR Risk Analyzer solves this with <strong>4-layer idempotency</strong> across an event-driven Fastify, PostgreSQL, and Redis/BullMQ pipeline:</p>
<ol>
<li><strong>Delivery deduplication:</strong> <code>POST /webhooks/github</code> verifies the <code>X-Hub-Signature-256</code> HMAC-SHA256 signature over the <strong>raw request bytes</strong> using constant-time <code>timingSafeEqual</code> <em>before</em> parsing JSON. Valid payloads insert into <code>webhook_deliveries</code> using <code>X-GitHub-Delivery</code> as a primary key (<code>ON CONFLICT DO NOTHING</code>), immediately returning <code>202</code> on duplicates.</li>
<li><strong>Commit-level uniqueness:</strong> Analysis runs enforce <code>UNIQUE (pull_request_id, head_sha)</code>. Concurrent deliveries for the same commit collapse into a single run, while newer commits automatically mark older queued runs as <code>superseded</code>.</li>
<li><strong>Compare-and-set worker claims:</strong> Jobs use <code>jobId = runId</code> in BullMQ. Workers claim runs with an atomic database compare-and-set (<code>queued -&gt; running</code>), check whether <code>head_sha</code> is still the PR's <code>latest_head_sha</code>, and lean on a repeatable <strong>sweeper job</strong> (a lightweight outbox pattern) to re-enqueue runs left stranded if the API crashes right after committing to Postgres.</li>
<li><strong>SSRF-safe outbound calls:</strong> The worker never fetches URLs found inside webhook payloads. Every GitHub API request URL is constructed strictly from validated IDs (<code>owner</code>, <code>repo</code>, <code>pull_number</code>, <code>sha</code>) against a fixed base URL.</li>
</ol>
<p><img src="https://cdn-images-1.medium.com/max/2160/1*wKz0b2hUqWpWyCnx4pIVzg.png" alt="Chaotic webhooks &amp; worker crashes funneled through the 4-layer reliability pipeline" /></p>
<hr />
<h2>Problem 2: Finding Blast Radius Without Executing Untrusted Code</h2>
<p>Even with reliable queues, how do you know that a five-line edit breaks 14 downstream files?</p>
<p>Linters only inspect the file in front of them. Running a full compiler or test suite inside an analyzer means running <code>npm install</code> or <code>pip install</code> on <strong>untrusted pull request code</strong>—an unacceptable remote code execution risk, especially for public repositories and fork PRs.</p>
<p>PR Risk Analyzer solves this with <strong>parse-only static analysis</strong>:</p>
<ul>
<li><strong>Quarantined snapshots:</strong> For each analysis, the worker fetches a single repository tarball at the <code>head</code> SHA and streams it into an isolated temporary directory—enforcing strict caps on compressed/extracted bytes, stripping leading paths, and blocking symlinks, hardlinks, and <code>..</code> path traversal. No repo code or build script is ever executed.</li>
<li><strong>WASM AST parsing:</strong> Using <strong><code>web-tree-sitter</code></strong> (WebAssembly grammars for TypeScript, JavaScript, TSX, and Python—avoiding fragile native C++ bindings), the analyzer parses source files across the snapshot and extracts import specifiers, resolving relative paths, <code>tsconfig</code> path aliases, and Python module roots into an in-memory adjacency graph.</li>
<li><strong>Bounded reverse-BFS impact:</strong> Starting from every changed file, a breadth-first traversal walks <em>backward</em> along reverse edges — answering <em>“who imports the code you just touched?”</em> Depth and node caps (such as max depth 3 and 200 nodes) keep traversal fast and bounded even in large monorepos.</li>
<li><strong>Breaking changes &amp; test gaps:</strong> The analyzer compares the exported API surface of changed files between <code>base</code> and <code>head</code> to flag removed exports or signature changes, and cross-references the import graph against test files. If a changed source module has no modified tests <em>and</em> no existing test file imports it, it gets flagged as a test coverage gap.</li>
</ul>
<p><img src="https://cdn-images-1.medium.com/max/2160/1*orZhnZuMZ9Zi87jf4rjnJA.png" alt="Parse-Only Static Analysis" /></p>
<hr />
<h2>Problem 3: Making LLM Risk Scoring Safe, Bounded, and Quiet</h2>
<p>Only <em>after</em> static analysis computes the concrete evidence package — impacted modules, exported API diffs, test gaps, and a capped diff — does an LLM enter the picture.</p>
<p>Unconstrained LLMs introduce three new failure modes in PR tooling: <strong>prompt injection</strong> hidden inside PR descriptions or code comments, <strong>runaway token bills</strong> on massive refactors, and <strong>comment fatigue</strong> from bots that post a fresh reply on every commit.</p>
<p>PR Risk Analyzer puts hard boundaries around the model:</p>
<ul>
<li><strong>Sanitized &amp; fenced evidence:</strong> Diffs pass through secret redaction (stripping tokens, private keys, and <code>.env</code>-style secrets) before leaving the worker. All PR-controlled text is wrapped in explicit data delimiters, and the LLM has <strong>zero side-effect tools</strong>.</li>
<li><strong>Forced schema, server-derived severity:</strong> The <code>RiskScorer</code> uses a forced tool-call JSON schema generated from <code>zod</code>, with one repair retry on malformed output. Crucially, the model outputs structured category scores (Architectural impact, Breaking changes, Test coverage, Security-sensitive changes)—<strong>the server computes the final risk level</strong> (<code>Low</code>, <code>Medium</code>, <code>High</code>, <code>Critical</code>), preventing prompt injection from forcing a "Low risk" badge on a dangerous change.</li>
<li><strong>Hard token budgets:</strong> Per-call input caps and per-repo daily token budgets prevent cost spikes, while Postgres records latency and token spend per repository for team visibility.</li>
<li><strong>One living PR comment:</strong> Instead of spamming threads on every push, the analyzer embeds a hidden HTML marker (<code>&lt;!-- pr-risk-analyzer:v1 --&gt;</code>) and upserts <strong>a single living comment</strong> per PR, neutralizing <code>@mentions</code> with zero-width spaces so automated updates never ping teammates unnecessarily.</li>
</ul>
<p><img src="https://cdn-images-1.medium.com/max/2160/1*mH7Y7adFv8npyOYExFHj2w.png" alt="Secret-redacted fenced evidence -&gt; schema-locked LLM scorer -&gt; single living PR comment" /></p>
<hr />
<h2>From Guessing on Diffs to Knowing Merge Risk</h2>
<p>Code review shouldn’t be a guessing game where reviewers mentally simulate an entire repository’s dependency graph from a 20-line diff.</p>
<p>By combining crash-safe webhook ingestion, parse-only WASM static analysis, and strictly bounded LLM scoring, PR Risk Analyzer turns a noisy, fragile AI gimmick into a dependable engineering signal: <strong>know what a pull request can break before you merge it.</strong></p>
]]></content:encoded></item><item><title><![CDATA[How Zoom and Google Meet Scale Video Calls (Without Breaking Peer-to-Peer)]]></title><description><![CDATA[Learn why peer-to-peer WebRTC breaks at scale, how SFUs power Zoom and Google Meet, and how to build your own SFU in Node.js with Mediasoup.]]></description><link>https://alokvermaa.hashnode.dev/how-zoom-and-google-meet-scale-video-calls-without-breaking-peer-to-peer</link><guid isPermaLink="true">https://alokvermaa.hashnode.dev/how-zoom-and-google-meet-scale-video-calls-without-breaking-peer-to-peer</guid><category><![CDATA[System Design]]></category><category><![CDATA[WebRTC]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[software architecture]]></category><dc:creator><![CDATA[Alok Verma]]></dc:creator><pubDate>Tue, 01 Dec 2026 08:21:54 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6ac92378224ea1b3deffccde/75534e8a-5c82-4e8b-83ee-21b6d5251cd5.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>If you have ever built a 1-on-1 video calling app with WebRTC, you probably felt like a wizard the first time two browser tabs connected directly to each other. No heavy media server. Almost zero latency. Just pure peer-to-peer magic.</p>
<p>Then you invite a third person. And a fourth. By the time ten people join the room, everyone’s laptop fan sounds like a jet engine, frames start dropping, and the call grinds to a halt.</p>
<p>Yet apps like Zoom, Google Meet, and Discord handle dozens — even hundreds — of participants smoothly in a single call.</p>
<p>They aren’t using magic, and they aren’t using plain peer-to-peer either. Behind the scenes, they rely on a smart routing architecture called a <strong>Selective Forwarding Unit (SFU)</strong>.</p>
<p>Let’s break down why pure peer-to-peer fails at scale, how SFUs solve it, and how you can build one yourself in Node.js using <strong>Mediasoup</strong>.</p>
<hr />
<h2>Part 1: The Peer-to-Peer Trap (Mesh Architecture)</h2>
<p>In a standard WebRTC call, browsers connect directly to one another in what is called a <strong>Mesh topology</strong>.</p>
<p>With 2 people, each browser sends 1 video stream and receives 1 video stream. Simple.</p>
<p>Now scale that to <strong>10 people</strong>:</p>
<ul>
<li>Every single participant has to encode and <strong>upload 9 separate streams</strong> (one to each other person).</li>
<li>Every single participant also has to <strong>download and decode 9 incoming streams</strong>.</li>
<li>Across the whole call, that is 90 active peer connections.</li>
</ul>
<p>Even if your server isn’t touching a single video frame, your users’ devices will collapse. Home internet connections almost always have much slower <strong>upload</strong> speeds than download speeds. Pushing 9 simultaneous HD video streams from a browser will saturate a user’s bandwidth and max out their CPU in seconds.</p>
<p>In practice, Mesh WebRTC breaks down after <strong>3 to 4 participants</strong>.</p>
<hr />
<h2>Part 2: Why Not Mix Everything on One Server? (MCU)</h2>
<p>The oldest server-based solution to the Mesh problem is called an <strong>MCU (Multipoint Control Unit)</strong>.</p>
<p>Instead of browsers connecting to each other, everyone sends their single audio/video stream to a central MCU server. The server then:</p>
<ol>
<li>Decodes all incoming video streams.</li>
<li>Composites them into a single grid layout (like one big video frame).</li>
<li>Re-encodes that combined video and sends <strong>just 1 stream</strong> back to each user.</li>
</ol>
<p>For the user’s device, this is a dream — one upload, one download.</p>
<p>For your cloud bill, it is a nightmare. Real-time video decoding, compositing, and re-encoding is extraordinarily CPU-intensive. Running an MCU at scale requires expensive GPU/CPU clusters, adds noticeable latency, and locks everyone into the same fixed video layout.</p>
<p>So how do modern apps get low client bandwidth <em>without</em> melting their servers?</p>
<hr />
<h2>Part 3: The Secret Sauce — Selective Forwarding Unit (SFU)</h2>
<p>An <strong>SFU (Selective Forwarding Unit)</strong> sits right in the sweet spot between Mesh and MCU.</p>
<p>Here is how it works:</p>
<ul>
<li>Each participant uploads <strong>only 1 copy</strong> of their audio and video stream to the SFU server.</li>
<li>The SFU <strong>does not decode or re-encode</strong> the video.</li>
<li>Instead, it acts like an ultra-fast network router — inspecting lightweight packet headers and <strong>selectively forwarding</strong> copies of those streams to the other participants.</li>
</ul>
<p>Because the server only routes packets instead of transcoding video, CPU usage stays remarkably low. Meanwhile, each user’s upload bandwidth is capped at <strong>just 1 outgoing stream</strong>, no matter whether there are 5 people in the room or 50.</p>
<p>Even better: because the SFU forwards individual streams rather than one baked-in grid, the frontend stays completely flexible. You can pin a speaker, hide off-screen participants, or let a user on slow mobile data request a lower-resolution layer (via <strong>Simulcast</strong>) without affecting anyone else on the call.</p>
<img src="https://cdn-images-1.medium.com/max/2160/1*FxZYn6yjmlwWwiNf3MaVbw.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>Part 4: Meet Mediasoup — Bringing SFUs to Node.js</h2>
<p>If you want to build your own SFU in JavaScript/TypeScript, <strong>Mediasoup</strong> is the gold standard.</p>
<p>There is an important architectural detail to understand first: <strong>Node.js is single-threaded, and JavaScript is not meant for raw real-time RTP packet forwarding.</strong> Mediasoup solves this cleanly by giving you a developer-friendly Node.js API that controls high-performance <strong>C++ worker processes</strong> (<code>libmediasoup-worker</code>) running under the hood.</p>
<p>To design a Mediasoup backend, you only need to master <strong>five core building blocks</strong>:</p>
<h3>1. Worker</h3>
<p>A Worker is an isolated C++ process running on your server that handles the heavy media packet routing. Because a single Worker runs on one CPU core, production servers typically spawn <strong>one Worker per CPU core</strong> to utilize the whole machine.</p>
<h3>2. Router</h3>
<p>A Router lives inside a Worker and acts as a <strong>virtual room</strong>. It is responsible for receiving media tracks and routing them between connected participants. Everyone in the same meeting room connects through the same Router.</p>
<h3>3. WebRtcTransport</h3>
<p>A Transport is the actual network pipe (ICE, DTLS, RTP) between a user’s browser and the Mediasoup Router. Typically, each client opens <strong>two transports</strong>:</p>
<ul>
<li><strong>Send Transport:</strong> For uploading the user’s microphone and camera tracks to the server.</li>
<li><strong>Receive Transport:</strong> For downloading other participants’ tracks from the server.</li>
</ul>
<h3>4. Producer</h3>
<p>When a user turns on their camera or microphone, the client sends that track over its Send Transport and registers a <strong>Producer</strong> on the Router. One user with audio and video on has two Producers (one audio, one video).</p>
<h3>5. Consumer</h3>
<p>Whenever User B wants to see User A’s video, User B asks the Router to create a <strong>Consumer</strong> attached to User A’s Producer, flowing down through User B’s Receive Transport.</p>
<blockquote>
<p><em><strong>The mental model:</strong></em> <em>A</em> <em><strong>Worker</strong></em> <em>runs the engine. A</em> <em><strong>Router</strong></em> <em>is the room.</em> <em><strong>Transports</strong></em> <em>are the pipes.</em> <em><strong>Producers</strong></em> <em>push media in;</em> <em><strong>Consumers</strong></em> <em>pull media out.</em></p>
</blockquote>
<img src="https://cdn-images-1.medium.com/max/2160/1*qt2z0NCzxzhM3QWck425sQ.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>Part 5: How a Call Actually Flows End-to-End</h2>
<p>Mediasoup intentionally leaves <strong>signaling</strong> up to you — meaning you use something like <strong>WebSockets (or</strong> <a href="http://Socket.io"><strong>Socket.io</strong></a><strong>)</strong> alongside Mediasoup to coordinate who joins, leaves, or starts streaming.</p>
<p>Here is the exact lifecycle when a user joins a call:</p>
<ol>
<li><strong>Connect to Signaling:</strong> The client connects to your Node.js server via WebSockets and joins a room.</li>
<li><strong>Sync Capabilities:</strong> The client asks the server for the Router’s supported codecs (<code>router.rtpCapabilities</code>) so the browser knows which video/audio formats to use.</li>
<li><strong>Create Transports:</strong> The server creates a Send <code>WebRtcTransport</code> and Receive <code>WebRtcTransport</code> for the user and sends the connection parameters back over WebSockets.</li>
<li><strong>Produce Media:</strong> The client captures the local camera/mic via <code>getUserMedia()</code>, connects the Send Transport, and calls <code>produce()</code>. The server creates the <code>Producer</code> and broadcasts a <code>"new-producer"</code> event via WebSockets to everyone else in the room.</li>
<li><strong>Consume Media:</strong> Other clients receive that event, tell the server <em>“I want to consume this Producer,”</em> and receive the parameters to attach a new <code>Consumer</code> to their Receive Transport—rendering the remote <code>&lt;video&gt;</code> element on screen.</li>
</ol>
<img src="https://cdn-images-1.medium.com/max/2160/1*SB6nk_PNQwPu8AzIOTHNtQ.png" alt="" style="display:block;margin:0 auto" />

<h3>One Gotcha Before You Deploy</h3>
<p>When running locally, Mediasoup binds to <code>127.0.0.1</code>. The moment you deploy to AWS, DigitalOcean, or inside Docker, clients won’t be able to connect unless you configure <code>listenIps</code> with your server’s <strong>public IP as</strong> <code>announcedIp</code> and open the configured UDP port range in your firewall.</p>
<hr />
<h2>Part 6: Which Architecture Should You Choose?</h2>
<p>You don’t always need an SFU on day one. Here is the quick rule of thumb:</p>
<ul>
<li><strong>2 to 4 participants (1-on-1 tutoring, quick support calls):</strong> Stick to <strong>Peer-to-Peer Mesh</strong>. It’s free to run and dead simple.</li>
<li><strong>5 to 100+ participants (video meetings, classrooms, live co-working):</strong> Use an <strong>SFU like Mediasoup</strong>. It keeps client bandwidth flat and server CPU lean.</li>
<li><strong>Legacy SIP/phone bridges or fixed single-stream broadcasting:</strong> Consider an <strong>MCU</strong> — or record/composite selectively on a dedicated media worker.</li>
</ul>
<p>Building your own SFU with Node.js and Mediasoup strips away the mystery behind Zoom and Google Meet. Once you understand Workers, Routers, Transports, Producers, and Consumers, real-time video stops feeling like black magic — and starts feeling like clean system design.</p>
]]></content:encoded></item></channel></rss>