<?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"><channel><title><![CDATA[Kernel to Cloud | Computer Science, Linux, Cloud & DevOps]]></title><description><![CDATA[Technical notes on computer science fundamentals, Linux, cloud, DevOps and software engineering, combining theory with practical workplace learnings.]]></description><link>https://blog.khansab.in</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Apr 2026 06:05:19 GMT</lastBuildDate><atom:link href="https://blog.khansab.in/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[What Is IMDSv2 in AWS? IMDSv1 vs IMDSv2 Explained with Examples]]></title><description><![CDATA[Overview
The Instance Metadata Service (IMDS) simplifies credential management on EC2 instances by providing temporary, automatically rotated credentials. This eliminates the need to hardcode or manua]]></description><link>https://blog.khansab.in/what-is-imdsv2-in-aws-imdsv1-vs-imdsv2-explained-with-examples</link><guid isPermaLink="true">https://blog.khansab.in/what-is-imdsv2-in-aws-imdsv1-vs-imdsv2-explained-with-examples</guid><category><![CDATA[AWS]]></category><category><![CDATA[ec2]]></category><category><![CDATA[cloud security]]></category><category><![CDATA[IMDSv2]]></category><category><![CDATA[Devops]]></category><category><![CDATA[IMDSv1]]></category><category><![CDATA[imds]]></category><category><![CDATA[instance-metadata-service]]></category><dc:creator><![CDATA[Mohsin Khansab]]></dc:creator><pubDate>Sat, 18 Apr 2026 06:05:42 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6633c2252c01edc0085a6004/04ec53f9-7231-467c-b335-9f047ca827a5.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Overview</h2>
<p>The Instance Metadata Service (IMDS) simplifies credential management on EC2 instances by providing temporary, automatically rotated credentials. This eliminates the need to hardcode or manually distribute sensitive credentials to applications. IMDS runs locally on every EC2 instance and is accessible via the link-local IP address <code>169.254.169.254</code>. It is also accessible over IPv6 for EC2 instances built on the Nitro System.</p>
<div>
<div>💡</div>
<div>By default, the IPv6 endpoint for the instance metadata service (IMDS) is disabled. You can enable the IPv6 endpoint at instance launch when the following requirements are met: 1) The selected instance type is built on the AWS Nitro System. 2) The selected subnet supports IPv6, where the subnet is either dual stack of IPv6 only. If the above requirements are not met, the field is disabled.</div>
</div>

<p>The EC2 IMDS provides important information about each individual EC2 instance. This includes several categories of information, such as AMI ID, hostname, associated security groups, instance id, local IPv4, etc</p>
<p>Here's an example of what IAM credentials might look like when retrieved from the EC2 instance metadata:</p>
<pre><code class="language-shell">$ curl http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance
{
  "Code" : "Success",
  "LastUpdated" : "2026-04-17T18:20:09Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "ASIAZYX123M4ABCD567E",
  "SecretAccessKey" : "exponentialTHlF2HmgNWsecretRNB2JXexample",
  "Token" : "IQoJb3JpluX2VjEBIaC//////wEQABoMMTzMjUyIgw8uDv8CA7wN9Y0wBwqpwSlpN654xzHp7mGsZ9gz5J8uoo2xJqG3Bc7C/1TAFZyEiSz0cN...",
  "Expiration" : "2026-04-18T00:45:39Z"
}
</code></pre>
<p><strong>Note</strong>: <em>The above</em> <code>curl</code> <em>request uses IMDSv1, as it does not include a session token in the request header.</em></p>
<hr />
<h2>Server-side request forgery (SSRF) and the Instance Metadata Service</h2>
<p>An attacker exploiting a Server-Side Request Forgery (SSRF) vulnerability can trick an application into making requests to the instance metadata endpoint (<code>169.254.169.254</code>). If IMDSv1 is enabled, this can allow the attacker to retrieve IAM credentials associated with the instance.</p>
<p>Recently, Mandiant identified a threat actor using a known vulnerability, <code>CVE-2021-21311</code>, to steal IAM credentials from EC2 instances using the metadata service post-compromise. <a href="https://cloud.google.com/blog/topics/threat-intelligence/cloud-metadata-abuse-unc2903/">[1]</a></p>
<p>IMDSv2 mitigates this risk by requiring a session token in request headers, which typical SSRF vulnerabilities cannot easily provide.</p>
<hr />
<h2>IMDSv2</h2>
<p>With IMDSv2, access to instance metadata is protected using session-based authentication. A session begins when a client requests a temporary token using a PUT request. This token must then be included in the header of all subsequent requests to access metadata.</p>
<p>This approach ensures that only requests originating from within the instance can successfully retrieve metadata, significantly reducing the risk of SSRF-based attacks.</p>
<p>For example, this curl recipe retrieves a session token that’s valid for the full six hours (21600 seconds) and then uses that token to access the EC2 instance’s profile metadata:</p>
<pre><code class="language-shell">TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")

curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance

