<?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 Shivangi Dixit on Medium]]></title>
        <description><![CDATA[Stories by Shivangi Dixit on Medium]]></description>
        <link>https://medium.com/@dixitsh02?source=rss-223c6b276708------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*Flm6zr2vq_VvZhdP</url>
            <title>Stories by Shivangi Dixit on Medium</title>
            <link>https://medium.com/@dixitsh02?source=rss-223c6b276708------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:12:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dixitsh02/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[Mastering JavaScript Set: The Most Underrated Data Structure in Modern Coding]]></title>
            <link>https://medium.com/@dixitsh02/mastering-javascript-set-the-most-underrated-data-structure-in-modern-coding-ad478459a4a4?source=rss-223c6b276708------2</link>
            <guid isPermaLink="false">https://medium.com/p/ad478459a4a4</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Shivangi Dixit]]></dc:creator>
            <pubDate>Fri, 20 Mar 2026 15:33:52 GMT</pubDate>
            <atom:updated>2026-03-20T15:33:52.039Z</atom:updated>
            <content:encoded><![CDATA[<p>When developers think about JavaScript data structures, most jump straight to arrays and objects. But there’s another built-in structure that quietly solves some of the most common performance and logic problems: <strong>Set</strong>.</p><p>If you’re working on performance sensitive applications, handling large datasets, or preparing for technical interviews, understanding Set properly can level up your coding significantly.</p><p>Let’s break it down.</p><h3>What is a JavaScript Set?</h3><p>A Set is a collection of <strong>unique values</strong>.</p><pre>const set = new Set([1, 2, 2, 3]);<br>console.log(set); // Set(3) {1, 2, 3}</pre><p>It automatically removes duplicates. That alone makes it powerful.</p><p>But that’s just the beginning.</p><h3>Why Set Matters in Advanced Coding</h3><p>The real strength of Set is not just uniqueness it’s <strong>fast lookups</strong>.</p><p>Under the hood, Set is implemented using a hash-based structure (in modern JS engines), which gives us:</p><pre>| Operation | Time Complexity|<br>|-----------|----------------|<br>| add()     | O(1) average   |<br>| delete()  | O(1) average   |<br>| has()     | O(1) average   |<br>| iteration | O(n)           |</pre><p>Compare that to arrays:</p><pre>arr.includes(value); // O(n)<br>set.has(value);      // O(1)</pre><p>On large datasets, that difference is massive.</p><h3>Core Set Operations (Complete Guide)</h3><h3>Create a Set</h3><pre>const set = new Set();<br>const set2 = new Set([1, 2, 3]);</pre><h3>Add Value</h3><pre>set.add(5);</pre><p>Duplicate adds are ignored.</p><h3>Delete Value</h3><pre>set.delete(5);</pre><p>Returns true if removed, false otherwise.</p><h3>Check Existence</h3><pre>set.has(3);</pre><p>Fast membership check.</p><h3>Get Size</h3><pre>set.size;</pre><h3>Clear All</h3><pre>set.clear();</pre><h3>Iterate</h3><pre>for (const value of set) {<br>  console.log(value);<br>}</pre><h3>Convert to Array</h3><pre>const arr = [...set];</pre><p>Very common pattern.</p><h3>Advanced Set Operations (Mathematical Patterns)</h3><p>JavaScript doesn’t provide built-in union/intersection methods, but they’re easy to implement.</p><h3>Union</h3><pre>const union = (a, b) =&gt; new Set([...a, ...b])<br></pre><h3>Intersection</h3><pre>const intersection = (a, b) =&gt;<br>  new Set([...a].filter(x =&gt; b.has(x)));</pre><h3>Difference</h3><pre>const difference = (a, b) =&gt;<br>  new Set([...a].filter(x =&gt; !b.has(x)));</pre><p>These patterns are heavily used in data processing and algorithm problems.</p><h3>Real-World Use Cases</h3><h3>1. Removing Duplicates</h3><pre>const unique = [...new Set(arr)];</pre><p>Clean and O(n).</p><h3>2. Fast Lookup Tables</h3><p>Instead of:</p><pre>if (arr.includes(id)) { ... }</pre><p>Use:</p><pre>const ids = new Set(arr);<br>if (ids.has(id)) { ... }</pre><p>Huge performance improvement.</p><h3>3. Graph Algorithms</h3><p>In BFS/DFS:</p><pre>const visited = new Set();</pre><p>Prevents infinite loops and ensures each node is processed once.</p><h3>4. Sliding Window Problems</h3><p>Used in problems like:<br> “Longest substring without repeating characters”</p><p>Set tracks unique characters in current window efficiently.</p><h3>5. Detecting Duplicates</h3><pre>const hasDuplicates = arr =&gt;<br>  new Set(arr).size !== arr.length;</pre><h3>Important Edge Cases</h3><h3>Objects in Set</h3><pre>const s = new Set();<br>s.add({a:1});<br>s.add({a:1});<br>console.log(s.size); // 2</pre><p>Objects are compared by reference, not by value.</p><h3>NaN Handling</h3><pre>new Set([NaN, NaN]).size // 1</pre><p>Unlike strict equality, Set treats NaN as equal.</p><h3>Set vs Array — When to Use What?</h3><p>Use Set when:</p><ul><li>You need uniqueness</li><li>You need fast membership checks</li><li>You’re solving graph or sliding-window problems</li><li>Performance matters</li></ul><p>Use Array when:</p><ul><li>Order manipulation is important</li><li>You need indexed access</li><li>Duplicates are meaningful</li></ul><h3>Performance Insight</h3><p>The biggest mistake developers make is using arrays for frequent lookups in large collections.</p><p>For example:</p><pre>for (let i = 0; i &lt; largeArray.length; i++) {<br>  if (largeArray.includes(target)) { ... }<br>}</pre><p>That’s potentially O(n²).</p><p>Using a Set reduces it to O(n).</p><p>That’s not micro-optimization. That’s architectural improvement.</p><h3>When Not to Use Set</h3><ul><li>When working with very small datasets</li><li>When you need ordering control</li><li>When memory usage must be minimized</li><li>When duplicates are meaningful business logic</li></ul><h3>Final Thoughts</h3><p>Set isn’t just a tool to remove duplicates.</p><p>It’s a performance-oriented data structure that:</p><ul><li>Improves algorithm efficiency</li><li>Simplifies logic</li><li>Reduces nested loops</li><li>Makes code cleaner and more expressive</li></ul><p>If you’re preparing for interviews, building scalable applications, or optimizing frontend/backend systems — mastering Set is non-negotiable.</p><p>Most developers know it exists. Few use it to its full potential.</p><p>Be in the second category.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ad478459a4a4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Designing Production Grade Voice AI for Elderly & Disabled Users]]></title>
            <link>https://medium.com/@dixitsh02/designing-voice-ai-systems-for-elderly-and-disabled-users-c2d5a3fc0271?source=rss-223c6b276708------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2d5a3fc0271</guid>
            <dc:creator><![CDATA[Shivangi Dixit]]></dc:creator>
            <pubDate>Mon, 09 Mar 2026 06:20:29 GMT</pubDate>
            <atom:updated>2026-03-09T06:29:57.426Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Problem</h3><p>Most voice AI assumes users speak <strong>clearly, quickly, neutral accent</strong>.</p><p><strong>Reality for elderly/disabled users:</strong></p><ul><li>Slower speech (60–80 wpm vs 150 wpm normal)</li><li>Long pauses (3–8 seconds between phrases)</li><li>Diverse accents, stutters, disfluencies</li><li>Soft volume, background noise</li><li>Cognitive load — need simple language, explicit confirmations</li></ul><p><strong>Result without accessibility design:</strong> 60–80% task failure rate, user frustration, abandonment.</p><h3>Production Architecture Overview</h3><p>Three planes: <strong>Experience → Realtime Pipeline → Control/Data</strong></p><pre>┌─────────────────┐    ┌──────────────────┐    ┌──────────────────┐<br>│   User Device   │    │  Profile &amp; Data  │    │   Monitoring     │<br>│ Web/Mobile/IVR  │◄──►│  Personalization │◄──►│   &amp; Analytics    │<br>└─────────┬───────┘    └──────────────────┘    └──────────────────┘<br>          │<br>          ▼ WebRTC/gRPC Streaming<br>┌─────────▼─────────┐<br>│   API Gateway     │ Kong + Cloudflare<br>│ (Auth/Rate Limit) │<br>└─────────┬─────────┘<br>          ▼<br>┌─────────▼─────────┐<br>│ Realtime Gateway  │ Node.js + mediasoup<br>│   (WebRTC SFU)    │<br>└─────────┬─────────┘<br>          ▼ Opus → PCM 16kHz<br>┌─────────▼─────────┐<br>│ Audio Preprocess  │ RNNoise + Silero VAD<br>│(Noise/VAD/AGC/AEC)│ 3-8s pause tolerance<br>└─────────┬─────────┘<br>          ▼ Streaming<br>┌─────────▼─────────┐<br>│   Streaming ASR   │ Deepgram Nova-3<br>│(170ms partials)   │ Whisper fallback<br>└─────────┬─────────┘<br>          ▼ Partial transcripts<br>┌─────────▼─────────┐<br>│Conversation Orche-│ XState + Temporal.io<br>│  strator (Brain)  │ Barge-in + Clarification<br>└─────────┬─────────┘<br>          ▼ Context + Intent<br>┌─────────▼─────────┐<br>│     LLM/NLU       │ Llama 3.3 8B + vLLM<br>│(Tool calling +    │ Accessibility persona<br>│ Accessibility LLM)│<br>└─────────┬─────────┘<br>          ▼ Streaming tokens<br>┌─────────▼─────────┐<br>│   Streaming TTS   │ ElevenLabs Flash 2.0<br>│(95ms first chunk) │ 0.85x speed + SSML<br>└─────────┬─────────┘<br>          ▼ Audio + Captions<br>┌─────────▼─────────┐<br>│     Client UI     │ Live captions + Replay<br>└───────────────────┘</pre><h3>Complete Tech Stack (Production Ready)</h3><h3>Client Layer</h3><pre>Web: React 19 + Tailwind + react-speech-recognition + mediasoup-client<br>Mobile: React Native 0.75 + react-native-webrtc<br>Telephony: FreeSWITCH 1.10 + SIP.js<br>Accessibility: ARIA 1.2 + react-aria-component</pre><h3>Infrastructure</h3><pre>Orchestration: Kubernetes 1.31 + ArgoCD + Nx monorepo<br>Cloud: AWS EKS / GCP GKE (multi-region)<br>Gateway: Kong 3.7 + Cloudflare Workers<br>Message Queue: NATS 2.10 + Redis 8.0 Streams<br>CDN: Cloudflare R2 (audio cache)<br>GPU: NVIDIA A100/H100 (Spot + reserved)</pre><h3>Realtime Pipeline</h3><pre>Realtime Gateway: Node.js 22 + mediasoup 3.15 SFU<br>Audio Processing: Rust + rnnoise-wasm + Silero VAD v4<br>ASR: Deepgram Nova-3 API → NeMo ASR (NVIDIA)<br>LLM: Llama 3.3 8B Q5_K_M (vLLM 0.6.3 + Ray Serve)<br>TTS: ElevenLabs Flash 2.0 → Piper TTS fallback<br>Orchestrator: Node.js + XState 5 + Temporal.io workflows</pre><h3>Data Layer</h3><pre>Profiles: PostgreSQL 17 + pgvector + Prisma ORM<br>History: ClickHouse 25.3 + TimescaleDB + Qdrant 1.10<br>Cache: Redis 8.0</pre><h3>Observability</h3><pre>Tracing: OpenTelemetry + Jaeger<br>Metrics: Prometheus 3.0 + Grafana 11<br>Errors: Sentry 8.0<br>Custom SLOs: E2E &lt;800ms P95, clarification_rate &lt;0.5%</pre><h3>Accessibility-First Implementation Details</h3><h3>1. Patient Audio Capture</h3><pre>// User-adaptive VAD (XState service)<br>const vadConfig = {<br>  silenceTimeout: userProfile.pauseTolerance || 5000, // 3-8s<br>  speechThreshold: -30, // Sensitive for soft speech<br>  hangupTimeout: 30000 // 30s no activity<br>}</pre><h3>2. Conversation State Machine (XState)</h3><pre>const conversationMachine = createMachine({<br>  states: {<br>    listening: {<br>      on: { VOICE_ACTIVITY: &#39;processing&#39; },<br>      after: { 8000: &#39;clarify_silence&#39; } // User patience<br>    },<br>    processing: {<br>      on: { <br>        LOW_CONFIDENCE: &#39;clarify&#39;,<br>        HIGH_CONFIDENCE: &#39;responding&#39;<br>      }<br>    },<br>    responding: {<br>      on: { BARGE_IN: &#39;listening&#39; } // Interrupt handling<br>    },<br>    clarify: {<br>      actions: &#39;ask_confirmation&#39;<br>    }<br>  }<br>})</pre><h3>3. Accessibility LLM Prompt</h3><pre>SYSTEM: &quot;You are a patient assistant for elderly/disabled users.<br>RULES:<br>1. Simple sentences (&lt;15 words)<br>2. Confirm before actions: &#39;Did you mean [X]? Yes/No&#39;<br>3. Slow speech rate (SSML rate=&#39;0.85&#39;)<br>4. Offer examples: &#39;You can say &quot;doctor appointment&quot; or &quot;reminder&quot;&#39;<br>5. Never rush - repeat if unclear<br>Always return: {response, speechRate, needsConfirmation, examples}&quot;</pre><h3>4. Multi-Modal Output</h3><pre>TTS Stream (ElevenLabs SSML):<br>&lt;speak rate=&quot;0.85&quot;&gt;<br>  Your appointment is &lt;prosody pitch=&quot;+10%&quot;&gt;tomorrow at 2 PM&lt;/prosody&gt;.<br>  &lt;break time=&quot;500ms&quot;/&gt;<br>  Say &quot;yes&quot; or &quot;change time&quot;.<br>&lt;/speak&gt;</pre><pre>Client receives:<br>- Audio chunks (live playback)<br>- Text captions (large font, high contrast)<br>- Visual state (&quot;Speaking...&quot;, progress bar)</pre><h3>Production SLOs &amp; Metrics</h3><p>MetricTarget P95MonitoringAudio → Partial ASR&lt;200msPrometheusASR → First TTS Audio 50msJaeger tracesE2E Turn Time&lt;800msGrafana dashboardASR Word Error Rate&lt;15% (elderly cohort)Custom evalClarification Rate&lt;0.5%ClickHouse analyticsTask Completion&gt;92%Session analysis</p><h3>Implementation Roadmap</h3><h3>Phase 1: MVP (2 weeks)</h3><pre>React + WebRTC + Deepgram + ElevenLabs + Basic XState<br>Manual accessibility tuning</pre><h3>Phase 2: Production Core (4 weeks)</h3><pre>Microservices + Kubernetes + User profiles<br>A/B test pause thresholds<br>Live captions + barge-in</pre><h3>Phase 3: Scale &amp; Optimize (8 weeks)</h3><pre>Regional edge deployment<br>LLM fine-tuning (accent adaptation)<br>Advanced analytics + human handoff<br>Mobile + telephony integration</pre><h3>Why This Works for Accessibility</h3><ol><li><strong>Patience built-in</strong>: 3–8s pauses, adaptive VAD</li><li><strong>Clear feedback</strong>: Visual states, live captions, progress</li><li><strong>Confirmation safety</strong>: Explicit yes/no for actions</li><li><strong>Personalization</strong>: Per-user speech rate, accent hints</li><li><strong>Multi-modal</strong>: Hear + see + repeat options</li><li><strong>Human fallback</strong>: Escalate low-confidence turns</li></ol><h3>Start Today</h3><p><strong>Quick prototype:</strong></p><pre>npx create-react-app voice-ai<br>npm i react-use-webrtc deepgram-sdk elevenlabs-js xstate</pre><p><strong>Deploy to production:</strong></p><pre>GitHub → ArgoCD → EKS → Cloudflare → Users</pre><p>Voice AI accessibility isn’t a feature — it’s <strong>table stakes for production</strong>. Build patient systems that respect how people actually speak</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2d5a3fc0271" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Your React Components Keep Re-Rendering (and How Engineers with Deep Understanding Think About…]]></title>
            <link>https://medium.com/@dixitsh02/why-your-react-components-keep-re-rendering-and-how-engineers-with-deep-understanding-think-about-8287b74d34d8?source=rss-223c6b276708------2</link>
            <guid isPermaLink="false">https://medium.com/p/8287b74d34d8</guid>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Shivangi Dixit]]></dc:creator>
            <pubDate>Mon, 16 Feb 2026 06:30:00 GMT</pubDate>
            <atom:updated>2026-02-16T06:30:00.219Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vzTsZswhkBiwTe2aEDU0BA.png" /></figure><h4>Why Your React Components Keep Re-Rendering (and How Engineers with Deep Understanding Think About It)</h4><p>React interviews aren’t about memorizing hooks.<br>They’re about <strong>understanding component behavior</strong> and being able to <strong>explain why something re-renders</strong>.</p><p>Most developers stop at: “<strong>Because state changed.</strong>”</p><p>Engineers with a deeper understanding go one step further: <strong><em>Which state changed, which props changed, and which references changed?</em></strong></p><p>Let’s walk through a real scenario.</p><h3>The Scenario: A Shopping Cart Counter</h3><p>You have <strong>one counter</strong> with <strong>two buttons</strong>:</p><ul><li>➕ Add item</li><li>➖ Remove item</li></ul><p>They share the same state.<br>But <strong>clicking one should NOT re-render the other</strong>.</p><p>Let’s start with the broken version.</p><h3>Broken Version (Why Everything Re-renders)</h3><pre>function CartButton() {<br>  const [count, setCount] = useState(0);<br>  const inc = () =&gt; setCount(count + 1);<br>  const dec = () =&gt; setCount(count - 1);<br><br>  return (<br>    &lt;&gt;<br>      &lt;p&gt;Items: {count}&lt;/p&gt;<br>      &lt;ActionButton<br>        label=&quot;Add&quot;<br>        onClick={inc}<br>        style={{ background: &quot;orange&quot; }} // new object every render<br>      /&gt;<br>      &lt;ActionButton<br>        label=&quot;Remove&quot;<br>        onClick={dec}<br>        style={{ background: &quot;green&quot; }}  // new object every render<br>      /&gt;<br>    &lt;/&gt;<br>  );<br>}<br>const ActionButton = ({ label, onClick, style }) =&gt; {<br>  console.log(label, &quot;rendered&quot;);<br>  return &lt;button style={style} onClick={onClick}&gt;{label}&lt;/button&gt;;<br>};</pre><h3>What happens when you click Add?</h3><p>Console:</p><pre>Add rendered<br>Remove rendered</pre><p>Why?</p><p>Because <strong>every render creates new references</strong>:</p><p>What changed?Why it breaksincNew function every renderdecNew function every renderstyleNew object every render</p><p>So React thinks:</p><blockquote><em>“Props changed → must re-render.”</em></blockquote><p>Even though the UI <em>looks</em> fine, the app is doing <strong>extra work</strong>.</p><h3>What Engineers with Deep Understanding See</h3><p>They don’t ask: <em>“Does it work?”</em></p><p>They ask: <em>“Is this render necessary?”</em></p><p>Unnecessary re-renders cause:</p><ul><li>Broken memoization</li><li>Wasted CPU</li><li>Performance cliffs in large app</li><li>Janky UIs at scale</li></ul><h3>Fixed Version (Stable References + Memoization)</h3><pre>function CartButton() {<br>  const [count, setCount] = useState(0);<br>  const inc = React.useCallback(() =&gt; {<br>    setCount(c =&gt; c + 1);<br>  }, []);<br>  const dec = React.useCallback(() =&gt; {<br>    setCount(c =&gt; c - 1);<br>  }, []);<br>  const addStyle = React.useMemo(() =&gt; ({ background: &quot;orange&quot; }), []);<br>  const removeStyle = React.useMemo(() =&gt; ({ background: &quot;green&quot; }), []);<br>  return (<br>    &lt;&gt;<br>      &lt;p&gt;Items: {count}&lt;/p&gt;<br>      &lt;ActionButton<br>        label=&quot;Add&quot;<br>        onClick={inc}<br>        style={addStyle}<br>      /&gt;<br>      &lt;ActionButton<br>        label=&quot;Remove&quot;<br>        onClick={dec}<br>        style={removeStyle}<br>      /&gt;<br>    &lt;/&gt;<br>  );<br>}<br>const ActionButton = React.memo(<br>  ({ label, onClick, style }) =&gt; {<br>    console.log(label, &quot;rendered&quot;);<br>    return &lt;button style={style} onClick={onClick}&gt;{label}&lt;/button&gt;;<br>  }<br>);</pre><h3>Now what happens?</h3><p>Click <strong>Add</strong>:</p><pre>Add rendered</pre><p>Click <strong>Remove</strong>:</p><pre>Remove rendered</pre><p>Click <strong>Add</strong> → only Add renders</p><p>Click <strong>Remove</strong> → only Remove renders</p><p>The buttons are now <strong>render-isolated</strong>.</p><h3>The Mental Model</h3><ul><li><strong>State changes</strong> re-render parents</li><li><strong>Prop changes</strong> re-render children</li><li><strong>Reference changes</strong> break memoization</li></ul><p>So:</p><ul><li>useCallback stabilizes functions</li><li>useMemo stabilizes objects</li><li>React.memo blocks unnecessary renders</li></ul><h3>The Interview Answer</h3><p>If someone asks:<em>“</em><strong><em>Why does this component keep re-rendering?</em></strong><em>”</em></p><p>A surface-level answer: <em>“</em><strong><em>Because state changed</em></strong><em>.”</em></p><p>A deeper answer:<strong><em>“Because a new reference was created, so memoization failed.”</em></strong></p><p>That’s the real difference.</p><h3>Final Truth</h3><p>If your child component re-renders:</p><ol><li>Ask <strong>what prop changed</strong></li><li>Then ask <strong>did the reference change</strong></li><li>Then decide <strong>if it should have</strong></li></ol><p>That’s how engineers with deep understanding reason about React.</p><h3>Interview Insight</h3><p>An interviewer isn’t testing if you can write useCallback.</p><p>They’re testing whether you understand:</p><ul><li>Why React re-renders</li><li>How reference equality affects memoization</li><li>Where hidden performance issues live</li><li>When optimization is actually worth it</li></ul><p>If you can explain this clearly, you’re already operating at a high level in React.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8287b74d34d8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JavaScript Brain Twisters]]></title>
            <link>https://medium.com/@dixitsh02/javascript-brain-twisters-dee1be595d67?source=rss-223c6b276708------2</link>
            <guid isPermaLink="false">https://medium.com/p/dee1be595d67</guid>
            <category><![CDATA[javascript-challenge]]></category>
            <dc:creator><![CDATA[Shivangi Dixit]]></dc:creator>
            <pubDate>Mon, 09 Feb 2026 14:15:20 GMT</pubDate>
            <atom:updated>2026-02-09T14:18:29.390Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OW26R1IfgwC_ZVS0ga_BvQ.png" /></figure><p>Most devs “know” JavaScript. Far fewer can predict what the engine will do in gnarly closure + async + coercion puzzles.</p><ul><li>Promise + closure traps</li><li>Event loop + async scope</li></ul><p>Each snippet has:</p><ul><li>The output</li><li>A short why, focused on the mental model behind it.</li></ul><h3>1) Promise + Closure Traps</h3><h3>1. Same Promise, Same Value</h3><pre>function run() {<br>  let x = 1;<br>  return Promise.resolve().then(() =&gt; x++);<br>}<br>const fn = run();<br>fn.then(console.log);<br>fn.then(console.log);</pre><p><strong>Output:</strong></p><pre>1<br>1</pre><p><strong>Why</strong>: run returns a Promise that resolves once, with the value of x++ at the time its .then runs. Both fn.then(...) attach to the same resolved promise, so they see the same resolved value (1). The post-increment side effect (x becoming 2) doesn’t change the already resolved value.</p><h3>2. var in Loop with Promises</h3><pre>for (var i = 0; i &lt; 3; i++) {<br>  Promise.resolve().then(() =&gt; console.log(i));<br>}</pre><p><strong>Output:</strong></p><pre>3<br>3<br>3</pre><p><strong>Why: </strong>var is function scoped, so all .then callbacks close over the same i. By the time microtasks run, the loop is finished and i === 3, so each callback logs 3.​</p><h3>3. let in Loop with Promises</h3><pre>for (let i = 0; i &lt; 3; i++) {<br>  Promise.resolve().then(() =&gt; console.log(i));<br>}</pre><p><strong>Output:</strong></p><pre>0<br>1<br>2</pre><p><strong>Why: </strong>let creates a new binding per iteration. Each callback closes over its own i value, so you get 0, 1, 2 as expected.</p><h3>4. Counter with Promise</h3><pre>function counter() {<br>  let n = 0;<br>  return () =&gt; Promise.resolve(n++);<br>}<br>const c = counter();<br>c().then(console.log);<br>c().then(console.log);</pre><p><strong>Output:</strong></p><pre>0<br>1</pre><p><strong>Why:</strong> n is in closure. First call resolves with 0 then increments to 1. Second call resolves with 1 then increments to 2.</p><h3>5. Sync vs Microtask Ordering</h3><pre>let x = 10;<br>Promise.resolve().then(() =&gt; {<br>  console.log(x);<br>  x = 20;<br>});<br>console.log(x);</pre><p><strong>Output:</strong></p><pre>10<br>10</pre><p><strong>Why: </strong>The last line console.log(x) is synchronous and runs immediately, logging 10. The .then callback is a microtask that runs after the current call stack, still seeing x === 10 before it updates it.</p><h3>6. Two Microtasks Updating Same Variable</h3><pre>let a = 1;<br>Promise.resolve().then(() =&gt; a++);<br>Promise.resolve().then(() =&gt; console.log(a));</pre><p><strong>Output:</strong></p><pre>2</pre><p><strong>Why:</strong> Both .then handlers are microtasks queued in order. First microtask runs, a becomes 2. Second microtask logs 2.​</p><h3>7. Increment in Closure</h3><pre>function build() {<br>  let v = 0;<br>  return () =&gt; Promise.resolve(++v);<br>}<br>const f = build();<br>f().then(console.log);<br>f().then(console.log);</pre><p><strong>Output:</strong></p><pre>1<br>2</pre><p><strong>Why: </strong>++v increments before resolving. First call gives 1, second 2.</p><h3>8. Chained .then</h3><pre>let x = 5;<br>Promise.resolve()<br>  .then(() =&gt; x++)<br>  .then(() =&gt; console.log(x));</pre><p><strong>Output:</strong></p><pre>6</pre><p><strong>Why:</strong> First .then runs, x becomes 6. Second .then logs current x → 6.</p><h3>9. New Promise Each Call</h3><pre>let val = 0;<br>function inc() {<br>  return new Promise(res =&gt; res(val++));<br>}<br>inc().then(console.log);<br>inc().then(console.log);</pre><p><strong>Output:</strong></p><pre>0<br>1</pre><p><strong>Why:</strong> Each inc() creates a new promise that resolves immediately with current val, then increments it.</p><h3>10. Transforming Promise Result</h3><pre>const fn = () =&gt; Promise.resolve(1);<br>fn().then(v =&gt; v + 1).then(console.log);</pre><p><strong>Output:</strong></p><pre>2</pre><p><strong>Why:</strong> Promise resolves with 1, next handler returns 2, last console.log prints 2.</p><h3>11. Two Microtasks, Post-Increment</h3><pre>let x = 1;<br>Promise.resolve().then(() =&gt; console.log(x++));<br>Promise.resolve().then(() =&gt; console.log(x++));</pre><p><strong>Output:</strong></p><pre>1<br>2</pre><p><strong>Why:</strong> First microtask logs 1, then x becomes 2. Second logs 2, then x becomes 3.</p><h3>12. Synchronous Log vs .then</h3><pre>let a = 10;<br>new Promise(res =&gt; res()).then(() =&gt; {<br>  a = 20;<br>});<br>console.log(a);</pre><p><strong>Output:</strong></p><pre>10</pre><p><strong>Why: </strong>console.log(a) runs immediately before the .then microtask runs. At that point a is still 10.​</p><h3>13. Shared count in Closure</h3><pre>let count = 0;<br>const fn = () =&gt; Promise.resolve(count++);<br>fn().then(console.log);<br>fn().then(console.log);</pre><p><strong>Output:</strong></p><pre>0<br>1</pre><p><strong>Why: </strong>Same pattern as val++: shared closure, new promise each time.</p><h3>14. Nested Microtask</h3><pre>let x = 1;<br>Promise.resolve().then(() =&gt; {<br>  Promise.resolve().then(() =&gt; console.log(x));<br>});<br>x = 2;</pre><p><strong>Output:</strong></p><pre>2</pre><p><strong>Why: </strong>Outer .then queues inner .then. The assignment x = 2 runs before either microtask, so inner logs 2 when it runs.</p><h3>15. Two Microtasks, One Mutates</h3><pre>let v = 0;<br>Promise.resolve().then(() =&gt; v++);<br>Promise.resolve().then(() =&gt; console.log(v));</pre><p><strong>Output:</strong></p><pre>1</pre><p><strong>Why</strong>: First microtask increments v to 1. Second logs 1.</p><h3>2) Event Loop + Async Scope</h3><h3>16. Sync vs Promise vs Timeout</h3><pre>console.log(1);<br>setTimeout(() =&gt; console.log(2));<br>Promise.resolve().then(() =&gt; console.log(3));<br>console.log(4);</pre><p><strong>Output:</strong></p><pre>1<br>4<br>3<br>2</pre><p><strong>Why: </strong>Order:</p><ol><li>All synchronous: 1, 4</li><li>All microtasks (Promises): 3</li><li>Then macrotasks (timers): 2</li></ol><h3>17. Promise vs Timeout</h3><pre>setTimeout(() =&gt; console.log(&quot;A&quot;));<br>Promise.resolve().then(() =&gt; console.log(&quot;B&quot;));</pre><p><strong>Output:</strong></p><pre>B<br>A</pre><p><strong>Why</strong>: Promises (microtasks) always run before timers (macrotasks) on the next tick.</p><h3>18. async + await null</h3><pre>async function test() {<br>  console.log(1);<br>  await null;<br>  console.log(2);<br>}<br>test();<br>console.log(3);</pre><p><strong>Output:</strong></p><pre>1<br>3<br>2</pre><p><strong>Why</strong>: await splits execution. console.log(1) runs, then control returns to the main stack, logging 3. The continuation (console.log(2)) is queued as a microtask.</p><h3>19. Microtask Scheduling Timer</h3><pre>Promise.resolve().then(() =&gt; {<br>  setTimeout(() =&gt; console.log(&quot;X&quot;));<br>});<br>Promise.resolve().then(() =&gt; console.log(&quot;Y&quot;));</pre><p><strong>Output:</strong></p><pre>Y<br>X</pre><p><strong>Why</strong>: First microtask schedules a timeout; second microtask logs &quot;Y&quot;. Only after microtasks finish does the timeout log &quot;X&quot;.​</p><h3>20. Classic Event Loop Example</h3><pre>console.log(&quot;start&quot;);<br>setTimeout(() =&gt; console.log(&quot;timeout&quot;));<br>Promise.resolve().then(() =&gt; console.log(&quot;promise&quot;));<br>console.log(&quot;end&quot;);</pre><p><strong>Output:</strong></p><pre>start<br>end<br>promise<br>timeout</pre><p><strong>Why: </strong>Script: &quot;start&quot;, &quot;end&quot;. Then microtask &quot;promise&quot;. Then timeout &quot;timeout&quot;.</p><h3>21. Promise vs queueMicrotask vs Timeout</h3><pre>setTimeout(() =&gt; console.log(1), 0);<br>Promise.resolve().then(() =&gt; console.log(2));<br>queueMicrotask(() =&gt; console.log(3))</pre><p><strong>Output:</strong></p><pre>2<br>3<br>1</pre><p><strong>Why</strong>: Both then and queueMicrotask schedule microtasks. They run before timers, and in the order they were queued: Promise microtask then explicit microtask.​</p><h3>22. await Another async Function</h3><pre>async function a() {<br>  console.log(1);<br>  await b();<br>  console.log(2);<br>}<br>async function b() {<br>  console.log(3);<br>}<br>a();<br>console.log(4);</pre><p><strong>Output:</strong></p><pre>1<br>3<br>4<br>2</pre><p><strong>Why: </strong>a() logs 1, calls b() which logs 3, then await pauses a. Control returns and logs 4. Later, continuation of a logs 2 as a microtask.</p><h3>23. Promise Now, Promise in Timeout</h3><pre>Promise.resolve().then(() =&gt; console.log(&quot;P&quot;));<br>setTimeout(() =&gt; Promise.resolve().then(() =&gt; console.log(&quot;M&quot;)));</pre><p><strong>Output:</strong></p><pre>P<br>M</pre><p><strong>Why:</strong> First microtask logs &quot;P&quot;. Timeout callback runs in the future, inside it a new microtask logs &quot;M&quot;.</p><h3>24. queueMicrotask vs Promise vs Sync</h3><pre>queueMicrotask(() =&gt; console.log(1));<br>Promise.resolve().then(() =&gt; console.log(2));<br>console.log(3);</pre><p><strong>Output:</strong></p><pre>3<br>1<br>2</pre><p><strong>Why:</strong> Sync 3 first, then microtasks FIFO: 1, then 2.</p><h3>25. Two Timers, One Promise</h3><pre>setTimeout(() =&gt; console.log(&quot;T1&quot;));<br>setTimeout(() =&gt; console.log(&quot;T2&quot;));<br>Promise.resolve().then(() =&gt; console.log(&quot;P&quot;));</pre><p><strong>Output:</strong></p><pre>P<br>T1<br>T2</pre><p><strong>Why:</strong> Microtask &quot;P&quot; runs before any timer callbacks. Timers fire later in scheduling order.</p><h3>26. async Function and await Promise.resolve()</h3><pre>async function run() {<br>  console.log(&quot;A&quot;);<br>  await Promise.resolve();<br>  console.log(&quot;B&quot;);<br>}<br>run();<br>console.log(&quot;C&quot;);</pre><p><strong>Output:</strong></p><pre>A<br>C<br>B</pre><p><strong>Why:</strong><br>await defers the rest of run to a microtask. &quot;A&quot; and then &quot;C&quot; log synchronously, &quot;B&quot; later.</p><h3>27. Two Promise .thens</h3><pre>Promise.resolve().then(() =&gt; console.log(1));<br>Promise.resolve().then(() =&gt; console.log(2));</pre><p><strong>Output:</strong></p><pre>1<br>2</pre><p><strong>Why: </strong>Microtasks preserve registration order.</p><h3>28. Two Timers</h3><pre>setTimeout(() =&gt; console.log(1));<br>setTimeout(() =&gt; console.log(2));</pre><p><strong>Output:</strong></p><pre>1<br>2</pre><p><strong>Why: </strong>Both timers have same delay; callbacks fire in scheduling order.</p><h3>29. Microtask Queuing Microtask</h3><pre>Promise.resolve().then(() =&gt; {<br>  console.log(&quot;A&quot;);<br>  Promise.resolve().then(() =&gt; console.log(&quot;B&quot;));<br>});</pre><p><strong>Output:</strong></p><pre>A<br>B</pre><p><strong>Why: </strong>First microtask logs &quot;A&quot; and queues another microtask, which runs immediately after, logging &quot;B&quot;.​</p><h3>30. Top-Level await in Script</h3><pre>console.log(&quot;X&quot;);<br>await Promise.resolve();<br>console.log(&quot;Y&quot;);</pre><p><strong>Output:</strong></p><pre>SyntaxError</pre><p><strong>Why:</strong> Top-level await is only allowed in modules, not in classic script context.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dee1be595d67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a High Performance, Scalable System with React, Node.js & Redis]]></title>
            <link>https://medium.com/@dixitsh02/building-a-high-performance-scalable-system-with-react-node-js-redis-241638c4f2d2?source=rss-223c6b276708------2</link>
            <guid isPermaLink="false">https://medium.com/p/241638c4f2d2</guid>
            <dc:creator><![CDATA[Shivangi Dixit]]></dc:creator>
            <pubDate>Wed, 04 Feb 2026 07:22:19 GMT</pubDate>
            <atom:updated>2026-02-04T07:22:19.654Z</atom:updated>
            <content:encoded><![CDATA[<p>Lately I’ve been deep‑diving into how Redis can transform large scale applications into real time, low latency, highly scalable systems. When paired with React and Node.js, Redis becomes the backbone that keeps everything fast under massive load.</p><p>Modern systems need to handle:</p><ul><li>Millions of requests</li><li>Real‑time updates</li><li>Heavy API traffic</li><li>Distributed workflows</li><li>Multi‑service communication</li></ul><p>A database alone can’t keep up. Redis fills that gap.</p><h3>High‑Level Architecture</h3><pre>React UI<br>   ↓<br>Node.js API (cache first)<br>   ↓<br>Redis Layer (cache, Pub/Sub, sessions, queues)<br>   ↓<br>Core Services (DB, microservices, integrations)</pre><p>Principle: Always hit Redis first. Only hit the database when necessary.</p><h3>Cache‑First Data Flow (Node.js)</h3><pre>const key = `sys:data:${id}`;<br>const cached = await redis.get(key);</pre><pre>if (cached) return res.json(JSON.parse(cached));</pre><pre>const data = await fetchFromCoreService(id);<br>await redis.setEx(key, 120, JSON.stringify(data));</pre><pre>res.json(data);</pre><p>This pattern alone can take a system from <em>“slow but working”</em> to <em>“fast and scalable.”</em></p><h3>Real‑Time Event Flow (Pub/Sub)</h3><p>Perfect for notifications, dashboards, analytics, IoT, monitoring, and distributed systems.</p><h3>Publisher</h3><pre>redis.publish(&quot;events&quot;, JSON.stringify({<br>  type: &quot;UPDATE&quot;,<br>  payload: { id, status: &quot;processed&quot; },<br>  timestamp: Date.now()<br>}));</pre><h3>Subscriber → WebSocket → React UI</h3><pre>redis.subscribe(&quot;events&quot;, (msg) =&gt; {<br>  ws.broadcast(JSON.parse(msg));<br>});</pre><p>React receives updates instantly no polling.</p><h3>🛡️ API Rate Limiting for System Stability</h3><pre>const attempts = await redis.incr(`rate:api:${userId}`);<br>if (attempts === 1) redis.expire(`rate:api:${userId}`, 60);</pre><pre>if (attempts &gt; 100) {<br>  return res.status(429).json({ error: &quot;Rate limit exceeded&quot; });<br>}</pre><p>This protects your system from overload and abuse.</p><h3>Scaling Redis for Millions of Users</h3><p>To scale a system to enterprise levels:</p><ul><li>Redis Cluster for horizontal sharding</li><li>Key patterns like sys:data:{id} for even distribution</li><li>Dedicated clusters for cache, sessions, Pub/Sub, queues</li><li>Short TTLs to balance freshness + performance</li><li>Avoid hot keys by sharding per user/tenant</li><li>Use pipelines to reduce round‑trip latency</li></ul><p>This architecture supports millions of users, high concurrency, and real‑time workloads.</p><h3>Architecture for Redis Horizontal Scaling with React, Node.js, and Core Services</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3KuaRrHemVxeDfAZ" /></figure><h3>Final Thought</h3><p>Redis turns a traditional system into a real time, scalable, developer friendly architecture. React handles the UI. Node.js handles the API. Redis handles the speed.</p><p>A powerful trio for building modern, high performance systems.</p><p>#Redis #NodeJS #React #ScalableSystems #DistributedSystems #WebPerformance #SoftwareArchitecture #EngineeringDesign</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=241638c4f2d2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How Redis Powers a Social Media Platform at Scale]]></title>
            <link>https://medium.com/@dixitsh02/how-redis-powers-a-social-media-platform-at-scale-ba6f87fdd0b8?source=rss-223c6b276708------2</link>
            <guid isPermaLink="false">https://medium.com/p/ba6f87fdd0b8</guid>
            <dc:creator><![CDATA[Shivangi Dixit]]></dc:creator>
            <pubDate>Tue, 03 Feb 2026 10:43:29 GMT</pubDate>
            <atom:updated>2026-02-03T10:43:29.874Z</atom:updated>
            <content:encoded><![CDATA[<p>When people talk about scaling social platforms, they often jump straight to databases. In reality, Redis is the system that keeps everything alive under heavy traffic. Here’s how Redis fits into a real, enterprise grade social media architecture.</p><h3>Redis as the Real Time Brain</h3><p>Redis sits between your API layer and your databases, handling everything that cannot wait.</p><p>What Redis handles:</p><ul><li>Sharded Counters Likes, views, shares are never written directly to the DB. Instead, Redis uses sharded counters to avoid hot keys and scale horizontally.</li></ul><pre>INCR likes:{postId}:{shard}</pre><ul><li>Millions of writes/sec → no bottlenecks.</li><li>Hot Post Detection Redis continuously tracks engagement velocity to detect trending posts in real time.</li><li>Databases tell you what <em>happened</em>. Redis tells you what’s <em>happening now</em>.</li><li>Rate Limiting &amp; Abuse Protection Redis acts as a first line firewall:</li></ul><pre>INCR user:{id}:likes:minute<br>EXPIRE 60</pre><ul><li>Bots get blocked before they ever touch your backend.</li></ul><h3>Write Fast, Read Smart</h3><pre>Client → API → Redis (real-time)<br>                ↓<br>          Kafka / Streams<br>                ↓<br>              Workers<br>                ↓<br>               DB</pre><ul><li>Users see instant updates</li><li>DB writes are batched</li><li>System stays alive during traffic spikes</li></ul><h3>Databases Are Not Real Time Systems</h3><p>Postgres, MongoDB, analytics stores all critical. But none of them should sit on your hot path. Redis absorbs volatility. Databases store truth.</p><p>That separation is what enables:</p><ul><li>Viral posts</li><li>Millions of users</li><li>Stable p99 latency</li></ul><h3>Why This Scales</h3><ul><li>No hot keys</li><li>Stateless application servers</li><li>Horizontal Redis Cluster</li><li>Auto-scaling workers</li><li>Active-active load balancing</li></ul><p>This is how platforms like Instagram, TikTok, Twitter, and YouTube survive spikes.</p><p>Hard Truth</p><p>If your architecture is:</p><pre>Client → API → Database</pre><p>You don’t have a scalable system.</p><p>If it’s:</p><pre>Client → API → Redis → Database</pre><p>Now you’re building social network grade infrastructure.</p><p>#Redis #SystemDesign #Architecture #Scalability #BackendEngineering #SocialMedia #HighAvailability #DistributedSystems</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ba6f87fdd0b8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>