<?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 Ali Asghar on Medium]]></title>
        <description><![CDATA[Stories by Ali Asghar on Medium]]></description>
        <link>https://medium.com/@aliasghar37?source=rss-605719a2c837------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*1L6m84eH-IOoyYFal7tVxA.jpeg</url>
            <title>Stories by Ali Asghar on Medium</title>
            <link>https://medium.com/@aliasghar37?source=rss-605719a2c837------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 22:27:32 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aliasghar37/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[What does it mean by ACID in databases and is MongoDB ACID compliant?]]></title>
            <link>https://medium.com/@aliasghar37/what-does-it-mean-by-acid-in-databases-and-is-mongodb-acid-compliant-526cbbd969b6?source=rss-605719a2c837------2</link>
            <guid isPermaLink="false">https://medium.com/p/526cbbd969b6</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[software-engineering]]></category>
            <dc:creator><![CDATA[Ali Asghar]]></dc:creator>
            <pubDate>Wed, 24 Dec 2025 11:52:11 GMT</pubDate>
            <atom:updated>2025-12-24T11:54:42.085Z</atom:updated>
            <content:encoded><![CDATA[<p>In 1983, computer scientist Andreas Reuter and Theo Härder formally defined the four ACID properties (Atomicity, Consistency, Isolation and Durability). Their work gave the database community a common language to describe the requirements for reliable database transactions. Each property was intended to address a specific challenge in ensuring that data remained valid and processed reliably, even when failures occurred:</p><ul><li><strong>Atomicity</strong> ensures that multiple operations in a transaction act as a single unit, either all succeed or fail.</li><li><strong>Consistency</strong> ensures that the database remains in a valid state that adheres to defined rules and constraints.</li><li><strong>Isolation</strong> prevents concurrent transactions from interfering with each other.</li><li><strong>Durability</strong> makes sure that once a transaction commits, the results are permanent, even after system failures.</li></ul><p>This framework became standard for Relational Database Management Systems (RDBMS) as enterprises adopted them.</p><h3>Is MongoDB ACID compliant?</h3><p>There has been a misconception that if you need 100% data consistency (ACID), you must use a SQL database like PostgreSQL or MySQL. There are many devs who believe that migrating to MongoDB means sacrificing transaction safety.</p><p>The truth is that MongoDB has become ACID compliant since v4.0. It also has a support for multi-document transactions so that you can update multiple documents (like a User, Booking and a Tour document in a tour application) at the same time. Either all the changes happen or none of them do.</p><p>However, here is why senior engineers still hesitate:</p><p>Just because MongoDB has transactions does not mean you should misuse them.</p><ol><li><strong>Performance issue: </strong>In MongoDB, multi-document transactions carry a heavy processing overhead. Unlike SQL databases which are built from the ground level to handle row locking and complex joins efficiently, MongoDB is designed for high speed read of denormalized data.</li><li><strong>The Scaling Issue: </strong>MongoDB excels at horizontal scaling (Sharding). But one drawback to this is that running ACID transactions across distributed shards can be expensive and add latency.</li><li><strong>The Design Conflict: </strong>If you put every request in a transaction, you are forcing a relational structure into a NoSQL engine. At that point, you are just using the wrong tool for the job and should be considering SQL.</li></ol><p>Yes, MongoDB is ACID compliant. Just use it for the critical moments (such as payment processing). But if you need complicated transactions for every user interaction, stick to SQL. Use the right tool for the right architecture.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=526cbbd969b6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Master React Reusability: A guide to Custom Hooks (with practical)]]></title>
            <link>https://medium.com/@aliasghar37/master-react-reusability-a-guide-to-custom-hooks-with-practical-759c2c1d3e1f?source=rss-605719a2c837------2</link>
            <guid isPermaLink="false">https://medium.com/p/759c2c1d3e1f</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[react-hook]]></category>
            <category><![CDATA[react-tutorial]]></category>
            <category><![CDATA[reactjs]]></category>
            <category><![CDATA[react]]></category>
            <dc:creator><![CDATA[Ali Asghar]]></dc:creator>
            <pubDate>Fri, 31 Oct 2025 12:52:21 GMT</pubDate>
            <atom:updated>2025-10-31T12:52:21.965Z</atom:updated>
            <content:encoded><![CDATA[<p>If you have spent any time in building React applications, you probably have run into the same problem: repetitive logic dispersed throughout multiple components. When handling a basic functionality like fetching data, you end up writing the same useState and useEffect code many times. This causes code duplication, complexity and maintenance nightmare.</p><p>The solution? Custom Hooks. They are essential to create functional components that are truly clean, scalable and reusable.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gmCPe6Ztgb7ywkDdEhLC2g.png" /><figcaption>Thumbnail</figcaption></figure><h3>What is a Custom Hook?</h3><p>In short, a custom hook is a function whose name starts with use (e.g., useFetch, useToggle).</p><p><strong>Two principles</strong></p><ol><li>It must be a JavaScript/TypeScript function.</li><li>It uses React’s built-in hooks (useState, useEffect, useContext, etc).</li></ol><p>The main goal is to <em>extract and reuse component logic</em> without sharing the actual state itself. When you use a custom hook in two different components, each component has its own independent state managed by hook.</p><h3>Example: useFetch hook</h3><p>Data fetching involves managing several pieces of state (i.e., data, loading, error) and side effects (useEffect). By putting all into a custom hook (useFetch), you component becomes genuinely concerned with rendering the date.</p><pre>import { useState, useEffect } from &quot;react&quot;;<br><br>const useFetch = &lt;T&gt;(url: string) =&gt; {<br>    // State to hold the fetched data<br>    const [data, setData] = useState&lt;T | null&gt;(null);<br>    // State to track if data is currently being loaded<br>    const [loading, setLoading] = useState(true);<br><br>    useEffect(() =&gt; {<br>        // Creating the function to fetch data<br>        const fetchData = async () =&gt; {<br>            // Start loading<br>            setLoading(true);<br>            try {<br>              const response = await fetch(url);<br>              // Basic error handling for non-200 responses<br>              if (!response.ok) {<br>                throw new Error(&quot;HTTP error, status: &quot;, response.status);<br>              }<br>              const result = await response.json();<br>              // Setting the fetched data<br>              setData(result);<br>            } catch(error) {<br>              console.error(&quot;Fetching error: &quot;, error);<br>            } finally {<br>              // ending the loading no matter if fetching succeeded or failed<br>              setLoading(false)<br>            }<br>            <br>            <br>        };<br>        // run the fetchData function when component mounts or url changes<br>        fetchData();<br>    // rerun effect when the url changes<br>    }, [url]); <br>    // returning an object for better destructuring and readablity<br>    return { data, loading };<br>};<br>export default useFetch;</pre><p><strong>How to use it?</strong></p><pre>// importing the useFetch hook that we have just written<br>import useFetch from &quot;./hooks/useFetch&quot;;<br>function App {<br>  // fetching data using our custom useFetch hook<br>  const { data, loading } = useFetch(<br>        &quot;https://jsonplaceholder.typicode.com/todos&quot;<br>    );<br><br>    // checking if data is being loaded or not<br>    if (loading) return &lt;p&gt;Loading data....&lt;/p&gt;;<br>    // returning if there no data found<br>    if (!data) return &lt;p&gt;No data found&lt;/p&gt;;<br><br>    // logging the data if found<br>    console.log(data);<br>    return &lt;p&gt;Data is in the console&lt;/p&gt;;<br>}</pre><p><strong>Final Output</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rIjrrCG9J415pXi5lXVm9Q.png" /><figcaption>Final output of our custom hook</figcaption></figure><p>To practice custom hooks, you can add some more things to this simple useFetch hook or even you can write your own custom hooks such as useToggle, useWindowResize, useInterval, useTimeout, useLocalStorage, etc.</p><h3>Final thoughts 💭</h3><p>Custom hooks are the most important pattern in modern React development for reusing the same component logic. By following a simple convention of starting with use and using other hooks, you can make complex and repetitive logic into clean and reusable code.</p><h4>I’m Ali Asghar, a Full Stack Developer</h4><p>My core expertise is the MERN Stack (MongoDB, Express, React, Node.js), delivering dynamic, efficient and user-centric web applications. I also know technologies like JavaScript, Git, GitHub, Docker and Figma. Feel free to reach out on <a href="https://www.linkedin.com/in/aliasghar37">LinkedIn!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=759c2c1d3e1f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>