Output:
{
  "Code" : "Success",
  "LastUpdated" : "2026-04-17T18:42:35Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "ASIAZYX123M4ABCD567E",
  "SecretAccessKey" : "exponentialC/wmIczuv7CGuOmm8iXPSCexample",
  "Token" : "IQoJb3JpZ2luTEiSDBGAiEA9+W761PO/4SOcqcQ3Ty4PsnK4WsSzEZP6WgCIQD4+koxgcjdEPnL9whM0R0TyZdjhFPY5cfBirTBAjc//////////8rxcf1/OykGpvb46+VEIFL+5...",
  "Expiration" : "2026-04-18T01:06:48Z"
}
</code></pre>
<p><strong>Note</strong>: <em>The above</em> <code>curl</code> <em>request uses IMDSv2, as it includes the session token in the request header.</em></p>
<hr />
<h2>IMDSv1 vs IMDSv2</h2>
<p>There are two versions of the Instance Metadata Service: IMDSv1 and IMDSv2.</p>
<p>IMDSv1 is a simple request and response protocol. When you make a request to the IMDS from the EC2 instance, you receive the result of your request. There are no additional parameters to be passed. Because of this, IMDSv1 is a perfect candidate for SSRF attacks.</p>
<p>IMDSv2, on the other hand, is session-oriented. This means that, before making a request to the IMDS, you must first create a session token with a PUT request and pass it along in subsequent requests inside a header. This provides an additional security benefit, as an adversary is unlikely to be able to set a request header via SSRF. IMDSv2 can be enforced during instance creation by configuring the Instance Metadata Options to require session tokens.</p>
<hr />
<h2>How to enable IMDS during Instance creation</h2>
<p>While creating the instance, In the Advanced Details you can configure Instance metadata options</p>
<img src="https://cdn.hashnode.com/uploads/covers/6633c2252c01edc0085a6004/1ba01c8f-9244-4891-9ba8-075220bd0d07.png" alt="" style="display:block;margin:0 auto" />

<hr />
<h2>How to Verify IMDS Version in AWS EC2</h2>
<p>Two ways:</p>
<ol>
<li><p>Console<br />In the EC2 console, navigate to:<br /><strong>EC2 → Instances → Select your instance id</strong></p>
<img src="https://cdn.hashnode.com/uploads/covers/6633c2252c01edc0085a6004/a26a16aa-443a-4cb1-9fc5-8eb2f41ed8e4.png" alt="" />

<img src="https://cdn.hashnode.com/uploads/covers/6633c2252c01edc0085a6004/12cc41e5-e552-4502-9287-63c041aa7ccc.png" alt="" style="display:block;margin:0 auto" />

<p><code>HttpTokens = required</code> → IMDSv2 is enforced (IMDSv1 disabled)<br /><code>HttpTokens = optional</code> → Both IMDSv1 and IMDSv2 are allowed</p>
</li>
<li><p>CLI<br />When IMDS v2 is enabled</p>
<pre><code class="language-shell">$ aws ec2 describe-instances --instance-ids i-0f581c1c90fc521c2 --query "Reservations[].Instances[].MetadataOptions.HttpTokens" --output table
-------------------
|DescribeInstances|
+-----------------+
|  required       |
+-----------------+
</code></pre>
<p>When IMDS v1 is enabled</p>
<pre><code class="language-shell">$ aws ec2 describe-instances --instance-ids i-0ef0ce715ba1fc912 --query "Reservations[].Instances[].MetadataOptions.HttpTokens" --output table
-------------------
|DescribeInstances|
+-----------------+
|  optional       |
+-----------------+
</code></pre>
</li>
</ol>
<hr />
<h2>How to Modify Instance Metadata</h2>
<ol>
<li><p>Console</p>
<img src="https://cdn.hashnode.com/uploads/covers/6633c2252c01edc0085a6004/71c7592c-01d0-4b55-8d72-440273394c9c.png" alt="" style="display:block;margin:0 auto" />
</li>
<li><p>CLI<br />To transition from IMDSv1 to IMDSv2</p>
<pre><code class="language-shell">$ aws ec2 modify-instance-metadata-options --instance-id i-0ef0ce715ba1fc912 --http-endpoint enabled --http-tokens required
{
    "InstanceId": "i-0ef0ce715ba1fc912",
    "InstanceMetadataOptions": {
        "State": "pending",
        "HttpTokens": "required",
        "HttpPutResponseHopLimit": 2,
        "HttpEndpoint": "enabled",
        "HttpProtocolIpv6": "disabled",
        "InstanceMetadataTags": "disabled"
    }
}
</code></pre>
<p>To transition from IMDSv2 to IMDSv1</p>
<pre><code class="language-shell">$ aws ec2 modify-instance-metadata-options --instance-id i-0ef0ce715ba1fc912 --http-endpoint enabled --http-tokens optional
</code></pre>
<p><code>HttpTokens = required</code> → IMDSv2 is enforced (IMDSv1 disabled)<br /><code>HttpTokens = optional</code> → Both IMDSv1 and IMDSv2 are allowed</p>
<p>To disable IMDS</p>
<pre><code class="language-shell">$ aws ec2 modify-instance-metadata-options --instance-id i-0ef0ce715ba1fc912 --http-endpoint disabled
</code></pre>
</li>
</ol>
<blockquote>
<p>Enforcing IMDSv2 is a simple yet effective step to improve the security posture of your EC2 instances, especially in environments where applications may be exposed to untrusted input.</p>
</blockquote>
<h3>References</h3>
<p>[1] Google Cloud – Cloud Metadata Abuse (UNC2903 Case Study)<br /><a href="https://cloud.google.com/blog/topics/threat-intelligence/cloud-metadata-abuse-unc2903/">https://cloud.google.com/blog/topics/threat-intelligence/cloud-metadata-abuse-unc2903/</a></p>
<p>[2] Amazon Web Services – Configure Instance Metadata Service<br /><a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html">https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html</a></p>
<p>[3] Amazon Web Services – IMDSv2 on Amazon Linux 2023<br /><a href="https://docs.aws.amazon.com/linux/al2023/ug/imdsv2.html">https://docs.aws.amazon.com/linux/al2023/ug/imdsv2.html</a></p>
<p>[4] Amazon Web Services Security Blog – SSRF and IMDS Protection<br /><a href="https://aws.amazon.com/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service/">https://aws.amazon.com/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service/</a></p>
<p>[5] Datadog Security Labs – IMDS Misconfiguration Spotlight<br /><a href="https://securitylabs.datadoghq.com/articles/misconfiguration-spotlight-imds/">https://securitylabs.datadoghq.com/articles/misconfiguration-spotlight-imds/</a></p>
]]></content:encoded></item><item><title><![CDATA[Introduction to Computer Networks: Key Concepts and Basics]]></title><description><![CDATA[Imagine waking up in a world without the internet:

No way to instantly message your friends or see what’s trending on social media.

No ability to stream music, attend virtual classes, or play online]]></description><link>https://blog.khansab.in/introduction-to-computer-networks-key-concepts-and-basics</link><guid isPermaLink="true">https://blog.khansab.in/introduction-to-computer-networks-key-concepts-and-basics</guid><dc:creator><![CDATA[Mohsin Khansab]]></dc:creator><pubDate>Thu, 24 Jul 2025 18:18:49 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/M5tzZtFCOfs/upload/b3ea93678ca09b98a3324599bf79993e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><strong>Imagine waking up in a world without the internet:</strong></p>
<ul>
<li><p>No way to instantly message your friends or see what’s trending on social media.</p>
</li>
<li><p>No ability to stream music, attend virtual classes, or play online games.</p>
</li>
<li><p>No quick access to information, collaboration tools, or even emailing for work or school.</p>
</li>
<li><p>Forget about video calls with loved ones across the world</p>
</li>
</ul>
<p><strong>Well, that's the world without computer networks.</strong></p>
<h2>Why Learn Computer Networks?</h2>
<p>Simple answer: to do all the things we couldn’t do in a world without them.</p>
<p>Whether it’s browsing the web, sending messages, working remotely, streaming videos, or making video calls, computer networks are the backbone that make modern life seamless and connected. Every device—laptop, desktop, smartphone, smartwatch, or tablet—is a different form of a computer.</p>
<p>Regardless of your career path—whether you're a Software Development Engineer (SDE), Big Data Engineer, Network Engineer, or any other role in tech—<strong>understanding computer network fundamentals is essential</strong>.</p>
<p>Learning computer networks means understanding the hidden “plumbing” that powers our digital world.</p>
<h2>OSI Model ( Open-Systems-Interconnection )</h2>
<p>Also referred to as a reference model, this model provides a high-level overview of how data is transmitted from one computer to another.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753359381396/7cb9ec76-e91f-426a-b639-2fde802eec24.png" alt="" style="display:block;margin:0 auto" />

