<?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 Mradulnatani on Medium]]></title>
        <description><![CDATA[Stories by Mradulnatani on Medium]]></description>
        <link>https://medium.com/@mradulnatani0?source=rss-ec67be89dad4------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*FiHYXJaiOD4jRwPF</url>
            <title>Stories by Mradulnatani on Medium</title>
            <link>https://medium.com/@mradulnatani0?source=rss-ec67be89dad4------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 19:41:36 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mradulnatani0/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[AWS Services Explained: A Practical Tour Through a Real Architecture]]></title>
            <link>https://medium.com/@mradulnatani0/aws-services-explained-a-practical-tour-through-a-real-architecture-b459ab36cd3f?source=rss-ec67be89dad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/b459ab36cd3f</guid>
            <dc:creator><![CDATA[Mradulnatani]]></dc:creator>
            <pubDate>Thu, 20 Aug 2026 14:31:32 GMT</pubDate>
            <atom:updated>2026-08-20T14:31:32.537Z</atom:updated>
            <content:encoded><![CDATA[<p>If you’ve ever opened the AWS console and felt your eyes glaze over at the sheer number of services on offer, you’re not alone. AWS has over 200 services, and most tutorials either drown you in exhaustive documentation or oversimplify things to the point of uselessness.</p><p>This post takes a different approach. Instead of listing services alphabetically, we’ll walk through a <strong>single, realistic web application architecture</strong> from the moment a user types a URL into their browser to the moment their action ends up as a chart on an executive dashboard. Every AWS service mentioned here earns its place because it solves a specific problem in that journey.</p><p>Here’s the full picture we’re going to unpack, piece by piece:</p><p><em>A request enters through DNS, passes through a load balancer, hits a web backend layer, flows into an application layer backed by databases and caches, triggers event coordination, lands in object storage, gets crunched by analytical processing, and finally surfaces in a data warehouse and dashboard all wrapped inside a network boundary, secured by IAM, and built/monitored through a dedicated deployment and observability pipeline.</em></p><p>Let’s go layer by layer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kDsD6sr9Q6p39o86CBSuOQ.png" /><figcaption>Backend application Architecture</figcaption></figure><h3>1. The Front Door: DNS and Routing</h3><p>Every request starts somewhere, and on AWS that somewhere is usually <strong>Amazon Route 53</strong>.</p><p>Route 53 is AWS’s DNS service, and it does more than just translate www.yourapp.com into an IP address. It also lets you:</p><ul><li>Define DNS configuration for your domains</li><li>Decide where traffic from the internet should be routed</li><li>Run health checks against your endpoints so it can stop sending traffic to something that’s down</li><li>Apply traffic-shaping strategies (weighted routing, latency-based routing, geolocation routing, and so on)</li></ul><p>Think of Route 53 as the receptionist of your architecture — it doesn’t do any of the actual work, but it decides which door you walk through.</p><p>If your app needs a single entry point that also handles authentication, throttling, and request validation before traffic ever reaches your backend, that’s where <strong>API Gateway</strong> comes in — often paired with <strong>Amazon Cognito</strong> for authentication. API Gateway acts as a software layer that gives clients one entry point to reach multiple backend services, while simultaneously managing the client-server interaction (throttling, API-level authorization, request/model validation). Cognito, in turn, handles “everything auth-related” and can be layered on top of, or integrated with, other authentication providers your application might already use.</p><h3>2. Load Balancing</h3><p>Once a request is routed, it hits the <strong>Elastic Load Balancer (ELB)</strong>. AWS actually offers several load balancer types, but ELB specifically the <strong>Application Load Balancer</strong> and <strong>Network Load Balancer</strong> — is the one you’ll see most often.</p><ul><li><strong>Application Load Balancer (ALB):</strong> operates at the HTTP/HTTPS layer, good for routing based on URL paths, hostnames, and content.</li><li><strong>Network Load Balancer (NLB):</strong> operates at the transport layer, built for extreme performance and static IPs.</li></ul><p>The load balancer’s job is simple in concept but critical in practice: spread incoming traffic across multiple healthy compute nodes so no single server gets overwhelmed, and stop sending traffic to nodes that fail health checks.</p><h3>3. The Web Backend and Application Layer: Compute Choices</h3><p>This is where the real “how do I run my code” decision happens, and AWS gives you three fundamentally different philosophies, all visible in the diagram as <strong>Node 1, Node 2, Node 3</strong> across the Web Backend and Application layers.</p><h3>Amazon EC2 — Rent a Virtual Machine</h3><p>EC2 lets you rent virtual machines that you pay for by the hour (or by the second, depending on billing mode). It’s the most flexible option — you can install anything, configure anything, and run anything you want — but that flexibility comes at the cost of setup and maintenance overhead.</p><h3>AWS Lambda — Serverless Functions</h3><p>Lambda is the serverless computing option. Instead of managing a server, you define just the <em>function </em>a code snippet, in any of several supported programming languages without worrying about the underlying infrastructure. You write your code, click deploy, and AWS handles scaling behind the scenes. Billing follows a “pay per invocation” model, which makes Lambda extremely cost-efficient for spiky or infrequent workloads.</p><h3>Containers — ECS, EKS, and Fargate</h3><p>Sitting conceptually between EC2 (full control) and Lambda (zero control) is the world of containers.</p><ul><li><strong>Amazon ECS (Elastic Container Service):</strong> an AWS-originated, fully managed container orchestration service. Despite the name similarity, it is explicitly <em>not</em> a simplified version of Kubernetes it’s its own scheduler. ECS decides:</li></ul><ol><li>Where a container runs</li><li>How many copies get started</li><li>How resources are allocated</li></ol><ul><li>The typical ECS workflow is: containerize your application → push the container image to <strong>Amazon ECR (Elastic Container Registry)</strong> → define a service in ECS to run that image. ECS also integrates easily with Application/Network Load Balancers and CloudWatch.</li><li><strong>Amazon EKS (Elastic Kubernetes Service):</strong> a variation of ECS that gives you a fully managed Kubernetes cluster. The key architectural difference between ECS and EKS is <em>how they handle networking and supporting components</em>. ECS relies on AWS-provided mechanisms (ALB, Route 53, etc.) baked in directly, whereas EKS handles all of that internally — you just plug in any standard Kubernetes-compatible tooling (like Calico for networking policies). EKS gives you the full vocabulary of Kubernetes — pods, deployments, etc. — while ECS deploys containers directly. The tradeoff: EKS increases architectural complexity even as it stays “managed.”</li><li><strong>AWS Fargate:</strong> even with managed container services, you’re still thinking about <em>servers</em> underneath. Fargate removes that entirely it’s a pay-as-you-go serverless compute engine for containers. You build and ship containers, and AWS manages the servers without any user involvement. The catch: Fargate can’t be used in highly regulated environments with strict security and compliance requirements, since you lose direct access to the underlying servers. Also worth noting: both ECS and Fargate only support AWS’s own VPC networking model.</li></ul><h3>The “Packaged Infrastructure” Shortcut</h3><p>Sometimes you don’t want to choose between EC2, Lambda, and containers at all — you just want to ship an app. This is where AWS’s <strong>packaged infrastructure</strong> services live: a “combination of all the required services as a single product” that bundles everything and abstracts away the complexity.</p><ul><li><strong>Elastic Beanstalk:</strong> the “old” service for standing up a web app with everything bundled together a kind of orchestration service. You’re still somewhere close to accessing the infrastructure underneath, if you need to.</li><li><strong>AWS App Runner:</strong> newer than Beanstalk, using ECS and Fargate in the background. You specify your containers and don’t worry about infrastructure at all — “total abstraction of all low-level components.”</li><li><strong>Amazon Lightsail:</strong> similar to other simplified cloud hosting providers (think GoDaddy or DigitalOcean). You pick the type of stack you want for your application, with prepackaged, predictable pricing.</li><li><strong>AWS AppSync:</strong> a fully managed GraphQL-as-a-service offering. Great for frontend-heavy applications, and it can interoperate with other AWS-backed services.</li></ul><h3>4. Storing and Caching Application Data</h3><p>Underneath the application layer, every real app needs somewhere to put its data and AWS splits this into relational, NoSQL, and caching tiers.</p><h3>Relational Databases: Amazon Aurora and RDS</h3><ul><li><strong>Amazon Aurora:</strong> AWS’s in-house-built database engine, compatible with both MySQL and PostgreSQL. It’s more hands-off, offering storage autoscaling and compute autoscaling, and it even provides a Data API so you can call your database using a REST API instead of a traditional connection. Aurora also has a serverless mode.</li><li><strong>Amazon RDS (Relational Database Service):</strong> gives you more choice and more hands-on control you pick which database engine you want (MySQL, PostgreSQL, Oracle, and others), so it’s less abstracted than Aurora but more flexible in engine choice.</li></ul><h3>NoSQL Databases</h3><ul><li><strong>Amazon DynamoDB:</strong> a fully managed NoSQL database optimized for key-value lookups. Scaling configuration and autoscaling are handled entirely behind the scenes — you don’t worry about it.</li><li><strong>Amazon DocumentDB:</strong> a MongoDB-compatible document database.</li><li><strong>Amazon OpenSearch:</strong> essentially “Elasticsearch behind the scenes,” used for search and log analytics workloads.</li></ul><h3>Caching: Amazon ElastiCache</h3><p>ElastiCache provides caching services based on key-value lookups, so you never have to worry about hosting the caching infrastructure yourself it’s relatively hands-off. It comes in two flavors: <strong>Memcached-based</strong> and <strong>Redis-based</strong>.</p><h3>5. Serving Static Content: CloudFront</h3><p>Not every request needs to hit your servers at all. Static files images, stylesheets, cached pages — are much cheaper and faster to serve from the edge. <strong>Amazon CloudFront</strong> is AWS’s CDN (Content Delivery Network); it caches content geographically close to your users so repeat requests never have to travel all the way back to your origin servers.</p><h3>6. Coordinating Events Between Services</h3><p>Modern applications rarely run as one monolith they’re built from services that need to talk to each other asynchronously. AWS’s <strong>Event Coordination</strong> services handle exactly this:</p><ul><li><strong>Amazon SNS (Simple Notification Service):</strong> a pub-sub service. It pushes a notification to a <em>topic</em>, and a topic can have many different subscribers. Use SNS when you want to broadcast the fact that data changed to many interested parties.</li><li><strong>Amazon SQS (Simple Queuing Service):</strong> responsible for holding messages so they can be processed later. You define queues, and those queues can connect to many different types of services or compute infrastructure. The rule of thumb: use SNS when you want to tell people about <em>your</em> data changing; use SQS when you want to be notified when something changes in <em>someone else’s</em> data.</li><li><strong>Amazon EventBridge:</strong> uses event buses (similar in spirit to SNS). A typical example: integrating an event bridge with an EC2 instance so that when it gets terminated, you can write rules specifying where to deliver that event. EventBridge lets you define multiple definitions of the data to be sent, helping subscribers get access to the specific models being delivered from the event bus. It’s also commonly used for third-party integrations for instance, whenever someone places an order on your Shopify store, that event can be directly integrated into an event bridge.</li><li><strong>AWS Step Functions:</strong> helps you define workflows for example, a customer delivery workflow with multiple sequential or branching steps.</li></ul><h3>7. Object Storage: Amazon S3 (and Glacier)</h3><p>Once events are coordinated, data often needs to land somewhere durable. <strong>Amazon S3 (Simple Storage Service)</strong> is AWS’s general-purpose object storage: very cheap, very scalable, and highly available. It’s commonly paired with CloudFront to serve static files efficiently through the CDN.</p><p>For data you rarely need to access but must retain think compliance archives <strong>Amazon S3 Glacier</strong> provides cold storage at an even lower cost.</p><h3>8. Analytical Processing</h3><p>Raw data sitting in S3 isn’t useful until something processes it. Two services dominate this space:</p><ul><li><strong>Amazon EMR (Elastic MapReduce):</strong> a large-scale distributed data processing system that lets you run many different big-data frameworks.</li><li><strong>Amazon Athena:</strong> lets you run SQL-like queries directly against data sitting in S3 completely serverless. You just store your data in S3 and run Athena queries on it; Athena automatically infers your S3 data’s schema, so there’s no separate ETL step required just to query.</li></ul><h3>9. Handling Secrets: AWS Secrets Manager</h3><p>Before we get to warehousing, it’s worth calling out a service that quietly sits underneath the analytical processing layer: <strong>AWS Secrets Manager (SSM)</strong>. Its job is exactly what it sounds like securely storing and managing secrets (database credentials, API keys, tokens) so they never end up hardcoded in your application or pipeline configuration. Any service in this architecture that needs to authenticate to another EMR reading from S3, Athena connecting to a data source, a Lambda function calling an external API can pull its credentials from Secrets Manager instead of embedding them directly in code.</p><h3>10. Data Warehousing: Amazon Redshift</h3><p>Once your data has been processed, it typically needs a home built for heavy analytical querying. <strong>Amazon Redshift</strong> is a columnar-style database purpose-built to run very large queries concurrently. It’s a central repository used to collect, integrate, and store large volumes of current and historical data from multiple disparate sources. It costs a bit more than S3 storage alone, but it also offers a serverless mode. The typical flow is straightforward: <strong>S3 → Redshift</strong>.</p><h3>11. Dashboarding</h3><p>At the very top of the stack, all of this processed and warehoused data needs to become something a human can actually look at.</p><ul><li><strong>Amazon QuickSight:</strong> AWS’s native business intelligence tool, great for end users, and it can connect to any data sitting in S3 or Redshift.</li><li><strong>Power BI (and other third-party tools):</strong> also commonly connected to AWS data sources when organizations already have BI tooling in place.</li></ul><h3>12. The Network Boundary: VPC and Subnets</h3><p>Everything described so far lives inside a <strong>Virtual Private Cloud (VPC)</strong> a private network space for your infrastructure to sit in. Within a VPC, <strong>subnets</strong> let you further segment that space (for example, separating public-facing resources from private backend resources). The VPC is effectively the outer boundary you saw wrapped around the entire architecture diagram — nothing in this stack exists outside of it.</p><h3>13. Identity and Access Management (IAM)</h3><p>Sitting above the whole architecture because it touches every layer — is <strong>AWS IAM (Identity and Access Management)</strong>. IAM is where you create roles and policies and associate them with resources, controlling exactly who (or what service) can do what, and where. Nothing in the architecture above should be reachable without an IAM policy explicitly allowing it.</p><h3>14. Rapid Development and Infrastructure as Code</h3><p>Building all of the above by hand, by clicking through the console, doesn’t scale. AWS provides Infrastructure as Code (IaC) and rapid-development tooling to make architecture reproducible:</p><ul><li><strong>AWS CloudFormation:</strong> define your infrastructure declaratively using JSON or YAML templates.</li><li><strong>AWS CDK (Cloud Development Kit):</strong> lets you define infrastructure using actual code (in a language like TypeScript or Python) rather than static templates.</li><li><strong>AWS Amplify:</strong> a toolkit-style service for building and deploying either web or mobile applications. It’s a CLI tool that focuses more on functionality than infrastructure, offering a set of purpose-built tools and features that let frontend web and mobile developers quickly build full-stack applications on AWS. It eliminates the need for complex backend configuration by providing automated hosting, authentication, data storage, and CI/CD — even adding an API can be as simple as a CLI command. Notably, it’s designed to work “even if you do not know other AWS services.”</li><li><strong>AWS SAM (Serverless Application Model):</strong> a shorthand syntax for IaC, purpose-built as a framework designed to simplify building, testing, and deploying serverless applications. SAM is also what lets your Lambda functions run and be tested locally before you ever deploy them.</li></ul><h3>15. Deploying the Application: The CI/CD Pipeline</h3><p>Once your infrastructure is defined, you need a repeatable way to ship code changes into it. AWS’s CI/CD suite covers this end to end:</p><ol><li><strong>AWS CodeCommit:</strong> stores your source code, or integrates with an external repository host like GitHub.</li><li><strong>AWS CodeBuild:</strong> takes source code from CodeCommit (or GitHub) and builds it into a deployable artifact. It also lets you create and run tests in a test environment as part of the build.</li><li><strong>AWS CodeDeploy:</strong> takes the built artifact and deploys the source code onto your compute infrastructure.</li><li><strong>AWS CodePipeline:</strong> the deployment orchestration service that ties it all together, letting you define a workflow across multiple application stages (build → test → deploy → production, for example).</li></ol><h3>16. Monitoring the Whole Thing</h3><p>Deploying is only half the job — you also need visibility into what’s actually happening in production.</p><ul><li><strong>AWS CloudWatch:</strong> contains a wide range of different features. You can view different metrics on CloudWatch for your services, and it maintains your application logs. <strong>CloudWatch Insights</strong> adds search capability on top of very large volumes of CloudWatch data using a SQL-styled query language.</li><li><strong>AWS CloudTrail:</strong> an audit trail of every operation performed on your services and infrastructure. It exists to answer three questions: <em>Who performed an action? On what application? What exactly were they doing?</em></li></ul><h3>Bringing It All Together</h3><p>Laid end to end, the journey of a single user request looks like this:</p><p><strong>Route 53</strong> resolves the domain → <strong>API Gateway</strong> (with <strong>Cognito</strong> for auth) accepts the request → the <strong>Elastic Load Balancer</strong> distributes it → the <strong>Web Backend Layer</strong> (EC2 / Lambda / ECS) and <strong>Application Layer</strong> process it, reading and writing to <strong>Aurora/RDS</strong>, <strong>DynamoDB/DocumentDB</strong>, and <strong>ElastiCache</strong> → a search query gets submitted downstream → <strong>SNS, SQS, EventBridge,</strong> and <strong>Step Functions</strong> coordinate what happens next → results land in <strong>S3</strong> → <strong>EMR</strong> and <strong>Athena</strong> crunch the data → it’s warehoused in <strong>Redshift</strong> → and finally visualized in <strong>QuickSight</strong> or <strong>Power BI</strong>.</p><p>Wrapping around all of it: a <strong>VPC</strong> for network isolation, <strong>IAM</strong> for access control, <strong>CloudFormation/CDK/SAM</strong> and <strong>Amplify</strong> for defining and rapidly shipping infrastructure, <strong>CodeCommit → CodeBuild → CodeDeploy → CodePipeline</strong> for continuous delivery, and <strong>CloudWatch/CloudTrail</strong> for keeping an eye on all of it once it’s live.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jKOZ6Sll7O3cm8MI8iDscw.png" /><figcaption>Mapping the Architecture with the AWS Servives</figcaption></figure><p>It’s a lot of moving parts but once you see how each service maps to a specific step in a request’s journey, the AWS service catalog stops feeling like an overwhelming list and starts feeling like a toolbox where every tool has an obvious job.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b459ab36cd3f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Quick introduction to WebSockets]]></title>
            <link>https://medium.com/@mradulnatani0/quick-introduction-to-websockets-61d305629e35?source=rss-ec67be89dad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/61d305629e35</guid>
            <dc:creator><![CDATA[Mradulnatani]]></dc:creator>
            <pubDate>Sat, 21 Jun 2025 21:03:51 GMT</pubDate>
            <atom:updated>2026-02-11T15:27:32.474Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong><em>Note:</em></strong><em> Before going into WebSockets we should know that what is HTTP, Three way handshake and types of polling.</em></blockquote><h3><strong>What is HTTP?</strong></h3><p>The Hypertext Transfer Protocol (HTTP) is a protocol which operates on TCP, it is the foundation of the World Wide Web, and is used to load webpages using hypertext links. When ever you open a website on your browser you send the HTTP request to the server, in exchange of which the server sends you the responce, it is a stateless protocol once the responce is sent to the client the connection is closed for each request new connection is needed to be established.<br>An HTTP request is the way Internet communications platforms such as web browsers ask for the information they need to load a website.</p><p>Example:</p><pre>Client: Get me the website<br>Server: Here is your website<br>Connection: Closed</pre><h3><strong>what are HTTP methods?</strong></h3><p>HTTP methods are referred as the HTTP verbs, the HTTP methods tells the requests sent what action should be performed. The most common form of the HTTP methods are the POST, GET, PUT and DELETE (these HTTP methods are used to perform the CRUD operations).</p><h3><strong>What is a Three Way Handshake?</strong></h3><p>When any two machine of the internet want to communicate using Transmission Control Protocol they have to follow a process that is the Three Way Handshake. Let’s understand Three Way Handshake using an example from one of our day to day activity, when you have to talk to someone you pickup your phone and dial their number, the person on the other side of the phone picks up the call and then you introduce yourself “Hello I am Tomato!”, in response to this, the original receiver will often acknowledge the caller by saying “Oh, hi Tomato!”. At this point both people have enough information for the conversation to continue as normal. <br>Computers too work the same way the first machine which want to establish the communication sends a SYN packed to the second machine listening to a port , then the second machine will send the SYN/ACK to the first machine, then the first machine will send a ACK and now the normal communication is been established between the two servers.<br><em>The HTTP uses the Three Way Handshake to establish the connection.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/298/1*FxdtFjG3AheRM0W9LKDdKg.jpeg" /><figcaption>Three Way Handshake</figcaption></figure><h3><strong>What is Polling and its types?</strong></h3><p>Polling in computer networks refers to the process of repeatedly checking the status of an external device or resource by a client program. This is often used in input/output (I/O) operations and is also known as polled I/O or software-driven I/O. In the context of web development, polling is a technique where the client makes requests to the server at regular intervals to check for updates or new data. Polling is based of the simplex mode of communication.<br>There are two types of polling that are short polling and long polling<strong>. </strong>In short polling the client repeatedly check the server “ Any updates my lord?” ,if there are any updates the server sends them in the response else it sends a blank response or no response and then the connection is broken. Short polling is wastes bandwidth and adds latency. <br>On the other hand in the long polling the client waits and maintains the connection with the server for the response as long as it recieves an updated value in the response, it is more efficient than short polling, but still HTTP-based and has overhead.</p><h3><strong>Now a question arrises that ,What should we do to fix the issues with polling?</strong></h3><p><em>“Till now the communication was more like a walike talkie but WebSocket will change the whole picture it will turn the walkie talkie into a phone call.”</em></p><h3><strong>What is a WebSocket?</strong></h3><p>WebSocket is a full-duplex communication protocol that enables real-time, bidirectional communication between a client (typically a browser) and a server. Unlike HTTP, where the client always initiates the request and the server responds, WebSocket allows both the client and server to send and receive<strong> </strong>messages independently at any time making it ideal for dynamic, real-time applications like live chats, gaming, trading platforms, or collaborative tools.<br>Once a WebSocket connection is established, it remains open<strong> </strong>until either the client or the server explicitly closes it. If the connection breaks from one end, the other end cannot continue communication until a new WebSocket session is created.</p><h3>How is a connection established in a WebSocket?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/632/1*nWYh3YFUKzEcPsnpojCkuQ.png" /><figcaption>WebSocket Connection</figcaption></figure><p>WebSocket use the HTTP three way handshake to start the connection with the server the connection lasts as long as any of the participating parties lays the connection off, if any one of them breaks the connection the another party cannot connect as the connection is broken at its front.<br>To understand the WebSocket connection in detail let’s understand the concept of URI. A Uniform Resource Identifier (URI) is a string that uniquely identifies a resource on the web. For WebSockets, the URIs start with:<br>ws:// – WebSocket (insecure)<br>wss:// – WebSocket Secure (encrypted, like HTTPS)</p><p>Example:</p><pre>ws://example.com/socket<br>wss://example.com/socket</pre><p>The WebSocket protocol begins with a HTTP-based handshake, followed by an upgrade to a persistent WebSocket connection. Here’s how the request/response looks:</p><p><strong>CLIENT REQUEST:</strong></p><pre>GET /socket HTTP/1.1<br>Host: example.com:8181<br>Upgrade: websocket<br>Connection: Upgrade<br>Pragma: no-cache<br>Cache-Control: no-cache<br>Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==<br>Sec-WebSocket-Version: 13</pre><p>When a client, such as a web browser, wants to initiate a WebSocket connection, it begins by sending a HTTP GET request to the server. This request starts with the line GET /socket HTTP/1.1, where /socket is the endpoint the WebSocket server is listening on . The Host header specifies the server&#39;s domain and port here, example.com:8181 to tell the server where the request is headed. To signal that the client wants to switch from HTTP to the WebSocket protocol, it includes the headers Upgrade: websocket and Connection: Upgrade. These two headers are crucial, as they inform the server that the client wishes to upgrade the communication protocol from HTTP to WebSocket. To ensure the request is not cached by intermediate proxies or browsers, the headers Pragma: no-cache and Cache-Control: no-cache are included, though they are more precautionary than required.<br>One of the most important parts of this request is the Sec-WebSocket-Key header. This is a randomly generated, Base64-encoded string that acts as a challenge key for the server. The server uses this key in a predefined hashing process to validate the request and generate a corresponding response. This mechanism ensures that the request is genuine and compliant with the WebSocket protocol. Alongside this, the Sec-WebSocket-Version header is included—usually set to 13, which is the most widely supported version defined in RFC 6455. This versioning helps the server understand which WebSocket protocol version the client expects. Once the server receives this request, it will respond with a 101 switching protocols response if it supports WebSockets, thereby completing the handshake and opening a persistent, full-duplex connection between the client and server.</p><p><strong>SERVER RESPONSE:</strong></p><pre>HTTP/1.1 101 Switching Protocols<br>Upgrade: websocket<br>Connection: Upgrade<br>Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=</pre><p>After receiving a WebSocket handshake request from the client, the server validates it and responds with a special HTTP status code and headers that signal the successful protocol upgrade. The response begins with HTTP/1.1 101 Switching Protocols, which is an official HTTP status code indicating that the server is agreeing to switch from the HTTP protocol to another protocol—WebSocket, in this case. The Upgrade: websocket header confirms the specific protocol the server is switching to, and Connection: Upgrade echoes the client&#39;s intent, reaffirming that the connection should now transition away from traditional HTTP. The most critical part of the response is the Sec-WebSocket-Accept header, which contains a hashed key that proves the server has correctly received and understood the client’s request. To compute this value, the server takes the Sec-WebSocket-Key provided by the client, appends a fixed GUID string (258EAFA5-E914–47DA-95CA-C5AB0DC85B11), applies a SHA-1 hash to the combined string, and then encodes the result in Base64. This resulting value—such as s3pPLMBiTxaQ9kYGzzhZRbK+xOo= is returned in the Sec-WebSocket-Accept header. This mechanism ensures that only compliant WebSocket clients and servers can establish a valid connection, providing a layer of handshake verification. Once this response is sent, the HTTP connection is successfully upgraded, and the WebSocket protocol takes over, allowing real-time, bidirectional communication between the client and server.</p><h3>The WebSocket Protocol</h3><pre>                                           <br>+-------+-------+---------------+-------------------------------+<br>| FIN   | RSV1-3| Opcode        | MASK | Payload Length          |<br>+-------+-------+---------------+-------------------------------+<br>| Masking Key (if MASK = 1)                                    |<br>+--------------------------------------------------------------+<br>| Payload Data                                                 |<br>+--------------------------------------------------------------+</pre><p>Once the WebSocket connection is successfully established, all communication between the client and the server takes place through frames, which are small, structured packets of data. Each WebSocket frame contains several fields that define how the message should be interpreted and processed.</p><p>The first bit in the frame is the FIN bit, which indicates whether this is the final fragment of the message (1) or if more frames are coming (0).<br>Following that are three reserved bits — RSV1, RSV2, and RSV3 which are typically set to 0unless a protocol extension uses them.<br>The Opcode, a 4-bit value that defines the frame type. For example, 0x1 represents a text frame, 0x2 is for binary data, 0x8 signals connection closure, 0x9 is a ping, and 0xA is a pong response.<br>After the Opcode, there is the MASK bit, which indicates whether the payload data is masked. This bit is always set to 1 for messages sent from the client, meaning the data is encoded using a masking key, and set to 0 for server responses.<br>Then comes the Payload Length, which tells how much actual data is being sent. If the length is between 0 and 125, it fits directly in 7 bits; if it&#39;s 126, the next two bytes describe the length; and if it&#39;s 127, the length is stored in the next eight bytes.If the MASK bit is set to 1, the next 4 bytes contain the masking key, which is a 32-bit key used to encode (on the client side) or decode (on the server side) the payload using XOR operations.<br>Finally, the frame contains the Payload Data, which is the actual content being transmitted — whether it’s a text string, binary file, JSON object, or any other data format. This well-defined framing structure allows WebSockets to maintain lightweight, flexible, and efficient real-time communication with minimal overhead.</p><h3>When to use WebSockets and when not</h3><p>When it comes to real-time applications such as cryptocurrency platforms, trading dashboards, gaming environments, or chat systems where continuous data streaming and instant updates are crucial, WebSockets become an essential choice. They enable seamless, low-latency communication between the client and server, allowing data to flow in both directions in real time. However, in scenarios where only one-time data exchange is required such as fetching a user profile, downloading a report, viewing a blog post, or retrieving historical logs or archived messages WebSockets are not necessary. In these cases, using standard HTTP-based communication protocols like REST or SOAP is more efficient and appropriate. These traditional protocols are ideal for request-response models where real-time updates are not needed.</p><h3>Final Thoughts</h3><blockquote>In this blog, we started from exploring how TCP connections are established through a 3-way handshake, what is HTTP, HTTP requests and methods, and what are traditional techniques like short and long polling fall short when it comes to real-time applications. We then saw how WebSockets overcome these limitations by establishing a persistent, full-duplex connection that allows seamless, low-latency communication between a client and server. We also dove into the WebSocket handshake process and unpacked the frame structure that powers this efficient protocol. Understanding how WebSockets work under the hood gives developers the tools to build fast, interactive, and modern web applications whether it’s chat apps, live dashboards, multiplayer games, or collaborative tools. As the web continues to evolve toward more dynamic, real-time experiences, mastering WebSockets will be an essential skill for developers building the next generation of web apps.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=61d305629e35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Let’s know about Terraform modules]]></title>
            <link>https://medium.com/@mradulnatani0/lets-know-about-terraform-modules-7ab4e3c3f2a5?source=rss-ec67be89dad4------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ab4e3c3f2a5</guid>
            <category><![CDATA[uses-and-best-practises]]></category>
            <category><![CDATA[use-and-create-modules]]></category>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[terraform-modules]]></category>
            <category><![CDATA[extra-stuff]]></category>
            <dc:creator><![CDATA[Mradulnatani]]></dc:creator>
            <pubDate>Tue, 18 Mar 2025 18:49:39 GMT</pubDate>
            <atom:updated>2025-03-18T18:51:17.061Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>what is Terraform?</strong></h3><p>Terraform is an infrastructure as code tool that lets you define both cloud and on-prem resources in human-readable configuration files that you can version, reuse, and share. You can then use a consistent workflow to provision and manage all of your infrastructure throughout its lifecycle. Terraform can manage low-level components like compute, storage, and networking resources, as well as high-level components like DNS entries and SaaS features.</p><h3><strong>How Terraform works?</strong></h3><p>The user writes the Terraform code using the HCL i.e. the declerative language used for infrastructure management the code is manages at the registeries or at any version control then the push and pull operations can be performed accordingly at an automation API or server and then the desired infrastructure is created on the servers on the cloud or at the on-premise infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/721/1*d6KOZivdX4Qq6AUCL3Sgxg.png" /><figcaption>Terraform workflow</figcaption></figure><p>Terraform works by using the following Terraform commands:<br> <br>1. <strong>init</strong> — The ‘terraform init’ command should be run after the HCL code is been written, running this command initializes the working directory, downloads provider plugins and modules, and sets up the backend for state management.</p><p>2. <strong>plan</strong> — The ‘terraform plan’ command is run after the initialization of the current code, this command compares the current state of the infrastructure with the desired state defined in the configuration files also generates an execution plan that previews the changes Terraform will make without actually applying them.</p><p>3. <strong>apply</strong> — The ‘terraform apply’ command executes the plan, provisioning or modifying resources to match the desired state defined in the configuration.</p><p>4. <strong>destroy</strong> — The ‘terraform destroy’ command removes all the resources managed by Terraform, cleaning up insrastructure when no longer needed is considered a good practise.</p><h3><strong>What are Terraform Modules?</strong></h3><p>A module is a container for multiple resources that are used together. You can use modules to create lightweight abstractions, so that you can describe your infrastructure in terms of its architecture, rather than directly in terms of physical objects.</p><p>When and why to use Terraform modules?<br>HashiCorp Configuration Language (HCL) is a declerative language i.e. you do not need to define that how things have to be done you just have to tell that what things are needed to by made and by just justifing them in the desired .tf or .json format the required infrastructure can be created. Being a declerative language writting the same thing again and again would be a typical thing, so we just write it once and just use it again and again. Terrafom modules make the code reuasble and more readable at the same time.</p><p>A typical modules usually looks like this -</p><pre> .<br> |<br> | - main.tf<br> | - outputs.tf<br> | - README.md<br> | - variables.tf</pre><p><strong>Difference between the modules and the resources<br></strong>People generally confuse themselves between these two terms a resource is that infrastrucrure which we want the create using our code or which is going to be created where as a module is the collection of resources that are used togrther in a reusable form to construct the desired infrastructure.</p><p><strong>Types of modules<br></strong>The are 4 types of Terraform modules but we will divide these modules into 2 categories that are “How they are written?” and “are the modules Published?”<br><strong>The first category consists of Root Modules and child modules.<br>The second catrgory conists of Local modules and the Published Modules.</strong></p><blockquote><strong>Root Modules</strong><em><br></em>Every Terraform configuration has at least one module, known as its root module, which consists of the resources defined in the .tf files in the main working directory.</blockquote><blockquote><strong>Publised modules<br></strong>A Terraform module (usually the root module of a configuration) can call other modules to include their resources into the configuration. A module that has been called by another module is often referred to as a child module. Child modules can be called multiple times within the same configuration, and multiple configurations can use the same child module.</blockquote><blockquote><strong>Local modules<br></strong>A local module is a module that wasn’t published in any registry and when it is sourced, it is using the path to that particular module.</blockquote><blockquote><strong>Published modules<br></strong>A published module refers to a module that has been pushed to a Terraform Registry, or even simply on a VCS and has a tag associated with it. When a published module is sourced, the URL of that module is used either from the registry or from the VCS itself.</blockquote><p><strong>How to use Terraform modules?</strong></p><blockquote><strong>Step 1</strong>. Create the module block</blockquote><p>Example of module block:-</p><pre>module &quot;test_module&quot; {<br> source = &quot;https://github.com/xyz&quot;<br> version = &quot;1.0.0&quot;<br>arg_1 = var.example<br> arg_2 = var.example<br> arg_3 = var.example<br>}</pre><p>Example 2 (main.tf)</p><pre>provider &quot;aws&quot; {<br> region = var.region<br>}<br>resource &quot;aws_s3_bucket&quot; &quot;example&quot; {<br> bucket = var.bucket_name<br>}</pre><blockquote>-&gt; <strong>source</strong> = The source can be local if the module we are calling are stored in the same working directory you can just directly specify the path into the source, this is called local source where as if the modules are in some registry or it any VCS you can give the link to that registry in the source this is called remote source.</blockquote><blockquote>-&gt; <strong>version</strong> = Determining the version helps you to control what module changes should be introduced into your infrastructure.</blockquote><blockquote>-&gt; <strong>meta-arguments</strong> = Meta-Arguments are the special arguments that change the behaviour of Terraform when parsing the declared module<br>Types of meta-arguments:-</blockquote><pre>|- count<br>|- for_each<br>|- providers<br>|- depends_on</pre><p>count and for_each are used for almost the same job that is to create multiple instances of the same module or resource where as provider is used to define the provider which is to be used (In Terraform, providers are plugins that act as a bridge between Terraform and the cloud or infrastructure services you want to manage) and depends_on is used in the case where you need to declare that something should be created before something else.</p><blockquote><strong>Step 2</strong>. Declare module outputs and variables</blockquote><p>Example of output.tf file:-</p><pre>output &quot;bucket_arn&quot; {<br> value = aws_s3_bucket.example.arn<br> description = &quot;ARN of the S3 bucket&quot;<br>}</pre><p>Example of variable.tf file:-</p><pre>variable &quot;bucket_name&quot; {<br> type = string<br> description = &quot;The name of the S3 bucket&quot;<br>}<br>variable &quot;region&quot; {<br> type = string<br> default = &quot;us-east-1&quot;<br> description = &quot;The AWS region&quot;<br>}</pre><p>If we want to use the terraform module create in this file in other file we can go for the following approach as shown in this example code<br>let’s use this module in another Terraform configuration we will be writting the main.tf file in another directory (located outside the module directory)</p><pre>provider &quot;aws&quot; {<br> region = &quot;us-east-1&quot;<br>}<br>module &quot;my_s3_bucket&quot; {<br> source = &quot;../terraform-modules/s3-bucket-module&quot;<br>bucket_name = &quot;example-bucket-123&quot;<br>}<br>output &quot;s3_bucket_arn&quot; {<br> value = module.my_s3_bucket.bucket_arn<br> description = &quot;ARN of the S3 bucket created by the module&quot;<br>}</pre><p>Here we can clearly see that we have used the module that we defined in the another file, in the module block we give a local name to this instance of the module we mention the location of the module in the source block and then the bucket_name is an input variable defined in the module that specifies the name of the S3 bucket to be created.</p><blockquote><strong>Step 3</strong>. Taint Terraform Modules<br>In Terraform, the term “taint” refers to marking a resource as degraded or requiring replacement. This is done using the terraform taint command, which modifies the Terraform state file to indicate that a specificresource should be destroyed and recreated during the next terraform apply operation.</blockquote><p>Example — terraform taint aws_instance.example</p><p>The taint command is used when a resource is in undesirable or in unexected state, this command forces Terraform to destroy and recreate the resource during the next apply cycle.The terraform taint command updates the state file to mark a resource as “tainted.” This does not immediately destroy the resource but ensures it will be replaced during the next terraform apply.</p><blockquote><strong>Step 4</strong>. Test modules<br>Terraform modules are managed by the Spacelift, Spacelift alongside other upgrades and extensions provides automated module testing and you will absolutely love it. Terraform modules managed by the Spacelift registry get tested every time you push a new commit.</blockquote><p><strong>We can also send the output of one module as the input for another module</strong>, here is an example for this:</p><p><strong>Module A</strong>: Creates an AWS S3 bucket and outputs its name.<br><strong>Module B</strong>: Uses the S3 bucket name as an input to configure an AWS IAM policy.</p><p>This is the basic structure of our Terraform project</p><pre>.<br>├── main.tf<br>├── modules/<br>│ ├── s3_bucket/<br>│ │ ├── main.tf<br>│ │ └── outputs.tf<br>│ └── iam_policy/<br>│ ├── main.tf<br>│ └── variables.tf</pre><blockquote>modules/s3_bucket/main.tf</blockquote><pre>resource &quot;aws_s3_bucket&quot; &quot;example&quot; {<br> bucket = &quot;example-bucket-123&quot;<br>}</pre><blockquote>modules/s3_bucket/outputs.tf</blockquote><pre>output &quot;bucket_name&quot; {<br> description = &quot;Name of the S3 bucket&quot;<br> value = aws_s3_bucket.example.bucket<br>}<br>modules/iam_policy/variables.tf<br>variable &quot;bucket_name&quot; {<br> type = string<br> description = &quot;Name of the S3 bucket for the IAM policy&quot;<br>}j</pre><blockquote>modules/iam_policy/main.tf</blockquote><pre>resource &quot;aws_iam_policy&quot; &quot;example&quot; {<br> name = &quot;S3AccessPolicy&quot;<br> description = &quot;Policy to access S3 bucket&quot;<br>policy = jsonencode({<br> Version = &quot;2012–10–17&quot;<br> Statement = [<br> {<br> Effect = &quot;Allow&quot;<br> Action = [&quot;s3:GetObject&quot;]<br> Resource = &quot;arn:aws:s3:::${var.bucket_name}/*&quot;<br> }<br> ]<br> })<br>}</pre><blockquote>main.tf</blockquote><pre>provider &quot;aws&quot; {<br> region = &quot;us-east-1&quot;<br>}<br># Use the S3 bucket module<br>module &quot;s3_bucket&quot; {<br> source = &quot;./modules/s3_bucket&quot;<br>}<br># Use the IAM policy module, passing in the output from the S3 bucket module<br>module &quot;iam_policy&quot; {<br> source = &quot;./modules/iam_policy&quot;<br> bucket_name = module.s3_bucket.bucket_name<br>}</pre><p>S3 bucket module creates an S3 bucket named example-bucket-123<br>IAM Policy module takes the bucket_name as the input and creates an IAM policy that allows access to objects in the specified S3 bucket.<br>The main config file defines the AWS provider calls the S3 bucket module and creates the S3 bucket and calls the iam_policy module, passing in the output bucket_name from the s3_bucket module.</p><blockquote><strong>So now by you know that how Terraform works and how Terraform modules work here is the list of the best Terraform practises</strong><br>1. Minimal Structure: main.tf, vairables.tf, outputs.tf<br>2. Use input and output variables.<br>3. Use multiple resources, using a single resource is considered as a bad pracrise,<br>4. Test your module.<br>5. Take advantage of built-in functions.<br>6. use defaults and optionals depending on the data type of your variable.</blockquote><h3><strong>Problems solved by Terraform</strong></h3><p>1. Code Repetition<br>2. Lack of code clearity<br>3. Human Error<br>4. Lack of compliance</p><h3>Have an extra slice</h3><p>Variables are declared in a variable.tf file, there values are assigned in a terraform.tfvar file. Terraform automatically loads the values from terraform.tfvar during execution. Do not confuse yourself just simply remember that variable.tf file is used to simply declare the variables and optionally set default values for them, on the other hand the terraform.tfvars file is used to assign specific values to these declared variables.</p><p>.teraform.lock.hcl — When we run teraform init command. Terraform resolve provides dependencie and records them in .terraform.lock.hcl .This file ensures that subsequent runs use the same provider versions even if variables are available</p><p><strong>State Management — <br></strong>Imagine that we have multiple EC2 instances existing before the one created by Terraform, those resources won’tbe affected<br>Terraform only manages those resources that are the code written by us or created by us. For this, Terraform maintains the mapping of information regarding defined configurations and there corresponding real world cloud entities<br>Terraform.tfstate file thus maintains this mapping which in term helps terraform to identify the current state of the resources which are already provisional and the resources yet to be provisional or to be deleted.</p><p><strong>State Lock File:</strong> .terraform.tfstate.lock.info ,The existance of this file is temprory, only when plan, apply or destroy commands are being excecuted these files come into existance.<br>Run ‘terraform apply’ in the root directory of our project and do not enter anything when Terraform asks for confirmation or anything. Hold ofr a momend and observe the file directory.Here we can see .terraform.tfstate.lock.info is created automatically. If you now enter ‘yes’ this file exists for duration until terraform successfully provisions these resources. Similar behaviour is observed for the destroy command. The purpose of this lock file is to prevent race condition. imagine a scenario where a Terraform environment is set up on a shared VM and multiple developers are trying to apply their changes simultenously. To ensure changes are applied in a specific order, Terraform uses this lock file to manage the sequence of execution</p><p>Example file format:</p><pre>{<br> &quot;ID&quot;:&quot;&quot;<br> &quot;Operations&quot;:&quot;&quot;<br> &quot;Info&quot;:&quot;&quot;<br> &quot;Who&quot;:&quot;&quot;<br> &quot;Version&quot;:&quot;&quot;<br> &quot;Created&quot;:&quot;&quot;<br> &quot;Path&quot;:&quot;&quot;<br>}</pre><p>Any request that is prioritized to be executed, creates this temprory information set-stored in terraform.tfstate.lock.info file and add temperorily puts on hold any other results till the current execution is completed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ab4e3c3f2a5" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>