<?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 Ritika Sharma on Medium]]></title>
        <description><![CDATA[Stories by Ritika Sharma on Medium]]></description>
        <link>https://medium.com/@ritikasharma.sharma97?source=rss-9f5139f23c9a------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*iZomWdEZpco-4KgGRCR9xg.jpeg</url>
            <title>Stories by Ritika Sharma on Medium</title>
            <link>https://medium.com/@ritikasharma.sharma97?source=rss-9f5139f23c9a------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 22:04:46 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ritikasharma.sharma97/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[Why Simple UPDATE Queries Break Enterprise Billing Systems]]></title>
            <link>https://medium.com/@ritikasharma.sharma97/why-simple-update-queries-break-enterprise-billing-systems-5f6773a23ed0?source=rss-9f5139f23c9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f6773a23ed0</guid>
            <dc:creator><![CDATA[Ritika Sharma]]></dc:creator>
            <pubDate>Tue, 12 May 2026 18:35:07 GMT</pubDate>
            <atom:updated>2026-05-12T18:35:07.610Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8jL4Gatd15RxvlLE3QMKdA.png" /></figure><p>Most developers have written a query like this at some point:</p><pre>UPDATE contracts<br>SET rate = 0.5<br>WHERE account_id = &#39;ACC_123&#39;;</pre><p>Looks harmless.</p><p>One row changes. The database updates. Everyone moves on.</p><p>Except in enterprise billing systems, that single query can quietly break invoices, reconciliation, analytics, audit history, and downstream reporting — sometimes months later.</p><p>Over the last few years working on contract and billing-related systems, I’ve realised that some of the hardest engineering problems are not about scale or performance. They’re about preserving historical correctness while the business keeps changing underneath you.</p><p>And that changes how you design software entirely.</p><h3>The Illusion of a “Simple” Change</h3><p>In most CRUD applications, updating a value is straightforward.</p><p>But billing and contract systems behave differently because the past matters just as much as the present.</p><p>Changing a contract rate today may affect:</p><ul><li>invoices already generated</li><li>future invoice recalculations</li><li>customer disputes</li><li>settlement reports</li><li>finance reconciliation</li><li>analytics dashboards</li><li>regulatory or audit investigations</li></ul><p>Now imagine this situation:</p><ul><li>A customer had Rate A in January</li><li>Rate B in February</li><li>A correction needs to be applied retroactively in April</li><li>Finance wants previously issued invoices to remain reproducible</li><li>Analytics pipelines have already consumed the old values</li></ul><p>Suddenly, a simple UPDATE becomes a historical data problem.</p><p>The challenge is no longer:</p><blockquote><em>“What is the latest value?”</em></blockquote><p>The real challenge becomes:</p><blockquote><em>“What was the correct value at a specific point in time, according to the rules that existed back then?”</em></blockquote><p>That’s a very different system design problem.</p><h3>Why Enterprise Systems Prefer Immutable History</h3><p>One pattern I’ve seen repeatedly in mature financial and billing systems is this:</p><p>Instead of modifying records directly, systems append new versions.</p><p>Rather than overwriting history, they preserve it.</p><p>For example, instead of:</p><pre>UPDATE contract_rates<br>SET rate = 0.5;</pre><p>Systems often create something conceptually closer to:</p><pre>Contract Rate History<br>| Rate | Effective From | Effective To |<br>|------|----------------|--------------|<br>| 0.3  | Jan 1          | Feb 15       |<br>| 0.5  | Feb 15         | Active       |</pre><p>Why?</p><p>Because historical reconstruction matters.</p><p>Teams need to answer questions like:</p><ul><li>“What rate generated this invoice six months ago?”</li><li>“Why did this customer receive a different charge?”</li><li>“Can we reproduce the exact billing calculation from March?”</li><li>“What changed and who changed it?”</li></ul><p>Without preserved history, those answers become impossible.</p><h3>Temporal Data Changes Everything</h3><p>One concept that becomes extremely important in these systems is temporal data.</p><p>A record is no longer just “current.”</p><p>It exists within time boundaries.</p><p>Typical models start introducing fields like:</p><ul><li>effectiveFrom</li><li>effectiveTo</li><li>createdAt</li><li>supersededAt</li><li>version</li><li>validFrom</li></ul><p>At first glance this looks like overengineering.</p><p>Until the first retroactive correction request arrives.</p><p>Or finance asks for historical regeneration.</p><p>Or a customer disputes an invoice from three billing cycles ago.</p><p>Then suddenly time-aware data models become essential.</p><p>A surprising amount of backend complexity comes from trying to answer one deceptively simple question:</p><blockquote><em>“What did the system believe was true on a specific date?”</em></blockquote><h3>Bulk Updates Become Dangerous Very Quickly</h3><p>Another thing I underestimated early on was how risky bulk updates are in distributed systems.</p><p>Consider a request like:</p><blockquote><em>“Update the contract rates for all accounts under this portfolio effective from February.”</em></blockquote><p>Operationally, this sounds simple.</p><p>Technically, it introduces several concerns immediately:</p><ul><li>What happens if half the updates succeed?</li><li>Can the operation be retried safely?</li><li>Are downstream services notified correctly?</li><li>Do analytics pipelines remain consistent?</li><li>Will invoice regeneration pick up the correct version?</li><li>How do we preserve audit history?</li><li>What if multiple contracts exist per asset or billing period?</li></ul><p>The complexity isn’t only in writing the update.</p><p>It’s in guaranteeing consistency across the ecosystem surrounding the data.</p><p>That ecosystem often includes:</p><ul><li>billing engines</li><li>event consumers</li><li>reporting systems</li><li>data warehouses</li><li>DBT transformations</li><li>dashboards</li><li>reconciliation jobs</li></ul><p>A single incorrect mutation can spread surprisingly far.</p><h3>Event-Driven Systems Add Another Layer</h3><p>In modern architectures, contract or billing systems rarely operate in isolation.</p><p>Changes usually propagate through events.</p><p>Something updates a contract.</p><p>An event gets published.</p><p>Other services consume it.</p><p>Analytics pipelines ingest it.</p><p>Dashboards eventually display it.</p><p>Now timing matters too.</p><p>Questions become:</p><ul><li>Was the event published exactly once?</li><li>Did consumers process events in order?</li><li>Was the update idempotent?</li><li>Can downstream systems reconstruct historical state?</li><li>What happens during partial failures?</li></ul><p>This is where engineering shifts from simple CRUD logic into distributed systems thinking.</p><h3>The Most Valuable Lesson I Learned</h3><p>The biggest mindset shift for me was understanding this:</p><p>Enterprise billing systems are not just data storage systems.</p><p>They are historical truth systems.</p><p>Their job is not only to store the latest value.</p><p>Their job is to preserve:</p><ul><li>correctness</li><li>traceability</li><li>reproducibility</li><li>auditability</li></ul><p>And that requirement influences nearly every architectural decision:</p><ul><li>immutable records</li><li>append-only history</li><li>versioned entities</li><li>temporal models</li><li>event-driven flows</li><li>idempotent processing</li><li>reconciliation pipelines</li></ul><p>Ironically, some of the most sophisticated engineering work happens in systems most users never even see.</p><h3>Final Thoughts</h3><p>The next time a database update looks “simple,” it’s worth asking:</p><ul><li>Should this overwrite history?</li><li>Can we reproduce past calculations?</li><li>What downstream systems depend on this?</li><li>How will this behave during retries or failures?</li><li>Will finance trust these numbers six months later?</li></ul><p>Because in enterprise systems, correctness over time is often more important than the update itself.</p><p>And in my experience, that’s where backend engineering starts becoming truly interesting.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f6773a23ed0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Privacy by Design: How I’d Build a User-First App in 2025]]></title>
            <link>https://medium.com/@ritikasharma.sharma97/privacy-by-design-how-id-build-a-user-first-app-in-2025-54bb667a989b?source=rss-9f5139f23c9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/54bb667a989b</guid>
            <dc:creator><![CDATA[Ritika Sharma]]></dc:creator>
            <pubDate>Sun, 27 Jul 2025 11:02:16 GMT</pubDate>
            <atom:updated>2025-07-27T11:02:16.982Z</atom:updated>
            <content:encoded><![CDATA[<p>We live in a world where data is currency — and every user action feels like it’s being watched, recorded, or sold. But what if we flipped the model? What if we built digital products that <em>earn trust</em> from Day 1?</p><p>Here’s how I would build a privacy-first, user-centric app in 2025 — based on what I’ve learned working on enterprise platforms and building apps that scale.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vxpX1_tJ5jEKMGalDnIDLA.png" /></figure><h3>1. Start With Consent-Driven Design, Not Checkbox-Driven</h3><p>Too many apps still treat GDPR or India’s DPDP Act as a checkbox. Instead:</p><ul><li><strong>Design for granular control</strong>: Let users decide which data they want to share, not just an “Accept All” button.</li><li><strong>Use purpose tags</strong>: Explain clearly <em>why</em> you’re asking for each permission.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mG3_XDdoL8KX7jDyoZDVGw.png" /><figcaption>Progressive Consent Model</figcaption></figure><h3>2. Minimal Data Collection — Less is More</h3><p>Default to collecting the <em>minimum viable data</em> needed to function. If your app doesn’t need:</p><ul><li>Birthdate → Don’t ask.</li><li>Location → Delay until the feature genuinely requires it.</li></ul><p>Use <strong>Edge AI</strong> to analyze things locally, without uploading everything to a server.</p><p>📌 Example: If it’s a photo app, run ML models on-device to detect faces or filters.</p><h3>3. Data Should Expire — Not Live Forever</h3><p>Set <strong>default data expiration rules</strong>. For instance:</p><ul><li>Auto-delete unverified accounts after 90 days</li><li>Auto-archive inactive chat threads</li><li>Provide clear <em>data export</em> and <em>delete my account</em> options</li></ul><p>This also reduces your legal and operational risk.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AAKla2epLjpNpJQKN4xAUg.png" /><figcaption>Data Lifecycle Policy</figcaption></figure><h3>4. Give Users a Dashboard They Actually Understand</h3><p>Don’t hide behind obscure settings.</p><ul><li>Show active sessions, recent data shared, permissions granted</li><li>Provide toggles for each data stream (camera, mic, files, analytics)</li></ul><p>This empowers users — and makes your app stand out.</p><p>🧰 Tools I like:</p><ul><li>react-accessible-accordion for collapsible privacy FAQs</li><li>Open-source privacy dashboards like <strong>SimpleAnalytics</strong> UI</li></ul><h3>5. Move From Centralized to Hybrid Models</h3><p>Wherever possible, shift logic to the client:</p><ul><li>Use <strong>IndexedDB</strong>, <strong>localStorage</strong>, or <strong>secure Web Workers</strong> for temporary data</li><li>Sync to server only when essential</li><li>Implement <strong>end-to-end encryption</strong> for chat or file transfer</li></ul><p>This reduces exposure in case of breaches.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_BZEPsIeArZwK8Y0NS78dg.png" /><figcaption>Edge + Cloud Hybrid Design</figcaption></figure><h3>Bonus: Build Privacy Into Your Dev Flow</h3><ul><li>Use eslint-plugin-security to catch code smells</li><li>Create privacy.md just like we use readme.md</li><li>Run automated privacy checks in CI/CD pipelines</li></ul><p>Every sprint, ask: <em>What data are we touching — and why?</em></p><h3>Final Thoughts</h3><p>In 2025, users aren’t just choosing apps for features — they’re choosing <strong>who they trust</strong>. Privacy by design isn’t about being perfect, it’s about being <em>intentional</em>.</p><p>If we build apps that respect users as humans — not just data points — we’ll win their trust, loyalty, and maybe even some good karma. 🤪</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=54bb667a989b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I Built a Scalable Web Scraper: A Full-Stack Developer’s Journey]]></title>
            <link>https://medium.com/@ritikasharma.sharma97/how-i-built-a-scalable-web-scraper-a-full-stack-developers-journey-fd306acbc492?source=rss-9f5139f23c9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd306acbc492</guid>
            <category><![CDATA[full-stack-developer]]></category>
            <category><![CDATA[scraping]]></category>
            <dc:creator><![CDATA[Ritika Sharma]]></dc:creator>
            <pubDate>Mon, 04 Nov 2024 09:06:05 GMT</pubDate>
            <atom:updated>2024-11-04T09:07:03.911Z</atom:updated>
            <content:encoded><![CDATA[<p>In the era of data-driven decision-making, web scraping has become an essential tool for collecting information. Whether it’s for price monitoring, market research, or analyzing trends, web scraping is invaluable. As a full-stack developer, I recently had the opportunity to build a robust web scraper from scratch. Here, I’ll walk you through the key decisions, the tech stack, and some challenges faced during the journey.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LS_ETDKsn3U84aPPTUcSfw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@bugsster?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Taras Shypka</a> on <a href="https://unsplash.com/photos/person-holding-black-ipad-iFSvn82XfGo?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><h3><strong>Choosing the Right Tech Stack</strong></h3><p>As a full-stack developer, my approach is always to consider scalability, efficiency, and ease of maintenance. For this project, I opted for:</p><p>Frontend:</p><p><strong><em>React (TypeScript): </em></strong>With its declarative nature and powerful ecosystem, React enables us to build a responsive and user-friendly interface quickly. TypeScript adds static typing, enhancing reliability and maintainability.<br>Tailwind CSS: For styling, Tailwind offers a utility-first approach, which allowed me to create a clean and responsive layout efficiently.<br>Backend:</p><p><strong><em>Node.js:</em></strong> With asynchronous capabilities and strong support for APIs, Node.js is a natural choice for web scraping tasks. It allows us to handle multiple requests simultaneously, making it perfect for a data-intensive application like a web scraper.<br><strong><em>Express.js: </em></strong>To manage the API endpoints and route different functionalities, Express offered a simple and minimalist framework.<br><strong><em>Puppeteer:</em></strong> For actual scraping, I used Puppeteer. It is a powerful Node library that provides a high-level API over the Chrome DevTools Protocol. It’s great for interacting with dynamic pages and works well with headless browsers.</p><h4>Database:</h4><p><strong><em>MongoDB:</em></strong> MongoDB was an ideal choice for storing scraped data due to its schema-less, document-oriented nature. Plus, the Docker setup I created for MongoDB helped in setting up and managing the database seamlessly.<br>Containerization:</p><p><strong><em>Docker:</em></strong> Docker containers provide isolation, ensuring the scraper’s environment is consistent across different stages. This setup also makes it easy to scale the application when required.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-Ovw5LHzpnxVfvOsSTIgZw.png" /></figure><h3>Setting Up the Web Scraper</h3><p>With the tech stack selected, here’s a high-level view of how I structured the scraper:</p><ol><li><strong>Backend API</strong>:</li></ol><ul><li>Built an Express server to manage API requests and handle routing. The routes controlled different functionalities, such as fetching new data, viewing past results, and managing requests from the frontend.</li></ul><p><strong>2. Scraping Logic</strong>:</p><ul><li>With Puppeteer, I automated the browsing process. Puppeteer opened web pages, extracted the data, and returned it as structured JSON. The scraper could handle complex pages, including those with infinite scroll and dynamic content loading.</li><li>To minimize server strain, I implemented a rate-limiting feature to control how frequently data was scraped from specific sites.</li></ul><p><strong>3. Data Storage</strong>:</p><ul><li>Once the data was scraped, it was pushed to MongoDB, where each document represented an individual data point. MongoDB’s flexible schema allowed me to store various data formats from different websites effortlessly.</li></ul><p><strong>4. Error Handling</strong>:</p><ul><li>Web scraping often comes with unique challenges, such as handling CAPTCHA or blocked requests. I implemented error-handling mechanisms that could retry requests, use proxy servers, or handle browser events to bypass such restrictions.</li></ul><p><strong>5. Dockerization</strong>:</p><ul><li>With Docker, I containerized the entire application stack, including MongoDB and Node.js services. This allowed for easy deployment, scaling, and testing on different environments.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2YDvhS2Q9Z99IkFsRn0uCQ.png" /></figure><figure><img alt="When your scraper gets blocked by CAPTCHA" src="https://cdn-images-1.medium.com/max/924/1*JH8vriIeJrSqyp3GddvplQ.png" /><figcaption>When your scraper gets blocked by CAPTCHA</figcaption></figure><h3>Frontend: Displaying the Data</h3><p>After setting up the backend, I moved to the frontend, where the data would be displayed in a user-friendly manner.</p><ol><li><strong>Data Fetching</strong>:</li></ol><ul><li>I used Axios in React to communicate with the backend API, fetching and displaying the scraped data in real-time.</li></ul><p><strong>2. Displaying Results</strong>:</p><ul><li>Using Tailwind CSS, I designed a clean, responsive layout to make the data easy to navigate and visually appealing. I also incorporated a search and filter functionality, allowing users to quickly find relevant information.</li></ul><p><strong>3. Error Notifications</strong>:</p><ul><li>To keep the user informed, I implemented toast notifications. These would pop up if there was an issue with fetching data, making it easier for users to understand if something went wrong</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ph5BZGBspssXwl237PLfYg.png" /><figcaption>Screenshot of my application</figcaption></figure><h3>Challenges and Lessons Learned</h3><ol><li><strong>Handling Dynamic Content</strong>:</li></ol><ul><li>Many modern websites use dynamic content loading (infinite scroll, JavaScript-rendered elements), which can be tricky for traditional scrapers. Puppeteer helped a lot here, but it required some custom logic to handle dynamic content reliably.</li></ul><p><strong>2. IP Blocking and CAPTCHAs</strong>:</p><ul><li>Certain sites implement IP blocking and CAPTCHA challenges. Using proxy servers and rotating IP addresses helped in bypassing some of these obstacles, but it’s always a challenge that requires a cautious and ethical approach.</li></ul><p><strong>3. Performance Optimization</strong>:</p><ul><li>Scraping multiple pages simultaneously can consume significant resources. By implementing rate-limiting, caching frequently accessed data, and running scrapers on scheduled intervals, I was able to reduce resource consumption while still maintaining fresh data.</li></ul><p><strong>4. Ensuring Data Accuracy</strong>:</p><ul><li>Scraped data can sometimes be incomplete or inaccurate. Regularly validating the scraped data against known benchmarks and implementing logging helped maintain accuracy over time.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/1*sx8A_YZy5QtZWWGU-XuIFw.jpeg" /></figure><h3>Conclusion</h3><p>Building a web scraper as a full-stack developer is a fantastic project that combines frontend and backend skills while diving deep into challenges around data extraction, performance optimization, and error handling. This experience taught me how to balance technical complexity with user experience, as well as the importance of ethical scraping practices.</p><p>If you’re thinking of building a web scraper, I hope my journey gives you some insights into the challenges and rewards of the process. Remember, always check the terms of service for the websites you plan to scrape, as ethical considerations are crucial in this field.</p><p>Happy scraping!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd306acbc492" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Backend and Frontend Timeouts: What You Need to Know]]></title>
            <link>https://medium.com/@ritikasharma.sharma97/backend-and-frontend-timeouts-what-you-need-to-know-b95d2a7b6f6d?source=rss-9f5139f23c9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/b95d2a7b6f6d</guid>
            <category><![CDATA[time-out]]></category>
            <category><![CDATA[frontend]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Ritika Sharma]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 04:55:33 GMT</pubDate>
            <atom:updated>2024-09-18T04:55:33.958Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*V_Lpu8e0OyOWXljgZWlILA.png" /></figure><p>In web development, one of the more frequent challenges that developers face is managing timeouts — whether in the frontend or backend. Timeouts occur when a request to the server or the client takes too long to respond, causing an operation to fail. This can lead to frustration for users and requires careful handling from both sides of development. Understanding how to manage timeouts properly is key to building efficient and resilient applications.</p><p>In this blog, we’ll explore the concept of backend and frontend timeouts, how they occur, and strategies for handling them effectively.</p><p><strong>What Are Timeouts?</strong></p><p>A timeout occurs when a request, typically between a client and server, exceeds the amount of time allotted for it to complete. Essentially, it&#39;s aborted if the operation doesn’t finish within a given period. Timeouts can be set on both the front end (client-side) and back end (server-side) to prevent resources from being wasted on indefinitely running processes.</p><p><strong>Types of Timeouts</strong></p><p>1. <strong>Frontend Timeouts</strong></p><p>Frontend timeouts happen on the client side (browser or mobile app). This could be when a request sent to the server takes too long to return a response. HTTP client libraries typically define These types of timeouts (like Axios, Fetch, or native HTTP clients in mobile apps).</p><p>2. <strong>Backend Timeouts</strong></p><p>Backend timeouts occur when the server takes too long to process a request or return a response. This can be due to heavy computation, resource bottlenecks, database locks, or inefficient code execution. It’s important to handle timeouts correctly to avoid blocking other incoming requests and overwhelming the server.</p><p><strong>Causes of Timeouts</strong></p><p><strong>Frontend Timeouts</strong></p><p>• <strong>Slow Network</strong></p><p>If the user’s network connection is slow or unstable, the request might not be completed within the expected time.</p><p>• <strong>Large Data Transfers</strong></p><p>Sending or receiving large files (like images, videos, or bulk data) over the network can cause delays in response time.</p><p>• <strong>API Server Issues</strong></p><p>Even if the user’s connection is stable, the server you are requesting to might be experiencing issues such as high load or downtime.</p><p><strong>Backend Timeouts</strong></p><p>• <strong>Slow Database Queries</strong></p><p>Unoptimized database queries or lack of proper indexing can lead to slow responses from the database, causing timeouts on the server side.</p><p>• <strong>Overloaded Server</strong></p><p>If the server is handling too many requests at once, or its resources (CPU, memory, etc.) are fully utilized, it may not be able to process requests efficiently.</p><p>• <strong>Third-Party API Delays</strong></p><p>Sometimes, the backend depends on external APIs. If these APIs are slow to respond, the backend will be stuck waiting, potentially leading to a timeout.</p><p><strong>How to Handle Frontend Timeouts</strong></p><p><strong>1. Set Reasonable Timeout Limits</strong></p><p>Depending on the app, you can set a timeout threshold for HTTP requests using libraries like Axios or native Fetch API in JavaScript.</p><p><strong>Example using Axios:</strong></p><pre>axios.get(&#39;/data&#39;, {<br>  timeout: 5000  // Set a timeout of 5 seconds<br>}).catch(error =&gt; {<br>  if (error.code === &#39;ECONNABORTED&#39;) {<br>    console.error(&#39;Request timeout: &#39;, error);<br>  }<br>});</pre><p>This prevents the frontend from waiting indefinitely for a response and helps give the user feedback if a request fails due to a timeout.</p><p><strong>2. Handle Failures Gracefully</strong></p><p>Provide the user with a clear error message when a timeout occurs and offer actions like retrying the request. This improves user experience.</p><pre>// Fetch API example<br>fetch(&#39;/data&#39;, { timeout: 5000 })<br>  .then(response =&gt; response.json())<br>  .catch(error =&gt; {<br>    alert(&#39;Request timed out. Please try again.&#39;);<br>  });</pre><p><strong>3. Retry Mechanism</strong></p><p>You can implement an automatic retry mechanism to handle occasional slow requests. If the first attempt fails, you can try again a couple of times before showing an error message.</p><pre>const fetchData = (attempt = 1) =&gt; {<br>  return axios.get(&#39;/data&#39;)<br>    .catch(error =&gt; {<br>      if (attempt &lt; 3) {<br>        return fetchData(attempt + 1);<br>      }<br>      throw error;<br>    });<br>};<br><br>fetchData().catch(() =&gt; {<br>  console.error(&#39;Request failed after 3 attempts.&#39;);<br>});</pre><p><strong>4. Use Background Syncing</strong></p><p>For background tasks or actions that don’t require immediate responses (like data syncing), consider sending requests asynchronously without blocking the user’s interaction with the application.</p><p><strong>How to Handle Backend Timeouts</strong></p><p><strong>1. Optimize Code and Database Queries</strong></p><p>Efficient code and database optimization are key to preventing backend timeouts. Make sure database queries are indexed properly, avoid N+1 query issues, and cache data wherever possible.</p><p><strong>2. Set Server-Side Timeout Policies</strong></p><p>Configure your backend framework or API gateway to set appropriate timeout limits on requests.</p><p>For example, in Node.js with Express, you can set a timeout for all incoming requests:</p><pre>const express = require(&#39;express&#39;);<br>const app = express();<br><br>app.use((req, res, next) =&gt; {<br>  res.setTimeout(10000, () =&gt; {<br>    res.status(504).send(&#39;Request timed out&#39;);<br>  });<br>  next();<br>});</pre><p><strong>3. Async Processing for Long Operations</strong></p><p>For long-running operations (like file processing, video encoding, or large database updates), consider implementing an asynchronous process where the server queues tasks for later execution and sends a response back to the client immediately.</p><p><strong>4. Use a Circuit Breaker Pattern</strong></p><p>In cases where backend services are making calls to third-party APIs, use a circuit breaker pattern to avoid repeatedly sending requests to a failing service. This helps prevent cascading failures across services.</p><p>Popular libraries like <a href="https://github.com/Netflix/Hystrix">Hystrix</a> for Java and <a href="https://github.com/nodeshift/opossum">Opossum</a> for Node.js help implement this pattern.</p><p><strong>Conclusion</strong></p><p>Timeouts are an essential part of building resilient and responsive web applications. Both frontend and backend systems need to manage them effectively to avoid blocking resources and providing poor user experiences. Setting reasonable timeout limits, handling failures gracefully, optimizing code, and implementing retries or async processing are key strategies for dealing with timeouts.</p><p>By mastering these techniques, you can ensure that your applications remain efficient, scalable, and user-friendly.</p><p><strong>Further Reading:</strong></p><p>1. <a href="https://axios-http.com/docs/handling_errors">Timeouts in Axios</a></p><p>2. <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise">Understanding JavaScript Promises for Handling Timeouts</a></p><p>3. <a href="https://nodejs.dev/en/learn/nodejs-performance-best-practices">Best Practices for Node.js Performance</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b95d2a7b6f6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Harnessing the Potential of Microfrontends with React and Webpack 5]]></title>
            <link>https://medium.com/@ritikasharma.sharma97/harnessing-the-potential-of-microfrontends-with-react-and-webpack-5-315c19f97052?source=rss-9f5139f23c9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/315c19f97052</guid>
            <category><![CDATA[react-microfrontend]]></category>
            <category><![CDATA[monolithic]]></category>
            <category><![CDATA[architecture]]></category>
            <dc:creator><![CDATA[Ritika Sharma]]></dc:creator>
            <pubDate>Tue, 23 Jul 2024 08:15:26 GMT</pubDate>
            <atom:updated>2024-07-23T08:15:26.823Z</atom:updated>
            <content:encoded><![CDATA[<p>The landscape of web development is constantly evolving, bringing forth new methodologies and tools to tackle emerging challenges. One such approach that has gained significant traction is the concept of microfrontends. In this article, we will delve into the power of micro frontends, particularly when combined with React and Webpack 5.</p><p><strong>What are Microfrontends?</strong></p><p>Micro frontends extend the idea of microservices to the frontend. The goal is to break down a monolithic frontend into smaller, manageable pieces, each responsible for a distinct part of the user interface. This modular approach allows teams to work independently on different parts of the application, enhancing scalability, maintainability, and deployment flexibility.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KQh3BICetjusi9aYjo2Uzg.png" /><figcaption><strong>Traditional Monolithic Frontend vs. Microfrontends</strong></figcaption></figure><p><em>Traditional Monolithic Frontend vs. Microfrontends Diagram:</em></p><p>• The left side shows a traditional monolithic frontend, represented as a single large rectangle labeled “Monolithic App”.</p><ul><li>The right side illustrates a microfrontend architecture, with the application divided into several smaller rectangles, each labeled as a different microfrontend.</li></ul><p><strong>Why Microfrontends?</strong></p><p>1. <strong>Scalability</strong>: By dividing a large application into smaller parts, teams can work on different features simultaneously without stepping on each other’s toes.</p><p>2. <strong>Maintainability</strong>: Smaller codebases are easier to maintain, debug, and test.</p><p>3. <strong>Deployment Flexibility</strong>: Individual microfrontends can be deployed independently, allowing for faster releases and rollback capabilities.</p><p>4. <strong>Technology Diversity</strong>: Different microfrontends can be built using different technologies, enabling teams to choose the best tools for their specific needs.</p><p><strong>Implementing Microfrontends with React and Webpack 5</strong></p><p><strong>Setting Up the Environment</strong></p><p>To get started, we’ll set up a basic environment using React and Webpack 5. The following steps outline the process:</p><ol><li><strong>Create a React App</strong>: Use Create React App to bootstrap your project.</li></ol><p>2. <strong>Install Webpack 5</strong>: Add Webpack 5 to your project and configure it to work with React.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*7TbhPtdufCzRY1TBND3YRg.png" /><figcaption>A tree view of a typical project structure showing folders like src, public, and files like webpack.config.js, package.json.</figcaption></figure><p><strong>Configuring Webpack 5 for Module Federation</strong></p><p>Webpack 5 introduces Module Federation, a powerful feature that facilitates the implementation of microfrontends. Here’s how to configure it:</p><ol><li><strong>Install Dependencies</strong>: Add the necessary Webpack dependencies.</li></ol><p>2. <strong>Setup Module Federation Plugin</strong>: Configure the Module Federation Plugin in your Webpack config file.</p><pre>// webpack.config.js<br>const { ModuleFederationPlugin } = require(&#39;webpack&#39;).container;<br><br>module.exports = {<br>  // other configurations<br>  plugins: [<br>    new ModuleFederationPlugin({<br>      name: &#39;app&#39;,<br>      remotes: {<br>        header: &#39;header@http://localhost:3001/remoteEntry.js&#39;,<br>        footer: &#39;footer@http://localhost:3002/remoteEntry.js&#39;,<br>      },<br>      shared: [&#39;react&#39;, &#39;react-dom&#39;],<br>    }),<br>  ],<br>};</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*B6IydPxes6zAA4q5d6l8Zg.png" /><figcaption>A schematic showing a central application (App) loading remote modules from different URLs indicating the Module Federation configuration.</figcaption></figure><p><a href="https://webpack.js.org/concepts/module-federation/">https://webpack.js.org/concepts/module-federation/</a> can check their official documentation</p><p><strong>Building and Integrating Microfrontends</strong></p><p>1. <strong>Create Remote Applications</strong>: Develop separate micro frontend applications (e.g., header, footer) and expose them using Module Federation.</p><p>2. <strong>Consume Remote Applications</strong>: Integrate these remote applications into your main application.</p><pre>// App.js<br>import React from &#39;react&#39;;<br><br>const Header = React.lazy(() =&gt; import(&#39;header/Header&#39;));<br>const Footer = React.lazy(() =&gt; import(&#39;footer/Footer&#39;));<br><br>function App() {<br>  return (<br>    &lt;div&gt;<br>      &lt;React.Suspense fallback=&quot;Loading Header...&quot;&gt;<br>        &lt;Header /&gt;<br>      &lt;/React.Suspense&gt;<br>      &lt;main&gt;<br>        &lt;h1&gt;Welcome to the Main App&lt;/h1&gt;<br>      &lt;/main&gt;<br>      &lt;React.Suspense fallback=&quot;Loading Footer...&quot;&gt;<br>        &lt;Footer /&gt;<br>      &lt;/React.Suspense&gt;<br>    &lt;/div&gt;<br>  );<br>}<br><br>export default App;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dUlP0wQxvCQadH-pUaUvwA.png" /><figcaption><strong>Microfrontend Integration</strong></figcaption></figure><p>A layout diagram showing the main application with placeholders for the header and footer, illustrating where the remote components are integrated.</p><p><strong>Benefits and Challenges</strong></p><p><strong>Benefits</strong></p><p>• <strong>Independent Deployability</strong>: Each microfrontend can be deployed independently, enabling rapid iterations.</p><p>• <strong>Team Autonomy</strong>: Teams can work on different microfrontends using their preferred technologies and release schedules.</p><p>• <strong>Resilience</strong>: A failure in one microfrontend doesn’t necessarily impact the entire application.</p><p><strong>Challenges</strong></p><p>• <strong>Increased Complexity</strong>: Managing multiple repositories and deployments can introduce complexity.</p><p>• <strong>Shared State Management</strong>: Coordinating shared state between microfrontends requires careful consideration.</p><p>• <strong>Performance Overhead</strong>: Multiple microfrontends can lead to increased initial load times if not managed properly.</p><p><strong>Conclusion</strong></p><p>Micro frontends, when combined with React and Webpack 5, offer a powerful approach to building scalable, maintainable, and flexible web applications. By breaking down a monolithic frontend into smaller, independently deployable pieces, teams can work more efficiently and adapt to changing requirements with ease. While there are challenges to consider, the benefits of adopting a microfrontend architecture make it a compelling choice for modern web development.</p><p>Embrace the potential of microfrontends and transform the way you build web applications, leveraging the strengths of React and Webpack 5 to create a more modular and resilient frontend architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=315c19f97052" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Top 6 React Hook Mistakes Beginners Make ]]></title>
            <link>https://medium.com/@ritikasharma.sharma97/top-6-react-hook-mistakes-beginners-make-3971ca2d7833?source=rss-9f5139f23c9a------2</link>
            <guid isPermaLink="false">https://medium.com/p/3971ca2d7833</guid>
            <dc:creator><![CDATA[Ritika Sharma]]></dc:creator>
            <pubDate>Fri, 19 Jul 2024 05:13:45 GMT</pubDate>
            <atom:updated>2024-07-24T11:51:42.490Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LGcdlTY5PrWsWmrq1OxfPQ.png" /></figure><p>React Hooks are a game-changer! They let you use state and other React features without writing a class. But, like any superpower, they come with their own set of pitfalls, especially for beginners. Let’s dive into six common mistakes and see how to avoid them, with some fun emojis to guide us! 🎉</p><ol><li><strong>Using Hooks Conditionally ❌➡️✅</strong></li></ol><p>Hooks should always be used at the top level of your functional component. This ensures that hooks are called in the same order each time a component renders.</p><p><strong>Mistake:</strong></p><pre><br>function MyComponent() {<br>  const [count, setCount] = useState(0);<br><br>  if (count &gt; 0) {<br>    useEffect(() =&gt; {<br>      console.log(&#39;Count is greater than 0&#39;);<br>    });<br>  }<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;{count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>Solution:</strong></p><pre>function MyComponent() {<br>  const [count, setCount] = useState(0);<br><br>  useEffect(() =&gt; {<br>    if (count &gt; 0) {<br>      console.log(&#39;Count is greater than 0&#39;);<br>    }<br>  }, [count]);<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;{count}&lt;/p&gt;<br>      &lt;button onClick={() =&gt; setCount(count + 1)}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>🧙‍♂️ <strong>Pro Tip:</strong> Always call hooks at the top level of your function!</p><p><strong>2. Not Specifying Dependencies Correctly in useEffect 🌀</strong></p><p>The dependency array in useEffect determines when the effect runs. Not specifying dependencies or specifying them incorrectly can lead to infinite loops or missed updates.</p><p><strong>Mistake:</strong></p><pre>function MyComponent({ userId }) {<br>  const [userData, setUserData] = useState(null);<br><br>  useEffect(() =&gt; {<br>    fetch(`/api/user/${userId}`)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; setUserData(data));<br>  }, []); // Missing userId as a dependency<br><br>  return &lt;div&gt;{userData ? userData.name : &#39;Loading...&#39;}&lt;/div&gt;;<br>}</pre><p><strong>Solution:</strong></p><pre>function MyComponent({ userId }) {<br>  const [userData, setUserData] = useState(null);<br><br>  useEffect(() =&gt; {<br>    fetch(`/api/user/${userId}`)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; setUserData(data));<br>  }, [userId]); // Correctly specify userId as a dependency<br><br>  return &lt;div&gt;{userData ? userData.name : &#39;Loading...&#39;}&lt;/div&gt;;<br>}</pre><p>🔍 <strong>Remember:</strong> Always specify your dependencies correctly!</p><p><strong>3. Ignoring Cleanup Functions in useEffect 🧹</strong></p><p>If your useEffect sets up any subscriptions or event listeners, you must clean them up to prevent memory leaks.</p><p><strong>Mistake:</strong></p><pre>function MyComponent() {<br>  useEffect(() =&gt; {<br>    const handleScroll = () =&gt; console.log(&#39;Scroll event&#39;);<br><br>    window.addEventListener(&#39;scroll&#39;, handleScroll);<br><br>    // Missing cleanup function<br>  }, []);<br><br>  return &lt;div&gt;Scroll to see effect in console&lt;/div&gt;;<br>}</pre><p><strong>Solution:</strong></p><pre>function MyComponent() {<br>  useEffect(() =&gt; {<br>    const handleScroll = () =&gt; console.log(&#39;Scroll event&#39;);<br><br>    window.addEventListener(&#39;scroll&#39;, handleScroll);<br><br>    return () =&gt; {<br>      window.removeEventListener(&#39;scroll&#39;, handleScroll);<br>    };<br>  }, []);<br><br>  return &lt;div&gt;Scroll to see effect in console&lt;/div&gt;;<br>}</pre><p>🧽 <strong>Tip:</strong> Clean up after yourself to avoid memory leaks!</p><p><strong>4. Using useState Incorrectly 🤔</strong></p><p>Sometimes beginners use useState in a way that doesn’t correctly update the state, especially when the new state depends on the previous state.</p><p><strong>Mistake:</strong></p><pre>function Counter() {<br>  const [count, setCount] = useState(0);<br><br>  const increment = () =&gt; {<br>    setCount(count + 1); // Directly using count<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;{count}&lt;/p&gt;<br>      &lt;button onClick={increment}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p><strong>Solution:</strong></p><pre>function Counter() {<br>  const [count, setCount] = useState(0);<br><br>  const increment = () =&gt; {<br>    setCount(prevCount =&gt; prevCount + 1); // Using function to get the previous state<br>  };<br><br>  return (<br>    &lt;div&gt;<br>      &lt;p&gt;{count}&lt;/p&gt;<br>      &lt;button onClick={increment}&gt;Increment&lt;/button&gt;<br>    &lt;/div&gt;<br>  );<br>}</pre><p>🕹️ <strong>Tip:</strong> Use functions in setState when your new state depends on the old state!</p><p><strong>5. Not Understanding Lazy Initialization in useState 💤</strong></p><p>When the initial state computation is expensive, it’s best to use lazy initialization.</p><p><strong>Mistake:</strong></p><pre>function ExpensiveComponent() {<br>  const initialState = computeExpensiveValue(); // This runs on every render<br>  const [value, setValue] = useState(initialState);<br><br>  return &lt;div&gt;{value}&lt;/div&gt;;<br>}</pre><p><strong>Solution:</strong></p><pre>function ExpensiveComponent() {<br>  const [value, setValue] = useState(() =&gt; computeExpensiveValue()); // This runs only once<br><br>  return &lt;div&gt;{value}&lt;/div&gt;;<br>}</pre><p>⚡ <strong>Pro Tip:</strong> Use lazy initialization for expensive computations!</p><p><strong>6. Not Using Custom Hooks for Reusable Logic ♻️</strong></p><p>When logic is reused across components, it should be extracted into a custom hook to maintain DRY (Don’t Repeat Yourself) principles.</p><p><strong>Mistake:</strong></p><pre>function ComponentA() {<br>  const [data, setData] = useState(null);<br><br>  useEffect(() =&gt; {<br>    fetch(&#39;/api/data&#39;)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; setData(data));<br>  }, []);<br><br>  return &lt;div&gt;{data}&lt;/div&gt;;<br>}<br><br>function ComponentB() {<br>  const [data, setData] = useState(null);<br><br>  useEffect(() =&gt; {<br>    fetch(&#39;/api/data&#39;)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; setData(data));<br>  }, []);<br><br>  return &lt;div&gt;{data}&lt;/div&gt;;<br>}</pre><p><strong>Solution:</strong></p><pre>function useFetchData(url) {<br>  const [data, setData] = useState(null);<br><br>  useEffect(() =&gt; {<br>    fetch(url)<br>      .then(response =&gt; response.json())<br>      .then(data =&gt; setData(data));<br>  }, [url]);<br><br>  return data;<br>}<br><br>function ComponentA() {<br>  const data = useFetchData(&#39;/api/data&#39;);<br>  return &lt;div&gt;{data}&lt;/div&gt;;<br>}<br><br>function ComponentB() {<br>  const data = useFetchData(&#39;/api/data&#39;);<br>  return &lt;div&gt;{data}&lt;/div&gt;;<br>}</pre><p>🔁 <strong>Pro Tip:</strong> Create custom hooks for reusable logic and keep your code DRY!</p><p>By being aware of these common mistakes and following best practices, you’ll be able to harness the full power of React Hooks in your applications. Happy coding! 🖥️✨</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3971ca2d7833" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>