<ul>
<li><p>Anything that is a part of the network that wants to communicate is called a <em><strong>Host</strong></em>.</p>
</li>
<li><p><em><strong>The server</strong></em> is a special type of computer. It is also a Host when receiving data from clients. The server is something that a host receives data from.</p>
</li>
<li><p>The OSI Model was finalized between the 1970s and 1980s. And it is a reference model, which means it acts as a reference guide to implement or form the network in the real world.</p>
</li>
<li><p>Based on the OSI model, the exact model that is implemented in the real world is the <strong>TCP/IP Model</strong>.</p>
</li>
<li><p>The <strong>OSI Model</strong> has <strong>7 different layers</strong>. And each layer has a bunch of protocols that need to be followed to implement a network in the real world.</p>
</li>
<li><p><strong>Protocols</strong> — A set of rules that everyone needs to agree upon.</p>
</li>
</ul>
<h3>Philosopher - Translator - Secretary Architecture</h3>
<p>OSI model is based on the architecture of philosopher-translator-secretary.</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753378922692/807452aa-2dd3-42cf-b378-fc159bf3f803.png" alt="" style="display:block;margin:0 auto" />

<p>In this architecture, there are two philosophers (A and B) in different locations, and they don’t speak the same language and want to transmit a message. So, some steps need to be followed by both to successfully send the message.</p>
<ul>
<li><p>Philosopher A gives the message to his secretary, and the secretary will convert the message into a common language that can be understood by the secretary in both locations.</p>
</li>
<li><p>Then the converted message will be sent through Fax to Location B. And the secretary in location B will understand the message and pass it to the philosopher in the language the philosopher understands.</p>
</li>
</ul>
<p>So, this way communication happens in this architecture. So, the same is followed in the OSI Model. Each layer states the different protocols that need to be followed for the successful transmission of the message.</p>
<p>Now, let’s look at the different layers in the OSI Model</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753379172076/9217c0fa-ec51-4415-a422-6078b1639133.png" alt="" style="display:block;margin:0 auto" />

