<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Tushar Garg on Medium]]></title>
        <description><![CDATA[Stories by Tushar Garg on Medium]]></description>
        <link>https://medium.com/@tshrgarg2010?source=rss-4dbb689fdf6d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*NFh8P4jgynu_LfYV</url>
            <title>Stories by Tushar Garg on Medium</title>
            <link>https://medium.com/@tshrgarg2010?source=rss-4dbb689fdf6d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 01:27:22 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tshrgarg2010/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Your AI reviewer doesn’t know your product. So I wrote it down.]]></title>
            <link>https://medium.com/@tshrgarg2010/your-ai-reviewer-doesnt-know-your-product-so-i-wrote-it-down-a9ed102edd4d?source=rss-4dbb689fdf6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9ed102edd4d</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[pr-review]]></category>
            <category><![CDATA[product]]></category>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[claude-code]]></category>
            <dc:creator><![CDATA[Tushar Garg]]></dc:creator>
            <pubDate>Fri, 23 Oct 2026 04:31:03 GMT</pubDate>
            <atom:updated>2026-10-23T04:31:03.492Z</atom:updated>
            <content:encoded><![CDATA[<h3>The problem: a diff shows what changed, not who it affects</h3><p>Open any pull request and you get a diff. Files, lines, red and green.</p><p>What you don’t get is the one thing a reviewer actually needs: which user flows could break because of this change.</p><p>A developer changes a shared date helper. The diff is three lines. But that helper is used in checkout, in invoices, and in a report the finance team runs every Monday. None of those screens appear anywhere in the PR.</p><p>An AI reviewer has the same blind spot. It can read code perfectly well. It just doesn’t know your product. It doesn’t know that “submit” on one screen kicks off an approval chain for three different roles, or that an old record created last year still has to render.</p><p>That knowledge usually lives in the heads of a few senior people on the team.</p><p>So I wrote it down, in a file the AI can read.</p><p>It’s one part of an all-in-one AI dev setup I’ve built into our repo, alongside a self-improving <a href="https://medium.com/@tshrgarg2010/my-team-started-writing-code-with-ai-so-i-built-ai-to-review-it-d15274522d32">AI PR review skill</a> and a <a href="https://medium.com/@tshrgarg2010/a9ed102edd4d">Sentry MCP pipeline</a> that goes from production crash to fix PR. All of them read from the same shared files. This file is the glue that holds them together.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4LEfdO9tKXTX6Hwj" /></figure><h3>The product scenarios file</h3><p>It’s a single markdown file in the repo: product-scenarios.md. A living list of every user flow in the product, grouped by area. Ours has grown past 600 lines.</p><p>The format is deliberately simple:</p><pre>## Orders<br>- Create an order from a saved draft<br>- Edit an order before it&#39;s approved<br>- Send an order back for changes (approver only)</pre><pre>- **Approval journey** — approver; from the notifications panel<br>    - Open the pending order<br>    - Approve, reject or send back with a remark<br>    - Requester sees the new status without a refresh</pre><p>A few rules keep it readable for humans and useful for the AI:</p><ul><li>One line per scenario: a verb, an object, and a condition if it matters</li><li>Multi-step journeys are nested, with the role and the entry point written up front</li><li>Behaviour only, never implementation. “Approve an order”, not “dispatch approveOrder thunk&quot;</li><li>Client-specific or role-specific flows are tagged, so nobody assumes they apply everywhere</li></ul><p>It reads like a test plan, because that’s effectively what it is.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/738/0*_G_F788um55_IR_B" /></figure><h3>Keeping it true is the whole game</h3><p>A scenarios file that’s out of date is worse than none. The bot trusts it completely. If the file describes a flow that doesn’t exist, the bot will confidently warn about it. If a new flow is missing, the bot will never mention it.</p><p>So three rules:</p><ol><li><strong>Every feature PR updates the scenarios in the same PR.</strong> New flow, changed flow, removed flow: the file changes alongside the code.</li><li><strong>Fix PRs don’t touch it.</strong> A bug fix restores intended behaviour; it doesn’t change what the product does.</li><li><strong>Only what’s real goes in.</strong> Behaviour that’s already merged, or that’s in this PR. Never flows from other branches that haven’t landed yet.</li></ol><p>The third rule is the one people break without noticing, and it’s the one that misleads the bot most.</p><p>I also stopped relying on people to remember. The AI PR review skill updates the scenarios file itself on feature PRs. It adds new flows, rewords changed ones, deletes removed ones, and adds edge cases it found during testing that are worth regression-checking later. The update shows up in the PR diff, so a human still reviews it.</p><h3>Start with one file</h3><p>You don’t need the whole system to get value. Start here:</p><ol><li>Create product-scenarios.md and list the 20 flows that would hurt most if they broke.</li><li>Use the simple format: one line per scenario, journeys nested with role and entry point.</li><li>Add a rule to your PR template: feature PRs update this file, fix PRs don’t.</li><li>Point your AI reviewer or a small CI job at it, and have it comment the affected flows on every PR.</li><li>Grow it every time a PR adds a flow, or a bug teaches you about one you forgot.</li></ol><p>AI can already read your code.</p><p>The edge comes from teaching it your product.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9ed102edd4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Sentry MCP + AI: from crash to fix PR, automatically]]></title>
            <link>https://medium.com/@tshrgarg2010/sentry-mcp-ai-from-crash-to-fix-pr-automatically-88d86b601b09?source=rss-4dbb689fdf6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/88d86b601b09</guid>
            <category><![CDATA[sentryio]]></category>
            <category><![CDATA[mcp-server]]></category>
            <category><![CDATA[claude]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Tushar Garg]]></dc:creator>
            <pubDate>Wed, 21 Oct 2026 04:31:03 GMT</pubDate>
            <atom:updated>2026-10-21T04:31:03.775Z</atom:updated>
            <content:encoded><![CDATA[<h3>The problem: most crash fixes are guesses</h3><p>A TypeError shows up in Sentry.</p><p>Cannot read properties of undefined (reading &#39;id&#39;).</p><p>The usual fix takes five minutes. Add a ?., ship it, resolve the issue, move on.</p><p>The error is gone. The bug isn’t.</p><p>The data was still missing. The user still saw a broken screen, just without the crash. And nobody knows why the data was missing in the first place, so it comes back a month later in a different component.</p><p>A real root cause analysis takes much longer. You open the Sentry issue, watch the session replay, read the trace, check the breadcrumbs, map the stack to your code, work out where the bad data came from, and check whether this release even contains the bug.</p><p>That’s a lot of tabs and a lot of context switching. So most teams skip it.</p><p>So I automated it. Not the five-minute guess. The full investigation, from Sentry issue to a reviewed fix PR.</p><h3>Step 1: give your AI eyes into Sentry, (Claude Code in my case)</h3><p>Sentry runs a hosted MCP server. MCP is the protocol Claude Code uses to talk to external tools, so connecting it means the agent can read Sentry directly instead of me copy-pasting stack traces.</p><p>The setup is one file committed at the repo root:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mUzn1AAomYwyaNaVcYnRCQ.png" /></figure><p>Notice what’s not in it: no token, no API key, no secret.</p><p>Each developer authenticates with their own Sentry account through OAuth. Pull the repo, open Claude Code, approve the server, run /mcp, log in. That&#39;s the whole setup. Nothing sensitive ever touches the repo, and everyone only sees what their own Sentry access allows.</p><p>Once connected, the agent can:</p><ul><li>Search issues and fetch any issue, event or trace</li><li>Search and read session replays</li><li>Search traces and logs</li><li>Ask Sentry’s own AI (Seer) for a second opinion</li><li>Update an issue’s status</li></ul><p>That’s the raw access. But access alone doesn’t produce a good RCA. An agent with Sentry access and no method will still add a ?. and call it a day.</p><h3>Step 2: turn the method into a pipeline</h3><p>So I wrote my investigation process as a pipeline the agent runs, in a markdown file in the repo: docs/sentry-rca-context.md. Hand it a Sentry issue ID and it runs end to end on its own: investigate, write the RCA, fix, open the PR, review.</p><p>The first step is the simplest, and it saves the most time.</p><p><strong>Is this bug already fixed?</strong> Before investigating anything, the agent finds the release that contains the fix, then compares it with the releases the events came from. If every event came from an older bundle, the user was simply running a stale version of the app. No code change needed. Resolve the issue and move on.</p><p>That single check filters out a whole class of fake bugs.</p><p>If the bug is real, the investigation continues:</p><ol><li><strong>Fetch the issue.</strong> Culprit, release, URL, and the app state captured at the moment of the crash.</li><li><strong>Watch the replay.</strong> What did the user click? What had loaded on screen by then?</li><li><strong>Read the trace.</strong> A long page load followed by a crash often means the user interacted before the data arrived.</li><li><strong>Read the breadcrumbs.</strong> The exact order of network calls versus user actions.</li><li><strong>Map it to code.</strong> Component, selector, data-fetching layer, including every fallback along the way.</li><li><strong>Get a second opinion.</strong> Optionally, ask Sentry’s Seer to analyse the issue independently.</li><li><strong>Write the RCA.</strong> (More on what that must contain below.)</li><li><strong>Fix it at the right layer</strong>, verify, and record the RCA.</li><li><strong>Open the PR</strong> with Fixes &lt;ISSUE-ID&gt; in the commit, so the Sentry issue resolves automatically on merge.</li><li><strong>Review it.</strong> The fix PR goes through the same AI PR review skill as every other PR, until it’s clean.</li></ol><blockquote>Attaching my article, regarding my own AI PR Review Skill, which has automated my review process and reduced my review bandwidth by about 60–70%. <a href="https://medium.com/@tshrgarg2010/my-team-started-writing-code-with-ai-so-i-built-ai-to-review-it-d15274522d32">Link</a></blockquote><p>A crash from an old bundle is closed immediately. Only real bugs go through the full investigation, and every fix still ends with a human merging it.</p><h3>The rule that matters most: a nil-check is not an RCA</h3><p>This line is written into the context doc in plain words, because without it every agent takes the shortcut.</p><p>Every RCA must answer:</p><ul><li><strong>Trigger:</strong> what the user did that led to the crash</li><li><strong>Data path:</strong> API → data layer → state → selector → component → the exact crashing line</li><li><strong>The exact field</strong> that was missing or wrong, and its actual vs expected value</li><li><strong>The real payload</strong> from the backend, sanitised. Required, never guessed</li><li><strong>The source of the bad data:</strong> usually both a backend contract that changed and a frontend that didn’t guard against it</li><li><strong>Why it wasn’t caught:</strong> git log -S to find when the code was introduced</li><li><strong>What’s confirmed vs inferred</strong>, clearly separated</li></ul><p>Then the fix goes in at the right layer.</p><p>If the backend sent bad data, the frontend still ships a sensible fallback so users aren’t stuck, and the agent drafts a note for the backend team explaining the contract problem. Both sides get fixed, not just the symptom.</p><h3>Step 3: give it memory with an RCA store</h3><p>Every finished RCA is saved as its own markdown file in docs/rca/, with frontmatter tags:</p><pre>---<br>component: SettingsDropdown<br>error_type: TypeError<br>root_cause: loading-race<br>flow: order-settings<br>release: v4.12.0<br>tags: [loading-race, premature-interaction]<br>---</pre><p>The tags are short words for the cause, not the symptom. loading-race, not undefined-id.</p><p>Before every new investigation, the agent greps these tags first. Seen this pattern before? It reads the earlier RCA and starts from there instead of from zero.</p><p>The more RCAs you write, the faster the next one gets. Your bugs start to rhyme, and the agent notices.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z4_a6wS48QYuPPF8.jpg" /></figure><h3>Guardrails: crash data is user data</h3><p>Sentry events contain real user information. So the context doc sets hard rules:</p><ul><li><strong>Never paste raw Sentry dumps</strong> into an RCA, a PR or a commit. Payloads are sanitised before they’re written anywhere.</li><li><strong>Staging is not production.</strong> Staging issues get a fix and a PR, but no RCA file. The store stays a record of real production failures.</li><li><strong>No commit, push or deploy</strong> without a human saying so.</li><li><strong>Every fix PR goes through review</strong>, the same as code a person wrote.</li></ul><p>The agent does the investigation. A human still decides what ships.</p><h3>What I learned</h3><p><strong>Access isn’t the hard part. Method is.</strong> Connecting Sentry took one config file. Getting good RCAs took writing down exactly how a good investigation works.</p><p><strong>Check the release before you debug.</strong> A surprising number of “bugs” come from users on an old bundle. One version comparison saves hours of hunting for something that’s already fixed.</p><p><strong>Docs are the agent’s context.</strong> The RCA doc, the RCA store and the review skill aren’t one-off prompts. They’re files in the repo that get better over time, and every session of the agent starts from them.</p><blockquote>Always remember, the crash is the symptom. The RCA is the fix.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=88d86b601b09" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My team started writing code with AI. So I built AI to review it.]]></title>
            <link>https://medium.com/@tshrgarg2010/my-team-started-writing-code-with-ai-so-i-built-ai-to-review-it-d15274522d32?source=rss-4dbb689fdf6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/d15274522d32</guid>
            <category><![CDATA[software-engineering]]></category>
            <category><![CDATA[ai-code-review]]></category>
            <category><![CDATA[claude-code]]></category>
            <category><![CDATA[developer-experience]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[Tushar Garg]]></dc:creator>
            <pubDate>Sun, 18 Oct 2026 19:03:08 GMT</pubDate>
            <atom:updated>2026-10-18T19:03:08.285Z</atom:updated>
            <content:encoded><![CDATA[<h3>The problem: AI made writing code cheap. Reviewing it didn’t get cheaper.</h3><p>Obviously, my team started using AI to write code.</p><p>Within weeks, the number of PRs waiting for my review roughly doubled or even tripled.</p><p>The code was coming in faster than ever. But every PR still needed someone to ask the questions that actually catch bugs. What else uses this component? Which user flows does this touch? What happens on refresh, on an empty list, on a slow network?</p><p>I was that someone. And I couldn’t keep up.</p><p>I had two options.</p><p>Lower the bar and skim. Or find a way to scale the way I review.</p><p>I wasn’t willing to do the first one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*mUdPT3wRBISDzT8M" /><figcaption>AI Slop PR Review</figcaption></figure><h3>The idea: don’t build a reviewer. Encode how I review.</h3><p>There are plenty of AI review bots. Most of them leave comments like “consider adding error handling” on line 42 and call it a day.</p><p>That’s not a review. That’s a linter with opinions.</p><p>When I review a PR, I don’t read the diff top to bottom. I follow a process. I look at what the change can break, walk through the flows a user would actually take, test it, and only then read the code line by line.</p><p>So instead of asking AI to “review this PR”, I wrote my process down as a Claude Code skill: a single markdown file in the repo that tells the agent exactly how to review, in what order, and what good looks like.</p><h3>How it reviews: six phases, in the order I’d do it</h3><ol><li><strong>Context.</strong> Read the PR description, the diff, existing review comments, CI results and any bot comments. Check the boring stuff too: commit format, branch name, the base branch, leftover console.logs and flags hardcoded to true for local testing. If the diff is huge, split it by area and review each part in parallel.</li><li><strong>Blast radius.</strong> For every changed export (component, hook, selector, API method), find every place it’s used. A one-line change to a shared component can break ten screens that aren’t in the diff. This phase ends with a map: changed files → product areas → user journeys.</li><li><strong>User journeys.</strong> Walk each affected journey step by step, for each type of user. Not just the happy path: empty state, error state, loading state, refresh mid-flow, back button, deep links, 0 rows, 1 row, 5,000 rows, old data created before this change.</li><li><strong>Code lenses.</strong> Now read the code, through specific lenses: correctness, async and lifecycle bugs (stale responses, state updates after unmount), render loops, security, money and date handling, performance, and whether the change can be rolled back safely.</li><li><strong>Triage.</strong> Every finding gets two questions. Did this PR introduce it, or was it already there on the base branch? And can a user actually reach it? Then a severity: Critical, High, Medium or Low. Only Medium and above must be fixed. Lows are collapsed, so the author isn’t buried in nitpicks.</li><li><strong>End-to-end testing.</strong> The agent opens the PR’s preview environment in a browser, drives each journey, reads network calls and console errors, and runs a regression pass over the core flows, even ones the PR didn’t touch. Every pass or fail gets a screenshot. It never types credentials; I log in myself.</li></ol><p>The output is a report: verdict, blast radius map, findings with exact file and line, a reproducible case for each, the E2E results table, and what was <em>not</em> tested and why.</p><p>It also rewrites the PR title and description to match what the PR actually does now: summary, changes, affected flows, testing and risks.</p><p>Every PR runs left to right through the six phases. If a medium or high issue is still open, it loops back through fix, re-review and retest; only a clean result reaches you.</p><h3>The fix loop: it doesn’t stop at the report</h3><p>Finding bugs is half the job. On your own PR, you can run it with --fix, and it goes further.</p><pre>loop:<br>  fix every open Medium+ finding<br>  run the linter on touched files<br>  re-review the new diff<br>  retest the affected journeys<br>  new Medium+ issue found? → loop again<br>  otherwise → stop</pre><p>Fix. Re-review. Retest. Repeat.</p><p>It keeps going until every medium and high priority issue is gone.</p><p>Two limits keep it honest. It stops after five rounds and asks me, because a bug that survives five fixes is usually a design problem, not a code problem. And it stops immediately if a fix needs a product or design decision. Those are mine to make.</p><p>It never commits. Every change stays in the working tree for me to read.</p><h3>Self-improvement: every review makes the next one sharper</h3><p>A review process written once goes stale. Teams learn things. Someone gets burned by a null check, and from then on everyone looks for it.</p><p>So I designed the skill to learn the same way a team does.</p><p>To start, I mined about 1,500 real review comments that engineers on my team had left on past PRs. Patterns jumped out fast: the same feedback, given by different people, over and over.</p><ul><li>Null-safety: using ?? where 0, false or &quot;&quot; are valid values, not ||</li><li>One source of truth: never reading the same flag from four different places</li><li>Every API call needs error handling the user can actually see</li><li>No magic strings or numbers; constants live in one place</li><li>Hygiene: dead code, debug logs, unrelated changes sneaking into the PR</li></ul><p>Those became a checklist the skill applies to every single PR.</p><p>Then I closed the loop. After every review, the skill reads the comments human reviewers left, on that PR and on any PR since the last run. A new recurring pattern gets folded back into the skill as a short rule. Generalized, not pasted. No duplicates.</p><p>The skill file is version-controlled like any other code, so every lesson it learns shows up in a diff I can review.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/0*1iClHOIW8f67mR_v.jpg" /></figure><h3>Guardrails: the agent does the work, a human makes the calls</h3><p>An agent that can edit code, open a browser and talk to GitHub needs hard limits. These are written into the skill as rules, not suggestions:</p><ul><li><strong>No commit, push or deploy</strong> without my explicit go-ahead. It edits the working tree only.</li><li><strong>Never touches protected branches.</strong> And it reads the PR’s base branch instead of assuming it.</li><li><strong>Comments are drafted, not posted.</strong> Posting on GitHub is an outward action, so it shows me the drafts and waits.</li><li><strong>Never types credentials.</strong> For E2E testing, I log in myself.</li><li><strong>Never approves or rejects a PR.</strong> That stays a human decision.</li><li><strong>Respects the stack.</strong> If the codebase is pinned to specific framework versions, any suggestion that breaks them gets flagged, not applied.</li></ul><p>The agent can find the bugs, fix them and prove the fix with screenshots.</p><p>I still approve every merge.</p><h3>What I learned building it</h3><p><strong>The prompt isn’t the product. The process is.</strong> The skill works because it encodes a review process that already worked when a human ran it. AI didn’t invent the method. It made the method repeatable.</p><p><strong>Triage matters more than detection.</strong> Finding 40 issues is easy. Telling the author which 3 actually matter, and which ones were already there before their PR, is what makes a review useful instead of exhausting.</p><p><strong>Your team’s comments are your best training data.</strong> Generic best practices are everywhere. The things your team keeps repeating in reviews are specific to your codebase, and they’re sitting in your PR history right now.</p><p><strong>Guardrails make it trustworthy.</strong> People only rely on an agent when they know what it will never do on its own.</p><blockquote>This is just my way of reviewing it, I wanted to share that everyone should be automating the PR Review process also in this era of AI.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ZhwJJN1e4ffNqixr.jpeg" /></figure><h3>Try it on your own repo</h3><p>I’ve open-sourced a generic version of the skill on GitHub, with the company-specific rules stripped out:</p><p><a href="https://github.com/tushargarg17/pr-review-skill">GitHub - tushargarg17/pr-review-skill</a></p><p>Fork it, swap in your own stack and conventions, and run it on your next PR.</p><p>AI made writing code cheap.</p><p>The review is where your judgement still lives. So scale the judgement, not just the speed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d15274522d32" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Countdown Timer Increased. That Should Be Impossible.]]></title>
            <link>https://medium.com/@tshrgarg2010/a-countdown-timer-increased-that-should-be-impossible-50e7e18c533b?source=rss-4dbb689fdf6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/50e7e18c533b</guid>
            <category><![CDATA[debugging]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[web-browser]]></category>
            <dc:creator><![CDATA[Tushar Garg]]></dc:creator>
            <pubDate>Thu, 14 May 2026 16:53:58 GMT</pubDate>
            <atom:updated>2026-05-14T16:53:58.268Z</atom:updated>
            <content:encoded><![CDATA[<p>A countdown timer increased, which should be impossible. And yet… that’s exactly what users were seeing in production.</p><p>A user reported:</p><blockquote>“It showed time T1… then later it showed time T2 (T2 &gt; T1)” <em>🤯</em></blockquote><p>At first, it sounded absurd. Timers don’t randomly increase, especially not countdown timers.</p><p>So naturally, I thought there would be some bug in the timer logic.</p><p>But reality turned out to be much stranger.</p><p>And honestly?</p><p>This bug completely changed how I think about browsers, caching, and frontend systems 🌐</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/0*sYwLV2NJaotfDZDH.gif" /><figcaption>Example Timer</figcaption></figure><h3>Everything Looked Correct</h3><p>Before diving deeper, a high-level overview of our timer:</p><p>The backend sent the start and end timestamps, and the frontend calculated the remaining time as a live countdown timer.</p><p>Coming back to the bug, the strange part was:</p><p>Nothing looked broken. No backend issues. No recent deployments. No logs showing an increase in the countdown timer. No obvious failures. Nothing suspicious.</p><p>We checked the timer logic. Correct.</p><p>We checked backend timestamps. Correct.</p><p>We checked logs on Amazon CloudWatch. Still nothing.</p><p>Not a single clue.</p><p>That’s when things started getting frustrating 😵.</p><blockquote>Debugging becomes very difficult when everything looks correct, but nothing works.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/389/0*UfuR1LpPmtPxDw_2.jpg" /><figcaption>The hardest bugs are the ones where everything appears normal.</figcaption></figure><h3>The Hardest Bugs Are the Ones You Can’t Reproduce</h3><p>I spent almost an hour trying random things.</p><p>Refreshing the page. Opening multiple tabs. Switching windows. Waiting for timers to update. Network throttling. Performing random user interactions.</p><p>Nothing worked.</p><p>At some point, I realized something important: I was debugging the code. But maybe the problem wasn’t in the code. So I changed the question.</p><p>Instead of asking, <strong>“What’s broken?”</strong>, I started asking: <strong>“What is the user doing differently?”</strong></p><p>And that changed everything.</p><h3>The Breakthrough</h3><p>After multiple failed attempts, I finally managed to recreate it.</p><p>Here’s what I did:</p><ol><li>Opened the timer page</li><li>Let the timer run for some time</li><li>Closed the tab</li><li>Reopened it</li></ol><p><strong>💥 The timer increased</strong>.</p><p>Now it finally made sense. Or at least… part of it did. Then I pushed it further.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*62BxA_uAzxik40Ql" /></figure><p>I opened multiple tabs of the same timer. Triggered the issue in one tab. Every tab broke. All of them started showing the same incorrect and increased time.</p><p>At this point, I showed it to my team.</p><p>Everyone was shocked. A few people even laughed because it made absolutely no sense.</p><p>And honestly?</p><p>That’s when it stopped feeling like a bug. It became a mystery 🕵️.</p><h3>The Real Problem Was Never the Timer</h3><p>The timer itself wasn’t broken. The real issue was our time synchronization system. Let’s first understand the architecture of our timer logic.</p><p>Our server was in India 🇮🇳</p><p>But our users were global 🌍</p><p>So, <strong>Server Time ≠ Client Device Time</strong></p><p>That meant users could be in different time zones, and thus local machine time couldn’t always be trusted.</p><p>So we had an API that returned the server time.</p><p>Then we calculated:</p><pre>timeDiff = serverTime - Date.now()<br>adjustedTime = Date.now() + timeDiff</pre><p>And this adjusted time was used across all timer calculations.</p><p>Simple. Reliable. Works perfectly ✅</p><p>Until it doesn’t ❌</p><h3>The Part That Finally Clicked</h3><p>Once I understood the setup and added a few logs, the bug suddenly became explainable.</p><p>Here’s what was actually happening.</p><p>At 5:00 PM:</p><pre>serverTime = 5:00<br>clientTime = 5:00<br>timeDiff = 0</pre><p>Everything worked. The timer behaved correctly.</p><p>Then the user closed the tab. Time passed. Now it was 5:05 PM. The user reopened the app.</p><p>Ideally, this should happen:</p><pre>serverTime = 5:05<br>clientTime = 5:05<br>timeDiff = 0</pre><p>Still correct. Still fine. But that’s NOT what happened.</p><p>And this is where things finally clicked 💥.</p><p>The API response was being cached at the browser level. So instead of getting fresh server time, the browser returned the OLD response.</p><p>Now the system looked like this:</p><pre>serverTime = 5:00 (cached)<br>clientTime = 5:05 (current)<br>timeDiff = 5 minutes</pre><p>The countdown timer gained 5 minutes.</p><p>This was the bug. Not timer logic. Not backend calculations. Just stale cached data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HGT6bLPTRAsNCg1d" /></figure><h3>But Why Did Every Tab Break?</h3><p>At this point, one mystery was solved.</p><p>But another remained. Why did ALL tabs show the wrong timer? And this is where things got worse.</p><p>We were storing timeDiff in localStorage. And localStorage is shared across browser tabs.</p><p>That means:</p><ol><li>One tab stores the wrong timeDiff value</li><li>Every other tab reads the same value</li></ol><p><strong>One stale value corrupted the entire timer system</strong> 💣</p><p>That’s what made this bug so dangerous. The issue silently spread across the app.</p><h3>The Mental Model That Changed Everything for Me</h3><p>This bug taught me something important.</p><p>Frontend bugs are not always:</p><ul><li>bad logic</li><li>broken APIs</li><li>incorrect calculations</li></ul><p>Sometimes they’re:</p><ul><li>stale data</li><li>browser caching</li><li>shared state</li><li>unexpected browser behavior</li></ul><p><strong>And those bugs are much harder to debug because everything appears normal.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*50blkpw5SF7Evnuy" /></figure><h3>Why This Bug Was So Hard to Debug</h3><p>The hardest part wasn’t fixing the issue. The hardest part was understanding it. Because this bug looked exactly like a logic issue.</p><p>But it wasn’t. The problem was happening somewhere deeper.</p><p><strong>And honestly? Those are the bugs that humble you.</strong></p><h3>The Fix</h3><p>We fixed this in two stages.</p><h4>Temporary Hotfix</h4><p>We started sending Date.now() in the API payload.</p><p>Since the payload changed every time, the response stopped getting cached.</p><h4>Proper Fix</h4><p>We disabled caching entirely for that endpoint:</p><pre>Cache-Control: no-store</pre><p>This ensured the browser always fetched fresh server time ✅.</p><h3>Final Thoughts</h3><p>This started as: <br><em>“Why is the timer increasing?”</em></p><p>But the real answer had nothing to do with the timer.</p><p>It was:</p><ul><li>stale cached data</li><li>shared browser storage</li><li>real-world user behavior</li></ul><p>And honestly?</p><p><strong>That’s what made this bug unforgettable.</strong></p><p><strong>Because sometimes the hardest frontend bugs are not about React, components, rendering, or state management.</strong></p><p><strong>Sometimes they’re about understanding how browsers actually behave.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=50e7e18c533b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CDN and Caching Didn’t Make My App Faster — Here’s Why]]></title>
            <link>https://medium.com/@tshrgarg2010/cdn-and-caching-didnt-make-my-app-faster-here-s-why-7062392b3752?source=rss-4dbb689fdf6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7062392b3752</guid>
            <category><![CDATA[web-performance]]></category>
            <category><![CDATA[frontend-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[content-delivery-network]]></category>
            <category><![CDATA[caching]]></category>
            <dc:creator><![CDATA[Tushar Garg]]></dc:creator>
            <pubDate>Sat, 18 Apr 2026 15:27:15 GMT</pubDate>
            <atom:updated>2026-04-18T15:27:15.174Z</atom:updated>
            <content:encoded><![CDATA[<p>When I first implemented aggressive caching using a CDN, I was convinced my Web Vitals would improve significantly.</p><p>Edge locations. Cached assets. Lower latency.</p><p>What could possibly go wrong?</p><p>A few days into monitoring production metrics, reality hit.</p><p>TTFB improved noticeably ✅<br>FCP barely moved ❌<br>LCP was still poor ❌</p><p>That didn’t make sense.</p><p>If content was being served faster from the edge…<br>why weren’t users <em>seeing</em> it faster?</p><p>At that point, I started questioning everything:</p><ul><li>Was edge computing not as effective as I thought?</li><li>Was my CDN misconfigured?</li></ul><p>Instead of randomly tweaking configs, I decided to step back.</p><p>I went back to the fundamentals — <br>the actual definitions of Web Vitals.</p><p>Specifically:</p><ul><li>TTFB</li><li>FCP</li><li>LCP</li></ul><p>And that’s when things finally clicked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UOCA6H0-ctw6x05O" /><figcaption>TTFB improved with CDN, but FCP and LCP remained almost unchanged — the moment things stopped making sense</figcaption></figure><h3>Revisiting the Definitions (This Matters More Than You Think)</h3><p>At this point, I realized something important:</p><blockquote><strong><em>I was trying to fix performance… without fully understanding what I was measuring.</em></strong></blockquote><p>So I went back to basics.</p><p>Not blog summaries.<br>Not assumptions.</p><p>The actual definitions of Web Vitals.</p><p>And that changed everything.</p><h3>Time To First Byte (TTFB) ⏱️</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/892/0*sO9SQb315L_q0bfD" /><figcaption>TTFB</figcaption></figure><p>TTFB measures:</p><blockquote><em>The time from when the browser starts navigation — to when it receives the </em><strong><em>first byte of HTML</em></strong></blockquote><h4>What actually happens here?</h4><p>Before that first byte arrives, a lot happens:</p><ul><li>DNS lookup</li><li>TCP + TLS handshake</li><li>CDN edge processing</li><li>Origin fetch (on cache miss)</li></ul><h4>Real-world analogy</h4><p>Think of ordering food:</p><p>TTFB = time until the waiter <em>brings the first dish</em></p><p>Not the full meal. Just the first sign that something has arrived.</p><h4>Key insight</h4><p>TTFB is a <strong>delivery metric</strong></p><p>And this is exactly where CDNs shine.</p><h3>First Contentful Paint (FCP) 🎨</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qFmfIptseoPzYfH2.jpg" /><figcaption>FCP Visualisation</figcaption></figure><p>FCP measures:</p><blockquote><strong><em>The moment when the browser renders anything visible on screen</em></strong></blockquote><p>Text. Image. Background. SVG.</p><p>Anything.</p><h4>But here’s the catch 👇</h4><p>FCP doesn’t depend on just “getting data fast”</p><p>It depends on <strong>rendering readiness</strong></p><h4>What it waits for:</h4><ul><li>HTML parsing</li><li>CSS download + parsing</li><li>Style calculation</li><li>Layout</li><li>Paint</li></ul><h4>What can block it:</h4><ul><li>Render-blocking CSS</li><li>Blocking JavaScript</li></ul><h4>What it does NOT wait for:</h4><ul><li>Full JS bundles</li><li>Hydration</li><li>Data fetching (unless it blocks rendering)</li></ul><h4>Real-world analogy</h4><p>TTFB brought food to your table.</p><p>FCP is when you can <strong>actually see the food</strong></p><h4>Key insight</h4><p>FCP is a <strong>rendering metric</strong>, not just a loading metric.</p><h3>Largest Contentful Paint (LCP) 🏁</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*82wRP_sKF9onowcj" /><figcaption>FCP n LCP comparison</figcaption></figure><p>LCP measures:</p><blockquote><em>When the </em><strong><em>largest visible element</em></strong><em> in the viewport finishes rendering</em></blockquote><p>Usually:</p><ul><li>Hero image</li><li>Large heading</li><li>Main content block</li></ul><h4>What LCP depends on:</h4><ul><li>When element is added to DOM</li><li>When CSS is ready</li><li>When resource (image/font) loads</li><li>When it is painted</li></ul><h4>Crucial detail</h4><p>LCP does NOT wait for:</p><ul><li>Entire page load</li><li>Full route completion</li></ul><p><strong>Only the largest visible element</strong></p><h4>Real-world analogy</h4><p>TTFB = food arrived<br> FCP = you see food<br> LCP = <strong>your main dish is finally served</strong></p><h3>Who Actually Measures Web Vitals? 📊</h3><p>At a low level, Web Vitals are measured by the <strong>browser itself</strong>. There are different tools, which record that data and present it in a usable way.</p><p>Specifically, browsers like Google Chrome use internal APIs to track performance events.</p><p>These include:</p><ul><li>Navigation timing (for TTFB)</li><li>Paint timing (for FCP)</li><li>Largest content tracking (for LCP)</li></ul><p>The browser observes what’s happening during page load and records these metrics.</p><h3>Why caching helped TTFB (but not FCP or LCP) 🤯</h3><p>Once these definitions were clear…</p><p>Everything made sense.</p><h4>TTFB: Big win with caching</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/785/0*8M0agx6qVNqoJ3nH" /><figcaption>CDN and Edge Locations</figcaption></figure><p>With CDN caching:</p><ul><li>HTML served from nearby edge</li><li>Network latency reduced</li><li>Fewer origin hits</li></ul><p>First byte arrives faster</p><p>This shows up immediately in metrics.</p><p>No surprises.</p><h3>Reality check 💣</h3><p>Caching cannot speed up:</p><ul><li>JavaScript execution</li><li>Client-side rendering</li><li>Hydration delays</li></ul><h3>The mental model that finally clicked</h3><p>This is what made everything simple:</p><p><strong>TTFB → How fast did the page arrive?</strong><br><strong>FCP → When did something appear?</strong><br><strong>LCP → When did the page feel complete?</strong></p><p>And most importantly:</p><p>CDNs strongly affect <strong>arrival</strong><br>Weakly affect <strong>rendering</strong><br>Barely affect <strong>execution</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7062392b3752" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Optimized React Performance Without Touching React Code]]></title>
            <link>https://medium.com/@tshrgarg2010/i-optimized-react-performance-without-touching-react-code-1b488720d01e?source=rss-4dbb689fdf6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1b488720d01e</guid>
            <category><![CDATA[cdn]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[compression]]></category>
            <dc:creator><![CDATA[Tushar Garg]]></dc:creator>
            <pubDate>Tue, 10 Feb 2026 10:55:29 GMT</pubDate>
            <atom:updated>2026-02-10T16:37:20.788Z</atom:updated>
            <content:encoded><![CDATA[<h3>TL;DR</h3><p>My React app was already behind a <strong>CDN</strong>,<strong> Amazon CloudFront</strong>, but performance still had headroom because I wasn’t using all the CDN&#39;s benefits.</p><p><strong>Caching and Compression.</strong></p><p>Once configurations were set up correctly, the results were clear:</p><ul><li><strong>TTFB improved mostly due to caching</strong></li><li>Cache invalidation was added to deployments</li><li>Zero React code changes</li></ul><p>Made these changes to the Staging Env first, then rolled the same setup into Production after one week of observation.</p><p>Result: <strong>faster loads, smaller payloads, zero React code changes</strong>.</p><p>If the TL;DR sparked your interest, this article walks through the path I took to discover these concepts, apply them in a real system, and work through the challenges along the way.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*J7qIyrWJWol1gMAG.jpg" /></figure><h3>Still looking at how to improve performance</h3><p>I was looking for ways to make my React application even faster, even after resolving <a href="https://medium.com/@tshrgarg2010/why-my-react-app-felt-slow-even-though-nothing-was-broken-2f1b6c65b975"><strong>812+ cyclic dependencies</strong>, which had already delivered a noticeable performance boost</a>.</p><p>I knew the usual playbook: reduce bundle and chunk sizes by removing unused code and improving code splitting. Those techniques work, and we were already using them. But I wanted to explore something beyond the obvious, which pushed me into a bit of research.</p><p>For context, this is a <strong>React + Vite</strong> application deployed on <strong>S3 behind CloudFront</strong>.</p><p>While digging deeper, I started reading about compression. That immediately triggered a realization — <strong>we already rely on Gzip compression for XHR and Fetch</strong> requests. If compression works so well for API responses, why wouldn’t the same idea apply to frontend assets as well?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/0*sdl6__KC2dj_ikoE.png" /><figcaption>high level working of Cloudfront</figcaption></figure><h3>What Compression Actually Does?</h3><p><strong>Compression improves performance by reducing the number of bytes sent over the network</strong>. It uses compression algorithms to encode files more efficiently, which works especially well for text-based assets like JavaScript, CSS, and HTML.</p><p>When a browser requests a resource, it advertises supported compression methods using the Accept-Encoding header. The server or CDN responds with a compressed version, and the browser automatically decompresses it before rendering or execution.</p><p>Smaller payloads mean faster downloads, which leads to quicker rendering and earlier page interactivity — all without any changes to application code.</p><h3>A Quick Detour: Gzip, Brotli, and Zstandard</h3><p>Browsers and servers agree on how to compress responses using the Accept-Encodingheader. Based on this header, the server or CDN chooses the best algorithm both sides understand.</p><p>You can also check which encoding is being applied based on the Content-Encodingheader.</p><p>Historically, <strong>Gzip</strong> has been the default.</p><p>It’s widely supported, fast to decompress, and good enough for most text-based assets. That’s why it became the standard for years.</p><p>Then came <strong>Brotli</strong>.</p><p>Brotli was designed specifically for web content like JavaScript, CSS, and HTML.<br>It produces significantly smaller files than Gzip for these asset types, especially at higher compression levels.</p><p>Modern browsers support Brotli out of the box, which is why <strong>Amazon CloudFront prefers it automatically</strong>, if configured<strong>.</strong></p><p>Smaller payloads.<br>Fewer bytes over the wire.<br>Better real-world performance.</p><p>There’s also <strong>Zstandard (zstd)</strong>.</p><p>Zstd is a newer compression algorithm that aims to balance <strong>very high compression ratios</strong> with <strong>extremely fast decompression</strong>.<br>It’s popular in backend systems, databases, and internal services.</p><p>However, browser support for zstd is still limited, which is why it’s not commonly used for web asset delivery yet.<br>Until browser adoption improves, CDNs stick to Brotli and Gzip for frontend content, if configured properly.</p><p>In practice, this means you don’t need to choose anything manually.</p><p>CloudFront looks at what the browser supports and makes the decision for you.<br>Brotli when possible.<br>Gzip as a fallback.</p><p>You get the best option automatically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/538/1*UoNd6uaYMnpS4JZ5eSHVaw.png" /><figcaption>accept encoding network request header</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/569/1*lYX5_XWgfIrxAN1hwHCNqw.png" /><figcaption>content encoding network request header</figcaption></figure><blockquote>Coming back to the story — just a quick clarification. At this point, we still hadn’t implemented anything yet. Everything discussed so far was purely informational, meant to build a clear understanding of what compression is and the different techniques involved.</blockquote><h3>Vite supports built-in compression</h3><p>Vite provides built-in support for asset compression through a plugin. By installing vite-plugin-compression as a development dependency and adding it to your Vite plugins configuration, you can easily enable compression for all generated build files.</p><pre>viteCompression<br>({<br>        algorithm: &quot;gzip&quot;, // or &#39;brotliCompress&#39;<br>        threshold: 1024, // only compress files &gt; 1KB<br>})</pre><p>You can read more about this on the official <a href="https://www.npmjs.com/package/vite-plugin-compression">NPM Docs</a>.</p><p>After testing this in staging, I could see that chunk sizes were genuinely smaller due to compression, which also reduced the time required to fetch each chunk. At that point, it already felt like a solid win. Lighthouse scores improved locally, and I was close to rolling the changes into production — but I didn’t.</p><h3>But we do have a CDN. Is it helpful?</h3><p>My application was already hosted on <strong>Amazon S3</strong> and served through <strong>Amazon CloudFront</strong>. From an architectural standpoint, this was an ideal setup. However, <strong>placing a CDN in front of your application doesn’t automatically guarantee optimal delivery </strong>if you haven’t made the proper configurations.</p><p>While going through CloudFront’s documentation, I realized that it natively supports <strong>response compression in addition to caching</strong>. I enabled caching and compression for the staging environment and reverted the compression-related changes I had previously added via the Vite plugin. In the end, it came down to a configuration toggle — <strong>CloudFront already had the capability, it just needed to be enabled</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HdyMV4Q_LCi7FWZyABEgIA.png" /><figcaption>option that needs to be selected for enabling caching and compression</figcaption></figure><h3>Was it actually that easy, just a toggle?</h3><p>Not quite. Any architectural change comes with the risk of unexpected issues.</p><p>The <strong>first problem was cache invalidation</strong> — the classic CDN challenge. The solution was straightforward: I added a step to the staging deployment pipeline (using GitHub Actions) to <strong>invalidate the CloudFront cache on every new deployment</strong>. That addressed the issue cleanly.</p><pre>- name: Invalidate CloudFront Cache<br>        run: |<br>          aws cloudfront create-invalidation \<br>            --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \<br>            --paths &quot;/${{ steps.format.outputs.branch }}/*&quot;</pre><p>Before I could fully validate this, a second challenge surfaced: <strong>IAM permissions</strong>. The AWS user used by GitHub Actions already had access to S3, but it also needed permissions to trigger CloudFront invalidations. Once the required access was added, the pipeline could manage both asset uploads and cache invalidation.</p><p>With these changes in place, caching and compression started working seamlessly in the staging environment. I decided to let it run for a while and observe the behavior before moving forward.</p><h3>What were the results now?</h3><p>Once I enabled proper caching policies in CloudFront along with response compression, the impact was immediate. <strong>Assets started being served from CloudFront edge locations</strong> instead of the origin, which significantly reduced <strong>TTFB</strong>. At the same time, those assets were delivered in compressed form, <strong>reducing payload sizes and improving download times</strong>.</p><p>This was the first clear signal that the application was finally being delivered the way it should have been from the start — fast responses from the edge and smaller assets over the wire.</p><h3>Rolling the Same Setup into Production</h3><p>After monitoring the setup for a week and finding no issues, I rolled the same configuration into production.</p><p>The CloudFront configuration and IAM permissions remained the same. The only difference was the cache invalidation logic.</p><p>In staging, multiple branches were deployed, each mapped to a branch-specific domain, so cache invalidation needed to be scoped to the corresponding branch path. In production, the domain was shared, which meant a global invalidation was sufficient.</p><pre>- name: Invalidate CloudFront Cache (Prod)<br>        run: |<br>          aws cloudfront create-invalidation \<br>            --distribution-id ${{ secrets.CLOUDFRONT_DISTRIBUTION_ID }} \<br>            --paths &quot;/*&quot;</pre><p>But the impact was immediate. Payloads were smaller, and deployments remained predictable — all without changing a single line of React code.</p><p>Given that the infrastructure setup was largely the same, I rolled these changes out across all of my repositories. <strong>The results were consistent: Lighthouse scores improved, TTFB Web Vital improved, and one new Sentry alert appeared</strong>.</p><p>The alert showed up only in production, because we had Sentry and logging only for the production env. It flagged an <a href="https://docs.sentry.io/product/issues/issue-details/performance-issues/uncompressed-asset/">U<strong>ncompressed Asset</strong></a> error — something we hadn’t seen before — and it was limited to a single repository.</p><p>After digging deeper, I discovered that <strong>CloudFront doesn’t compress files larger than 10 MB</strong>. That limitation made sense, but it raised another question: why did we even have <strong>a chunk larger than 10 MB</strong>?</p><p>Further investigation revealed the real issue. That repository wasn’t using proper lazy loading or code splitting, which caused all the code to be bundled into a single, oversized chunk. Once these were implemented, the chunks became smaller, were loaded only when needed, and CloudFront compression started working as expected.</p><p>The oversized chunk disappeared — and so did the Sentry alert.</p><h3>A misunderstanding resolved</h3><p>I was confident my Web Vitals would improve <strong>massively</strong>.</p><p>Edge locations. Cached assets. Lower latency.<br>What could go wrong?</p><p>After a few days of monitoring production metrics, reality hit.</p><ul><li><strong>TTFB improved noticeably</strong> ✅</li><li><strong>FCP and LCP barely moved</strong> ❌</li></ul><p>That made me curious.<br>Was edge computing not working?<br>Was my CDN misconfigured?</p><p>So instead of tweaking configs blindly, I went back to the <strong>actual definitions</strong> of Web Vitals — specifically <strong>TTFB, FCP, and LCP</strong>. That’s when things finally clicked.</p><p>After digging deeper into these metrics, I gained a clearer understanding of what they actually measure. <strong>TTFB is fundamentally a delivery-level metric</strong>, and this is where CDNs provide the most value. Caching and compression can only optimize how fast bytes reach the browser — they can’t speed up JavaScript execution, client-side rendering decisions, hydration delays, or other frontend computations.</p><p>If the goal is to cache data on the client, that’s a separate concern altogether and better handled using tools like Redux, the Context API, or other state management solutions.</p><h3>What This Experience Reinforced</h3><p>This entire journey reinforced one key idea.</p><p>Not all frontend performance wins live inside React components.</p><p>They also live in how your app is delivered over the network.</p><p>If your React app is already behind CloudFront, or any other CDN, but still feels slower than expected, caching and compression are the first places worth looking at.</p><p>They’re simple.<br>They’re powerful.<br>And they’re a guaranteed way to make your React app faster.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1b488720d01e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why My React App Felt Slow Even Though Nothing Was Broken]]></title>
            <link>https://medium.com/@tshrgarg2010/why-my-react-app-felt-slow-even-though-nothing-was-broken-2f1b6c65b975?source=rss-4dbb689fdf6d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f1b6c65b975</guid>
            <category><![CDATA[cyclic-dependency]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[frontend]]></category>
            <dc:creator><![CDATA[Tushar Garg]]></dc:creator>
            <pubDate>Wed, 21 Jan 2026 10:52:00 GMT</pubDate>
            <atom:updated>2026-01-31T10:37:08.576Z</atom:updated>
            <content:encoded><![CDATA[<h3>TL;DR</h3><p>I was trying to make a React app feel faster — not fixing a bug, not responding to an outage. Everything <em>worked</em>, but initial loads felt heavier than they should. Digging into production bundles revealed something alarming: feature-specific code was being shipped in the base chunk, even though it was supposed to be lazy-loaded.</p><p>The underlying issue was <strong>circular dependencies</strong> — more than <strong>800 of them</strong>, with some chains extending <strong>15–16 levels deep</strong>. At a high level, a cyclic dependency means that when two modules (say, A and B) depend on each other and are <strong>lazily loaded independently</strong>, loading module A also pulls module B into the same chunk — and vice versa.</p><p>These cycles quietly undermined <strong>tree-shaking and code-splitting</strong>, causing unnecessary code to be duplicated across chunks. The outcome was predictable but costly: <strong>bloated bundles, degraded Core Web Vitals, unstable local development behavior, and “lazy-loaded” modules that weren’t actually lazy at all.</strong></p><p>After <strong>refactoring over 300 files</strong> to correct dependency direction and enforce clearer architectural boundaries, the number of circular dependencies dropped from <strong>812 to 3</strong>. <strong>Bundle size fell from ~17 MB to &lt;5 MB, Lighthouse Performance jumped from 49 → 72, and FCP/LCP improved</strong> dramatically. The feature code finally loaded only when routes were visited.</p><p>Nothing magical happened — we simply stopped shipping code that users didn’t ask for. Circular dependencies don’t fail loudly, but fixing them delivers some of the highest-ROI performance wins you can get in a modern frontend codebase.</p><p>If the TL;DR sparked your interest, this article walks through <strong>the debugging process, mental models, and tooling</strong> that helped me identify <strong>cyclic dependencies as the real performance bottleneck — and prove it</strong>.</p><p>I wasn’t chasing a bug.<br>I wasn’t responding to an outage.</p><p>I was simply trying to make our <strong>React</strong> application feel faster.</p><p>The app worked fine. Lighthouse scores weren’t alarming. Sentry dashboards (error and performance tracking tool) were quiet, and there were no customer complaints. Yet something didn’t feel right — initial loads felt heavier than expected, and route transitions didn’t behave as lazily as the code implied they should.</p><blockquote>“Nothing was broken. And that’s what made it dangerous.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H0NgAt6uLc8k5h1YgirQtw.png" /></figure><p>When performance issues don’t announce themselves loudly, my first instinct is to slow down and understand the system. I started by going through the codebase, trying to reason about what could realistically be contributing to the delay. I reviewed recent changes, walked through critical paths, and then moved to Sentry — focusing specifically on network request waterfalls to understand where time was actually being spent.</p><p>Nothing looked broken. Requests were being completed. There were no obvious spikes, no failed calls. But one thing kept surfacing consistently: the <strong>initial JavaScript payload</strong> was taking longer than it should to download and execute.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/381/0*-NW5yjLiMrIH_Xvo.png" /><figcaption>image depicting different stages of a network request</figcaption></figure><p>That’s when a few very basic questions started forming in my head.</p><p>What loads on first paint?<br>What truly belongs in the base bundle?<br>What should only appear after a route change?</p><p>With those questions in mind, <strong>I opened the production build and started inspecting the chunks.</strong></p><p>At first, what I found didn’t seem alarming. There were a few pieces of code in the base chunk that could technically be avoided — <strong>some unused logic sitting at the root level</strong>. We also had internationalization support via i18n, and in our case, <strong>two large JSON files (two languages) were being bundled upfront. That explained <em>part</em> of the size.</strong></p><p>I cleaned those up. Reduced the base chunk a bit. Optimized what I could.</p><p>But the impact wasn’t meaningful.</p><p>The base chunk was smaller, yes — but not <em>enough</em> to explain what I was seeing. The initial load still felt heavier than expected. The numbers didn’t justify the feeling.</p><p>So I went back again. Slower this time.</p><p>I kept going through the production chunks, reading minified code line by line, constantly checking what I was seeing against those same questions — what belongs here, and what absolutely does not.</p><p>That’s when something genuinely made me stop.</p><p>There were pieces of <strong>feature-specific code</strong> sitting inside the base chunk.</p><p>Not shared utilities. Not core infrastructure.</p><p><strong>Actual feature logic — code that should only be fetched when components are rendered, when routes are visited, when lazy loading kicks in.</strong></p><p>And yet, it was already there. <strong>Loaded upfront. For every user.</strong></p><p>At that point, this stopped feeling like a minor optimization issue and started feeling like something deeper.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LbDwDVrTUsjNlC3n" /><figcaption>image depicting a sentry dashboard for network requests</figcaption></figure><h3>When minified bundles start telling uncomfortable truths</h3><p>Looking at minified JavaScript isn’t glamorous — but it’s honest.</p><p>Once you know what you’re looking for, patterns start to reveal themselves quickly. Code that clearly belonged to feature-specific components was sitting inside the base chunk — the code downloaded by every single user on first load.</p><p>This wasn’t a small helper. It wasn’t a shared constant.</p><p>It was real feature logic, and not just one feature, but a lot of them.</p><p>And the worst part?</p><p>That feature was already lazily loaded.</p><blockquote>“If code is lazy in theory but eager in production, the problem isn’t React — it’s architecture.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/0*f_XfGCvD8TRaAUMF.png" /><figcaption>image depicting from where to see minified code of frontend chunks</figcaption></figure><h3>At first, I blamed the usual suspects</h3><p>Bad imports.<br>Over-shared utilities.<br>Maybe an accidental re-export hiding behind a barrel file.</p><p>Those are usually the culprits when code shows up where it shouldn’t.</p><p>So I checked.</p><p>But the imports looked clean. Routes were defined correctly. React.lazy was doing exactly what it promised. There were no obvious static imports pulling feature code into the base bundle. Nothing that directly explained why this code was ending up there.</p><p>That’s when I stopped trying to explain the problem line by line and started thinking more abstractly.</p><p>If the code wasn’t being pulled in <em>explicitly</em>, then something implicit had to be at play.</p><p>And that’s when an old concept resurfaced.</p><p><strong>CIRCULAR DEPENDENCIES.</strong></p><p>I had come across them before — mostly in theory. I knew the definition: <strong>modules importing each other directly or indirectly, forming loops. I’d seen ESLint warnings about them</strong>. I’d even ignored a few in the past, assuming they were harmless because nothing seemed to break.</p><p>But I had never really seen circular dependencies <em>in action</em>.<br>Never seen what they do in a real, growing codebase.<br>Never seen how they might show up outside of obvious runtime errors.</p><p>At that moment, it wasn’t a conclusion — it was a suspicion.</p><p>But it was the first explanation that felt like it could connect the dots.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*ImDKSwP2lQTBhZkX.png" /></figure><p>Most of us have seen circular dependencies before.<br>Most of us have ignored them.</p><p>They often look harmless:<br>“A imports B, B imports A — but it works.”</p><p>What I didn’t fully appreciate until this point was how <strong>destructive circular dependencies become at scale</strong>, especially in modern bundlers like Vite (Rollup under the hood).</p><p>I went deeper. I read more. I traced how modules are evaluated, how bundlers reason about graphs, how tree-shaking decides what is “safe” to remove.</p><p>And one thing became very clear:</p><blockquote>“Circular dependencies don’t break your app loudly. They break it silently, expensively, and everywhere.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/429/0*kN5g5OmP4SW5Qq9d.png" /></figure><h3>The moment Madge removed all doubt</h3><p>Speculation wasn’t enough anymore. I needed something concrete.</p><p>So I ran <strong>Madge</strong> — a tool that analyzes your codebase and visualizes the dependency graph, making circular dependencies explicit instead of invisible.</p><pre>npx madge src --circular</pre><p>I expected to find a few cycles.</p><p>What I got instead was a punch to the gut.</p><p><strong>812 circular dependencies.</strong></p><p>And they weren’t just simple loops. Many of them were deeply nested — some stretching <strong>15–16 levels</strong> deep.</p><p>Paths like:</p><pre>A → B → C → D → E → F → G → H → I → J → K → L → M → N → O → A</pre><p>At that depth, this isn’t just a dependency issue anymore. <strong>It’s a structural failure.</strong></p><p>What made it worse was that this wasn’t a static problem. New cycles were being introduced almost daily. Not out of negligence, but because circular dependencies are easy to ignore when nothing visibly breaks. Feature development kept moving forward, and the dependency graph quietly became more tangled with each change.</p><p>By the time I looked at it closely, this wasn’t just technical debt that had accumulated in the past — it was <strong>debt that was still compounding in the present</strong>.</p><blockquote>“A dependency graph that deep isn’t a graph anymore — it’s a knot.”</blockquote><h3>Why did everything suddenly started making sense</h3><p>Once I saw the scale of the circular dependencies, a lot of confusing behavior finally had an explanation.</p><p>When circular dependencies exist, some modules are accessed before they’ve finished initializing. That means exports can be partially defined, or undefined, depending on execution order — which isn’t always obvious or consistent.</p><p>It also explains something many teams experience during local development.</p><p>Sometimes the app just breaks — an import is suddenly undefined, even though nothing obvious changed. Other times, <strong>Hot Module Replacement </strong>stops behaving correctly, and instead of a clean hot update, the entire application reloads. These issues are notoriously hard to reproduce and even harder to trace back to a single line of code.</p><p>Build-time behavior starts to suffer as well.</p><p>Tree-shaking relies on the bundler being able to reason about the dependency graph. <strong>When deep cycles exist, the bundler can’t safely determine what’s unused.</strong> So it keeps more code than necessary.</p><h3>Refactoring 300+ files was the easy part</h3><p>Once I accepted how big the problem was, it was clear there was no shortcut.</p><p>This wasn’t about silencing warnings.<br><strong> It was about fixing how the code was structured</strong>.</p><p>I refactored more than <strong>300 files</strong>, and the biggest shift was rethinking <em>where</em> code actually belonged. In several places, functions were defined inside a module even though they were being used by multiple others. That arrangement made dependencies flow sideways. <strong>Moving that code one level up — into a shared parent that all consumers could depend on — immediately simplified those relationships.</strong></p><p>State-related code needed similar clarity. In areas where Redux was used, helpers and constants that were meant for a single slice had slowly started leaking into others. <strong>Pulling those back into their respective slices restored clear boundaries and prevented unrelated parts of the state layer from depending on each other</strong>.</p><p>For code that was genuinely common — shared components, constants, and helpers referenced across large parts of the application — the solution was to lift it out entirely. These p<strong>ieces were moved to the root level and made deliberately independent</strong>, so they could be consumed without pulling feature-specific logic along with them.</p><p>The goal wasn’t just to remove circular dependencies — it was to <strong>make import direction obvious</strong>.</p><p>One thing I learned during this process is that circular dependency counts can be misleading. In many cases, the same underlying problem shows up as multiple cycles. A single bad dependency can be detected in many different ways, which makes the total number look much worse than it really is.</p><p>This often happened with large files that tried to do too much. For example, one file contained constants, helpers, hooks, and other shared logic, and it was imported across many parts of the codebase. Once that file became part of a cycle, the number of reported circular dependencies increased very quickly, simply because there were so many paths that led to it.</p><p>The good news was that fixing the root problem had the opposite effect. By restructuring that file and cleaning up its imports, many circular dependencies disappeared at once. One structural fix could reduce the count by dozens, sometimes even more.</p><p>After every meaningful change, I ran Madge again.</p><pre>812 → 179 → 110 → 40 → 8 → 5 → 3</pre><p>Watching that number drop was addictive, because each reduction made the codebase easier to reason about and safer to evolve.</p><blockquote>“Every circular dependency removed felt like paying off invisible interest.”</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*YlnWDmdmgyeGCNnb.png" /></figure><h3>So… did the app actually become faster?</h3><p>At this point, it was fair to ask the obvious question.</p><p>All this refactoring, all this architectural cleanup — did it actually make a difference?</p><p>A bit of context first.<br>This is a <strong>React + Vite</strong> application, and we had vendor chunking enabled. That means third-party dependencies are extracted into a separate vendor chunk, while application code lives in the base app chunk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*7e1DSLGS8zLavLu-OR2tag.png" /></figure><p>Before any refactoring, the numbers told a clear story.</p><p>The base app andvendor chunks had ballooned to <strong>17MB</strong>.<br>Lighthouse Performance hovered around <strong>49</strong>.</p><p>Core Web Vitals reflected that as well:</p><ul><li><strong>First Contentful Paint (FCP): 3.51 seconds</strong></li><li><strong>Largest Contentful Paint (LCP): 3.91 seconds</strong></li></ul><p>Once the dust settled, the bundles told a very different story.</p><p>The base app and vendor chunks reduced to less than <strong>5MB</strong>. Lighthouse Performance jumped from <strong>49 to 72</strong>.</p><p>For the first time, chunk sizes actually matched intent.</p><p>And the Web Vitals followed:</p><ul><li><strong>First Contentful Paint (FCP): 1.9 seconds</strong></li><li><strong>Largest Contentful Paint (LCP): 2.3 seconds</strong></li><li><strong>Total Blocking Time dropped</strong></li><li><strong>Time to Interactive improved noticeably</strong></li></ul><p>But the most important change wasn’t just the numbers.</p><p>Feature chunks were finally fetched <strong>only when their routes were visited</strong> — not on first load. Network logs confirmed it. Bundle graphs confirmed it. And, most importantly, users could feel it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*DF31QaHftCCFUL16" /><figcaption>sample image depicting lighthouse score and other metrics</figcaption></figure><h3>Why these metrics improved</h3><p>These improvements weren’t the result of micro-optimizations or tuning individual components. They came from fixing the structure of the dependency graph.</p><p>By removing circular dependencies, the bundler could finally do what it’s designed to do. Tree-shaking became effective again, so unused code stopped leaking into shared chunks. Code-splitting started working as intended, which meant feature code stayed inside feature chunks instead of being pulled into the base bundle.</p><p>With a much smaller initial JavaScript payload, the browser had less code to download, parse, and execute on first load. That directly reduced First Contentful Paint and Largest Contentful Paint. Fewer scripts competing for the main thread also meant lower Total Blocking Time and a faster Time to Interactive.</p><p>In short, nothing magical happened — we simply stopped shipping work the user didn’t ask for.</p><blockquote>The smaller the chunk, the sooner it arrives — and the faster the app feels.”</blockquote><h3>Making sure this never happens again</h3><p>Fixing it once wasn’t enough.</p><p>I added <a href="https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-cycle.md">ESLint rules</a> to block new cycles.<br>I wired Madge into GitHub Actions so builds fail if circular dependencies creep back in. You can also refer to this <a href="https://github.com/tushargarg17/Cyclic-Dependencies">GitHub repo</a> for the same.</p><p>Circular dependencies stopped being “someone else’s problem” and became a <strong>hard regression</strong>.</p><blockquote>“Architecture doesn’t stay clean by accident — it stays clean by enforcement.”</blockquote><h3>What I actually learned</h3><p>I started this journey trying to make a React app faster.</p><p>What I really fixed was something deeper:<br>unclear boundaries<br>dishonest chunking<br>hidden coupling</p><p>Circular dependencies aren’t just a code smell.</p><p>In modern React + Vite applications, they are:<br>a performance tax<br>a chunking disaster<br>a reliability risk</p><p>Removing them isn’t glamorous work.</p><p>But it’s some of the <strong>highest-ROI engineering work</strong> you can do.</p><p>And once you see it — really see it — you’ll never ignore a circular dependency again.</p><h3>References &amp; Further Reading</h3><p>If you’re curious to go deeper into how JavaScript modules, bundlers, and dependency graphs actually work, these resources were especially helpful while researching and validating the ideas in this post:</p><ul><li><strong>ES Modules &amp; Circular Dependencies — Exploring JavaScript</strong><br><a href="https://exploringjs.com/es6/ch_modules.html#sec_cyclic-dependencies">https://exploringjs.com/es6/ch_modules.html#sec_cyclic-dependencies</a><br>A clear and thorough explanation of how ES modules are evaluated and why circular dependencies behave the way they do.</li><li><strong>How Rollup Tree-Shaking Works (Official Docs)</strong><br><a href="https://rollupjs.org/guide/en/#tree-shaking">https://rollupjs.org/guide/en/#tree-shaking</a><br>A great deep dive into how bundlers decide what code is safe to remove — and why cycles make that harder.</li><li><strong>Madge — Visualizing JavaScript Dependency Graphs</strong><br><a href="https://github.com/pahen/madge">https://github.com/pahen/madge</a><br>The tool used to detect and visualize circular dependencies throughout the codebase.</li><li><strong>Tree-Shaking and JavaScript Bundling — web.dev</strong><br><a href="https://web.dev/reduce-javascript-payloads-with-tree-shaking/">https://web.dev/reduce-javascript-payloads-with-tree-shaking/</a><br>A high-level overview of tree-shaking, code-splitting, and their impact on performance.</li><li><strong>Github Repo for preventing cyclic dependencies<br></strong><a href="https://github.com/tushargarg17/Cyclic-Dependencies">https://github.com/tushargarg17/Cyclic-Dependencies</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f1b6c65b975" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>