<?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 Sahil Bhati on Medium]]></title>
        <description><![CDATA[Stories by Sahil Bhati on Medium]]></description>
        <link>https://medium.com/@sahilbhati?source=rss-b9e596b90549------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ppOf_x_4HzJwNBve.</url>
            <title>Stories by Sahil Bhati on Medium</title>
            <link>https://medium.com/@sahilbhati?source=rss-b9e596b90549------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:58:23 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sahilbhati/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[Database Isolation Levels]]></title>
            <link>https://medium.com/@sahilbhati/database-isolation-levels-aca221f7a9be?source=rss-b9e596b90549------2</link>
            <guid isPermaLink="false">https://medium.com/p/aca221f7a9be</guid>
            <category><![CDATA[transactions]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[relational-databases]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Sahil Bhati]]></dc:creator>
            <pubDate>Wed, 01 Nov 2023 18:16:39 GMT</pubDate>
            <atom:updated>2023-11-01T18:16:39.967Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*iyY6IHsAhhd5sUhcBdbiPw.jpeg" /></figure><p>In my recent work, I encountered a scenario that required a deep dive into the world of database isolations. We often hear about SQL databases following the <strong>ACID</strong> properties, which serve as a foundation for robust data management:</p><ul><li>A — Atomicity: This concept dictates that a transaction is an all-or-none operation, meaning it is either fully executed or not at all.</li><li>C — Consistency: Consistency ensures that the database remains in a stable and predictable state. When you perform queries, you’ll receive either new or old data, but never a confusing mix of the two.</li><li>I — Isolation: Isolation plays a critical role in data integrity. It ensures that transactions run as if they are the only ones operating on the database. This concept balances performance with concurrency.</li><li>D — Durability: Durability is about the safety of committed data. Once data is committed, it should be rock-solid and never get lost.</li></ul><p>Now, let’s explore the intriguing world of isolation levels and the problems they’re designed to solve. You might wonder why we need different isolation levels when we could have opted for a single approach of either executing everything in strict serial order or letting all transactions run in parallel. The answer lies in the diversity of scenarios we encounter in the world of databases.</p><h3>Problems Addressed by Isolation Levels</h3><p><strong>Dirty Reads</strong>: In simpler terms, dirty reads occur when transactions can read non-committed data. Since non-committed data can be rolled back, you might find yourself reading data that no longer exists, leading to confusion and inconsistencies.</p><p><strong>Non-Repeatable Read</strong>: Here, you’re reading only committed data, but for a specific row, data can change between multiple reads. This can result in inconsistencies and unexpected outcomes.</p><p><strong>Phantom Reads</strong>: Even if you address the issue of non-repeatable reads by locking the row to prevent updates, someone can still add new rows. This introduces the possibility of different query outcomes within a single transaction, creating a “phantom” effect.</p><p>Now, let’s explore how different isolation levels tackle these challenging issues.</p><h3>Isolation Levels</h3><h4><strong>Uncommitted Read:</strong></h4><ul><li>In this isolation level, transactions can read all uncommitted data.</li><li>It’s the least restrictive isolation level, virtually offering no isolation, and all three problems can occur.</li></ul><h4><strong>Committed Read:</strong></h4><ul><li>Transactions at this level can only read committed data.</li><li>This level effectively solves the problem of dirty reads.</li></ul><h4><strong>Repeatable Read:</strong></h4><ul><li>This isolation level prevents non-repeatable reads by locking rows when they are read. This ensures no updates or deletions can occur during the transaction.</li></ul><h4><strong>Serialized:</strong></h4><ul><li>Serialized is the most restrictive isolation level.</li><li>It essentially means that all transactions are running in strict serial order, one after the other.</li></ul><p>Each isolation level has its unique use cases, and the choice of which to use depends on the specific requirements of your application. It’s a balancing act between data consistency and system performance, and the right choice can make a world of difference in your database management.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aca221f7a9be" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Machines , Virtual Machines and Containers]]></title>
            <link>https://medium.com/@sahilbhati/machines-virtual-machines-and-containers-b4e8569b3722?source=rss-b9e596b90549------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4e8569b3722</guid>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[servers]]></category>
            <category><![CDATA[vm]]></category>
            <dc:creator><![CDATA[Sahil Bhati]]></dc:creator>
            <pubDate>Wed, 01 Nov 2023 17:55:03 GMT</pubDate>
            <atom:updated>2023-11-01T17:55:03.266Z</atom:updated>
            <content:encoded><![CDATA[<h3>Machines , Virtual Machines and Containers</h3><p>In the era of cloud computing, the use of virtual machines (VMs) and containers has become a prevailing trend. Regardless of the technology or company you work with, you’ll likely encounter container deployments frequently. But what exactly are containers and virtual machines, and why do we use them?</p><h3>Understanding the Basics</h3><p>Let’s begin with the fundamental concept of a machine or server. Just like your laptop or mobile device, a server is a machine composed of three primary components: hardware, an operating system that interacts with the hardware, and software that runs on top of the operating system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1oVXBm91zkUD-gNwNPgq1Q.jpeg" /></figure><p>Now, let’s dive deeper into what a virtual machine is. But before we do that, let’s familiarize ourselves with some terminology that will help us comprehend the information that follows.</p><ul><li>Platform: It’s the amalgamation of the operating system and hardware.</li><li>RAM: This stands for Random Access Memory, which is the volatile memory available in hardware.</li><li>Disk: This is the permanent memory in a machine.</li><li>CPU: The central processing unit is responsible for handling the computation processes.</li><li>Network: It’s the physical network layer in hardware that manages network communication.</li></ul><h3>Virtual Machines (VMs)</h3><p>A virtual machine can be described as a software-built emulation of a machine. It abstracts specific resources from the actual machine and operates as an independent entity running on top of the host machine. The software responsible for this emulation is known as a hypervisor. A VM isolates its subset of RAM, disk, CPU, and a software-defined network layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SHAIrhm_Bj48Sv916D-IVw.jpeg" /></figure><p>Characteristics of Virtual Machines:</p><ul><li>VMs allow you to run software designed for a particular platform even on non-compatible platforms. For instance, you can run Android on a Mac using an emulator.</li><li>They provide strong isolation of resources, creating a safe sandbox for applications.</li><li>VMs eliminate the need to install all dependencies for software experimentation, keeping the host machine clean and independent.</li></ul><h3>Containers</h3><p>After learning about virtual machines, you might wonder if containers are essentially the same. Containers do serve a similar purpose — running processes within constrained resources on a machine. However, there are key distinctions. Containers don’t install an entire operating system on top of the host machine’s OS. Instead, they run your processes on the host OS with their dedicated slice of resources. This means they won’t allow you to run software from a different OS or platform on the machine. However, they are faster and more lightweight since they don’t involve booting a guest OS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2q9I8lHOi1dA-EwtxAv0nA.jpeg" /></figure><p>Characteristics of Containers:</p><ul><li>Containers offer most of the benefits of VMs but won’t permit you to run cross-platform applications on your machine.</li><li>They are lightweight and require fewer system resources compared to VMs.</li><li>Containers are generally considered less secure than VMs because the host OS still has access to their processes.</li></ul><p>In summary, both containers and virtual machines have their unique use cases and advantages. The choice between them depends on your specific requirements and the level of isolation, performance, and resource utilisation you need for your applications.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4e8569b3722" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding CORS (Cross-Origin Resource Sharing)]]></title>
            <link>https://medium.com/@sahilbhati/understanding-cors-cross-origin-resource-sharing-9babd6d3af44?source=rss-b9e596b90549------2</link>
            <guid isPermaLink="false">https://medium.com/p/9babd6d3af44</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[http-security-headers]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[preflight-request]]></category>
            <category><![CDATA[cors]]></category>
            <dc:creator><![CDATA[Sahil Bhati]]></dc:creator>
            <pubDate>Thu, 24 Aug 2023 17:01:19 GMT</pubDate>
            <atom:updated>2023-08-24T17:23:44.471Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you ever encountered CORS errors while browsing the web, struggling to grasp their causes and solutions? Let’s delve into the world of CORS, understand its significance, why it exists, and the impact it has on your applications.</p><h3>CORS in a World of XSS Attacks</h3><p>Before we dive into CORS intricacies, let’s take a brief detour to cross-site scripting (XSS) attacks — imagine mischievous users injecting code into web applications through browser-side scripts. Understanding this is key before we tackle CORS.</p><h3>The What and Why of CORS</h3><p>Imagine web browsers as vigilant guardians. They want to ensure that websites don’t recklessly interact with others — like ensuring order at a bustling marketplace. CORS comes into play when a website wants to fetch data from a different domain, like a merchant seeking goods from a different stall. But why the fuss?</p><h3>Safeguarding Against Unauthorized Access</h3><p>In simpler terms, browsers prevent web pages from making requests to domains other than their own to avoid digital chaos. CORS can rear its head during any HTTP request when the requested resource resides on a different domain than the origin of the requesting page. There’s a catch, though — the server must explicitly allow cross-origin requests.</p><h3>The Trust Factor: Validating Domains</h3><p>So, what’s the deal? When you load resources from a domain different from your browser’s current one, the browser wants to ensure that this new domain is credible and trusted by the web application. It’s like verifying credentials before allowing someone into an exclusive club.</p><h3>CORS Headers: The Negotiators</h3><p>To perform this validation, your browser initiates a special HTTP call named OPTIONS also known as preflight request. This call is like a diplomatic envoy seeking permission for a conversation. The server hosting the resource responds with headers — these headers lay down the ground rules for the interaction. Here’s the lowdown on those headers:</p><ul><li>Access-Control-Allow-Origin: This specifies who’s allowed to the party — set it to specific domains or * for any origin.</li><li>Access-Control-Allow-Methods: It defines how the allowed participants can communicate.</li><li>Access-Control-Allow-Headers: These list the permissible conversation topics, or headers that can be included in the actual request.</li><li>Access-Control-Expose-Headers: Specify which response headers are ready for the world to see.</li><li>Access-Control-Allow-Credentials: Indicate whether credentials (like cookies) should be shared in the cross-origin request.</li><li>Access-Control-Max-Age: Set how long the preflight request (OPTIONS) response can be cached.</li></ul><h3>The Verdict: Accept or Reject</h3><p>Once your browser receives the response from OPTIONS, it checks these headers to see if the request it intended to make is still on the table. Think of it as the bouncer checking the guest list before giving the green light to enter a club. If everything matches up, the conversation proceeds smoothly.</p><h3>Practical Scenarios</h3><p>Now, let’s illustrate with some examples to shed light on how CORS works in real-world situations:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sHC4NMDfYctLTZqLZNfBUQ.png" /></figure><h3>Balancing Act: CORS and Performance</h3><p>One might raise a valid concern — CORS introduces an extra layer, potentially causing a slight slowdown. It’s similar to an airport security check — a bit of a hassle, but necessary for safety. However, there’s a reason for this added step.</p><p>You might wonder, “Can we skip CORS to speed things up?” Technically, yes, but it’s akin to leaving your front door wide open. Security matters, even in the digital realm.</p><h3>Finding Harmony: CORS and Efficiency</h3><p>To strike a balance between security and performance:</p><ul><li>Simple Requests Rule: Opt for simple requests like GET or POST. They bypass the extra security check.</li><li>Cache the Rules: Configure your server to provide suitable caching headers for preflight responses. This reduces the need for repeated preflight requests.</li><li>Trim the Headers: Keep your request headers concise. Excessive headers in cross-origin requests could trigger preflight checks.</li><li>Curbing Cross-Origin Requests: Minimize the number of such requests your application makes. Explore strategies like server-side APIs, reverse proxies, or content delivery networks (CDNs).</li></ul><h3>Demystifying “Simple Requests”</h3><p>Hold on — what exactly qualifies as a “simple request”? And if these don’t trigger preflight requests, does it create a security gap? Let’s clarify:</p><p>Simple Requests: Think of these as the straightforward interactions — like casual chats in the digital realm. A simple request possesses the following characteristics:</p><ul><li>Non-Simple Methods: These are methods other than GET, POST, or HEAD. When your request involves one of these standard methods, browsers understand that it’s a simple request and proceed accordingly.</li><li>Custom Headers: If your request includes headers beyond the standard ones like Accept, Accept-Language, Content-Type, and Content-Language, it’s still considered a simple request, as long as it adheres to these predefined headers.</li><li>Content Types: While content types like application/json might sound complex, they fall under the category of “simple” when it comes to requests. In the context of these content types, the browser recognises the simplicity of the request.</li></ul><p>Why No Preflight?: Now, you might wonder — if these are considered “simple requests,” why don’t they trigger the preflight requests we discussed earlier? Well, it’s because browsers understand that these characteristics signify a familiar and safe interaction. It’s like visiting a neighbour — you don’t need an elaborate introduction.</p><h3>The Twist: CORS’s Limitations</h3><p>Wait, something doesn’t add up. If the server determines whether a request is legitimate, what stops a malicious server from faking it by sending the right headers? Sadly, you’ve stumbled upon a truth — CORS, like other security measures, isn’t bulletproof. There’s even a name for this — the “confused deputy” attack.</p><h3>Embracing CORS’s Positive Side</h3><p>Despite its limitations, CORS offers valuable advantages:</p><ul><li>Origin Validation: CORS validates request origins. Even if a cunning server sets lenient CORS headers, the browser greenlights cross-origin requests only if headers match the actual request source. This thwarts attempts to trick the browser into sending requests unknowingly.</li><li>Restricted Permissions: CORS headers restrict the types of requests, methods, and headers allowed for cross-origin interactions. Malicious servers can’t manipulate the browser into sending unauthorised requests or accessing sensitive data.</li><li>Browser Vigilance: Browsers are vigilant enforcers of CORS policies ingrained in their security models. They allow or block requests based on the CORS headers the server provides, curbing unauthorised access from web pages and scripts.</li><li>Countering CSRF: A primary aim of CORS is to combat CSRF attacks. It prevents malicious sites from making authenticated requests on users’ behalf. When a cross-origin request carries credentials, the server relies on CORS headers to validate its origin.</li></ul><h3>In a Nutshell: CORS’s Role</h3><p>To sum it up, CORS isn’t a flawless shield against all threats. It’s an essential piece of the security puzzle, preventing certain types of attacks. But to ensure comprehensive protection, remain vigilant about app security. Combine CORS with other best practices like input validation, authentication, and authorization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9babd6d3af44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Browser request Caching and Proxy servers]]></title>
            <link>https://medium.com/@sahilbhati/browser-request-caching-and-proxy-servers-607c4970a60b?source=rss-b9e596b90549------2</link>
            <guid isPermaLink="false">https://medium.com/p/607c4970a60b</guid>
            <category><![CDATA[caching]]></category>
            <category><![CDATA[browsers]]></category>
            <category><![CDATA[http-request]]></category>
            <category><![CDATA[proxy]]></category>
            <category><![CDATA[rest]]></category>
            <dc:creator><![CDATA[Sahil Bhati]]></dc:creator>
            <pubDate>Mon, 14 Aug 2023 15:40:38 GMT</pubDate>
            <atom:updated>2023-08-14T15:42:15.265Z</atom:updated>
            <content:encoded><![CDATA[<p>Caching is a cornerstone of web performance optimisation, reducing load times and server strain. In this blog post, we’ll delve into the intricate world of caching, focusing on cache control headers and strategies. Whether you’re a developer, system administrator, or curious web enthusiast, understanding these concepts will empower you to create a blazing-fast web experience for your users</p><h3><strong>Caching By Browser</strong></h3><h3>ETags: Uniquely Identifying Resources</h3><p>ETags, or Entity Tags, serve as unique identifiers for specific versions of resources. When a client or proxy requests a resource, the server attaches an ETag to the response. This ETag is derived from various factors, such as the content’s hash, timestamp, or version number. Subsequent requests for the same resource include the ETag in the If-None-Match header, allowing the server to determine if the cached copy is still valid.</p><h3>Conditional Headers for Cache Invalidation</h3><p>Conditional headers, namely If-None-Match and If-Modified-Since, facilitate precision cache invalidation by enabling revalidation only when necessary:</p><p>If-None-Match:</p><ul><li>The client sends this header with the ETag value of its cached resource.</li><li>The server compares the provided ETag with the current version of the resource.</li><li>If the ETag matches, the server responds with a “304 Not Modified” status, signaling that the cached copy remains valid.</li><li>If the ETag doesn’t match, the server sends the updated resource along with a new ETag, ensuring that the cache is refreshed.</li></ul><p>If-Modified-Since:</p><ul><li>The client includes this header with the timestamp of its cached resource’s last modification.</li><li>The server checks if the resource has been modified since the provided timestamp.</li><li>If the resource hasn’t changed, the server responds with a “304 Not Modified.”</li><li>If the resource has been updated, the server delivers the new version.</li></ul><p>Note: The combination of etags and conditional headers can be used to make informed cache invaldiation decisions. Both of them have their own limitations. Etags are tough to implement and maintain and caching based on timestamp can cause redundant data load in the cases when updated time is changed but there is no change in data for the user.</p><h3>Proxy Server Caching</h3><p>Proxy servers, including CDNs, play a crucial role in optimising content delivery for both browser and non-browser clients. Their caching implementation involves:</p><ul><li>Cache Hierarchies: Proxies can create a hierarchy of caches, with CDNs at the edge and intermediary proxies closer to users. Resources are cached at various levels for efficient content delivery.</li><li>Shared Caches: Proxy servers respect cache control headers to determine whether a resource should be cached and for how long. public and private directives control cache access.</li></ul><pre><strong>Note: The public and private directives in the Cache-Control header are used to specify who is allowed to cache a particular resource-either any cache (public) or only the client&#39;s browser cache (private).It means private Cache-Control requests cant be cached by proxies</strong></pre><h3><strong>Conclusion</strong></h3><p>Understanding and implementing caching behaviours using cache control headers is essential for optimising web performance and content delivery. Browser and proxy server caching, combined with proper header configuration, can enhance user experiences, reduce server load, and improve overall website responsiveness. By mastering these caching concepts, you can create a optimised and efficient web presence for your users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=607c4970a60b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>