<p>Now, let’s briefly look at what each layer is,</p>
<h3>Application Layer (Layer 7)</h3>
<ul>
<li><p>Browser → HTTPS / FTP (File Transfer Protocol)</p>
</li>
<li><p>Outlook → SMTP (Simple Mail Transfer Protocol)</p>
</li>
<li><p>Skype → Skype protocol</p>
</li>
<li><p>Remote Desktop → Telnet for Unix-based systems), RDP (Remote Desktop Protocol)</p>
</li>
</ul>
<p>The application layer has a bunch of protocols that are used for various tasks. Outlook uses SMTP for mail transfers and HTTPS to fetch a web page securely.</p>
<h3>Presentation Layer (Layer 6)</h3>
<p>The presentation layer is mostly responsible for</p>
<ul>
<li><p><strong>Translation</strong></p>
<p>  Translates data received from the application layer into the form of ASCII or binary</p>
<ul>
<li><p>e.g</p>
<ul>
<li><p>Data: Hello o ASCII: 72 101 108 108 111</p>
</li>
<li><p>Binary: 01001000 01100101 01101100 01101100 01101111</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Data Compression</strong></p>
<p>  Suppose after translation we get 1MB of Data. So, Data Compression tries to reduce the size of the data without much loss because the less the size is the faster transmission can happen over the network.</p>
</li>
<li><p><strong>Encryption</strong></p>
<p>  Encrypts the data so that it can’t be misused. HTTPS uses SSL (Secure Socket Layer), which is a cryptographic protocol designed to provide communications security over a computer network.</p>
</li>
</ul>
<h3>Session Layer (Layer 5)</h3>
<div>
<div>💡</div>
<div>These days, most modern browsers manage (Application, Presentation, Session layers)</div>
</div>

<ul>
<li><p><strong>Establish</strong>, <strong>manage,</strong> and <strong>terminate</strong> connections.</p>
<ul>
<li><p>Establishment of a connection means making a connection in which both server and client have agreed to transfer the data.</p>
</li>
<li><p>Managing connection states, getting knowledge of the connections that were established, and the data transfer can be done effectively.</p>
</li>
<li><p>In terminating the connection, after the data transfer completes then the connection must be terminated.</p>
</li>
</ul>
</li>
<li><p><strong>Authentication</strong> and <strong>Authorization</strong></p>
<ul>
<li><p>Authentication: validation of the user ID and password</p>
</li>
<li><p>Authorization: whether a user has permission to access a file or not</p>
</li>
</ul>
</li>
<li><p>An example of a session is a login and a logout</p>
</li>
</ul>
<h3>Transport Layer (Layer 4)</h3>
<ol>
<li><p><strong>Segmentation</strong></p>
<p> Data is broken into segments to transfer one chunk at a time, i.e., manageable. A general segment has Source IP, Destination IP, and Data (of the segment)</p>
 <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753379737991/9315c397-9cda-48b3-a44c-70a7aedc9a62.png" alt="" style="display:block;margin-left:auto" />
 </li>
<li><p><strong>Flow Control</strong></p>
<p> Managing the flow of data transmitted from one host to another host. The server is sending 10Mbps, but the host is not able to process. So, it requests the server to transmit 1Mbps transfer rate.</p>
 <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753379781138/0994b75f-c8b2-45db-857d-0b629da3df46.png" alt="" style="display:block;margin:0 auto" />
 </li>
<li><p><strong>Error Control</strong></p>
<p> There can be a loss of data or data might be corrupted. So, we use error control. These can be fixed in the Transport layer by something called Automatic Repeat Request (in case of loss of data receiver will ask to resend the data) or checksum (checks if the data is corrupted or not).</p>
 <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753379812987/a2ef54b0-ac45-422e-bc71-7b90190cf799.png" alt="" style="display:block;margin:0 auto" /></li>
</ol>
<h3>Network Layer (Layer 3)</h3>
<p>The network layer’s main task is to recognize the network through which the data must be transmitted. It has something called packets. Each packet has a segment, which is received from the above layer and is encapsulated with a header in which we have source and destination addresses. We include the IP address in the TCP packet. Logical Addressing (IP Address).</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753379857143/6bc2a04e-0205-4111-bbe3-d557f8f378ca.png" alt="" style="display:block;margin:0 auto" />

<p><em>What is an IP address?</em></p>
<ul>
<li><p>Range of IP address: 0.0.0.0 to 255.255.255.255</p>
</li>
<li><p>It is the address that the network system has uniquely identified. It is a 32-bit or 4-byte address in IPv4, and each byte has an address range of 0-255, called an octet.</p>
</li>
<li><p>So, the task of the network layer is to provide the IP address to each host. And it also does Routing.</p>
</li>
</ul>
<p><em>What is Routing?</em></p>
<p>The task of Routing is to route the packet from the source to the destination.</p>
<p><em>How do routers do that?</em></p>
<p>We have destination address it does Masking Masking is a simple bit wise operation. The router sets some bits to 0 and performs a bitwise AND operation, and after masking on the destination IP address, it will get the network IP address.</p>
<p>Now, with the help of the IP address, it will decide the next router for the packet it has to send.</p>
<p><strong>DNS</strong> (Domain Name System) is used to connect a hostname like amazon.com to its IP address.</p>
<h3>Data Link Layer (Layer 2)</h3>
<ul>
<li><p>The MAC Address is also called a physical address because it contains the address of the physical network device from which the data is going to be transmitted.</p>
</li>
<li><p>It is assigned to the network devices, such as NIC (Network Interface Card), Wi-Fi Card, USB Wi-Fi Dongle, etc., by the manufacturer.</p>
</li>
<li><p>The packet received from the network layer Data Link Layer encapsulates that with source and destination MAC addresses and creates something called, frame.</p>
  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753380118257/1a2cad6b-0740-489e-8e8f-279727453243.png" alt="" style="display:block;margin:0 auto" />
  </li>
<li><p>But Why MAC Address?</p>
<p>  The MAC Address helps us to uniquely identify the device. If a packet is received, it helps us to determine which device it belongs to.</p>
</li>
</ul>
<p>Apart from all these Data Link Layer does a few other things, such as</p>
<ol>
<li><p><strong>Access to Media:</strong> Media like (Copper wire, Fiber optic cable, Wireless). Since it has access to all these, it can detect Congestion, Error, Collision, etc.</p>
</li>
<li><p><strong>Media Access Control</strong></p>
<p> Media does not mean audio, video. Here, media means the medium through which the data is transferred. DLL helps to control the medium, such as when to transmit the data.</p>
<ul>
<li><p>If Multiple hosts are connected to the same router, all the hosts cannot send packets at the same time. MAC ensures avoids collisions.</p>
  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753380218841/ec560a65-f8fb-46ec-8989-7f0fe5060e10.png" alt="" style="display:block;margin:0 auto" /></li>
</ul>
</li>
<li><p>Error Detection</p>
<p> It is added in the tail part; It is the mechanism to detect any error in the data. Some algorithms, like CRC (Cyclic redundancy check), Checksum, Bit Parity, etc., help us do that.</p>
</li>
</ol>
<h3>Physical Layer (Layer 1)</h3>
<p>The physical layer deals with the encoding of the stream of bits into the signals. These signals are categorized based on the media (or medium).</p>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753380281819/eec2782d-45ba-4012-b9b7-95790ecd097a.png" alt="" style="display:block;margin:0 auto" />

<p>The physical layer’s job is to transmit bits to a signal based on the medium used.</p>
<h2>TCP vs UDP</h2>
<table>
<thead>
<tr>
<th><em><strong><mark>TCP</mark></strong></em></th>
<th><em><strong><mark>UDP</mark></strong></em></th>
</tr>
</thead>
<tbody><tr>
<td>Slow, lossless</td>
<td>Fast, lossy</td>
</tr>
<tr>
<td>Feedback (whether the packet is received or not)</td>
<td>No feedback</td>
</tr>
<tr>
<td>Example: Email, Webpage</td>
<td>Example: Video call</td>
</tr>
<tr>
<td>Connection-oriented</td>
<td>Connection-less</td>
</tr>
</tbody></table>
<h2>OSI Model vs TCP/IP</h2>
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1753380443704/f2e78aba-ae9e-4795-bdde-1da89705154c.png" alt="" style="display:block;margin:0 auto" />]]></content:encoded></item><item><title><![CDATA[Selection Sort Algorithm in Javascript]]></title><description><![CDATA[Overview

O(n²) Time Complexity in all cases.

Does less “Memory writes” when compared with other algorithms such as Quick sort, Merge sort, Insertion sort and Bubble sort.

However, not an optimal algorithm in terms of “Memory writes”. There is othe...]]></description><link>https://blog.khansab.in/selection-sort-algorithm-in-javascript</link><guid isPermaLink="true">https://blog.khansab.in/selection-sort-algorithm-in-javascript</guid><category><![CDATA[in-place sorting algorithm]]></category><category><![CDATA[basic-algorithms]]></category><category><![CDATA[selection sort]]></category><dc:creator><![CDATA[Mohsin Khansab]]></dc:creator><pubDate>Mon, 25 Nov 2024 13:34:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/zvKx6ixUhWQ/upload/55b9f944391b69a1e323b9329815e3de.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h3 id="heading-overview">Overview</h3>
<ul>
<li><p>O(n²) Time Complexity in all cases.</p>
</li>
<li><p>Does less <em>“Memory writes”</em> when compared with other algorithms such as Quick sort, Merge sort, Insertion sort and Bubble sort.</p>
</li>
<li><p>However, not an optimal algorithm in terms of “Memory writes”. There is other algorithm called Cycle sort which is optimal in terms of memory writes.</p>
</li>
<li><p>Basic idea for Heap sort.</p>
</li>
<li><p>Not Stable (order of elements may change).</p>
</li>
<li><p>In-Place Algorithm</p>
</li>
</ul>
<h3 id="heading-idea">Idea</h3>
<ul>
<li><p>Iterate through loop</p>
</li>
<li><p>First iteration, find the minimum element and put it in the first place.</p>
</li>
<li><p>Second iteration, find the minimum element and put it in the second place.</p>
</li>
<li><p>Repeat this process, at the end the array is sorted.</p>
</li>
</ul>
<h3 id="heading-code">Code</h3>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://codepen.io/mohs-in/pen/azooEmp">https://codepen.io/mohs-in/pen/azooEmp</a></div>
<p> </p>
<h3 id="heading-time-complexity">Time Complexity</h3>
<p>The internal for-loop runs:</p>
<p>$$\begin{align*} (n-1) + (n-2) + \dots + 2 + 1 \\ = \frac{n(n-1)}{2} \\ \theta(n^2) \end{align*}$$</p>]]></content:encoded></item><item><title><![CDATA[What You Need to Know About Cloud Computing]]></title><description><![CDATA[Traditional IT Overview
IT Terminology
Network
Cables, routers and servers connected with each other.
Router
A networking device that forwards data packets between computer networks. They know where to send your packets on the internet.
Switch
Takes ...]]></description><link>https://blog.khansab.in/what-you-need-to-know-about-cloud-computing</link><guid isPermaLink="true">https://blog.khansab.in/what-you-need-to-know-about-cloud-computing</guid><category><![CDATA[advantages of cloud computing]]></category><category><![CDATA[Cloud Computing]]></category><category><![CDATA[Cloud Deployment Models]]></category><category><![CDATA[types of cloud computing]]></category><category><![CDATA[AWS]]></category><category><![CDATA[aws regions]]></category><category><![CDATA[AWS Availability zones]]></category><dc:creator><![CDATA[Mohsin Khansab]]></dc:creator><pubDate>Sat, 14 Sep 2024 07:36:00 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/TKAg3WignSw/upload/f6b1d19866ac94c5ef7c968344fad415.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<hr />
<h1 id="heading-traditional-it-overview">Traditional IT Overview</h1>
<h2 id="heading-it-terminology">IT Terminology</h2>
<h3 id="heading-network">Network</h3>
<p>Cables, routers and servers connected with each other.</p>
<h3 id="heading-router">Router</h3>
<p>A networking device that forwards data packets between computer networks. They know where to send your packets on the internet.</p>
<h3 id="heading-switch">Switch</h3>
<p>Takes a packet and send it to the correct server / client on your network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1726298298675/ce7932c9-10bc-4937-ab14-185490d9ab99.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-problems-with-traditional-it-approach">Problems with traditional IT approach</h2>
<ul>
<li><p>Pay for the rent for the data centre</p>
</li>
<li><p>Pay for power supply, cooling, maintenance</p>
</li>
<li><p>Adding and replacing hardware takes time</p>
</li>
<li><p>Scaling is limited</p>
</li>
<li><p>Hire 24/7 team to monitor the infrastructure</p>
</li>
<li><p>How to deal with disasters (earthquake, power shutdown, fire, …)</p>
</li>
</ul>
<hr />
<h1 id="heading-what-is-cloud-computing">What is Cloud Computing?</h1>
<ul>
<li><p>Cloud computing is the <strong>on-demand delivery</strong> of <em>compute power</em>, <em>database storage</em>, <em>applications</em>, and other IT resources</p>
</li>
<li><p>Through a cloud services platform with <strong>pay-as-you-go pricing</strong></p>
</li>
<li><p>You can provision exactly the right type and size of computing resources you need</p>
</li>
<li><p>You can access as many resources as you need, almost instantly</p>
</li>
<li><p>Simple way to access servers, storage, databases and a set of application services</p>
</li>
<li><p>Amazon Web Services owns and maintain the network-connected hardware required for these application services, while you provision and use what you need via a web application</p>
</li>
</ul>
<h2 id="heading-the-deployment-models-of-the-cloud">The Deployment Models of the Cloud</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Private Cloud</td><td>Public Cloud</td><td>Hybrid Cloud</td></tr>
</thead>
<tbody>
<tr>
<td>Cloud services used by a single organisation, not exposed to the public</td><td>Cloud resources owned and operated by a third-party cloud service provider delivered over the Internet</td><td>Keep some servers on premises and extend some capabilities to the Cloud</td></tr>
<tr>
<td>Complete control &amp; Security for sensitive applications</td><td>Six advantages of Cloud Computing</td><td>Control over sensitive assets in your private infrastructure</td></tr>
<tr>
<td>Meet specific business needs</td><td></td><td>Flexibility and cost-effectiveness of the public cloud</td></tr>
<tr>
<td>Ex: Rackspace</td><td>Ex: Azure, GCP, AWS</td><td>Ex: On-premises ↔ AWS</td></tr>
</tbody>
</table>
</div><h2 id="heading-the-five-characteristics-of-cloud-computing">The Five Characteristics of Cloud Computing</h2>
<ol>
<li><p><strong><em>On-demand self service:</em></strong></p>
<p> Users can provision resources and use them without human interaction from the service provider</p>
</li>
<li><p><strong><em>Broad network access:</em></strong></p>
<p> Resources available over the network, and can be accessed by diverse client platforms</p>
</li>
<li><p><strong><em>Multi-tenancy and resource pooling:</em></strong></p>
<ul>
<li><p>Multiple customers can share the same infrastructure and applications with security and privacy</p>
</li>
<li><p>Multiple customers are serviced from the same physical resources</p>
</li>
</ul>
</li>
<li><p><strong><em>Rapid elasticity and scalability:</em></strong></p>
<ul>
<li><p>Automatically and quickly acquire and dispose resources when needed</p>
</li>
<li><p>Quickly and easily scale based on demand</p>
</li>
</ul>
</li>
<li><p><strong><em>Measured service:</em></strong></p>
<p> Usage is measured, users pay correctly for what they have used</p>
</li>
</ol>
<h2 id="heading-six-advantages-of-cloud-computing">Six Advantages of Cloud Computing</h2>
<ol>
<li><p>Trade capital expense (CAPEX) for operational expense (OPEX)</p>
<ul>
<li><p><strong><em>Pay On-Demand:</em></strong> don’t own hardware</p>
</li>
<li><p>Reduced <strong><em>Total Cost of Ownership (TCO)</em></strong> &amp; <strong><em>Operational Expense</em></strong> (OPEX)</p>
</li>
</ul>
</li>
<li><p>Benefit from massive economies of scale</p>
<p> Prices are reduced as AWS is more efficient due to large scale</p>
</li>
<li><p>Stop guessing capacity</p>
<p> Scale based on actual measured usage</p>
</li>
<li><p>Increase speed and agility</p>
</li>
<li><p>Stop spending money running and maintaining data centres</p>
</li>
<li><p>Go global in minutes: leverage the AWS global infrastructure</p>
</li>
</ol>
<h2 id="heading-problems-solved-by-the-cloud">Problems solved by the Cloud</h2>
<ul>
<li><p><strong>Flexibility:</strong> change resource types when needed</p>
</li>
<li><p><strong>Cost-Effectiveness:</strong> pay as you go, for what you use</p>
</li>
<li><p><strong>Scalability:</strong> accommodate larger loads by making hardware stronger or adding additional nodes</p>
</li>
<li><p><strong>Elasticity:</strong> ability to scale out and scale-in when needed</p>
</li>
<li><p><strong>High-availability and fault-tolerance:</strong> build across data centres</p>
</li>
<li><p><strong>Agility:</strong> rapidly develop, test and launch software applications</p>
</li>
</ul>
<hr />
<h1 id="heading-types-of-cloud-computing">Types of Cloud Computing</h1>
<h2 id="heading-infrastructure-as-a-serviceiaas">Infrastructure as a Service(IaaS)</h2>
<ul>
<li><p>Provide building blocks for cloud IT</p>
</li>
<li><p>Provides networking, computers, data storage space</p>
</li>
<li><p>Highest level of flexibility</p>
</li>
<li><p>Easy parallel with traditional on-premises IT</p>
</li>
</ul>
<blockquote>
<p>Ex: Amazon EC2(AWS), GCP, Azure, Rackspace, Digital Ocean, Linode</p>
</blockquote>
<h2 id="heading-platform-as-a-servicepaas">Platform as a Service(PaaS)</h2>
<ul>
<li><p>Removes the need for your organizationo to manage the underlying infrastructure</p>
</li>
<li><p>Focus on the deployment and management of your applications</p>
</li>
</ul>
<blockquote>
<p>Elastic Beanstalk(AWS), Heroku, Google App Engine(GCP), Windows Azure(Microsoft)</p>
</blockquote>
<h2 id="heading-software-as-a-servicesaas">Software as a Service(SaaS)</h2>
<ul>
<li>Completed product that is run and managed by the service provider</li>
</ul>
<h2 id="heading-on-premises-vs-iaas-vs-paas-vs-saas">On-premises vs Iaas vs Paas vs Saas</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1726298893269/ba8776c5-c672-423e-9ef5-837457680d54.png" alt class="image--center mx-auto" /></p>
<hr />
<h1 id="heading-aws-cloud-overview">AWS Cloud Overview</h1>
<h2 id="heading-aws-regions">AWS Regions</h2>
<ul>
<li><p>AWS has Regions all around the world</p>
</li>
<li><p>Names can be us-east-I, eu-west-3, …</p>
</li>
<li><p>A region is a cluster of data centers</p>
</li>
<li><p>Most AWS services are region-scoped</p>
</li>
</ul>
<h2 id="heading-how-to-choose-an-aws-region">How to choose an AWS Region?</h2>
<ul>
<li><p><strong><em>Compliance</em></strong> <strong>with data governance and legal requirements:</strong> data never leaves a region without your explicit permission</p>
</li>
<li><p><strong><em>Proximity</em> to customers:</strong> reduced latency</p>
</li>
<li><p><strong><em>Available services</em> within a Region:</strong> new services and new features aren’t available in every Region</p>
</li>
<li><p><strong><em>Pricing</em>:</strong> pricing varies region to region and is transparent in the service pricing page</p>
</li>
</ul>
<h2 id="heading-aws-availability-zones">AWS Availability Zones</h2>
<ul>
<li><p>Each region has many availability zones. (usually3, min is 3, max is 6). Example:</p>
<ul>
<li><p>ap-southeast-2a</p>
</li>
<li><p>ap-southeast-2b</p>
</li>
<li><p>ap-southeast-2c</p>
</li>
</ul>
</li>
<li><p>Each availablity zone (AZ) is one or more discrete data centers with redundant power, networking, and connectivity</p>
</li>
<li><p>They’re separate from each other, so that they’re isolated from disasters</p>
</li>
<li><p>They’re connected with high bandwidth, ultra-low latency networking</p>
</li>
</ul>
<h2 id="heading-aws-points-of-presence-edge-locations">AWS Points of Presence (Edge Locations)</h2>
<ul>
<li><p>Amazon has 400+ Points of Presence (400+ Edge Locations &amp; 10+ Regional Caches) in 90+cities across 40+ countries</p>
</li>
<li><p>Content is delivered to end users with lower latency</p>
</li>
</ul>
<hr />
]]></content:encoded></item><item><title><![CDATA[Key React Hooks Explained: useState, useEffect, and useContext]]></title><description><![CDATA[useState()
The purpose of useState is to handle reactive data. Any data that changes in the application is called state. When the state changes you want react to update the UI, so the latest changes are reflected to the end user.
How to use it?
const...]]></description><link>https://blog.khansab.in/key-react-hooks-explained</link><guid isPermaLink="true">https://blog.khansab.in/key-react-hooks-explained</guid><dc:creator><![CDATA[Mohsin Khansab]]></dc:creator><pubDate>Sat, 29 Jun 2024 17:15:56 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1719681839583/1a3df9b2-0f88-4d7c-bb69-ddae349cdd4e.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-usestate"><code>useState()</code></h1>
<p>The purpose of <code>useState</code> is to handle reactive data. Any <mark>data that changes in the application is called state</mark>. When the state changes you want react to update the UI, so the latest changes are reflected to the end user.</p>
<h3 id="heading-how-to-use-it">How to use it?</h3>
<pre><code class="lang-jsx"><span class="hljs-keyword">const</span> [count, setCount] = useState(<span class="hljs-number">0</span>)
</code></pre>
<blockquote>
<p><code>useState()</code> returns an array with 2 values:</p>
<ol>
<li><p>Current state</p>
<p> In our example, count is the state variable which is set to 0. This initial state can be a number, boolean, string, or object</p>
</li>
<li><p>Set function to update the state.</p>
<p> You can update the state in two ways:</p>
<p> i. Directly passing the next state <code>setCount(2)</code> // Now, the updated state of</p>
<p> count will be 2.</p>
<p> ii. Using function <code>setCount( prevCount =&gt; prevCount + 1)</code> In this function, we check the current state which is 2. The value of <code>prevCount</code> will be 2, then</p>
<p> we increment it by 1.</p>
</li>
</ol>
</blockquote>
<p><strong>Docs:</strong><a target="_blank" href="https://react.dev/reference/react/useState#usage">https://react.dev/reference/react/useState#usage</a></p>
<h1 id="heading-useeffect"><code>useEffect()</code></h1>
<p><code>useEffect</code> is a Hook in React that allows you to <mark>synchronise a component with an external system</mark>. It is a way to handle side effects, such as fetching data or subscribing to a event in a functional component.</p>
<h3 id="heading-how-to-use-it-1">How to use it?</h3>
<pre><code class="lang-jsx">useEffect(<span class="hljs-function">() =&gt;</span> {
    <span class="hljs-built_in">console</span>.log(<span class="hljs-string">'count changed'</span>)
},[count])
</code></pre>
<p>Here, the `count changed ` will be logged every time the count changes.</p>
<blockquote>
<p><code>useEffect</code> takes two arguments:</p>
<ol>
<li><p>A callback function</p>
<p> The callback function is called after the component has rendered.</p>
</li>
<li><p>A list of dependencies</p>
<p> The list of dependencies is used to determine when to re-run the effect, by comparing the current values of the dependencies to the previous values.</p>
</li>
</ol>
</blockquote>
<p>In the callback function, you can perform any side effects, such as fetching data or subscribing to an event. You can also return a cleanup function, which is called before the component is unmounted or the effect is re-run.</p>
<blockquote>
<p>Note:</p>
<ol>
<li><p>If you don’t pass dependencies the effect will re-run on every render of component.</p>
</li>
<li><p>When state variables are used in useEffect , make sure to include in dependency array.</p>
</li>
<li><p>Make sure to handle side effects, with a cleanup function.</p>
</li>
</ol>
</blockquote>
<p><strong>Docs:</strong><a target="_blank" href="https://react.dev/reference/react/useEffect#reference">https://react.dev/reference/react/useEffect#reference</a></p>
<h1 id="heading-usecontext"><code>useContext()</code></h1>
<p><code>useContext</code> is a way to <mark>manage state globally without passing props</mark> down through multiple levels of the component tree.</p>
<h3 id="heading-the-problem">The Problem</h3>
<blockquote>
<p><mark>Prop Drilling:</mark> Prop drilling refers to the process of passing down props through multiple layers of components, even when some of those components do not directly use the props. We can solve this problem using <code>useContext()</code></p>
</blockquote>
<h3 id="heading-how-to-use-it-2">How to use it?</h3>
<blockquote>
<p>Three things to understand:</p>
</blockquote>
<ol>
<li><p>Creating context</p>
<pre><code class="lang-jsx"> <span class="hljs-keyword">const</span> EmailContext = React.createContext(<span class="hljs-literal">null</span>);
</code></pre>
</li>
<li><p>Provide a value for the context using ContextName.Provider</p>
<pre><code class="lang-jsx"> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">App</span>(<span class="hljs-params"></span>) </span>{
     <span class="hljs-keyword">const</span> value = { <span class="hljs-attr">email</span>: <span class="hljs-string">"in.mohsin@outlook.com"</span> };

     <span class="hljs-keyword">return</span> (
       <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">EmailContext.Provider</span> <span class="hljs-attr">value</span>=<span class="hljs-string">{value}</span>&gt;</span>
         <span class="hljs-tag">&lt;<span class="hljs-name">Child</span> /&gt;</span>
       <span class="hljs-tag">&lt;/<span class="hljs-name">EmailContext.Provider</span>&gt;</span></span>
     );
 }
</code></pre>
</li>
<li><p>Use <code>useContext()</code> in the component that needs to consume the context</p>
<pre><code class="lang-jsx"> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">Child</span>(<span class="hljs-params"></span>) </span>{
     <span class="hljs-keyword">const</span> context = useContext(EmailContext);
     <span class="hljs-keyword">return</span> <span class="xml"><span class="hljs-tag">&lt;<span class="hljs-name">div</span>&gt;</span>The email is: {context.email}<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span></span>;
 }
</code></pre>
</li>
</ol>
<blockquote>
<p>When the context value is updated by the provider, the component consuming the context re-renders automatically. This allows the component to always have the latest data.</p>
</blockquote>
<p><strong>Docs:</strong><a target="_blank" href="https://react.dev/reference/react/useContext#usage">https://react.dev/reference/react/useContext#usage</a></p>
]]></content:encoded></item></channel></rss>