<?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[Learn With Jay]]></title><description><![CDATA[Learn With Jay]]></description><link>https://blog.devwithjay.com</link><generator>RSS for Node</generator><lastBuildDate>Mon, 13 Apr 2026 22:48:30 GMT</lastBuildDate><atom:link href="https://blog.devwithjay.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Cache Strategies in Distributed Systems]]></title><description><![CDATA[Introduction
In modern distributed systems, performance is not just an optimization metric; it has a direct impact on business outcomes. Even small delays in response time can reduce user engagement, ]]></description><link>https://blog.devwithjay.com/cache-strategies-in-distributed-systems</link><guid isPermaLink="true">https://blog.devwithjay.com/cache-strategies-in-distributed-systems</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[System Design]]></category><category><![CDATA[distributed system]]></category><category><![CDATA[TTL]]></category><category><![CDATA[caching]]></category><category><![CDATA[caching strategies]]></category><category><![CDATA[scalability]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Sun, 01 Mar 2026 07:19:10 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/aecb2db3-2b07-4e91-915e-7f5d77d85327.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Introduction</h2>
<p>In modern distributed systems, performance is not just an optimization metric; it has a direct impact on business outcomes. Even small delays in response time can reduce user engagement, conversions, and overall trust in a product. When millions of users interact with an application, every database call and every network round trip matters.</p>
<p>One of the most powerful techniques used to improve system performance is caching. Almost every large-scale platform relies on it to reduce latency, lower database pressure, and handle massive traffic efficiently. Without caching, many modern applications would struggle to scale beyond a few thousand users.</p>
<p>But caching is not just about storing data temporarily. At scale, caching is really about controlling timing.</p>
<p>When data is refreshed matters just as much as what data is stored.</p>
<p>In small systems, adding a simple TTL (Time-To-Live) to a cache entry feels sufficient. You store a value, set it to expire in 60 seconds, and refresh it when needed. This approach works fine when traffic is low and user behavior is mostly random.</p>
<p>However, in distributed systems where thousands or millions of users depend on the same data, fixed expiration can create dangerous synchronization patterns. Instead of protecting your backend, the cache can unintentionally trigger a traffic explosion.</p>
<p>In this article, we will go deeper into why basic TTL caching is not enough in distributed systems. We will understand how cache expiry can create traffic spikes, explore advanced strategies used in production systems, and examine the tradeoffs between freshness, latency, and consistency.</p>
<h2>What is Caching and Why Does It Matter?</h2>
<p>Caching is a technique in which frequently accessed data is stored in a faster storage layer so that subsequent requests can be served more quickly. Instead of repeatedly querying a slower data source such as a database or remote service, the system retrieves the data from a cache, which is typically stored in memory and optimized for rapid access.</p>
<p>The main benefit of caching comes from the speed difference between memory and persistent storage. Accessing data from memory is orders of magnitude faster than retrieving it from disk, and retrieving data from a nearby cache server is significantly faster than querying a remote server. By reducing the number of expensive backend operations, caching improves response times, increases throughput, and enhances overall user experience.</p>
<p>The effectiveness of a caching system is often measured using the cache hit ratio, which represents the proportion of requests served directly from the cache. A higher hit ratio indicates that the system is successfully intercepting requests before they reach the database, thereby reducing backend load and improving performance.</p>
<p>However, caching also introduces complexity. It creates new challenges related to data freshness, consistency, synchronization, and invalidation. In distributed systems, these challenges become more pronounced because multiple servers and users interact with shared data simultaneously.</p>
<h2>How Caching Works in a Distributed Architecture</h2>
<p>Consider a simple architecture where a client sends requests to an application server, which then retrieves data from a database. Without caching, every request results in a database query. As traffic increases, the database becomes a bottleneck because it must process every incoming request.</p>
<p>When a cache layer is introduced between the application server and the database, the workflow changes. The application first checks whether the requested data exists in the cache. If the data is present, it is returned immediately. If the data is not present, the application retrieves it from the database, returns it to the user, and stores it in the cache for future use.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/7e6504cf-5179-4638-a3ad-4e435f29cfe4.png" alt="" style="display:block;margin:0 auto" />

<p>This approach significantly reduces database load under normal traffic conditions. However, this simple model assumes that requests arrive randomly over time and that cache expiration events do not create coordination problems. In distributed systems with synchronized user behavior, this assumption does not always hold true.</p>
<h2>The Core Problem: Synchronized Expiration</h2>
<p>To understand why basic TTL caching can become dangerous, consider a popular product page on an e-commerce platform during a flash sale. Suppose the product data is cached with a TTL of 60 seconds, and 100,000 users are actively viewing the page.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/27c0a2b1-97d3-45a2-86af-d153372badaf.png" alt="" style="display:block;margin:0 auto" />

<p>For the first 60 seconds, everything operates smoothly. The cache serves responses quickly, and the database remains largely idle. Latency is low, and the system appears stable.</p>
<p>At the exact moment the TTL expires, however, the cache entry becomes invalid. If thousands of users request the same data at that moment, they will all experience a cache miss simultaneously. As a result, they will all trigger database queries to regenerate the same information.</p>
<p>The total number of users has not increased, but the timing of their requests has become synchronized. Instead of spreading the database load evenly over time, the system concentrates it into a very small time window. This phenomenon is commonly referred to as a cache stampede or the thundering herd problem.</p>
<p>The issue here is not high traffic; it is coordinated traffic. Distributed systems are designed to handle scale, but they struggle when many operations occur simultaneously in a synchronized manner.</p>
<h2>Why Basic TTL Caching Is Insufficient at Scale</h2>
<p>Basic TTL caching is deterministic, meaning that each cache entry expires at a precise and predictable moment. While determinism may seem beneficial, it introduces risk in distributed systems because it creates synchronization points.</p>
<p>When many users depend on the same cache key, the expiration time becomes a trigger event. All requests that arrive after that moment must regenerate the same data, which can overwhelm backend services. In real-world systems, user behavior is often synchronized due to scheduled events, product launches, live streaming events, or flash sales. If cache expiration aligns with these events, the resulting traffic spike can be severe.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/047c5c19-deb3-4d6b-ab65-01b77dc4b212.png" alt="" style="display:block;margin:0 auto" />

<p>In smaller systems, the effect may be negligible. In high-scale environments, even a few milliseconds of synchronized recomputation can cause cascading failures, increased latency, and retry storms.</p>
<h2>Advanced Cache Strategies for Distributed Systems</h2>
<p>To prevent synchronization failures, production systems use more advanced cache management techniques that distribute load more intelligently.</p>
<h3>TTL Jitter</h3>
<p>TTL jitter introduces randomness into expiration times. Instead of assigning a fixed TTL of 60 seconds to every cache entry, the system adds a small random variation, such as 60 seconds plus or minus 10 seconds. This ensures that not all entries expire simultaneously.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/b0d5ec5f-c52c-4000-bfd5-f1d9a310d878.png" alt="" style="display:block;margin:0 auto" />

<p>By spreading expiration events across a time window, TTL jitter transforms a single large spike into smaller, more manageable waves of traffic.</p>
<h3>Probability-Based Early Expiration</h3>
<p>In probability-based early expiration, the system begins refreshing cache entries before they fully expire. As a cache key approaches its TTL limit, the probability of recomputation gradually increases.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/c5b95a73-ba0b-4ea3-ae29-5220e7510037.png" alt="" style="display:block;margin:0 auto" />

<p>This prevents a sudden spike at the exact expiration moment by distributing refresh operations over time. The main idea is simple: instead of waiting for a deadline, the system prepares for it gradually.</p>
<h3>Mutex or Cache Locking</h3>
<p>Another powerful technique is cache locking. When a cache entry expires, only one request is allowed to regenerate the data, while others wait for the result. Without locking, thousands of identical database queries could occur simultaneously.</p>
<p>With locking, only a single database query is executed, and its result is shared with all waiting requests. Although this may slightly increase latency for some users, it protects backend systems from overload.</p>
<h3>Stale-While-Revalidate (SWR)</h3>
<p>Stale-While-Revalidate allows the system to continue serving expired data temporarily while refreshing it in the background. This strategy prioritizes availability and user experience over strict freshness.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/868b75b3-e869-4468-b034-902e3a04f70b.png" alt="" style="display:block;margin:0 auto" />

<p>It is widely used in CDNs and edge caching systems because it prevents users from experiencing delays during recomputation. Although the data may be slightly outdated for a short period, the system remains stable under heavy load.</p>
<h3>Cache Warming</h3>
<p>Cache warming involves preloading frequently accessed data into the cache before anticipated traffic spikes. This approach is especially useful for predictable events such as product launches, live sports matches, or streaming releases.</p>
<p>By preparing the cache in advance, the system avoids an initial surge of database queries when traffic increases.</p>
<h2>Cache Invalidation and Eviction</h2>
<p>Caching introduces additional responsibilities beyond storing data. Cache invalidation ensures that outdated data is removed or updated when changes occur. Invalidation can be time-based, event-driven, or manual. Choosing the appropriate invalidation strategy depends on how frequently the underlying data changes and how critical consistency is for the application.</p>
<p>When cache storage reaches its capacity, eviction policies determine which entries should be removed. Common policies include <strong>Least Recently Used (LRU)</strong>, <strong>Least Frequently Used (LFU)</strong>, and <strong>First-In-First-Out (FIFO)</strong>. Each policy makes different tradeoffs between recency and frequency of access.</p>
<h2>Scaling Distributed Caching</h2>
<p>Scaling a distributed cache requires careful planning around data partitioning, replication, and fault tolerance. Techniques such as consistent hashing and sharding ensure even data distribution across nodes. Replication ensures availability if a node fails. Monitoring tools are essential to track hit rates, latency, and system health.</p>
<p>Popular distributed caching solutions include Redis, Memcached, Hazelcast, and Apache Ignite, each offering different capabilities for scalability and fault tolerance.</p>
<h2>Conclusion</h2>
<p>Caching is a foundational component of modern distributed systems. It reduces latency, improves scalability, and protects backend services from excessive load. However, basic TTL caching is insufficient at scale because deterministic expiration creates synchronization points that can lead to traffic spikes and cascading failures.</p>
<p>Advanced strategies such as TTL jitter, probabilistic early expiration, mutex locking, stale-while-revalidate, and cache warming are essential for preventing coordination failures. Ultimately, effective caching is not merely about speed; it is about designing systems that behave predictably under stress.</p>
<p>In distributed systems, the most dangerous problems are rarely caused by insufficient capacity. They are caused by synchronization. A well-designed caching strategy ensures that work is distributed over time, protecting both system stability and user experience.</p>
<h3>Want More…?</h3>
<p>I write articles on <a href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Understanding the Thundering Herd Problem]]></title><description><![CDATA[Introduction
We all know that most modern applications are built to handle thousands, sometimes millions of users.
But sometimes systems don't fail because of heavy traffic. They fail because of synch]]></description><link>https://blog.devwithjay.com/thundering-herd-problem</link><guid isPermaLink="true">https://blog.devwithjay.com/thundering-herd-problem</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[System Design]]></category><category><![CDATA[thundering-herd]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Tue, 24 Feb 2026 11:01:53 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/357e96b6-39d0-459f-be27-d80158992325.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2>Introduction</h2>
<p>We all know that most modern applications are built to handle thousands, sometimes millions of users.</p>
<p>But sometimes systems don't fail because of heavy traffic. They fail because of synchronized traffic.</p>
<p>When many users try to access the same resource at the same time, systems can collapse unexpectedly. This is called the <strong>Thundering Herd Problem</strong>.</p>
<p><strong>Example:</strong><br />Imagine a store opening at 9 AM.<br />At 8:59 AM, 500 people are waiting outside.<br />The shutter lifts.<br />Everyone rushes in at once.</p>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/2ce08430-6d80-4c80-ba46-e3e39c4bc105.png" alt="" style="display:block;margin:0 auto" />

<p>The store wasn’t designed for that instant load.</p>
<p>That is exactly how the Thundering Herd Problem behaves in distributed systems.</p>
<p>In this article, we'll understand what this problem is, where it commonly occurs, and why it is dangerous, and finally, we'll discuss techniques to prevent or reduce it.</p>
<h2>What is the Thundering Herd Problem?</h2>
<p>The Thundering Herd Problem occurs when a large number of clients simultaneously attempt to access the same resource.</p>
<p>It is not just high traffic, but synchronized traffic.</p>
<p>This sudden burst of simultaneous requests can overload servers, databases, or caching layers, causing performance degradation or complete system collapse.</p>
<h2>Where Does It Commonly Occur?</h2>
<p>The problem appears in:</p>
<ul>
<li><p>Caching systems</p>
</li>
<li><p>Databases</p>
</li>
<li><p>Load balancers</p>
</li>
<li><p>Distributed systems</p>
</li>
<li><p>Retry mechanisms</p>
</li>
</ul>
<p>The most common scenario is cache expiry.</p>
<h2>Real-World Example</h2>
<p>Consider a system with the following architecture</p>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/552932ec-d3d7-4fe2-8fb5-6575c4674610.png" alt="" style="display:block;margin:0 auto" />

<p>Let's assume:</p>
<ul>
<li><p>Cache TTL (Time to Live) = 60 seconds</p>
</li>
<li><p>10,000 users are requesting the same data.</p>
</li>
</ul>
<p>For 60 seconds:</p>
<ul>
<li><p>Cache servers responses</p>
</li>
<li><p>Database remains protected</p>
</li>
</ul>
<p>After 60 seconds:</p>
<ul>
<li>Cache entry expires</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/fb1c18bc-2756-4470-94b4-777f963b262a.png" alt="" style="display:block;margin:0 auto" />

<p>Now, all 10,000 users:</p>
<ul>
<li><p>Miss the cache</p>
</li>
<li><p>Hit the database at the same time</p>
</li>
</ul>
<p>The database receives a sudden burst of requests and may not handle it properly.</p>
<p>This is called a cache stampede, which is a common form of the Thundering Herd Problem.</p>
<h2>Why Basic TTL Caching is Risky?</h2>
<p>Basic TTL caching works like this:</p>
<ul>
<li><p>Store data for a fixed duration.</p>
</li>
<li><p>After expiry, remove it.</p>
</li>
</ul>
<p>But if many users depend on the same key, fixed expiration becomes dangerous.</p>
<p>If multiple keys expire together:</p>
<ul>
<li><p>Traffic synchronizes</p>
</li>
<li><p>Backend services get overwhelmed</p>
</li>
<li><p>Latency increases</p>
</li>
<li><p>Failures cascade</p>
</li>
</ul>
<p>Basic TTL alone is not enough in distributed systems. Smarter cache control strategies are required.</p>
<h2>How Traffic Spikes Overload Systems?</h2>
<p>A normal traffic spike increases gradually:</p>
<p><strong>Example:</strong></p>
<ul>
<li><p>IPL streaming traffic increases over time</p>
</li>
<li><p>Viewers join slowly</p>
</li>
<li><p>Auto-scaling may handle it</p>
</li>
</ul>
<p>But in a thundering herd scenario:</p>
<ul>
<li><p>All users refresh at the same moment</p>
</li>
<li><p>Ticket booking opens at the exact time</p>
</li>
<li><p>Netflix releases a new season at midnight</p>
</li>
<li><p>Flash sale starts at 12:00 PM sharp</p>
</li>
</ul>
<p>Traffic doesn't grow here; it explodes.</p>
<p>Systems don't get time to adapt.</p>
<h2>Why Does It Become Dangerous in Distributed Systems?</h2>
<p>Distributed systems amplify the problem. Why?</p>
<p>Because:</p>
<ul>
<li><p>Multiple server instances may try to regenerate the same cache simultaneously</p>
</li>
<li><p>Retry mechanisms may trigger additional requests</p>
</li>
<li><p>Failures in one service can cascade to others.</p>
</li>
</ul>
<p>Failure → Retry → More Load → More Failure</p>
<p>This loop can crash entire systems.</p>
<p>Synchronization is the real danger.</p>
<h2>Impact on System Components</h2>
<h3>CPU</h3>
<ul>
<li><p>Thread pool exhaustion</p>
</li>
<li><p>High context switching</p>
</li>
<li><p>100% utilization</p>
</li>
<li><p>Increased response time</p>
</li>
</ul>
<p>When the CPU saturates, the entire application slows down.</p>
<h3>Database</h3>
<p>This is usually the most affected layer.</p>
<ul>
<li><p>Connection pool exhaustion</p>
</li>
<li><p>Lock contention</p>
</li>
<li><p>Slow queries</p>
</li>
<li><p>Potential crashes</p>
</li>
</ul>
<p>Databases are optimized for steady load. Not for sudden synchronized bursts.</p>
<h3>Cache</h3>
<p>Instead of protecting the database:</p>
<ul>
<li><p>Multiple regeneration attempts may occur</p>
</li>
<li><p>Duplicate recomputation increases pressure</p>
</li>
<li><p>Memory and network usage spike</p>
</li>
</ul>
<p>The cache becomes part of the problem.</p>
<h3>Latency</h3>
<p>Users experience:</p>
<ul>
<li><p>Slow responses</p>
</li>
<li><p>Timeouts</p>
</li>
<li><p>Failed requests</p>
</li>
</ul>
<p>When timeouts occur, retries begin.</p>
<p>Retries amplify the load even further.</p>
<h2>Normal Traffic Spike vs Thundering Herd</h2>
<table style="min-width:50px"><colgroup><col style="min-width:25px"></col><col style="min-width:25px"></col></colgroup><tbody><tr><th><p>Normal Traffic Spike</p></th><th><p>Thundering Herd</p></th></tr><tr><td><p>Gradual increase</p></td><td><p>Sudden synchronized burst</p></td></tr><tr><td><p>Predictable Pattern</p></td><td><p>All clients act at the same time</p></td></tr><tr><td><p>The system may scale</p></td><td><p>No scaling window</p></td></tr><tr><td><p>Manageable load</p></td><td><p>Immediate overload</p></td></tr></tbody></table>

<h2>Techniques to Prevent or Reduct It</h2>
<p>Preventing the Thundering Herb Problem requires careful system design.</p>
<h3>Request Coalescing</h3>
<p>Instead of allowing multiple identical requests to hit the database:</p>
<ul>
<li><p>First request goes to the database</p>
</li>
<li><p>Other requests wait</p>
</li>
<li><p>Response is shared</p>
</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/0e379763-de18-4baa-a296-85b12f97c509.png" alt="" style="display:block;margin:0 auto" />

<p>This ensures only one regeneration happens.</p>
<h3>Cache Locking / Mutex</h3>
<p>When cache expires:</p>
<ul>
<li><p>First thread acquires a lock</p>
</li>
<li><p>Regenerates data</p>
</li>
<li><p>Others wait</p>
</li>
</ul>
<img src="https://cdn.hashnode.com/uploads/covers/6783bc702b3943a91ecff19a/1566e440-62e6-407a-8e65-9468a61f445e.png" alt="" style="display:block;margin:0 auto" />

<p>This prevents parallel database hits.</p>
<h3>Staggered Expiry (Adding Jitter)</h3>
<p>Instead of:</p>
<ul>
<li>TTL = 60 seconds for all entries</li>
</ul>
<p>Use:</p>
<ul>
<li>TTL = 60 ± random(10 seconds)</li>
</ul>
<p>This spreads out expiry times and prevents synchronization.</p>
<h3>Exponential Backoff</h3>
<p>Instead of retrying immediately:</p>
<p>Wait:</p>
<ul>
<li><p>100 ms</p>
</li>
<li><p>200 ms</p>
</li>
<li><p>400 ms</p>
</li>
<li><p>800 ms</p>
</li>
</ul>
<p>This reduces retry storms and gives the system time to recover.</p>
<h3>Rate Limiting</h3>
<p>Limit incoming requests to protect downstream services.</p>
<p>Techniques:</p>
<ul>
<li><p>Token bucket</p>
</li>
<li><p>Leaky bucket</p>
</li>
</ul>
<p>It is better to reject some traffic than to crash the entire system.</p>
<h2>Why Is This Important for Interviews?</h2>
<p>Interviewers use this problem to test:</p>
<ul>
<li><p>Understanding of caching</p>
</li>
<li><p>Distributed system thinking</p>
</li>
<li><p>Failure handling</p>
</li>
<li><p>Retry strategies</p>
</li>
<li><p>Traffic Behavior Modeling</p>
</li>
</ul>
<h2>Mental Model</h2>
<p>The problem is not high traffic.</p>
<p>The problem is synchronized traffic.</p>
<p>Systems are built for scale.</p>
<p>They struggle with coordination failure.</p>
<h2>Conclusion</h2>
<p>The Thundering Herd Problem is one of the most important failure patterns in distributed systems.</p>
<p>It teaches us that:</p>
<ul>
<li><p>Cache expiry timing matters</p>
</li>
<li><p>Retries can amplify failure</p>
</li>
<li><p>Synchronization can crash systems</p>
</li>
</ul>
<p>Good system design is not just about handling more users.</p>
<p>It is about predicting behavior under stress and preventing chaos before it begins.</p>
<h3>Want More…?</h3>
<p>I write articles on <a href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Connecting Your Domain to Hashnode]]></title><description><![CDATA[Introduction
If you’re serious about blogging, having a custom domain makes a real difference. If makes your blog look professional and gives you ownership.
Hashnode makes this process easy, but many students still get confused, mainly with CNAME rec...]]></description><link>https://blog.devwithjay.com/hashnode-custom-domain</link><guid isPermaLink="true">https://blog.devwithjay.com/hashnode-custom-domain</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[dns]]></category><category><![CDATA[cloudflare]]></category><category><![CDATA[Hashnode]]></category><category><![CDATA[cname]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Mon, 19 Jan 2026 14:32:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1768828526758/921c96c6-b619-41ad-a8cc-c69aff14c496.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>If you’re serious about blogging, having a <strong>custom domain</strong> makes a real difference. If makes your blog look professional and gives you ownership.</p>
<p>Hashnode makes this process easy, but many students still get confused, mainly with <strong>CNAME records</strong> and <strong>blog setup</strong>.</p>
<p>This article will guide you on how to connect a custom domain name using <strong>CNAME</strong> and common mistakes I see students making (and how to avoid them).</p>
<h2 id="heading-prerequisites">Prerequisites</h2>
<ul>
<li><p>A HashNode account ❕</p>
</li>
<li><p>A domain name (from providers like Spaceship, GoDaddy, Namecheap)</p>
</li>
<li><p>Some Patience 😌</p>
</li>
</ul>
<h2 id="heading-creating-blog">Creating Blog</h2>
<p><strong>Wrong Approach:</strong></p>
<ul>
<li><p>Creating a new Hashnode article for every article</p>
</li>
<li><p>Trying to attach a custom domain to each blog</p>
</li>
</ul>
<p><strong>Correct Approach:</strong></p>
<ul>
<li><p>Create <strong>one main blog</strong></p>
</li>
<li><p>Add your custom domain to that blog</p>
</li>
<li><p>Publish <strong>all articles inside that same blog</strong></p>
</li>
</ul>
<p><strong>Steps to create a blog:</strong></p>
<ol>
<li><p>Go to https://hashnode.com</p>
</li>
<li><p>Click on <strong>New Blog</strong></p>
<p> <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768815064047/6738c8fb-4984-44e4-91f3-bb62b042d471.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Enter your <strong>Blog name (e.g. Learn With Jay)</strong></p>
</li>
<li><p>Choose your <strong>Blog URL</strong> (this will be <code>yourname.hashnode.dev</code> for now)</p>
</li>
<li><p>Click <strong>Create</strong></p>
</li>
</ol>
<p>This single blog will contain <strong>all your articles.</strong> Do not create a new blog for every article.</p>
<h2 id="heading-adding-custom-domain-to-hashnode-using-cloudflare">Adding Custom Domain to Hashnode (Using Cloudflare)</h2>
<p>In this guide, I’m using Cloudflare becuase:</p>
<ul>
<li><p>It’s free</p>
</li>
<li><p>It’s fast</p>
</li>
<li><p>Most developers prefer using it</p>
</li>
</ul>
<h3 id="heading-step-1-add-domain-in-hashnode"><strong>Step 1: Add Domain in Hashnode</strong></h3>
<ul>
<li><p><strong>Steps:</strong></p>
<ol>
<li><p>Open your Hashnode <strong>Dashboard</strong></p>
</li>
<li><p>Select the blog you just created</p>
</li>
<li><p>Navigate to <strong>Domain Tab</strong></p>
</li>
<li><p>Enter your Domain Name (e.g. <code>blog.yourdomain.com</code>)</p>
</li>
</ol>
</li>
<li><p>Hashnode will now show you <strong>CNAME record details.</strong></p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768833011806/3d15cff9-dc3c-4f4f-ba92-16416cf6100f.png" alt class="image--center mx-auto" /></p>
</li>
</ul>
<ul>
<li><p>Hashnode recommends using a <strong>subdomain</strong>, not the root domain.</p>
<p>  <strong>Avoid:</strong> <code>yourdomain.com</code></p>
<p>  <strong>Prefer:</strong> <code>blog.yourdomain.com</code></p>
</li>
</ul>
<h3 id="heading-step-2-add-domain-to-cloudflare"><strong>Step 2: Add Domain to Cloudflare</strong></h3>
<ul>
<li><p><strong>Steps:</strong></p>
<ol>
<li><p>Go to <a target="_blank" href="https://dash.cloudflare.com">https://dash.cloudflare.com</a></p>
</li>
<li><p>Click <strong>Add a site</strong></p>
</li>
<li><p>Enter your domain name (e.g. <a target="_blank" href="http://yourdomain.com"><code>yourdomain.com</code></a>)</p>
</li>
<li><p>Choose the <strong>Free plan</strong></p>
</li>
<li><p>Cloudflare will scan existing DNS records (you can continue)</p>
</li>
</ol>
</li>
<li><p>Once added, Cloudflare will ask you to update <strong>nameservers</strong> at your domain provider.</p>
</li>
</ul>
<h3 id="heading-step-3-update-nameservers-at-domain-provider"><strong>Step 3: Update Nameservers at Domain Provider</strong></h3>
<ul>
<li><p>Go to your domain provider (Spaceship, GoDaddy, Namecheap):</p>
<ol>
<li><p>Open <strong>DNS / Nameserver settings</strong></p>
</li>
<li><p>Replace existing nameservers with Cloudflare nameservers</p>
</li>
<li><p>Save changes</p>
</li>
</ol>
</li>
<li><p>DNS propagation may take some time.</p>
</li>
</ul>
<h3 id="heading-step-4-add-cname-record-mentioned-by-hashnode">Step 4: Add CNAME Record Mentioned by Hashnode</h3>
<ul>
<li><p>In Cloudflare:</p>
<ol>
<li><p>Open your domain</p>
</li>
<li><p>Go to <strong>DNS → Records</strong></p>
</li>
<li><p>Click <strong>Add record</strong></p>
</li>
</ol>
</li>
<li><p>Fill the values:</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768816763451/1fb75615-f459-4cb0-b637-16210ba5dcca.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Type: <code>CNAME</code></p>
</li>
<li><p>Name: <code>blog</code></p>
</li>
<li><p>Target: <code>hashnode.network</code></p>
</li>
<li><p>Proxy status: <strong>DNS only</strong> (important)</p>
</li>
<li><p>TTL: Auto</p>
</li>
</ul>
</li>
<li><p>Save the record.</p>
</li>
<li><p>Do not add extra spaces or change values.</p>
</li>
</ul>
<h3 id="heading-step-5-verify-domain-on-hashnode">Step 5: Verify Domain on Hashnode</h3>
<ul>
<li><p><strong>Steps:</strong></p>
<ol>
<li><p>Go back to <strong>Hashnode → Settings → Domain</strong></p>
</li>
<li><p>Click <strong>Verify Domain</strong></p>
</li>
</ol>
</li>
<li><p>If DNS has propagated, you’ll see a success message.</p>
</li>
<li><p>If not, wait a little and try again.</p>
</li>
</ul>
<h3 id="heading-step-6-ssl-https">Step 6: SSL (HTTPS)</h3>
<ul>
<li><p>Hashnode automatically provides <strong>free SSL</strong>.</p>
<ul>
<li><p>No manual setup needed</p>
</li>
<li><p>HTTPS may take a few minutes to activate</p>
</li>
</ul>
</li>
<li><p>Once done, your blog will open securely.</p>
</li>
</ul>
<h2 id="heading-how-publishing-works-after-this">How Publishing Works After This</h2>
<p>Once the domain is connected:</p>
<ul>
<li><p>You will write <strong>all articles in the same blog</strong></p>
</li>
<li><p>URLs will look like:</p>
<p>  <code>https://blog.yourdomain.com/article-title</code></p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Connecting a custom domain to Hashnode using CNAME is simple once you understand the flow.</p>
<blockquote>
<p><strong>One Blog. One Domain. Unlimited Articles</strong></p>
</blockquote>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Understanding Tokenization]]></title><description><![CDATA[Introduction
When you talk to AI like ChatGPT, it feels like it understands full sentences.
It feels like it reads words the same way humans do.
But that’s not true.
AI does not read words.AI does not read sentences.
AI reads tokens.
To understand ho...]]></description><link>https://blog.devwithjay.com/understanding-tokenization</link><guid isPermaLink="true">https://blog.devwithjay.com/understanding-tokenization</guid><category><![CDATA[AI]]></category><category><![CDATA[genai]]></category><category><![CDATA[Tokenization]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[llm]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Mon, 12 Jan 2026 04:40:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1768205914732/fa7c8cf5-359b-423c-bc9a-1ceb495245c4.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>When you talk to AI like ChatGPT, it feels like it understands full sentences.</p>
<p>It feels like it reads words the same way humans do.</p>
<p>But that’s not true.</p>
<p>AI does <strong>not</strong> read words.<br />AI does <strong>not</strong> read sentences.</p>
<p>AI reads <strong>tokens</strong>.</p>
<p>To understand how AI works, tokenization is one of the most important concepts to learn.</p>
<h2 id="heading-computers-dont-understand-language">Computers Don’t Understand Language</h2>
<p>Humans understand language naturally.</p>
<p>When you read:</p>
<blockquote>
<p>“My name is Jay.”</p>
</blockquote>
<p>You understand the meaning instantly.</p>
<p>A computer cannot do this.</p>
<p>Computers only understand <strong>numbers</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768150570670/d4a5129f-5d2e-46ee-898f-b26d320590b5.png" alt class="image--center mx-auto" /></p>
<p>So before AI can work with language, text must be converted into a form computers can process.</p>
<p>That process is called <strong>tokenization</strong>.</p>
<h2 id="heading-what-is-tokenization">What Is Tokenization?</h2>
<p><strong>Tokenization</strong> means breaking text into small parts called <strong>tokens</strong>.</p>
<p>AI models like GPT do not predict letters or full sentences.</p>
<p>They predict <strong>tokens</strong>, one at a time.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768150608594/c24ed538-83a0-42a2-b037-63fb360d4d3e.png" alt class="image--center mx-auto" /></p>
<p>A token can be:</p>
<ul>
<li><p>a single letter</p>
</li>
<li><p>a full word</p>
</li>
<li><p>or part of a word</p>
</li>
</ul>
<p>There is no fixed rule.</p>
<p>How text is split depends on the <strong>tokenizer</strong> used by the model.</p>
<h2 id="heading-what-is-a-token">What Is a Token?</h2>
<p>A <strong>token</strong> is the smallest unit of text that AI understands.</p>
<p>A token can be:</p>
<ul>
<li><p><code>"My"</code></p>
</li>
<li><p><code>"name"</code></p>
</li>
<li><p><code>"is"</code></p>
</li>
<li><p><code>"Jay"</code></p>
</li>
</ul>
<p>Or it can be smaller:</p>
<ul>
<li><p><code>"M"</code>, <code>"y"</code></p>
</li>
<li><p><code>"n"</code>, <code>"a"</code>, <code>"m"</code>, <code>"e"</code></p>
</li>
</ul>
<p>Even spaces and punctuation can become tokens.</p>
<h2 id="heading-same-sentence-different-tokens">Same Sentence, Different Tokens</h2>
<p>Let’s take a simple sentence:</p>
<pre><code class="lang-plaintext">My name is Jay.
</code></pre>
<p>Different models can break this sentence differently.</p>
<h3 id="heading-model-a-word-based-tokenization">Model A (Word-based tokenization)</h3>
<pre><code class="lang-plaintext">My
name
is
Jay
</code></pre>
<h3 id="heading-model-b-character-sub-word-tokenization">Model B (Character / sub-word tokenization)</h3>
<pre><code class="lang-plaintext">M
y
(space)
n
a
m
e
(space)
i
s
(space)
J
a
y
</code></pre>
<p>Both models see the <strong>same sentence</strong>.</p>
<p>But the tokens are different.</p>
<p>That is why:</p>
<ul>
<li><p>Token count changes</p>
</li>
<li><p>Cost changes</p>
</li>
<li><p>Behavior changes slightly</p>
</li>
</ul>
<h2 id="heading-why-tokenization-is-important">Why Tokenization Is Important</h2>
<p>AI does not think in words.</p>
<p>It thinks in <strong>tokens</strong>.</p>
<p>When you type a prompt, the model predicts the <strong>next token</strong>, not the next sentence.</p>
<p>It keeps doing this again and again until a full response is created.</p>
<p>That is how AI “writes”.</p>
<h2 id="heading-how-gpt-predicts-text">How GPT Predicts Text</h2>
<p>Let’s say you type:</p>
<pre><code class="lang-plaintext">Once upon a
</code></pre>
<p>GPT might predict:</p>
<pre><code class="lang-plaintext">time
</code></pre>
<p>Then it predicts:</p>
<pre><code class="lang-plaintext">there
</code></pre>
<p>Then:</p>
<pre><code class="lang-plaintext">was
</code></pre>
<p>One token at a time.</p>
<p>This continues until the response is complete.</p>
<p>That’s it.</p>
<p>No thinking.<br />No understanding.<br />Just prediction.</p>
<h2 id="heading-why-small-prompt-changes-matter">Why Small Prompt Changes Matter</h2>
<p>Because AI works with tokens, even small changes affect the output.</p>
<p><strong>For example:</strong></p>
<pre><code class="lang-plaintext">Explain JavaScript.
</code></pre>
<p><strong>vs</strong></p>
<pre><code class="lang-plaintext">Explain JavaScript simply.
</code></pre>
<p>These two prompts produce different tokens.</p>
<p>Different tokens → different predictions → different output.</p>
<p>That’s why prompt wording matters so much.</p>
<h2 id="heading-what-are-token-limits">What are Token Limits?</h2>
<p>Every AI model has a <strong>token limit</strong>.</p>
<p>This limit includes:</p>
<ul>
<li><p>Your input</p>
</li>
<li><p>Previous messages</p>
</li>
<li><p>The model’s reply</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1768150647490/ae70c316-cb60-4dd0-85e7-c626a9236774.png" alt class="image--center mx-auto" /></p>
<p>If the total tokens exceed the limit, older messages are removed.</p>
<p>That’s why AI sometimes “forgets” things.</p>
<p>It did not forget.</p>
<p>The tokens just did not fit.</p>
<h2 id="heading-tokenization-depends-on-the-model">Tokenization Depends on the Model</h2>
<p>Each AI model uses its own tokenizer.</p>
<p><strong>For example:</strong></p>
<ul>
<li><p>GPT has its own tokenizer</p>
</li>
<li><p>Gemini has a different one</p>
</li>
<li><p>Claude uses another</p>
</li>
</ul>
<p>So the same text can produce <strong>different token counts</strong> in different models.</p>
<p>There is no universal token system.</p>
<h2 id="heading-tokenization-happens-first">Tokenization Happens First</h2>
<p>Before AI can do anything useful, tokenization happens.</p>
<p>The basic flow looks like this:</p>
<pre><code class="lang-plaintext">Text
→ Tokens
→ Numbers
→ AI Model
→ Predicted Tokens
→ Text Output
</code></pre>
<p>Everything starts with tokens.</p>
<h2 id="heading-why-freshers-should-learn-tokenization">Why Freshers Should Learn Tokenization</h2>
<p>Understanding tokenization helps you understand:</p>
<ul>
<li><p><strong>Why prompt engineering works</strong></p>
</li>
<li><p><strong>Why AI pricing is token-based</strong></p>
</li>
<li><p><strong>Why context is limited</strong></p>
</li>
<li><p><strong>Why AI answers change with wording</strong></p>
</li>
</ul>
<p>Once you understand tokens, AI stops feeling <strong>magical</strong>.</p>
<p>It starts feeling <strong>logical</strong>.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Tokenization is the first step in how AI understands language.</p>
<p>Before a model can answer, explain, or generate anything, it must break text into tokens.<br />Those tokens decide <strong>what the model sees</strong>, <strong>how much it remembers</strong>, and <strong>what it predicts next</strong>.</p>
<p>Once you understand tokenization, many AI behaviors start making sense:<br />why prompts matter, why limits exist, and why wording changes results.</p>
<p>AI may feel intelligent, but at its core, it’s simply working with tokens and probabilities.</p>
<p>And that’s exactly where everything begins.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Vector Embeddings]]></title><description><![CDATA[Introduction
AI can translate languages, answer questions, recommend movies and even understand emotions in text.
But behind all of this intelligence, there is one concept that makes everything work: Vector Embeddings
You may not hear the term often,...]]></description><link>https://blog.devwithjay.com/vector-embeddings</link><guid isPermaLink="true">https://blog.devwithjay.com/vector-embeddings</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[vector embeddings]]></category><category><![CDATA[AI]]></category><category><![CDATA[transformers]]></category><category><![CDATA[genai]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Sun, 16 Nov 2025 15:12:07 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1763300376084/d1db6201-52af-42a0-b90c-07d81d14eebb.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>AI can translate languages, answer questions, recommend movies and even understand emotions in text.</p>
<p>But behind all of this intelligence, there is one concept that makes everything work: <strong>Vector Embeddings</strong></p>
<p>You may not hear the term often, but embeddings are the foundation of how AI understands meaning.</p>
<p>They help models like GPT recognize relationships between words, compare ideas, and respond in a way that feels surprisingly human.</p>
<h2 id="heading-why-do-we-need-embeddings">Why Do We Need Embeddings?</h2>
<p>Humans understand language naturally. A single world like “apple” brings images, taste, color and memories.</p>
<p>But Computers? They only understand <strong>numbers.</strong></p>
<p>Earlier methods tried to convert words into numbers using simple techniques, but they had a major flaw:</p>
<blockquote>
<p>Old Methods Didn’t Capture Meaning</p>
</blockquote>
<ul>
<li><p>“king” and “queen” looked unrelated</p>
</li>
<li><p>“car” and “vehicle” were treated like strangers</p>
</li>
<li><p>“bank (river)” and “bank (money)” looked identical</p>
</li>
</ul>
<p>AI needed a better way, a method to represent <strong>meaning</strong>, not just text.</p>
<p>That method is <strong>vector embeddings</strong>.</p>
<h2 id="heading-what-are-vector-embeddings">What are Vector Embeddings?</h2>
<p>Vector embeddings are numerical representations that capture the meaning of words, sentences or even images.</p>
<p>Instead of storing words as plain text, AI converts them into <strong>vectors</strong>, long lists of numbers like:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763300407901/c3d0a147-4a2a-4007-bb6a-a9456ab1a456.png" alt class="image--center mx-auto" /></p>
<p>The numbers store:</p>
<ul>
<li><p>context</p>
</li>
<li><p>relationships</p>
</li>
<li><p>meaning</p>
</li>
<li><p>similarity</p>
</li>
</ul>
<p>So AI doesn’t just see the word “king”.<br />It sees how “king” relates to “queen”, “royal”, “monarch”, “crown”, and so on.</p>
<h2 id="heading-how-embeddings-actually-work">How Embeddings Actually Work?</h2>
<p>A good way to understand embeddings is to image a <strong>giant map.</strong></p>
<p>Every word is a point on this map.</p>
<p>Words with similar meanings appear <strong>close together.</strong><br />Words with opposite or unrelated meanings appear <strong>far apart.</strong></p>
<p><strong>Example:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763300502598/f239f891-c584-4a28-8a1f-95b0caca4063.png" alt class="image--center mx-auto" /></p>
<p>This is how AI <strong><em>feels</em></strong> meaning.</p>
<p>Embeddings allow AI to reason like this:</p>
<ul>
<li><p>“queen” is close to “king”</p>
</li>
<li><p>“doctor” is close to “hospital”</p>
</li>
<li><p>“sun” is close to “light”</p>
</li>
<li><p>“milk” is close to “cow”</p>
</li>
</ul>
<h2 id="heading-where-do-embeddings-come-from">Where Do Embeddings Come From?</h2>
<p>Many people think embeddings magically appear, but they are created through <strong>Transformer models</strong>, the same architecture used in GPT, Gemini, Claude, and more.</p>
<blockquote>
<p><strong>A Transformer takes input, processes it, and produces meaningful output.</strong></p>
</blockquote>
<p>Transformers were introduced by Google in 2017 in a research paper titled: “<strong>Attention is All You Need.”</strong></p>
<p>This paper changed everything in AI.</p>
<p>Transformers learn embeddings by reading massive amounts of text and discovering how words appear together, their context, relationships and patterns.</p>
<h2 id="heading-working-of-transformer">Working of Transformer</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763305729096/d849b783-ea84-4bbc-ab73-cf4538c1d2ed.png" alt class="image--center mx-auto" /></p>
<p><strong>Step 1: Tokenization</strong></p>
<ul>
<li><p>AI Doesn’t read full words It breaks text into <strong>token</strong>(small units) like:</p>
<ul>
<li><p>“Hello” → “Hel”, “lo”</p>
</li>
<li><p>“Jay” → “J”, “a”, “y”</p>
</li>
<li><p>“Running” → “run”, “ning”</p>
</li>
</ul>
</li>
<li><p>Each token is assigned a number.</p>
</li>
<li><p>These numbers enter the embedding layer.</p>
</li>
</ul>
<p><strong>Step 2: Input Embedding Layer</strong></p>
<ul>
<li><p>This is where tokens into <strong>vector embeddings.</strong></p>
</li>
<li><p>Each token becomes a coordinate in multi-dimensional space.</p>
</li>
<li><p>Words with similar meaning end up close together.</p>
</li>
</ul>
<p><strong>Step 3: Positional Encoding</strong></p>
<ul>
<li><p>Embeddings capture meaning, but not order.</p>
</li>
<li><p><strong>Example:</strong></p>
<ul>
<li><p>“Dog bites man”</p>
</li>
<li><p>“Man bites dog”</p>
</li>
</ul>
</li>
</ul>
<p>    Same Words. Different Meaning.</p>
<ul>
<li>Positional encoding helps the model understand <strong>word order.</strong></li>
</ul>
<p><strong>Step 4: Self-Attention</strong></p>
<p>This is where Transformer shine.</p>
<p>Self-attention allows the model to understand <strong>context</strong>:</p>
<ul>
<li><p>“bank” near “river” → water</p>
</li>
<li><p>“bank” near “loan” → finance</p>
</li>
</ul>
<p>This steps refines the embeddings based on their surroundings.</p>
<p><strong>Step 5: Learned Meaning</strong></p>
<ul>
<li><p>After millions of sentences, the model learns relationships like:</p>
<ul>
<li><p>Paris → France</p>
</li>
<li><p>Tokyo → Japan</p>
</li>
<li><p>Apple → Fruit</p>
</li>
<li><p>Tiger → Animal</p>
</li>
</ul>
</li>
<li><p>This knowledge lives inside <strong>vector embeddings.</strong></p>
</li>
</ul>
<h2 id="heading-where-are-embeddings-used-in-real-life">Where are Embeddings Used in Real Life?</h2>
<p>Embeddings power almost every AI system we use today.</p>
<ol>
<li><p><strong>Search Engines</strong></p>
<p> Search “best movies about space”</p>
<p> The system uses embeddings to find content with similar meaning, not just matching keywords.</p>
</li>
<li><p><strong>ChatGPT</strong></p>
<p> Your message → embedding</p>
<p> GPT response → based on embeddings of related ideas.</p>
</li>
<li><p><strong>Recommendations</strong></p>
<p> Netflix, Spotify, YouTube, all use embeddings to understand your taste.</p>
</li>
<li><p><strong>Document Similarity</strong></p>
<p> AI can detect:</p>
<p> “This paragraph means the same thing as that one”,</p>
<p> even if the words are totally different.</p>
</li>
<li><p><strong>Image Search</strong></p>
<p> With image embeddings, AI can find:</p>
<ul>
<li><p>“pictures similar to this one”</p>
</li>
<li><p>“objects related to this shape”</p>
</li>
</ul>
</li>
</ol>
<p>    Embeddings go far beyond text.</p>
<h2 id="heading-why-embeddings-feel-so-magical">Why Embeddings Feel So Magical?</h2>
<p>Embeddings give AI the ability to:</p>
<ul>
<li><p>understand meaning</p>
</li>
<li><p>detect relationships</p>
</li>
<li><p>identify similarities</p>
</li>
<li><p>follow context</p>
</li>
<li><p>bridge languages</p>
</li>
</ul>
<p>They make AI feel smart, even though, in reality, the model is just a <strong>powerful prediction machine.</strong></p>
<p>AI does not think.<br />It predicts the next best output using patterns it has learned.</p>
<h2 id="heading-types-of-embeddings">Types of Embeddings</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1763300691523/c874452e-4ed1-4965-96ec-eac944d0d32b.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Word Embeddings</strong></p>
<ul>
<li><p>Word Embeddings represent the <strong>meaning</strong> <strong>of individual words</strong> as vectors.</p>
</li>
<li><p>They help the model understand:</p>
<ul>
<li><p>which words are similar(“happy” and “joyful”)</p>
</li>
<li><p>which words are related(“car” and “engine”)</p>
</li>
<li><p>which words are opposite(“hot” and “cold”)</p>
</li>
</ul>
</li>
<li><p>These embeddings are useful in tasks like:</p>
<ul>
<li><p>spell-check</p>
</li>
<li><p>suggestions while typing</p>
</li>
<li><p>simple search systems</p>
</li>
<li><p>sentiment analysis</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Sentence Embeddings</strong></p>
<ul>
<li><p>Sentence embeddings capture the the <strong>overall meaning of an entire sentence</strong>, not just individual words.</p>
</li>
<li><p><strong>For example:</strong></p>
<ul>
<li><p>“I’m feeling great today!”</p>
</li>
<li><p>“Today, I’m in a very good mood".</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<p>        Both contain different words but have <strong>the same meaning.</strong></p>
<p>        Sentence embeddings make this clarity possible.</p>
<ul>
<li><p>These are use in:</p>
<ul>
<li><p>chatbots</p>
</li>
<li><p>document search</p>
</li>
<li><p>duplicate question detection(e.g. StackOverflow)</p>
</li>
<li><p>summary and Q&amp;A systems</p>
</li>
</ul>
</li>
<li><p>Sentence embeddings help AI understand context, tone and intention.</p>
</li>
</ul>
<ol start="3">
<li><p><strong>Document Embeddings</strong></p>
<ul>
<li><p>Document embeddings represent <strong>whole paragraphs, articles, reports, or long texts</strong> as single vectors.</p>
</li>
<li><p>They help AI:</p>
<ul>
<li><p>search inside large knowledge bases</p>
</li>
<li><p>find related articles</p>
</li>
<li><p>retrieve the right information for ChatGPT(RAG systems)</p>
</li>
<li><p>group documents by theme</p>
</li>
<li><p>detect plagiarism or similarity</p>
</li>
</ul>
</li>
<li><p>If you’ve ever used “semantic search” or “AI-powered search”, document embeddings are running behind the scenes.</p>
</li>
</ul>
</li>
<li><p><strong>Image Embeddings</strong></p>
<ul>
<li><p>Image embeddings convert images into numbers based on what the image <em>contains</em>.</p>
</li>
<li><p><strong>For example, an AI sees:</strong></p>
<ul>
<li><p>a dog → “animal, four legs, fur, outdoors”</p>
</li>
<li><p>a car → “vehicle, wheels, metal, road”</p>
</li>
<li><p>a sunset → “sky, light, orange colors”</p>
</li>
</ul>
</li>
<li><p>These embeddings allow AI to:</p>
<ul>
<li><p>find similar images</p>
</li>
<li><p>label images automatically</p>
</li>
<li><p>match text with images (like “dog running”)</p>
</li>
<li><p>understand what an image represents in visual search</p>
</li>
</ul>
</li>
<li><p>Image embeddings are used in systems like Google Photos, Pinterest and modern vision-language models.</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-the-future-of-embeddings">The Future of Embeddings</h2>
<p>Embeddings are improving rapidly.</p>
<p>The next generation will handle:</p>
<ul>
<li><p>text</p>
</li>
<li><p>image</p>
</li>
<li><p>audio</p>
</li>
<li><p>video</p>
</li>
<li><p>emotions</p>
</li>
<li><p>real-world context</p>
</li>
</ul>
<p>All inside a single vector space.</p>
<p>This will allow AI models to understand <em>everything together</em>, not in separate parts.</p>
<p>The more embeddings evolve, the more natural AI will become.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Vector embeddings are the hidden power behind modern AI.<br />They let machines turn text and images into numbers, not randomly, but meaningfully.</p>
<p>This is how AI understands relationships, compares ideas, and communicates like a human.</p>
<p>Embeddings don’t store words. They store <strong>meaning</strong>.</p>
<p>And that’s why they are one of the most revolutionary concepts in the world of AI today.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Understanding GPT]]></title><description><![CDATA[Introduction
You’ve probably seen people talking about GPT, ChatGPT, or AI that writes like a human.
But what exactly is GPT? And how can a computer understand what we say or even talk back intelligently?
To understand how GPT works, let’s start with...]]></description><link>https://blog.devwithjay.com/understanding-gpt</link><guid isPermaLink="true">https://blog.devwithjay.com/understanding-gpt</guid><category><![CDATA[genai]]></category><category><![CDATA[ChaiCode]]></category><category><![CDATA[chatgpt]]></category><category><![CDATA[gpt]]></category><category><![CDATA[openai]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Sat, 08 Nov 2025 09:23:21 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1762586175751/58bbce16-38fa-4974-a803-0f4630914c0d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>You’ve probably seen people talking about GPT, ChatGPT, or AI that writes like a human.</p>
<p>But what exactly is GPT? And how can a computer understand what we say or even talk back intelligently?</p>
<p>To understand how GPT works, let’s start with a simple comparison, between how we’ve always told computers what to do, and how AI has completely changed that approach.</p>
<h2 id="heading-traditional-coding-vs-ai">Traditional Coding vs AI</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1762589957289/478cefd9-b0eb-4fd6-9017-8cad6ff45342.png" alt class="image--center mx-auto" /></p>
<p>In traditional programming, we tell computers exactly what to do.<br />We use fixed instructions like <code>if</code>, <code>else</code>, or <code>return</code>.</p>
<p>Every step is predefined, meaning the computer follows only the rules we write.<br />The output is fixed, predictable, and repeatable.</p>
<p><strong>For example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">if</span>(input === <span class="hljs-string">"Hi"</span>) {
  <span class="hljs-keyword">return</span> <span class="hljs-string">"Hello!"</span>;
}
</code></pre>
<p>No matter how many times you run it, the answer will always be <code>“Hello!”</code>, nothing more, nothing less.</p>
<p>Now comes Artificial Intelligence(AI), especially Generative AI(GenAI).<br />AI doesn’t follow any hard-coded rules. It doesn’t have prewritten answers.</p>
<p>Instead, it learns patterns from large data and then <strong>creates</strong> <strong>answers dynamically</strong>, based on what is has learned.</p>
<p>This means the response is not fixed. It’s <strong>generated on the go</strong>, depending on the <strong>context</strong> and <strong>prompt</strong>.</p>
<p>That’s what makes AI so interesting. It doesn’t just follow instructions, it actually creates results.</p>
<h2 id="heading-what-is-generative-ai">What is Generative AI?</h2>
<p>Generative AI is a special types of AI that doesn’t just analyze, it <strong>creates</strong>.</p>
<p>The word Generative means to produce or bring into existence.<br />So, Generative AI refers to a system capable of <strong>generating new content</strong>, such as text, images, code, music, or even video.</p>
<p><strong>For example:</strong></p>
<ul>
<li><p>A normal AI might look at an image and say: <strong><em>“This is a cat.”</em></strong></p>
</li>
<li><p>A Generative AI, however, can <strong>create</strong> a brand-new image of a cat, one that never existed before.</p>
</li>
</ul>
<p>That’s the difference between <strong>recognizing</strong> and <strong>creating</strong>.</p>
<p>Generative AI doesn’t just interpret data, it uses what is has learned to produce new ideas, words, or visuals, almost like a storyteller or digital artist.</p>
<p>Today, many companies have built similar generative models:</p>
<ul>
<li><p><strong>Google</strong> → Gemini</p>
</li>
<li><p><strong>Anthropic</strong> → Claude</p>
</li>
<li><p><strong>Meta</strong> → LLaMA</p>
</li>
</ul>
<p>All of these belong to the same family of <strong>Generative AI</strong>, systems that can produce human-like text or content.</p>
<h2 id="heading-what-is-gpt">What is GPT?</h2>
<p><strong>GPT</strong> stands for <strong>Generative Pretrained Transformer</strong>, and it’s type of <strong>Generative AI model</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1762592117111/54aacd1c-284b-44c4-886e-1613c324cdd3.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p><strong>Generative</strong> <strong>→</strong> It can <strong>generate</strong> new content (text, articles, stories, code, etc.).</p>
</li>
<li><p><strong>Pretrained</strong> <strong>→</strong> It was <strong>trained in advance</strong> using a large amount of publicly available data, from books, websites, articles, and more.</p>
</li>
<li><p><strong>Transformer →</strong> It’s a <strong>deep learning architecture</strong> designed to <strong>understand relationships between words</strong> and <strong>context</strong>.</p>
</li>
</ul>
<p><strong>For example, if you say:</strong></p>
<blockquote>
<p><strong>“Write me a nice bedtime story.”</strong></p>
</blockquote>
<p>GPT won’t pull a prewritten story. Instead, it creates one instantly, word by word, predicting what comes next based on everything it has learned.</p>
<p>The company who build GPT is <strong>OpenAI</strong>, a research organization focused on developing safe and useful artificial intelligence.</p>
<p>The name <strong>“OpenAI”</strong> is given with their early mission, to make AI research <strong>open</strong>, <strong>collaborative</strong>, and <strong>beneficial for everyone.</strong></p>
<h2 id="heading-what-is-chatgpt">What is ChatGPT?</h2>
<p>When you hear the word <strong>ChatGPT</strong>, it simply means:</p>
<p><strong>Chat + GPT</strong> = Chat interface built on top of GPT.</p>
<p>It’s basically a chat version of the GPT model, where you type a question, and GPT replies in real time, like a conversation.</p>
<p>So, instead of interacting with code or data directly, you just talk naturally, and ChatGPT responds like a human.</p>
<p>It can:</p>
<ul>
<li><p>Answer questions</p>
</li>
<li><p>Write essays or emails</p>
</li>
<li><p>Generate Code</p>
</li>
<li><p>Summarize Articles</p>
</li>
<li><p>Translate Languages</p>
</li>
<li><p>Explain complex topics simply</p>
</li>
</ul>
<p>ChatGPT made AI accessible to everyone, not just developers or researchers.</p>
<h2 id="heading-how-gpt-actually-works">How GPT Actually Works</h2>
<p>Let’s say you are starting a sentence with:</p>
<blockquote>
<p><strong>“Once upon a…”</strong></p>
</blockquote>
<p>GPT instantly guesses the next word, maybe <strong><em>“time.”</em></strong><br />Then it predicts the next one, and the next, until you have a complete story.</p>
<p>That’s exactly how GPT works, it’s like a <strong>super advanced word predictor</strong> that has read almost the entire internet.</p>
<p>But instead of just guessing random words, GPT uses context, grammar, and meaning, allowing it to write responses that sound natural and logical.</p>
<h2 id="heading-is-ai-smart">Is AI “Smart”?</h2>
<p>Despite how impressive it seems, <strong>AI isn’t truly intelligent</strong>.</p>
<p>It doesn’t think, feel, or understand like humans do.<br />It’s more like a <strong>smart prediction machine</strong>, some even call it a <strong><em>“clever box that predicts the next word.”</em></strong></p>
<p>GPT doesn’t know what it’s saying, it just knows what usually comes next when people write about that topic.</p>
<p>That’s why sometimes AI can make mistakes or <em>hallucinate</em> (generate incorrect information confidently).</p>
<p>So, the idea that <strong><em>“AI will replace humans completely”</em></strong> is a <strong>myth</strong>.<br />AI only does what it’s trained and instructed to do, nothing more!</p>
<h2 id="heading-why-gpt-feels-so-human">Why GPT Feels So Human</h2>
<p>GPT feels natural because it’s incredibly good at <strong>understanding context</strong>.</p>
<p>When you ask a question, it doesn’t just look at a few words, it reads your entire sentence and infers you <strong>intent</strong>, <strong>tone</strong>, and <strong>style</strong>.</p>
<p><strong>For example, when you say:</strong></p>
<blockquote>
<p>“Explain quantum physics like I’m five,”<br />it knows how to respond playfully and simply.</p>
</blockquote>
<p>That’s why GPT can write essays, poems, jokes, and even technical documentation, all while matching your tone perfectly.</p>
<h2 id="heading-the-future-of-gpt">The Future of GPT</h2>
<p>GPT is evolving rapidly.<br />Each new version becomes smarter and more efficient than previous, and better at understanding the context.</p>
<p>But the real power of GPT isn’t just in technology, it’s in how humans use it.<br />Writers use it to brainstorm, teachers use it to explain topics, and developers use it to build faster.</p>
<p>GPT doesn’t replace human creativity, it just <em>amplifies</em> it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1762593694501/abb46b8d-a87f-4b42-8ae4-4ace20544929.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>GPT is just language model, a system trained to understand and generate human-like text.<br />It doesn’t truly understand like we do, but it’s so good at recognizing patterns that it feels almost magical.</p>
<p>From traditional coding to AI-powered creation, we’ve moved from writing rules to teaching machines to learn.</p>
<p>That’s what makes GPT special.<br />It’s not just following commands anymore, it’s learning how to think in words, how to respond naturally, and how to communicate like us.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[JavaScript on the Server]]></title><description><![CDATA[Introduction
We all know JavaScript as the language of the browser. But have you ever wondered how it became a part of backend development too?
At one point, JavaScript was limited to things like button clicks and animations. But with the introductio...]]></description><link>https://blog.devwithjay.com/javascript-on-the-server</link><guid isPermaLink="true">https://blog.devwithjay.com/javascript-on-the-server</guid><category><![CDATA[JavaScript]]></category><category><![CDATA[Node.js]]></category><category><![CDATA[V8]]></category><category><![CDATA[server]]></category><category><![CDATA[ip address]]></category><category><![CDATA[ecmascript]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Tue, 02 Sep 2025 16:04:58 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1756794593539/809b3f3e-d7f8-4fef-98bb-34af0a27e961.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>We all know JavaScript as the language of the browser. But have you ever wondered how it became a part of backend development too?</p>
<p>At one point, JavaScript was limited to things like button clicks and animations. But with the introduction of <strong>Node.js</strong>, everything changed.</p>
<p>In this article, we’ll learn what a server is, how JavaScript runs on it using the V8 engine, what makes Node.js a runtime, and how to write and run our first Node.js program.</p>
<h2 id="heading-what-is-a-server">What is a Server?</h2>
<p>A server is just a remote computer that sends data or services to other computers over the internet. For example, when you visit Google, your request goes to their server, not a physical office.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756796491783/cf8d1e55-25d5-4586-952c-c037d487b7fb.png" alt class="image--center mx-auto" /></p>
<p>Here's how the process works:</p>
<ul>
<li><p>Every website is associated with an IP address (for example, 142.250.191.14 for Google)</p>
</li>
<li><p>When you type a domain name, your computer resolves it to the corresponding IP address</p>
</li>
<li><p>Your browser sends a request to that IP address</p>
</li>
<li><p>The server processes the request and sends back the appropriate response</p>
</li>
<li><p>Your browser renders the received data</p>
</li>
</ul>
<p>Before Node.js, web development needed two separate skill sets. Frontend developers used JavaScript for building user interfaces, while backend developers used different languages like Java, Python, or PHP for server-side work. This created a clear gap between client-side and server-side development.</p>
<p>Node.js changed that. It allowed JavaScript developers to write both frontend and backend code using the same language. This led to full-stack development and popular stacks like MEAN (MongoDB, Express, Angular, Node) and MERN (MongoDB, Express, React, Node).</p>
<h2 id="heading-what-is-an-ip-address"><strong>What is an IP Address?</strong></h2>
<p>An <strong>IP address</strong> (Internet Protocol Address) is a unique number assigned to every device connected to the internet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756823259386/83bdf798-bab9-493d-b2a2-b490d759e375.png" alt class="image--center mx-auto" /></p>
<p>It acts like a digital address, helping data find the right destination.</p>
<p>Each section of an IPv4 address is called an octet, and together they form a 32-bit number.</p>
<h2 id="heading-what-is-the-v8-engine"><strong>What is the V8 Engine?</strong></h2>
<p>While you might assume Node.js is written in JavaScript, it's actually built using C++. This raises an important question: how can a C++ application execute JavaScript code?</p>
<p>What makes this possible is the V8 JavaScript engine, created by Google for the Chrome browser. It’s written in <strong>C++</strong> and is designed to run JavaScript quickly and efficiently.</p>
<p>One of its best features is that it can be embedded into any C++ application. Node.js uses this feature to include V8 inside it, allowing JavaScript to run outside the browser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1756826644847/17f38832-f3c2-4c61-85a3-568654453b08.png" alt class="image--center mx-auto" /></p>
<p>The process works like this:</p>
<ol>
<li><p>You write JavaScript code</p>
</li>
<li><p>Node.js (a C++ application) receives your code</p>
</li>
<li><p>The embedded V8 engine translates your JavaScript into machine code</p>
</li>
<li><p>Your computer executes the resulting machine code</p>
</li>
</ol>
<h2 id="heading-ecmascript-and-js-engines"><strong>ECMAScript and JS Engines</strong></h2>
<p>JavaScript engines like <strong>V8 (Chrome)</strong>, <strong>SpiderMonkey (Firefox)</strong>, <strong>Chakra (Microsoft)</strong>, and <strong>JavaScriptCore (Safari)</strong> all follow a standard called <strong>ECMAScript</strong>.</p>
<p>ECMAScript is like a rulebook. It defines how JavaScript should behave, so that your code runs the same way across different browsers and environments.</p>
<p>But here’s the catch: engines like V8 only run <em>core JavaScript</em>. They can’t do things like:</p>
<ul>
<li><p>Connect to a database</p>
</li>
<li><p>Read or write files</p>
</li>
<li><p>Make server-side API calls</p>
</li>
</ul>
<p>That’s where <strong>Node.js</strong> comes in.</p>
<p>Node.js uses V8 at its heart, but also gives it extra abilities — like file system access, network requests, and databases. This mix of V8 + extra powers is what makes Node.js a <strong>runtime</strong>.</p>
<h2 id="heading-how-v8-brings-your-code-to-life"><strong>How V8 Brings Your Code to Life</strong></h2>
<p>V8 itself is written in C++. When you write JavaScript, it doesn’t stay in that form. V8 translates your code into <strong>machine code</strong> and <strong>assembly code</strong>, which your computer’s CPU can actually understand.</p>
<p>So, the flow looks like this:</p>
<ol>
<li><p>You write JavaScript (high-level, human-friendly).</p>
</li>
<li><p>V8 converts it into machine instructions (low-level).</p>
</li>
<li><p>The CPU executes those instructions.</p>
</li>
</ol>
<h2 id="heading-what-is-low-level-code"><strong>What is Low-Level Code?</strong></h2>
<p>Low-level code is closer to the hardware and gives direct control over system resources.</p>
<ul>
<li><p><strong>Machine Language</strong> → The most basic form, just 0s and 1s. The CPU executes it directly.</p>
</li>
<li><p><strong>Assembly Language</strong> → A small step above machine code. Uses short mnemonics (like MOV, ADD) to represent operations, but still maps directly to machine instructions.</p>
</li>
</ul>
<p>Thanks to V8, we don’t need to write machine or assembly code ourselves. We just write JavaScript, and V8 does the heavy lifting behind the scenes.What is a JavaScript Runtime?</p>
<h2 id="heading-what-is-a-javascript-runtime"><strong>What is a JavaScript Runtime?</strong></h2>
<p>A <strong>JavaScript Runtime</strong> is basically two things combined:</p>
<ul>
<li><p>A <strong>JavaScript engine</strong> (like V8)</p>
</li>
<li><p>Plus <strong>extra features</strong> that let it work outside the browser</p>
</li>
</ul>
<p>Inside the browser, your JavaScript can only do things like manipulate the DOM or handle user events. It can’t directly access files on your computer or talk to a database.</p>
<p>Node.js changes that. Along with the V8 engine, it provides built-in modules and libraries such as:</p>
<ul>
<li><p>File system modules (to read and write files)</p>
</li>
<li><p>Network libraries (to handle HTTP requests)</p>
</li>
<li><p>Server APIs (to build servers easily)</p>
</li>
<li><p>Database connectors (to store and retrieve data)</p>
</li>
</ul>
<p>So the formula becomes:</p>
<blockquote>
<p><strong>JavaScript Runtime = V8 + Node.js APIs</strong></p>
</blockquote>
<p>This combination is what makes Node.js so powerful. It takes the speed of the V8 engine and adds the tools needed for real-world backend applications.</p>
<h2 id="heading-lets-write-some-code"><strong>Let’s Write Some Code</strong></h2>
<p>Now that we understand what Node.js is and how it works, let’s write and run our first program.</p>
<h3 id="heading-step-1-install-nodejs"><strong>Step 1: Install Node.js</strong></h3>
<p>Go to the official Node.js website and download the installer for your operating system:</p>
<p><a target="_blank" href="https://nodejs.org/en">https://nodejs.org/en</a></p>
<h3 id="heading-step-2-verify-installation"><strong>Step 2: Verify Installation</strong></h3>
<p>After installation, open your terminal and type:</p>
<pre><code class="lang-javascript">node -v
npm -v
</code></pre>
<ul>
<li><p>node -v shows the installed Node.js version.</p>
</li>
<li><p>npm -v shows the installed NPM (Node Package Manager) version.</p>
</li>
</ul>
<p>If both return version numbers, Node.js has been installed successfully.</p>
<h3 id="heading-step-3-try-the-node-repl"><strong>Step 3: Try the Node REPL</strong></h3>
<p>Type node in your terminal. This opens the <strong>REPL (Read-Evaluate-Print Loop)</strong> where you can run JavaScript interactively.</p>
<p><strong>For example:</strong></p>
<pre><code class="lang-javascript">&gt; <span class="hljs-keyword">let</span> x = <span class="hljs-number">10</span>;
&gt; <span class="hljs-keyword">let</span> y = <span class="hljs-number">15</span>;
&gt; x + y
<span class="hljs-number">25</span>
</code></pre>
<p>The REPL is useful for quick tests, but writing everything here is not practical. Let’s move to a proper editor.</p>
<h3 id="heading-step-4-write-code-in-vs-code"><strong>Step 4: Write Code in VS Code</strong></h3>
<ol>
<li><p>Create a new folder on your computer (for example, my-node-project).</p>
</li>
<li><p>Open the folder in <strong>Visual Studio Code (VS Code)</strong>.</p>
</li>
<li><p>Create a file named app.js.</p>
</li>
<li><p>Write the following code:\</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> name = <span class="hljs-string">"My First Node App"</span>;
 <span class="hljs-keyword">let</span> a = <span class="hljs-number">5</span>;
 <span class="hljs-keyword">let</span> b = <span class="hljs-number">10</span>;
 <span class="hljs-keyword">let</span> c = a + b;

 <span class="hljs-built_in">console</span>.log(name);
 <span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Sum is:"</span>, c);
</code></pre>
</li>
<li><p>Open the terminal in VS Code:</p>
<ul>
<li><p>On Windows/Linux: <strong>Ctrl + Shift + `</strong></p>
</li>
<li><p>On macOS: <strong>Command + Shift + `</strong></p>
</li>
</ul>
</li>
<li><p>Run the program:</p>
<pre><code class="lang-javascript"> node app.js
</code></pre>
<p> <strong>Output:</strong></p>
<pre><code class="lang-javascript"> My First Node App
 Sum is: <span class="hljs-number">15</span>
</code></pre>
</li>
</ol>
<h2 id="heading-global-objects-in-nodejs"><strong>Global Objects in Node.js</strong></h2>
<p>In the browser, the global object is window.</p>
<p>In Node.js, the global object is called global.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">global</span>);
</code></pre>
<p>This will show methods like setTimeout, setInterval, and more.</p>
<p>Important note:</p>
<pre><code class="lang-javascript"><span class="hljs-built_in">console</span>.log(<span class="hljs-built_in">this</span>); <span class="hljs-comment">// {}</span>
</code></pre>
<p>At the top level in Node.js, this does not refer to the global object.</p>
<h2 id="heading-what-is-globalthis"><strong>What is globalThis?</strong></h2>
<p>To solve these differences across environments, <strong>ECMAScript 2020</strong> introduced globalThis.</p>
<ul>
<li><p>In browsers, globalThis refers to window.</p>
</li>
<li><p>In Node.js, globalThis refers to global.</p>
</li>
</ul>
<p>This gives us one consistent way to access the global object, no matter where our JavaScript code is running.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>JavaScript started as a language for browsers, but with Node.js, it expanded to the server side as well.</p>
<p>The V8 engine made it possible to run JavaScript outside the browser, while Node.js added the runtime features needed for real applications.</p>
<p>Now, developers can use a single language for both frontend and backend, making JavaScript truly universal.</p>
<p>From understanding servers and IP addresses to writing your first Node.js program, this is the foundation of JavaScript on the server.</p>
<p>In the next step, you can explore how the Node.js event loop works and how NPM helps manage packages.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[History of Node.JS]]></title><description><![CDATA[Introduction
Today, JavaScript runs on servers, desktops, mobile apps, and even smart TVs. But it wasn’t always like this. Before Node.js, JavaScript was just a browser language.
Node.js changed that. It gave JavaScript the power to run outside the b...]]></description><link>https://blog.devwithjay.com/history-of-nodejs</link><guid isPermaLink="true">https://blog.devwithjay.com/history-of-nodejs</guid><category><![CDATA[Node.js]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[V8]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Sat, 12 Jul 2025 10:45:48 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1752299855549/eb3e0405-8df1-4b3f-9442-81465956911d.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>Today, JavaScript runs on servers, desktops, mobile apps, and even smart TVs. But it wasn’t always like this. Before <strong>Node.js</strong>, JavaScript was just a browser language.</p>
<p><strong>Node.js</strong> changed that. It gave JavaScript the power to run outside the browser and opened up a whole new world for developers.</p>
<p>But where did it all begin? Who made it? Why was it created? Let’s explore the story of how Node.js started and made JavaScript more powerful than ever</p>
<h2 id="heading-what-is-nodejs">What is <strong>Node.js?</strong></h2>
<p>Node.js is a <strong>JavaScript runtime environment</strong> built on Chrome’s <strong>V8 engine</strong> (the engine that runs JavaScript in Google Chrome). It allows developers to run JavaScript <strong>outside the browser</strong>—on servers, desktops, or even IoT devices like smartwatches.</p>
<p>A few things to know about Node.js:</p>
<ul>
<li><p>Built on <strong>V8</strong> (Chrome’s JavaScript engine)</p>
</li>
<li><p>Created in <strong>2009</strong> by <strong>Ryan Dahl</strong></p>
</li>
<li><p>Supports <strong>asynchronous</strong> (non-blocking) I/O</p>
</li>
<li><p>Maintained by the <strong>OpenJS Foundation</strong></p>
</li>
<li><p>Lets you <strong>build servers, APIs, and more</strong> using JavaScript</p>
</li>
</ul>
<h2 id="heading-why-was-nodejs-created"><strong>Why was Node.js Created?</strong></h2>
<p>Before Node.js, developers used <strong>Apache HTTP Server</strong> for creating web servers. Apache was powerful but had a problem—it was <strong>blocking</strong>.</p>
<p>Blocking means if one user sends a request, the server waits until it’s handled before responding to the next one. This could slow things down when many users accessed a website at the same time.</p>
<p>Ryan Dahl had a simple thought:</p>
<blockquote>
<p><strong><em>“Why can’t we make servers that don’t wait around? What if JavaScript could handle multiple requests at once, without blocking anything?”</em></strong></p>
</blockquote>
<p>He imagined a system that worked like a modern restaurant — where the kitchen handles many orders in parallel instead of one at a time.</p>
<p> That idea led to <strong>Node.js</strong>.</p>
<h2 id="heading-the-early-days"><strong>The Early Days</strong></h2>
<ul>
<li><p>In <strong>2009</strong>, Ryan Dahl started building Node.js.</p>
</li>
<li><p>He first experimented with <strong>SpiderMonkey</strong>, the JavaScript engine used in Firefox.</p>
</li>
<li><p>But just <strong>two days in</strong>, he found it limiting.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752309166962/30952a6e-53f7-4cd1-a824-264cb66fcb44.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>He switched to <strong>Google’s V8 engine</strong>, which was <strong>faster</strong> and compiled JavaScript into <strong>machine code</strong>.</p>
</li>
<li><p>That made V8 the perfect choice for a fast and scalable JavaScript runtime.</p>
</li>
</ul>
<h2 id="heading-from-webjs-to-nodejs"><strong>From Web.js to Node.js</strong></h2>
<ul>
<li><p>Ryan originally named the project <strong>Web.js</strong>, because he built it to serve web pages.</p>
</li>
<li><p>But as he developed it further, he realized it had much bigger potential, it wasn’t just limited to websites.</p>
</li>
<li><p>So, he renamed it to <strong>Node.js</strong>, because it could act as a single “node” in a larger network of tools, services, and apps.</p>
</li>
</ul>
<h2 id="heading-the-role-of-joyent"><strong>The Role of Joyent</strong></h2>
<ul>
<li><p>Ryan was working solo until a company called <strong>Joyent</strong> noticed his work.</p>
</li>
<li><p>Joyent offered to <strong>fund the project</strong> and bring it under their wing.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752312277495/8c860b00-26a4-4000-9877-ccf614646010.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>This helped Node.js grow faster and gain more visibility.</p>
</li>
</ul>
<h2 id="heading-enter-npm-node-package-manager"><strong>Enter NPM (Node Package Manager)</strong></h2>
<ul>
<li><p>In <strong>2010</strong>, Node.js got a major boost: <strong>npm</strong> was launched.</p>
</li>
<li><p>npm is a package manager that made it easy to install and share reusable code.</p>
</li>
<li><p>Want to work with dates? Build a web server? Connect to a database? There’s an npm package for it.</p>
</li>
<li><p>Today, <strong>npm is the world’s largest software registry</strong> with millions of packages, and it was one of the biggest reasons behind Node.js’s success.</p>
</li>
</ul>
<h2 id="heading-growing-beyond-macos-amp-linux"><strong>Growing Beyond macOS &amp; Linux</strong></h2>
<ul>
<li><p>Node.js was first built for <strong>macOS and Linux</strong> only.</p>
</li>
<li><p>But in <strong>2011</strong>, with help from <strong>Microsoft</strong>, Node.js got support for <strong>Windows</strong> too.</p>
</li>
<li><p>This made Node.js available to an even larger group of developers and allowed it to run on nearly every platform.</p>
</li>
</ul>
<h2 id="heading-leadership-changes"><strong>Leadership Changes</strong></h2>
<ul>
<li><p>In <strong>2012</strong>, Ryan stepped away from the project.</p>
</li>
<li><p>Maintenance of Node.js was taken over by <strong>Isaac Z. Schlueter</strong>, who also created npm.</p>
</li>
<li><p>But over time, updates to Node.js became slower, and some developers in the community felt it wasn’t evolving fast enough.</p>
</li>
</ul>
<h2 id="heading-the-iojs-fork"><strong>The io.js Fork</strong></h2>
<ul>
<li><p>In <strong>2014</strong>, a developer named <strong>Fedor</strong> forked Node.js and started a new project called <strong>io.js</strong>.</p>
</li>
<li><p>It was meant to move faster, with more frequent updates and <strong>open community governance</strong>.</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752312944816/192379f0-9df2-421b-8951-6ba21d44e90d.png" alt class="image--center mx-auto" /></p>
</li>
<li><p>Many developers joined io.js because they wanted quicker improvements and more transparency.</p>
</li>
</ul>
<h2 id="heading-reuniting-the-community"><strong>Reuniting the Community</strong></h2>
<ul>
<li><p>The split didn’t last long.</p>
</li>
<li><p>In <strong>September 2015</strong>, both teams agreed to <strong>merge io.js and Node.js</strong> back into a single project.</p>
</li>
<li><p>This led to the creation of the <strong>Node.js Foundation</strong>, an independent group responsible for maintaining Node.js going forward.</p>
</li>
</ul>
<h2 id="heading-the-openjs-foundation"><strong>The OpenJS Foundation</strong></h2>
<ul>
<li><p>In <strong>2019</strong>, the <strong>Node.js Foundation</strong> merged with the <strong>JS Foundation</strong> (which managed other JavaScript projects like jQuery, ESLint, etc.).</p>
</li>
<li><p>The result was the <strong>OpenJS Foundation</strong>, a community-driven organization that now oversees Node.js and several other JavaScript projects.</p>
</li>
<li><p>Today, this foundation ensures Node.js continues to grow in a healthy and open way.</p>
</li>
</ul>
<h2 id="heading-summary-timeline"><strong>Summary Timeline</strong></h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1752314879185/3037ad7b-28c6-42de-87ee-b802efc1764e.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-conclusion"><strong>Conclusion</strong></h2>
<p>Node.js changed how we write JavaScript. It brought JavaScript to the server, allowed developers to write full-stack apps in one language, and made building modern tools and apps much simpler.</p>
<p>Today, it powers tools like <strong>Webpack</strong>, <strong>React CLI</strong>, <strong>Express</strong>, and even backend systems for companies like Netflix, PayPal, and LinkedIn.</p>
<p>Node.js taught the world that <strong>JavaScript isn’t just for the browser anymore</strong> — it’s for everywhere.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Arrays v/s Sets]]></title><description><![CDATA[Introduction
In JavaScript, Arrays and Sets are both used to store collections of values, but they serve different purposes and have distinct characteristics. While Arrays allow you to store ordered collections and can contain duplicate values, Sets ...]]></description><link>https://blog.devwithjay.com/arrays-vs-sets</link><guid isPermaLink="true">https://blog.devwithjay.com/arrays-vs-sets</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[array]]></category><category><![CDATA[Sets]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Mon, 31 Mar 2025 15:15:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1743433147928/153f7375-a01d-48b0-89a8-c4951d097a29.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>In JavaScript, <strong>Arrays</strong> and <strong>Sets</strong> are both used to store collections of values, but they serve different purposes and have distinct characteristics. While Arrays allow you to store ordered collections and can contain duplicate values, <strong>Sets</strong> are designed to store unique values and automatically remove duplicates.</p>
<p>In this article, we’ll understand the differences between Arrays and Sets, their performance characteristics, and practical use cases where each is most effective.</p>
<h2 id="heading-what-is-a-set">What is a Set?</h2>
<p>A <strong>Set</strong> is a special type of collection in JavaScript that stores <strong>unique values only</strong>. Unlike arrays or objects, a Set doesn’t use keys, and it doesn’t allow duplicate values.</p>
<p>Sets can store values of any type: strings, numbers, objects, or even other Sets. They’re useful when you want to keep a list of items <strong>without duplicates</strong>, such as a list of unique user IDs, selected tags, or visited pages.</p>
<h2 id="heading-creating-a-set">Creating A Set</h2>
<p>In JavaScript, a <strong>Set</strong> can be created using the Set constructor.</p>
<ol>
<li><p><strong>Creating an Empty Set</strong></p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> mySet = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>();
</code></pre>
<p> This creates a Set that doesn’t contain any values.</p>
</li>
<li><p><strong>Creating a Set with Initial Values</strong></p>
<p> You can also create a Set and initialize it with values by passing an <strong>array</strong> or another iterable to the constructor:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> mySet = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]);
</code></pre>
<p> This creates a Set with the values 1, 2, 3, 4, 5.</p>
</li>
<li><p><strong>Adding Values to a Set</strong></p>
<p> You can add individual values to a Set using the <code>.add()</code> method:</p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> mySet = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>();
 mySet.add(<span class="hljs-number">1</span>);
 mySet.add(<span class="hljs-number">2</span>);
 mySet.add(<span class="hljs-number">3</span>);
</code></pre>
</li>
</ol>
<h2 id="heading-methods-amp-properties">Methods &amp; Properties</h2>
<ol>
<li><p><strong>new Set([iterable])</strong> – Creates a Set. If an iterable object (usually an array) is provided, it copies the values from it into the Set.</p>
</li>
<li><p><strong>set.add(value)</strong> – Adds a value to the Set. It returns the Set itself. If the value already exists in the Set, it does nothing (i.e., Sets only store unique values).</p>
</li>
<li><p><strong>set.delete(value)</strong> – Removes the specified value from the Set. It returns true if the value existed at the moment of the call, and false otherwise.</p>
</li>
<li><p><strong>set.has(value)</strong> – Returns true if the specified value exists in the Set, and false otherwise.</p>
</li>
<li><p><strong>set.clear()</strong> – Removes all elements from the Set.</p>
</li>
<li><p><strong>set.size</strong> – Returns the number of elements in the Set.</p>
</li>
</ol>
<p>The main feature of a Set is that repeated calls to set.add(value) with the same value <strong>don’t add the value again</strong>. This ensures that each value appears in a Set only once.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">const</span> set = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>]);
<span class="hljs-built_in">console</span>.log([...set]); <span class="hljs-comment">// [1, 2, 3]</span>
</code></pre>
<h2 id="heading-chaining-methods">Chaining Methods</h2>
<p>Just like with Maps, you can chain multiple method calls together for cleaner and more concise code when working with Sets.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> userSet = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>()
  .add(<span class="hljs-string">'Jay'</span>)
  .add(<span class="hljs-number">20</span>)
  .add(<span class="hljs-string">'developer'</span>);
</code></pre>
<h2 id="heading-iteration-over-set">Iteration Over Set</h2>
<p>You can loop over a Set using either the for...of loop or the forEach() method.</p>
<ol>
<li><p><strong>Using for...of Loop</strong></p>
<pre><code class="lang-javascript"> <span class="hljs-keyword">let</span> set = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>([<span class="hljs-string">"oranges"</span>, <span class="hljs-string">"apples"</span>, <span class="hljs-string">"bananas"</span>]);

 <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> value <span class="hljs-keyword">of</span> set) {
   alert(value);
 }
</code></pre>
</li>
<li><p><strong>Using forEach() Method</strong></p>
<p> You can also use set.forEach() to iterate over the values in a Set. The callback function passed to forEach() takes three arguments:</p>
<pre><code class="lang-javascript"> set.forEach(<span class="hljs-function">(<span class="hljs-params">value, valueAgain, set</span>) =&gt;</span> {
   alert(value);
 });
</code></pre>
<ul>
<li><p><strong>value</strong>: The current value of the Set.</p>
</li>
<li><p><strong>valueAgain</strong>: This is the <strong>same</strong> value as value. It is included for compatibility with Map, where the callback also receives three arguments.</p>
</li>
<li><p><strong>set</strong>: The Set object itself.</p>
</li>
</ul>
</li>
</ol>
<p>    This might seem odd because the value appears twice, but it’s there for consistency with the Map object, which uses three arguments in its forEach() method.</p>
<p><strong>Additional Methods for Iterating</strong></p>
<p>Like Map, the Set object also supports the following iterator methods:</p>
<ul>
<li><p><strong>set.keys()</strong> – Returns an iterable for the values in the Set (same as set.values()).</p>
</li>
<li><p><strong>set.values()</strong> – Same as set.keys() for compatibility with Map.</p>
</li>
<li><p><strong>set.entries()</strong> – Returns an iterable for entries [value, value]. This exists for compatibility with Map.</p>
</li>
</ul>
<p>These methods are useful if you want to work with specific parts of a Set, similar to how they are used in a Map.</p>
<h2 id="heading-array-to-sets">Array to Sets</h2>
<p>Normally, when you create an array, it can contain duplicate values. But sometimes, you may want to remove duplicates from an array, and this is where <strong>Sets</strong> come in handy, as they only store unique values.</p>
<p>To convert an array into a <strong>Set</strong>, you can pass the array directly into the Set constructor.</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> array = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>, <span class="hljs-number">5</span>];
<span class="hljs-keyword">let</span> set = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>(array);

<span class="hljs-built_in">console</span>.log(set); <span class="hljs-comment">// Set { 1, 2, 3, 4, 5 }</span>
</code></pre>
<h2 id="heading-set-to-array">Set to Array</h2>
<p>Converting a Set back to an Array is just as easy. You can use the <strong>Array.from()</strong> method or the spread operator (...) to convert a Set into an array.</p>
<p><strong>Using Array.from():</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> set = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Set</span>([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>, <span class="hljs-number">5</span>]);
<span class="hljs-keyword">let</span> array = <span class="hljs-built_in">Array</span>.from(set);

<span class="hljs-built_in">console</span>.log(array); <span class="hljs-comment">// [1, 2, 3, 4, 5]</span>
</code></pre>
<p><strong>Using Spread Operator:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> array = [...set];
<span class="hljs-built_in">console</span>.log(array); <span class="hljs-comment">// [1, 2, 3, 4, 5]</span>
</code></pre>
<p><strong>Why Convert Set to Array?</strong></p>
<p>You might want to convert a Set back to an Array in cases where:</p>
<ul>
<li><p>You need to work with array-specific methods like .map(), .filter(), or .reduce().</p>
</li>
<li><p>You need to pass data to a function that expects an array.</p>
</li>
</ul>
<h2 id="heading-performance-benefits-of-sets">Performance Benefits of Sets</h2>
<ol>
<li><p><strong>Fast Lookups</strong>: Sets allow quick checks to see if a value exists. The time to check if an item is in a Set is constant (O(1)), making it faster than arrays or objects, especially when dealing with a large number of values.</p>
</li>
<li><p><strong>Unique Values</strong>: Sets automatically ensure that all values are unique. You don’t need to manually check for duplicates, which saves time and reduces the complexity of your code.</p>
</li>
<li><p><strong>Efficient Memory Usage</strong>: Since Sets only store unique values and don’t store duplicate entries, they use memory more efficiently than arrays when managing large collections of data.</p>
</li>
<li><p><strong>No Need for Indexing</strong>: Unlike arrays, Sets don’t rely on indexing. This can make operations like checking for the presence of an item faster and easier, without the overhead of index management.</p>
</li>
<li><p><strong>Order Preservation</strong>: Just like Maps, Sets maintain the order of items as they are added. This allows for predictable iteration when looping through the Set.</p>
</li>
</ol>
<h2 id="heading-practical-applications-of-sets"><strong>Practical Applications of Sets</strong></h2>
<ol>
<li><p><strong>Removing Duplicates</strong>: Automatically remove duplicates from a list, like user IDs or tags.</p>
</li>
<li><p><strong>Tracking Visited Pages</strong>: Store URLs of visited pages without repeats.</p>
</li>
<li><p><strong>Managing Permissions</strong>: Track unique user permissions or actions, like ‘edit’ or ‘view’.</p>
</li>
<li><p><strong>Unique Items Collection</strong>: Keep a collection of unique items, like feedback or tags.</p>
</li>
</ol>
<h2 id="heading-real-world-examples"><strong>Real-World Examples</strong></h2>
<ol>
<li><p><strong>Unique Tags on a Blog</strong>: On a blog, you might want to track tags that have been used across posts. A <strong>Set</strong> can store each tag as a unique value, automatically removing duplicates, so you don’t repeat tags.</p>
</li>
<li><p><strong>Tracking Visited Websites</strong>: If you’re building a browser extension that tracks visited websites, a <strong>Set</strong> can be used to store each URL only once. When the user visits a new site, you can check if it’s already in the Set before adding it.</p>
</li>
<li><p><strong>Membership List</strong>: A <strong>Set</strong> can be used to store unique membership IDs of users in a club or organization. This ensures no duplicate memberships and allows fast checks to see if someone is a member.</p>
</li>
</ol>
<h2 id="heading-differences-between-arrays-and-sets">Differences Between Arrays and Sets</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Feature</strong></td><td><strong>Array</strong></td><td><strong>Set</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Duplicates</strong></td><td>Allows duplicates (values can repeat).</td><td>Does not allow duplicate values (each value is unique).</td></tr>
<tr>
<td><strong>Order</strong></td><td>Elements are ordered by index (0, 1, 2, …).</td><td>Elements are ordered by the insertion order of values.</td></tr>
<tr>
<td><strong>Data Types</strong></td><td>Can store values of any type, including mixed types.</td><td>Can store values of any type, but each value is unique.</td></tr>
<tr>
<td><strong>Access</strong></td><td>Elements can be accessed by their index (e.g., array[0]).</td><td>Cannot be accessed by index; only through iteration.</td></tr>
<tr>
<td><strong>Methods</strong></td><td>Methods like .push(), .pop(), .shift(), .map(), .filter(), etc.</td><td>Methods like .add(), .delete(), .has(), .clear(), etc.</td></tr>
<tr>
<td><strong>Performance</strong></td><td>Slower for membership checking and removal due to the need to scan the array.</td><td>Faster lookups for membership (constant time O(1) complexity).</td></tr>
<tr>
<td><strong>Use Case</strong></td><td>Ideal for ordered collections where index-based access is important, and duplicates are allowed.</td><td>Ideal for collections where uniqueness is required and fast membership checks are needed.</td></tr>
<tr>
<td><strong>Iteration</strong></td><td>Iterates over elements by index (e.g., for...of, .forEach() on values).</td><td>Iterates over values in insertion order (e.g., for...of, .forEach() on values).</td></tr>
<tr>
<td><strong>Size Property</strong></td><td>.length gives the number of elements.</td><td>.size gives the number of unique values.</td></tr>
<tr>
<td><strong>Methods for Filtering</strong></td><td>Can use .filter() and .map() to manipulate or filter values.</td><td>Cannot directly use .map() or .filter() (as it’s designed for unique values).</td></tr>
</tbody>
</table>
</div><p>This comparison highlights the differences between arrays and sets, making it easier to choose the appropriate data structure based on the requirements of your project.</p>
<h2 id="heading-when-to-use-sets">When To Use Sets</h2>
<p><strong>Choose Sets when you need:</strong></p>
<ul>
<li><p>A collection of unique values with no duplicates.</p>
</li>
<li><p>Automatic removal of duplicates when adding new values.</p>
</li>
<li><p>Fast checks to see if a value exists in the collection.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In conclusion, Arrays are great when you need to keep things in a specific order or when duplicates are okay. On the other hand, Sets are perfect for storing unique items and checking quickly if something is already there, without worrying about duplicates.</p>
<p>By understanding these differences, you can choose the right data structure for your needs and write cleaner, more efficient code.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Objects v/s Maps]]></title><description><![CDATA[Introduction
In JavaScript, we usually use Objects to store key-value pairs, where the keys are strings or Symbols. Map, however, allow you to use any type of key, like numbers, objects, or functions, and they also remember the order in which the ite...]]></description><link>https://blog.devwithjay.com/objects-vs-maps</link><guid isPermaLink="true">https://blog.devwithjay.com/objects-vs-maps</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[Objects]]></category><category><![CDATA[maps]]></category><category><![CDATA[JavaScript]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Fri, 28 Mar 2025 10:13:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1743156669515/b49a28c5-df86-489a-9de2-989a3f9a266c.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>In JavaScript, we usually use Objects to store key-value pairs, where the keys are strings or Symbols. Map, however, allow you to use any type of key, like numbers, objects, or functions, and they also remember the order in which the items are added.</p>
<p>In this article, we understand the differences between Objects and Maps, their performance, and practical use cases.</p>
<h2 id="heading-what-is-a-map">What is a Map?</h2>
<p>A <strong>Map</strong> is a special type of object in JavaScript that stores data in <strong>key-value pairs</strong>. Similar to an object, but with a few differences. In a Map, the <strong>keys can be of any type</strong>—not just strings. You can use numbers, objects, or even functions as keys.</p>
<p>Maps also remember the order in which the items were added. This means when you loop through a Map, you get the items in the same order you put them in.</p>
<h2 id="heading-creating-a-map">Creating A Map</h2>
<p>To create a <strong>Map</strong> in JavaScript, you use the Map constructor. It allows <strong>two main ways</strong> to create a Map:</p>
<ol>
<li><p><strong>Passing an Array to new Map()</strong></p>
<ul>
<li><p>You can create a Map by passing an array of key-value pairs directly into the constructor.</p>
</li>
<li><p>Each key-value pair is represented as an inner array with two elements.</p>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> user = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>([
    [<span class="hljs-string">'name'</span>, <span class="hljs-string">'Jay'</span>],
    [<span class="hljs-string">'age'</span>, <span class="hljs-number">18</span>],
    [<span class="hljs-string">'city'</span>, <span class="hljs-string">'Pune'</span>]
  ]);
</code></pre>
</li>
</ul>
</li>
<li><p><strong>Creating a Map and Using</strong> <code>.set()</code> <strong>Method</strong></p>
<ul>
<li><p>Alternatively, you can create an empty Map and add key-value pairs one by one using the <code>.set()</code> method.</p>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-javascript">  <span class="hljs-keyword">const</span> user = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>();

  user.set(<span class="hljs-string">'name'</span>, <span class="hljs-string">'Jay'</span>);
  user.set(<span class="hljs-string">'age'</span>, <span class="hljs-number">18</span>);
  user.set(<span class="hljs-string">'city'</span>, <span class="hljs-string">'Pune'</span>);
</code></pre>
</li>
<li><p>This approach gives you more flexibility, especially when the values are dynamic or coming from different sources.</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-methods-amp-properties">Methods &amp; Properties</h2>
<ol>
<li><p><strong>new Map() -</strong> Creates a new, empty Map.</p>
</li>
<li><p><strong>map.set(key, value) -</strong> Adds a key-value pair to the Map. If the key already exists, it updates the value.</p>
</li>
<li><p><strong>map.get(key) -</strong> Returns the value associated with the given key. If the key doesn’t exist, it returns undefined.</p>
</li>
<li><p><strong>map.has(key) -</strong> Checks if a key exists in the Map. Returns true if found, otherwise false.</p>
</li>
<li><p><strong>map.delete(key) -</strong> Removes the key-value pair for the given key from the Map.</p>
</li>
<li><p><strong>map.clear() -</strong> Removes all key-value pairs from the Map.</p>
</li>
<li><p><strong>map.size -</strong> Returns the total number of key-value pairs in the Map.</p>
</li>
</ol>
<h2 id="heading-how-does-map-compare-keys">How Does Map Compare Keys?</h2>
<p>When checking if a key already exists, Map uses an internal algorithm called <strong>SameValueZero</strong> to compare keys.</p>
<p>This is <strong>very similar</strong> to the strict equality operator (===), but with <strong>one difference</strong>:</p>
<ul>
<li><p>In strict equality (===), NaN === NaN is <strong>false</strong>.</p>
</li>
<li><p>In <strong>SameValueZero</strong>, NaN is considered <strong>equal to NaN</strong>.</p>
</li>
</ul>
<p>This means you can <strong>use NaN as a key</strong> in a Map, and it will work as expected.</p>
<p>It’s also important to know that this comparison method is <strong>built-in</strong> and <strong>cannot be changed or customized</strong>.</p>
<h2 id="heading-chaining-methods">Chaining Methods</h2>
<p>You can chain multiple methods together for cleaner code:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> userMap = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>()
  .set(<span class="hljs-string">'name'</span>, <span class="hljs-string">'Jay'</span>)
  .set(<span class="hljs-string">'age'</span>, <span class="hljs-number">20</span>)
  .set(<span class="hljs-string">'role'</span>, <span class="hljs-string">'developer'</span>);
</code></pre>
<h2 id="heading-iteration-over-map">Iteration Over Map</h2>
<p>Map allows several ways to loop through its elements. Since it keeps items in the order they were added, you get predictable results when looping.</p>
<ol>
<li><p><strong>map.keys() - R</strong>eturns an <strong>iterable of all keys</strong> in the Map.</p>
</li>
<li><p><strong>map.values() -</strong> Returns an <strong>iterable of all values</strong> in the Map.</p>
</li>
<li><p><strong>map.entries() -</strong> Returns an <strong>iterable of [key, value] pairs</strong>. This is also the default when using for...of.</p>
</li>
</ol>
<p><strong>Example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> recipeMap = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>([
  [<span class="hljs-string">'cucumber'</span>, <span class="hljs-number">500</span>],
  [<span class="hljs-string">'tomatoes'</span>, <span class="hljs-number">300</span>],
  [<span class="hljs-string">'coriander'</span>, <span class="hljs-number">50</span>]
]);

<span class="hljs-comment">// iterate over keys (vegetables)</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> vegetable <span class="hljs-keyword">of</span> recipeMap.keys()) {
  alert(vegetable); <span class="hljs-comment">// cucumber, tomatoes, coriander</span>
}

<span class="hljs-comment">// iterate over values (amounts)</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> amount <span class="hljs-keyword">of</span> recipeMap.values()) {
  alert(amount); <span class="hljs-comment">// 500, 300, 50</span>
}

<span class="hljs-comment">// iterate over [key, value] entries</span>
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> entry <span class="hljs-keyword">of</span> recipeMap) { <span class="hljs-comment">// the same as of recipeMap.entries()</span>
  alert(entry); <span class="hljs-comment">// cucumber,500 (and so on)</span>
}
</code></pre>
<p><strong>Using map.forEach()</strong></p>
<p>The Map object also includes a forEach() method that works just like it does for arrays:</p>
<pre><code class="lang-javascript">recipeMap.forEach( <span class="hljs-function">(<span class="hljs-params">value, key, map</span>) =&gt;</span> {
  alert(<span class="hljs-string">`<span class="hljs-subst">${key}</span>: <span class="hljs-subst">${value}</span>`</span>); <span class="hljs-comment">// cucumber: 500 etc</span>
});
</code></pre>
<h2 id="heading-map-from-object">Map From Object</h2>
<p>Normally, when we create a Map, we pass an array (or any iterable) of <strong>key-value pairs</strong> to initialize it. For example:</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> map = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>([
  [<span class="hljs-string">'1'</span>,  <span class="hljs-string">'str1'</span>],
  [<span class="hljs-number">1</span>,    <span class="hljs-string">'num1'</span>],
  [<span class="hljs-literal">true</span>, <span class="hljs-string">'bool1'</span>]
]);
</code></pre>
<p>But, if you already have a <strong>plain JavaScript object</strong> and want to convert it into a Map, you can use the built-in method <code>Object.entries(obj)</code>.</p>
<p>The <code>Object.entries()</code> method returns an array of <strong>[key, value]</strong> pairs — exactly what Map needs for initialization.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> obj = {
  <span class="hljs-attr">name</span>: <span class="hljs-string">"Jay"</span>,
  <span class="hljs-attr">age</span>: <span class="hljs-number">20</span>
};

<span class="hljs-keyword">let</span> map = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>(<span class="hljs-built_in">Object</span>.entries(obj));
</code></pre>
<p>Now map behaves like a proper Map object, and you can use all the Map methods:</p>
<pre><code class="lang-javascript">map.get(<span class="hljs-string">'name'</span>); <span class="hljs-comment">// Returns: "Jay"</span>
map.has(<span class="hljs-string">'age'</span>);  <span class="hljs-comment">// Returns: true</span>
</code></pre>
<h2 id="heading-object-from-map">Object From Map</h2>
<p>Just like we can create a Map from a plain object using <code>Object.entries(obj)</code>, we can also do the <strong>reverse</strong>—convert a Map back into a plain object.</p>
<p>This is useful when:</p>
<ul>
<li><p>You store data in a Map (for features like non-string keys or maintaining order),</p>
</li>
<li><p>But need to pass that data to a function or third-party library that only accepts plain JavaScript objects.</p>
</li>
</ul>
<p>The method <code>Object.fromEntries()</code> takes an <strong>iterable of key-value pairs</strong> and converts it into a plain object.</p>
<p><strong>Example:</strong></p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> map = <span class="hljs-keyword">new</span> <span class="hljs-built_in">Map</span>();
map.set(<span class="hljs-string">'banana'</span>, <span class="hljs-number">1</span>);
map.set(<span class="hljs-string">'orange'</span>, <span class="hljs-number">2</span>);
map.set(<span class="hljs-string">'watermelon'</span>, <span class="hljs-number">4</span>);

<span class="hljs-comment">// Convert Map to Object</span>
<span class="hljs-keyword">let</span> obj = <span class="hljs-built_in">Object</span>.fromEntries(map.entries());

<span class="hljs-built_in">console</span>.log(obj.orange); <span class="hljs-comment">// Output: 2</span>
</code></pre>
<p>You can also write it more simply by skipping .entries():</p>
<pre><code class="lang-javascript"><span class="hljs-keyword">let</span> obj = <span class="hljs-built_in">Object</span>.fromEntries(map);
</code></pre>
<p>This works because Map is already iterable and returns key-value pairs by default when looped over.</p>
<h2 id="heading-performance-benefits-of-maps"><strong>Performance Benefits of Maps</strong></h2>
<ol>
<li><p><strong>Quick Access</strong>: Maps allow you to quickly access values using keys, with lookup times being constant (O(1)). This makes them much faster than objects, especially when you’re working with large amounts of data.</p>
</li>
<li><p><strong>Flexible Keys</strong>: Unlike objects, which only allow strings or symbols as keys, Maps can use any type of data as a key—such as numbers, objects, or even functions. This gives you more flexibility when working with complex data.</p>
</li>
<li><p>Maintains Insertion Order: Maps remember the order in which items are added. This ensures that when you loop through the Map, you’ll get the values in the exact order they were inserted, making iteration more predictable.</p>
</li>
<li><p><strong>No Prototype Conflicts</strong>: Since Maps don’t have a prototype chain (unlike objects), there’s less chance of conflicts with inherited properties. This makes your code cleaner and avoids potential issues.</p>
</li>
<li><p><strong>Efficient Memory Use</strong>: Maps are designed specifically for storing key-value pairs, which means they use memory more efficiently compared to objects, especially when handling large sets of data.</p>
</li>
</ol>
<h2 id="heading-practical-applications-of-maps"><strong>Practical Applications of Maps</strong></h2>
<ol>
<li><p><strong>Caching Data</strong>: Use Maps to store frequently accessed data for quick retrieval, like API responses.</p>
</li>
<li><p><strong>Configuration Settings</strong>: Store settings or options where each setting has a unique key.</p>
</li>
<li><p><strong>Tracking Relationships</strong>: Use Maps to link items, such as users and their profiles or products and prices.</p>
</li>
<li><p><strong>Data Grouping</strong>: Group items by a property, like categorizing books by genre.</p>
</li>
</ol>
<h2 id="heading-real-world-examples"><strong>Real-World Examples</strong></h2>
<ol>
<li><p><strong>User Profile Data</strong>: Imagine a website where each user has a profile. You could use a <strong>Map</strong> to store user information, where the key is the user’s unique ID, and the value is their profile data (name, age, location, etc.).</p>
</li>
<li><p><strong>Inventory System</strong>: In an online store, a <strong>Map</strong> could be used to link product IDs (keys) with product details (values), such as product name, description, and price. This allows for fast lookups when a user searches for a product.</p>
</li>
<li><p><strong>Student Grades</strong>: A <strong>Map</strong> can be used in schools to store student names (keys) and their corresponding grades (values). For example, the key “Jay” maps to the grade “A”, and the key “Nikhil” maps to the grade “B”.</p>
</li>
</ol>
<h2 id="heading-differences-between-objects-and-maps">Differences Between Objects and Maps</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Feature</strong></td><td><strong>Map</strong></td><td><strong>Object</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Key Type</strong></td><td>Can use any type (e.g., strings, numbers, objects)</td><td>Only strings and symbols can be used as keys</td></tr>
<tr>
<td><strong>Key Order</strong></td><td>Maintains the insertion order of keys</td><td>Does not guarantee order (though modern engines do maintain it)</td></tr>
<tr>
<td><strong>Size</strong></td><td>.size property to get the number of entries</td><td>No built-in property to get the size of the object</td></tr>
<tr>
<td><strong>Iteration</strong></td><td>Iterates in insertion order using .keys(), .values(), .entries(), or forEach()</td><td>Does not have built-in methods for direct iteration (requires for...in or Object.keys())</td></tr>
<tr>
<td><strong>Performance</strong></td><td>Faster for frequent additions/removals of key-value pairs</td><td>May perform worse with frequent modifications</td></tr>
<tr>
<td><strong>Default Prototype</strong></td><td>No default prototype chain, making it cleaner and less prone to inheritance issues</td><td>Inherits from Object.prototype, potentially causing conflicts</td></tr>
<tr>
<td><strong>Methods</strong></td><td>Built-in methods like .set(), .get(), .has(), .delete(), .clear()</td><td>Only has basic operations (assigning, deleting keys, etc.)</td></tr>
<tr>
<td><strong>Use Case</strong></td><td>Ideal for storing and working with dynamic or complex key-value pairs</td><td>Great for simple data structures and static properties</td></tr>
</tbody>
</table>
</div><h2 id="heading-when-to-use-maps">When To Use Maps</h2>
<p><strong>Choose Maps when you need:</strong></p>
<ul>
<li><p>Key-value pairs where the keys can be of any type (e.g., strings, numbers, objects).</p>
</li>
<li><p>Fast and efficient lookups for accessing data.</p>
</li>
<li><p>Ordered entries that maintain the insertion order.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Maps in JavaScript are great for storing collections of data as key-value pairs. They are useful when you need to associate one item with another, like linking a name to an age. By knowing when and how to use Maps, you can write cleaner and more efficient code.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[HTML Semantics]]></title><description><![CDATA[Introduction
A well-structured website isn’t just about design—it’s about clarity, accessibility, and better search rankings. Semantic HTML helps achieve this by using meaningful tags like <header>, <nav>, <article>, and <footer> instead of generic <...]]></description><link>https://blog.devwithjay.com/html-semantics</link><guid isPermaLink="true">https://blog.devwithjay.com/html-semantics</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[HTML5]]></category><category><![CDATA[html semantics]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Sat, 15 Mar 2025 09:56:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1742035734295/c368a600-036b-4500-8fc3-528eba2255d6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction"><strong>Introduction</strong></h2>
<p>A well-structured website isn’t just about design—it’s about clarity, accessibility, and better search rankings. <strong>Semantic HTML</strong> helps achieve this by using meaningful tags like <code>&lt;header&gt;</code>, <code>&lt;nav&gt;</code>, <code>&lt;article&gt;</code>, and <code>&lt;footer&gt;</code> instead of generic <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code>. These elements make code easier to read, improve SEO, and help screen readers navigate the page better.</p>
<p>Using semantic HTML also makes websites more organized, user-friendly, and easier to maintain. Search engines can understand content better, leading to higher rankings, and developers can quickly make updates without confusion.</p>
<p>In this article, we’ll understand <strong>what semantic HTML is, why it’s important, and how to use it effectively</strong>.</p>
<h2 id="heading-what-is-semantic-html">What Is Semantic HTML?</h2>
<p>Semantic HTML means using <strong>clear and meaningful tags</strong> in a webpage that <strong>describe their purpose</strong> to both people and computers.</p>
<p>Unlike <strong>non-semantic elements</strong>, which don’t explain their content, <strong>semantic elements help browsers, search engines, and developers</strong> understand the structure of a webpage more easily.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742035745791/ffa461be-969f-4fc0-a91b-af5e8912bdf2.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-why-use-semantic-html-tags"><strong>Why Use Semantic HTML Tags?</strong></h2>
<ol>
<li><p><strong>Improves Accessibility</strong></p>
<ul>
<li><p>Screen readers can easily understand and navigate the content.</p>
</li>
<li><p>Helps users with disabilities access the website more efficiently.</p>
</li>
<li><p>Makes keyboard navigation smoother and more intuitive.</p>
</li>
</ul>
</li>
<li><p><strong>Better SEO (Search Engine Optimization)</strong></p>
<ul>
<li><p>Search engines can easily read and index well-structured content.</p>
</li>
<li><p>Websites using semantic HTML have a higher chance of ranking better.</p>
</li>
<li><p>Improves visibility in search results without extra SEO efforts.</p>
</li>
</ul>
</li>
<li><p><strong>Easier to Maintain and Read</strong></p>
<ul>
<li><p>Code is more <strong>organized, readable, and easy to update</strong>.</p>
</li>
<li><p>Developers can understand the structure without unnecessary &lt;div&gt; elements.</p>
</li>
<li><p>Teams can collaborate better and make changes more efficiently.</p>
</li>
</ul>
</li>
<li><p><strong>Enhances User Experience (UX)</strong></p>
<ul>
<li><p>Helps browsers display pages correctly and consistently.</p>
</li>
<li><p>Makes the layout <strong>clearer and more structured</strong> for users.</p>
</li>
<li><p>Ensures that different sections of the page are well-defined and easy to follow.</p>
</li>
</ul>
</li>
<li><p><strong>Future-Proof and Standardized</strong></p>
<ul>
<li><p>Follows <strong>modern web development standards</strong> (HTML5).</p>
</li>
<li><p>Ensures better <strong>compatibility with new web technologies</strong>.</p>
</li>
<li><p>Prepares websites for <strong>AI-driven search engines and future updates</strong>.</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-semantic-elements-in-html">Semantic Elements in HTML</h2>
<p>Many websites use <strong>generic</strong> <code>&lt;div&gt;</code> <strong>elements</strong> like <code>&lt;div id="nav"&gt;</code>, <code>&lt;div class="header"&gt;</code>, and <code>&lt;div id="footer"&gt;</code> to define navigation, headers, and footers. However, these <strong>do not provide meaning</strong> about their content.</p>
<p>Instead, HTML provides <strong>semantic elements</strong> that clearly define different parts of a webpage. These elements improve <strong>readability, accessibility, and SEO</strong> by making the structure of the page more understandable for both browsers and developers.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1742035753472/0875ed9c-8614-4495-af58-a2c191436e2d.png" alt class="image--center mx-auto" /></p>
<p><strong>Common Semantic HTML Elements:</strong></p>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Semantic Element</strong></td><td><strong>Purpose</strong></td></tr>
</thead>
<tbody>
<tr>
<td><code>&lt;article&gt;</code></td><td>Represents independent content like blog posts, news articles, or user comments.</td></tr>
<tr>
<td><code>&lt;aside&gt;</code></td><td>Defines side content, such as sidebars, ads, or related links.</td></tr>
<tr>
<td><code>&lt;details&gt;</code></td><td>Creates an expandable/collapsible section for additional information.</td></tr>
<tr>
<td><code>&lt;figcaption&gt;</code></td><td>Provides a caption for an image, chart, or figure inside a &lt;figure&gt;.</td></tr>
<tr>
<td><code>&lt;figure&gt;</code></td><td>Wraps around an image, chart, or illustration along with a caption.</td></tr>
<tr>
<td><code>&lt;footer&gt;</code></td><td>Represents the footer section of a webpage or a section, usually containing copyright info or links.</td></tr>
<tr>
<td><code>&lt;header&gt;</code></td><td>Defines the header section of a webpage or section, often containing titles or navigation.</td></tr>
<tr>
<td><code>&lt;main&gt;</code></td><td>Represents the main content of a webpage, excluding sidebars, footers, and navigation.</td></tr>
<tr>
<td><code>&lt;mark&gt;</code></td><td>Highlights important or relevant text.</td></tr>
<tr>
<td><code>&lt;nav&gt;</code></td><td>Specifies a section for navigation links like menus or sidebars.</td></tr>
<tr>
<td><code>&lt;section&gt;</code></td><td>Groups related content together within a page.</td></tr>
<tr>
<td><code>&lt;summary&gt;</code></td><td>Provides a summary or title for the &lt;details&gt; element.</td></tr>
<tr>
<td><code>&lt;time&gt;</code></td><td>Represents a date or time in a structured format for better readability and SEO.</td></tr>
</tbody>
</table>
</div><h2 id="heading-understanding-semantic-html-elements"><strong>Understanding Semantic HTML Elements</strong></h2>
<ol>
<li><h3 id="heading-ltnavgt">&lt;nav&gt;</h3>
<ul>
<li><p>The <code>&lt;nav&gt;</code> element is used for defining a section of navigation links.</p>
</li>
<li><p>It contains links that help users navigate the website.</p>
</li>
<li><p><strong>Where to Use?</strong></p>
<ul>
<li><p>In the website’s main navigation menu.</p>
</li>
<li><p>In the sidebar containing category or section links.</p>
</li>
<li><p>In the footer for secondary navigation.</p>
</li>
</ul>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"home.html"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"about.html"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"contact.html"</span>&gt;</span>Contact<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why use</strong> <code>&lt;nav&gt;</code><strong>?</strong></p>
<ul>
<li><p>Helps screen readers recognize navigational links.</p>
</li>
<li><p>Makes it easier for search engines to differentiate navigation sections from the main content.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="2">
<li><h3 id="heading-ltmaingt">&lt;main&gt;</h3>
<ul>
<li><p>The <code>&lt;main&gt;</code> element represents the central content of a webpage.</p>
</li>
<li><p>It excludes other repeated sections such as <code>&lt;header&gt;,</code> <code>&lt;footer&gt;</code>, and <code>&lt;nav&gt;</code>.</p>
</li>
<li><p>It ensures that search engines and assistive technologies can focus on the primary content.</p>
</li>
<li><p><strong>Where to Use?</strong></p>
<ul>
<li><p>Around the main content area of a webpage.</p>
</li>
<li><p>Inside <code>&lt;body&gt;</code>, but outside <code>&lt;header&gt;</code>, <code>&lt;nav&gt;</code>, <code>&lt;footer&gt;</code>, and <code>&lt;aside&gt;</code>.</p>
</li>
</ul>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>Understanding Semantic HTML<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Benefits of Semantic HTML<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Using semantic elements improves readability, SEO, and accessibility...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why use</strong> <code>&lt;main&gt;</code><strong>?</strong></p>
<ul>
<li><p>Helps screen readers quickly access the main content.</p>
</li>
<li><p>Assists search engines in indexing only the primary information.</p>
</li>
<li><p>Ensures structured content organization for better user experience.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="3">
<li><h3 id="heading-ltheadergt">&lt;header&gt;</h3>
<ul>
<li><p>The <code>&lt;header&gt;</code> element represents introductory content, typically a group of headings, a logo, and navigational links.</p>
</li>
<li><p><strong>Where to Use?</strong></p>
<ul>
<li><p>At the top of the webpage as a site-wide header.</p>
</li>
<li><p>Inside an <code>&lt;article&gt;</code> or <code>&lt;section&gt;</code> to introduce a topic.</p>
</li>
</ul>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>My Blog<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Your source for web development knowledge.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why Use</strong> <code>&lt;header&gt;</code><strong>?</strong></p>
<ul>
<li><p>Helps users understand the page’s purpose at a glance.</p>
</li>
<li><p>Makes it easier for developers to manage page structure.</p>
</li>
<li><p>Enhances SEO by clearly defining the page introduction.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="4">
<li><h3 id="heading-ltarticlegt">&lt;article&gt;</h3>
<ul>
<li><p>The <code>&lt;article&gt;</code> element is used for independent content that can stand alone, such as blog posts, news articles, or user comments.</p>
</li>
<li><p><strong>Where to Use?</strong></p>
<ul>
<li><p>Blog posts, news articles, or forum posts.</p>
</li>
<li><p>User-generated content such as reviews or discussions.</p>
</li>
</ul>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>What is Semantic HTML?<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>Semantic HTML refers to the practice of using meaningful tags...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why Use</strong> <code>&lt;article&gt;</code><strong>?</strong></p>
<ul>
<li><p>Helps search engines recognize distinct content sections.</p>
</li>
<li><p>Enhances readability and content structuring.</p>
</li>
<li><p>Facilitates sharing specific articles separately.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="5">
<li><h3 id="heading-ltsectiongt">&lt;section&gt;</h3>
<ul>
<li><p>The <code>&lt;section&gt;</code> element is used to group related content together, helping structure a webpage.</p>
</li>
<li><p><strong>Where to Use?</strong></p>
<ul>
<li><p>Grouping multiple <code>&lt;article&gt;</code> elements under a category.</p>
</li>
<li><p>Separating different parts of a webpage.</p>
</li>
</ul>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Web Development Topics<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>HTML<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>HTML stands for HyperText Markup Language...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>CSS<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>CSS is used to style webpages...<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why Use</strong> <code>&lt;section&gt;</code><strong>?</strong></p>
<ul>
<li><p>Improves content structuring for readability and maintenance.</p>
</li>
<li><p>Helps search engines categorize and index sections efficiently.</p>
</li>
<li><p>Makes the layout cleaner and more manageable.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="6">
<li><h3 id="heading-ltfootergt"><strong>&lt;footer&gt;</strong></h3>
<ul>
<li><p>The <code>&lt;footer&gt;</code> element represents the bottom section of a webpage or article, usually containing contact information, links, and copyright notices.</p>
</li>
<li><p><strong>Where to Use?</strong></p>
<ul>
<li><p>At the bottom of a webpage.</p>
</li>
<li><p>At the end of articles or sections.</p>
</li>
</ul>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">footer</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>© 2025 My Website. All Rights Reserved.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"privacy.html"</span>&gt;</span>Privacy Policy<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span> | <span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"terms.html"</span>&gt;</span>Terms of Service<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">footer</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why Use</strong> <code>&lt;footer&gt;</code><strong>?</strong></p>
<ul>
<li><p>Clearly separates footer information from main content.</p>
</li>
<li><p>Helps in organizing legal and contact details.</p>
</li>
<li><p>Makes navigation easier for users.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="7">
<li><h3 id="heading-ltasidegt"><strong>&lt;aside&gt;</strong></h3>
<ul>
<li><p>The <code>&lt;aside&gt;</code> element is used for content related to the main content but not essential to it, such as advertisements, related links, or sidebars.</p>
</li>
<li><p><strong>Where to Use?</strong></p>
<ul>
<li><p>In a sidebar for displaying additional links or ads.</p>
</li>
<li><p>Inside an &lt;article&gt; for related information.</p>
</li>
</ul>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">aside</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Related Articles<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>SEO Best Practices<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Web Accessibility Guide<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">aside</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why Use</strong> <code>&lt;aside&gt;</code><strong>?</strong></p>
<ul>
<li><p>Keeps supplementary content separate from primary content.</p>
</li>
<li><p>Enhances user experience by providing extra context.</p>
</li>
<li><p>Helps search engines differentiate between main and side content.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="8">
<li><h3 id="heading-ltfiguregt-amp-ltfigcaptiongt"><strong>&lt;figure&gt; &amp; &lt;figcaption&gt;</strong></h3>
<ul>
<li><p>The <code>&lt;figure&gt;</code> element is used to wrap around images, charts, or illustrations, while <code>&lt;figcaption&gt;</code> provides a caption.</p>
</li>
<li><p><strong>Where to Use?</strong></p>
<ul>
<li><p>When adding images with descriptions or references.</p>
</li>
<li><p>To associate captions with images.</p>
</li>
</ul>
</li>
<li><p><strong>Example:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">figure</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">img</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"semantic-html.png"</span> <span class="hljs-attr">alt</span>=<span class="hljs-string">"Semantic HTML Example"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">figcaption</span>&gt;</span>A comparison of semantic vs non-semantic HTML.<span class="hljs-tag">&lt;/<span class="hljs-name">figcaption</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">figure</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why Use</strong> <code>&lt;figure&gt;</code> <strong>&amp;</strong> <code>&lt;figcaption&gt;</code><strong>?</strong></p>
<ul>
<li><p>Provides meaningful context to images for better accessibility.</p>
</li>
<li><p>Helps search engines understand the content of images.</p>
</li>
<li><p>Improves user experience by associating images with relevant captions.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<h2 id="heading-best-practices-for-using-semantic-html">Best Practices for Using Semantic HTML</h2>
<p>Using semantic HTML correctly improves accessibility, SEO, readability, and maintainability. Follow these best practices to ensure effective implementation of semantic elements.</p>
<ol>
<li><h3 id="heading-do-not-overuse"><strong>Do Not Overuse</strong> <code>&lt;div&gt;</code></h3>
<ul>
<li><p>Use semantic elements instead of generic <code>&lt;div&gt;</code> elements to provide clear meaning to your content.</p>
</li>
<li><p><strong>Do:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">header</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>My Website<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">header</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">nav</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Services<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Don’t:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"header"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">h1</span>&gt;</span>My Website<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"nav"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Services<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why?</strong></p>
<ul>
<li><p><code>&lt;header&gt;</code> and <code>&lt;nav&gt;</code> explicitly define their roles, making the structure more understandable.</p>
</li>
<li><p><code>&lt;div&gt;</code> lacks semantic meaning, reducing clarity for developers and search engines.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="2">
<li><h3 id="heading-structure-content-logically"><strong>Structure Content Logically</strong></h3>
<ul>
<li><p>Use semantic elements to organize content in a way that reflects its importance and role on the page.</p>
</li>
<li><p><strong>Do:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">main</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">section</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Our Services<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">article</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Web Development<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>We offer web development solutions for businesses.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">article</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">main</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Don’t:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"content"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"section"</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">h2</span>&gt;</span>Our Services<span class="hljs-tag">&lt;/<span class="hljs-name">h2</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"article"</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">h3</span>&gt;</span>Web Development<span class="hljs-tag">&lt;/<span class="hljs-name">h3</span>&gt;</span>
        <span class="hljs-tag">&lt;<span class="hljs-name">p</span>&gt;</span>We offer web development solutions for businesses.<span class="hljs-tag">&lt;/<span class="hljs-name">p</span>&gt;</span>
      <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why?</strong></p>
<ul>
<li><p>Using <code>&lt;section&gt;</code>, <code>&lt;article&gt;</code>, and <code>&lt;main&gt;</code> helps define different parts of the page properly.</p>
</li>
<li><p>Improves readability and search engine indexing.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="3">
<li><h3 id="heading-validate-your-html"><strong>Validate Your HTML</strong></h3>
<ul>
<li><p>Use HTML Validator tools to ensure your HTML follows best practices and is error-free.</p>
</li>
<li><p><strong>Do:</strong></p>
<ul>
<li><p>Regularly validate your HTML to check for improper nesting of elements.</p>
</li>
<li><p>Ensure elements are used in their correct context (e.g., <code>&lt;header&gt;</code> should not be inside <code>&lt;footer&gt;</code>).</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="4">
<li><h3 id="heading-validate-your-html-1"><strong>Validate Your HTML</strong></h3>
<ul>
<li><p>Use semantic elements alongside ARIA attributes where necessary to improve accessibility.</p>
</li>
<li><p><strong>Do:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">nav</span> <span class="hljs-attr">aria-label</span>=<span class="hljs-string">"Main navigation"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">nav</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Don’t:</strong></p>
<pre><code class="lang-xml">  <span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"menu"</span>&gt;</span>
    <span class="hljs-tag">&lt;<span class="hljs-name">ul</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>Home<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
      <span class="hljs-tag">&lt;<span class="hljs-name">li</span>&gt;</span><span class="hljs-tag">&lt;<span class="hljs-name">a</span> <span class="hljs-attr">href</span>=<span class="hljs-string">"#"</span>&gt;</span>About<span class="hljs-tag">&lt;/<span class="hljs-name">a</span>&gt;</span><span class="hljs-tag">&lt;/<span class="hljs-name">li</span>&gt;</span>
    <span class="hljs-tag">&lt;/<span class="hljs-name">ul</span>&gt;</span>
  <span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
</code></pre>
</li>
<li><p><strong>Why?</strong></p>
<ul>
<li><p><code>&lt;nav&gt;</code> with aria-label improves usability for screen reader users.</p>
</li>
<li><p>Enhances accessibility compliance for <a target="_blank" href="https://www.w3.org/TR/WCAG21/">WCAG guidelines</a>.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<h2 id="heading-differences-between-semantic-amp-non-semantic-elements">Differences Between Semantic &amp; Non-Semantic Elements</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Feature</strong></td><td><strong>Semantic Elements</strong></td><td><strong>Non-Semantic Elements</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Definition</strong></td><td>Elements that clearly describe their meaning and purpose.</td><td>Elements that do not provide meaningful context about their content.</td></tr>
<tr>
<td><strong>Readability</strong></td><td>Easier to read and understand for developers and search engines.</td><td>Requires additional classes, IDs, or comments for clarity.</td></tr>
<tr>
<td><strong>SEO Impact</strong></td><td>Helps search engines understand content better, improving ranking.</td><td>Does not provide meaningful structure for search engines.</td></tr>
<tr>
<td><strong>Accessibility</strong></td><td>Improves accessibility for screen readers and assistive technologies.</td><td>Requires extra ARIA attributes for accessibility.</td></tr>
<tr>
<td><strong>Example Elements</strong></td><td><code>&lt;header&gt;</code>, <code>&lt;nav&gt;</code>, <code>&lt;main&gt;</code>, <code>&lt;article&gt;</code>, <code>&lt;section&gt;</code>, <code>&lt;footer&gt;</code></td><td><code>&lt;div&gt;</code>, <code>&lt;span&gt;</code></td></tr>
<tr>
<td><strong>Use Case</strong></td><td>Used to define specific page sections like navigation, headers, and footers.</td><td>Used for generic layout and styling purposes.</td></tr>
</tbody>
</table>
</div><h2 id="heading-accessibility-benefits"><strong>Accessibility Benefits</strong></h2>
<ol>
<li><p><strong>Helps Screen Readers</strong></p>
<ul>
<li><p>Screen readers can read and understand the content better.</p>
</li>
<li><p>People with visual impairments can navigate the website more easily.</p>
</li>
</ul>
</li>
<li><p><strong>Improves Keyboard Navigation</strong></p>
<ul>
<li><p>Users can move through the website using only the keyboard.</p>
</li>
<li><p>Helpful for people who cannot use a mouse.</p>
</li>
</ul>
</li>
<li><p><strong>Better Structure for Assistive Technologies</strong></p>
<ul>
<li><p>Tags like <code>&lt;nav&gt;</code>, <code>&lt;main&gt;</code>, and <code>&lt;article&gt;</code> help assistive tools recognize different parts of the page.</p>
</li>
<li><p>Helps users understand how the page is structured.</p>
</li>
</ul>
</li>
<li><p><strong>Improves focus and interaction</strong></p>
<ul>
<li><p>Important sections are easier to find and interact with.</p>
</li>
<li><p>Helps people with physical disabilities use the website more comfortably.</p>
</li>
</ul>
</li>
<li><p><strong>Reduces Confusion for Users</strong></p>
<ul>
<li><p>Clear labels and well-structured content make it easier to find information.</p>
</li>
<li><p>Users do not have to guess what each section is about.</p>
</li>
</ul>
</li>
<li><p><strong>Supports ARIA (Accessible Rich Internet Applications)</strong></p>
<ul>
<li><p>Supports extra accessibility features like ARIA attributes.</p>
</li>
<li><p>Helps in improving interactive components for better usability.</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-seo-benefits-of-semantic-html"><strong>SEO Benefits of Semantic HTML</strong></h2>
<ol>
<li><p><strong>Helps search engines understand content</strong></p>
<ul>
<li><p>Semantic tags give meaning to different sections of a webpage.</p>
</li>
<li><p>Search engines can better interpret and rank the page.</p>
</li>
</ul>
</li>
<li><p><strong>Improves website ranking</strong></p>
<ul>
<li><p>Well-structured content is easier for search engines to index.</p>
</li>
<li><p>Pages with clear headings and sections have a better chance of ranking higher.</p>
</li>
</ul>
</li>
<li><p><strong>Enhances readability for search engines</strong></p>
<ul>
<li><p>Using <code>&lt;article&gt;</code>, <code>&lt;section&gt;</code>, <code>&lt;header&gt;</code>, and <code>&lt;footer&gt;</code> organizes content better.</p>
</li>
<li><p>Search engines can quickly find important information.</p>
</li>
</ul>
</li>
<li><p><strong>Increases chances of appearing in featured snippets</strong></p>
<ul>
<li><p>Clear structure helps search engines extract useful information for search results.</p>
</li>
<li><p>Well-organized content can be displayed in rich results, increasing visibility.</p>
</li>
</ul>
</li>
<li><p><strong>Reduces reliance on extra SEO efforts</strong></p>
<ul>
<li><p>A properly structured page naturally improves search performance.</p>
</li>
<li><p>Less need for additional optimization like excessive keywords.</p>
</li>
</ul>
</li>
<li><p><strong>Boosts accessibility, which improves SEO</strong></p>
<ul>
<li><p>Search engines prioritize accessible and user-friendly websites.</p>
</li>
<li><p>A well-structured site provides a better experience for users and improves rankings.</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-real-world-examples-of-websites-using-semantic-html"><strong>Real-World Examples of Websites Using Semantic HTML</strong></h2>
<p>Many major companies and media houses use <strong>semantic HTML</strong> in production to improve <strong>accessibility, SEO, and user experience</strong>.</p>
<ol>
<li><p><strong>Smashing Magazine</strong> (<a target="_blank" href="https://www.smashingmagazine.com/">smashingmagazine.com</a>)</p>
<ul>
<li><p>A popular web design and development publication that follows best practices for semantic HTML.</p>
</li>
<li><p>Uses <code>&lt;article&gt;</code>, <code>&lt;section&gt;</code>, and <code>&lt;figure&gt;</code> elements to structure content clearly.</p>
</li>
</ul>
</li>
<li><p><strong>Erik Kroes’ Personal Website</strong> (<a target="_blank" href="https://www.erikkroes.nl/blog/i-made-this-website-with-html/?utm_source=chatgpt.com">erikkroes.nl</a>)</p>
<ul>
<li><p>A fully <strong>semantic HTML website</strong> built without <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code>.</p>
</li>
<li><p>Demonstrates how semantic elements alone can structure content effectively.</p>
</li>
</ul>
</li>
<li><p><strong>Web.dev by Google</strong> (<a target="_blank" href="https://web.dev/learn/html/semantic-html?utm_source=chatgpt.com">web.dev</a>)</p>
<ul>
<li><p>Google’s educational platform that teaches developers best practices.</p>
</li>
<li><p>Uses <strong>semantic elements</strong> to ensure clarity and accessibility.</p>
</li>
</ul>
</li>
<li><p><strong>BBC News</strong> (<a target="_blank" href="https://www.bbc.com/">bbc.com</a>)</p>
<ul>
<li><p>A major news website that uses <code>&lt;article&gt;</code>, <code>&lt;aside&gt;</code>, and <code>&lt;nav&gt;</code> to organize content.</p>
</li>
<li><p>Implements semantic HTML for better indexing and accessibility.</p>
</li>
</ul>
</li>
<li><p><strong>Mozilla Developer Network (MDN Web Docs)</strong> (<a target="_blank" href="https://developer.mozilla.org/en-US/">developer.mozilla.org</a>)</p>
<ul>
<li><p>The go-to resource for web developers, using <strong>semantic tags</strong> for better structure.</p>
</li>
<li><p>Uses <code>&lt;header&gt;</code>, <code>&lt;section&gt;</code>, and <code>&lt;main&gt;</code> elements extensively.</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>Semantic HTML is a powerful way to build well-structured, accessible, and SEO-friendly websites. By using meaningful elements like <code>&lt;header&gt;</code>, <code>&lt;nav&gt;</code>, <code>&lt;main&gt;</code>, and <code>&lt;footer&gt;</code>, we make our code easier to read, maintain, and understand for both developers and search engines.</p>
<p>Instead of relying on <code>&lt;div&gt;</code> and <code>&lt;span&gt;</code> for everything, using semantic tags helps create cleaner, more organized websites that follow modern web standards. By adopting semantic HTML, we ensure our websites are future-proof, easy to manage, and rank better on search engines.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[HTTP v/s HTTPS]]></title><description><![CDATA[Introduction
Every time you browse the internet, you leave behind digital footprints—your IP address, browsing activity, and even personal details. If your connection isn’t secure, hackers can steal this data without you even realizing it. That’s why...]]></description><link>https://blog.devwithjay.com/http-vs-https</link><guid isPermaLink="true">https://blog.devwithjay.com/http-vs-https</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[https]]></category><category><![CDATA[http]]></category><category><![CDATA[SSL]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Fri, 28 Feb 2025 09:55:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1740735198353/1af4c6db-4dec-46a9-8188-77c6a50b5bca.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction"><strong>Introduction</strong></h2>
<p>Every time you browse the internet, you leave behind digital footprints—your IP address, browsing activity, and even personal details. If your connection isn’t secure, <strong>hackers can steal this data</strong> without you even realizing it. That’s why choosing between HTTP and HTTPS isn’t just a technical decision—it’s about <strong>protecting your privacy and online security</strong>.</p>
<p>In this article, we’ll understand the difference between HTTP and HTTPS, why HTTPS is now the safer standard, and why it’s essential for both individuals and businesses.</p>
<h2 id="heading-http">HTTP</h2>
<h3 id="heading-what-is-it">What Is It?</h3>
<p><strong>HTTP (Hypertext Transfer Protocol)</strong> is the fundamental communication protocol of the World Wide Web. It defines how information is requested and transmitted between a web browser (client) and a web server.</p>
<p>HTTP operates on a <strong>client-server model</strong>, where the browser (client) initiates a request, and the server processes it and sends back a response. Since HTTP is <strong>stateless</strong>, each request is processed independently, meaning the server doesn’t retain past interactions.</p>
<p>In the <strong>OSI model</strong>, HTTP functions as a <strong>Layer 7 (Application Layer) protocol</strong>. It uses <strong>port 80</strong> for standard communication.</p>
<h3 id="heading-what-is-http-request">What Is HTTP Request?</h3>
<p>An <strong>HTTP request</strong> is a message sent by a client (usually a web browser) to a server, asking for specific resources, such as web pages, images, or data from an API. This request defines what the client wants from the server and how the server should respond.</p>
<p><strong>Parts of an HTTP Request:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740735246869/f395ee88-9bc0-461b-bc02-3751f44e64b1.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Request Line:</strong></p>
<ul>
<li><p><strong>Method</strong>: Defines the action the client wants to perform (e.g., GET, POST, PUT, DELETE).</p>
</li>
<li><p><strong>URL</strong>: Specifies the resource being requested (e.g., /about in <a target="_blank" href="http://www.example.com/about">www.example.com/about</a>).</p>
</li>
<li><p><strong>HTTP Version</strong>: Indicates the version of HTTP being used (e.g., HTTP/1.1).</p>
</li>
</ul>
</li>
<li><p><strong>Headers:</strong></p>
<ul>
<li><p>Key-value pairs that provide extra details about the request. Common headers include:</p>
</li>
<li><p><strong>Host</strong>: Specifies the domain name of the server (e.g., <a target="_blank" href="http://www.example.com">www.example.com</a>).</p>
</li>
<li><p><strong>Content-Type</strong>: Indicates the format of the request body (e.g., application/json).</p>
</li>
<li><p><strong>Content-Length</strong>: Specifies the size of the request body in bytes.</p>
</li>
</ul>
</li>
<li><p><strong>Body (Optional):</strong></p>
<ul>
<li>Contains the actual data sent with the request, usually in <strong>POST</strong> and <strong>PUT</strong> requests (e.g., form data, JSON payload).</li>
</ul>
</li>
</ol>
<p><strong>Example of an HTTP Request:</strong></p>
<pre><code class="lang-plaintext">curl -v http://example.com
GET / HTTP/1.1
Host: example.com
User-Agent: curl/8.6.0
Accept: */*
</code></pre>
<p>In this example:</p>
<ul>
<li><p>The client sends a <strong>GET</strong> request to retrieve the homepage (/).</p>
</li>
<li><p>The <strong>Host</strong> header specifies <a target="_blank" href="http://example.com">example.com</a> as the target server.</p>
</li>
<li><p>The <strong>User-Agent</strong> header identifies the client making the request.</p>
</li>
<li><p>The <strong>Accept</strong> header indicates that the client can handle any response format (*/*).</p>
</li>
</ul>
<h3 id="heading-what-is-http-response">What Is HTTP Response?</h3>
<p>An <strong>HTTP response</strong> is a message sent by a server back to a client (like a web browser) after receiving an HTTP request. It contains essential information that tells the client whether the request was successful, failed, or needs further action.</p>
<p><strong>Parts of an HTTP Response:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740735257626/3c4643bc-7e11-4141-b002-5915fefa6932.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Status Line:</strong></p>
<ul>
<li><p><strong>HTTP Version</strong>: Indicates the version of HTTP used (e.g., HTTP/1.1).</p>
</li>
<li><p><strong>Status Code</strong>: A three-digit code representing the outcome of the request. Some common status codes include:</p>
<ul>
<li><p>200 OK – The request was successful.</p>
</li>
<li><p>404 Not Found – The requested resource doesn’t exist.</p>
</li>
<li><p>500 Internal Server Error – The server encountered an issue.</p>
</li>
</ul>
</li>
<li><p><strong>Status Message</strong>: A human-readable explanation of the status code (optional in HTTP/1.1).</p>
</li>
</ul>
</li>
<li><p><strong>Headers:</strong></p>
<ul>
<li><p>Additional details about the response, similar to HTTP request headers.</p>
</li>
<li><p>Common headers include:</p>
<ul>
<li><p><strong>Content-Type</strong>: Specifies the type of content returned (e.g., text/html or application/json).</p>
</li>
<li><p><strong>Content-Length</strong>: Indicates the size of the response body.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Body (Optional):</strong></p>
<ul>
<li>Contains the actual response content, such as an HTML webpage, a JSON object, an image, or an error message. Some responses, like redirects (302 Found), may not include a body.</li>
</ul>
</li>
</ol>
<p><strong>Example of an HTTP Response:</strong></p>
<pre><code class="lang-plaintext">HTTP/2 302
content-type: text/html; charset=UTF-8
location: /p/about-hussein.html
date: Mon, 12 Aug 2024 08:15:39 GMT
expires: Mon, 12 Aug 2024 08:15:39 GMT
cache-control: private, max-age=0
server: GSE

&lt;HTML&gt;
&lt;HEAD&gt;
&lt;TITLE&gt;Moved Temporarily&lt;/TITLE&gt;
&lt;/HEAD&gt;
&lt;/HTML&gt;
</code></pre>
<p>In this response:</p>
<ul>
<li><p>The <strong>status code 302</strong> indicates a temporary redirect.</p>
</li>
<li><p>The <strong>headers</strong> specify the content type (text/html), server details, and cache settings.</p>
</li>
<li><p>The <strong>body</strong> contains an HTML message telling the client that the resource has moved.</p>
</li>
</ul>
<h3 id="heading-how-does-it-work"><strong>How Does It Work?</strong></h3>
<p>HTTP follows a simple <strong>request-response</strong> model that allows clients (like web browsers) and servers to communicate over the internet.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740735343032/1792cb8d-0e11-474e-bb9d-3967651cffcb.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Client Sends a Request:</strong></p>
<ul>
<li><p>A web browser, mobile app, or other client sends an <strong>HTTP request</strong> to a web server, asking for a specific resource (e.g., a webpage, an image, or data from an API).</p>
</li>
<li><p>The request includes <strong>headers</strong>, which provide additional details such as the <strong>user-agent (browser type)</strong> and the <strong>host (website domain)</strong>.</p>
</li>
<li><p>Common request methods include <strong>GET (retrieve data)</strong>, <strong>POST (send data)</strong>, <strong>PUT (update data)</strong>, and <strong>DELETE (remove data)</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Server Processes the Request:</strong></p>
<ul>
<li><p>The web server receives the request and decides how to handle it.</p>
</li>
<li><p>If the requested resource exists and the request is valid, the server prepares a response.</p>
</li>
</ul>
</li>
<li><p><strong>Server Sends a Response:</strong></p>
<ul>
<li><p>The server responds with an <strong>HTTP status code</strong> (e.g., 200 OK for success, 404 Not Found for missing resources).</p>
</li>
<li><p><strong>Headers</strong> provide metadata about the response, such as content type and length.</p>
</li>
<li><p>If applicable, the <strong>body</strong> contains the actual content (e.g., HTML, JSON, images, or videos).</p>
</li>
</ul>
</li>
</ol>
<p><strong>Security Concern in HTTP</strong></p>
<p>One major issue with HTTP is that <strong>data is sent in plain text</strong>, making it <strong>unencrypted and vulnerable</strong> to cyberattacks. Hackers or malicious third parties can intercept HTTP traffic and steal sensitive details like login credentials, payment information, or browsing activity.</p>
<p>This is why <strong>HTTPS (HTTP Secure)</strong> is now widely used—it encrypts communication, ensuring that data remains private and protected from attackers.</p>
<h3 id="heading-advantages">Advantages</h3>
<ol>
<li><p><strong>Lower CPU and Memory Usage</strong> – Since HTTP does not require multiple connections, it reduces the load on system resources.</p>
</li>
<li><p><strong>Supports Request Pipelining</strong> – Multiple HTTP requests can be sent at once, improving efficiency.</p>
</li>
<li><p><strong>Reduces Network Congestion</strong> – Fewer TCP connections mean less strain on the network.</p>
</li>
<li><p><strong>Lower Latency for Subsequent Requests</strong> – Unlike HTTPS, HTTP does not require a handshake process for every request, leading to faster response times.</p>
</li>
<li><p><strong>Error Reporting Without Termination</strong> – The connection remains active even if an issue occurs, allowing for smoother communication.</p>
</li>
</ol>
<h3 id="heading-disadvantages">Disadvantages</h3>
<ol>
<li><p><strong>Limited to Point-to-Point Connections</strong> – HTTP only works between a single client and server, making it less suitable for modern distributed systems.</p>
</li>
<li><p><strong>Not Mobile-Friendly</strong> – It does not optimize well for mobile networks, leading to slower performance.</p>
</li>
<li><p><strong>Lack of Push Capability</strong> – HTTP cannot proactively send data to the client unless requested.</p>
</li>
<li><p><strong>High Overhead in Data Transmission</strong> – HTTP messages contain a lot of text-based metadata, making them larger than necessary.</p>
</li>
<li><p><strong>No Built-in Reliability</strong> – HTTP does not have a built-in retry mechanism to handle lost or failed requests.</p>
</li>
<li><p><strong>Persistent Connection Issue</strong> – Even after a client has received all the required data, the connection may remain open, unnecessarily keeping the server engaged.</p>
</li>
</ol>
<h2 id="heading-https">HTTPS</h2>
<h3 id="heading-what-is-it-1">What Is It?</h3>
<p><strong>HTTPS (Hypertext Transfer Protocol Secure)</strong> is the <strong>secure version</strong> of HTTP, designed to protect data transferred between a user’s browser and a website. It ensures that all communication is <strong>encrypted</strong> using <strong>Transport Layer Security (TLS)</strong> or <strong>Secure Sockets Layer (SSL)</strong>, making it difficult for hackers to <strong>intercept or manipulate data</strong>.</p>
<p>The main purpose of HTTPS is to provide <strong>confidentiality, integrity, and authenticity</strong>. This means that the information sent between a user and a website remains <strong>private</strong>, cannot be <strong>tampered with</strong>, and comes from a <strong>verified source</strong>.</p>
<p>Websites that require users to <strong>enter sensitive information</strong>, such as <strong>passwords, banking details, or personal data</strong>, must use HTTPS to <strong>protect users from cyber threats</strong> like <strong>man-in-the-middle attacks</strong> and <strong>data breaches</strong>.</p>
<h3 id="heading-how-does-it-work-1">How Does It Work?</h3>
<p>HTTPS works similarly to HTTP but with <strong>one major difference</strong>—it <strong>encrypts</strong> the data before it is transmitted, ensuring secure communication between the client (browser) and the web server.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740735353090/8dec577c-3415-44e2-b859-2a8e1c3f9dc1.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Client Sends a Request</strong></p>
<ul>
<li><p>A browser or application sends an <strong>HTTP request</strong> (GET, POST, PUT, DELETE) to the server, just like in a regular HTTP interaction.</p>
</li>
<li><p>The request contains <strong>headers</strong> with details about the client (user-agent, requested resource, etc.).</p>
</li>
</ul>
</li>
<li><p><strong>TLS/SSL Handshake Begins</strong></p>
<ul>
<li>Before processing the request, the server and client <strong>initiate a handshake</strong> to establish a <strong>secure connection</strong>.</li>
</ul>
</li>
<li><p><strong>Server Verifies Identity with an SSL/TLS Certificate</strong></p>
<ul>
<li><p>The server presents its <strong>SSL/TLS certificate</strong>, which includes a <strong>public key</strong> that verifies its authenticity.</p>
</li>
<li><p>The client (browser) checks if the certificate is <strong>valid and issued by a trusted Certificate Authority (CA)</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Encryption Keys Are Exchanged</strong></p>
<ul>
<li><p>Both the client and server agree on a <strong>secure encryption algorithm</strong>.</p>
</li>
<li><p>A <strong>session key</strong> is created, allowing them to encrypt and decrypt data securely.</p>
</li>
</ul>
</li>
<li><p><strong>Server Processes the Request &amp; Sends an Encrypted Response</strong></p>
<ul>
<li><p>Once the connection is secure, the server <strong>processes the request</strong> and sends an <strong>HTTP response</strong>.</p>
</li>
<li><p>This response <strong>contains encrypted data</strong>, protecting it from hackers and unauthorized third parties.</p>
</li>
</ul>
</li>
</ol>
<p>With HTTPS, even if a hacker intercepts the data, they won’t be able to read it because it’s encrypted. This makes HTTPS important for secure logins, online transactions, and protecting sensitive user information.</p>
<h3 id="heading-how-does-tlsssl-encrypt-http-requests-amp-responses">How Does TLS/SSL Encrypt HTTP Requests &amp; Responses?</h3>
<p>TLS (Transport Layer Security) and its predecessor SSL (Secure Sockets Layer) use <strong>public key cryptography</strong> to <strong>encrypt</strong> HTTP requests and responses, ensuring that data remains private and secure.</p>
<p><strong>How It Works?</strong></p>
<ol>
<li><p><strong>Public &amp; Private Key Pair</strong></p>
<ul>
<li><p>Each HTTPS-enabled server has a <strong>public key</strong> and a <strong>private key</strong>.</p>
</li>
<li><p>The <strong>public key</strong> is shared with clients through an <strong>SSL/TLS certificate</strong>, while the <strong>private key</strong> remains confidential on the server.</p>
</li>
</ul>
</li>
<li><p><strong>Establishing Secure Communication (TLS Handshake)</strong></p>
<ul>
<li><p>When a client (browser) connects to a secure website, it <strong>retrieves the public key</strong> from the server’s SSL/TLS certificate.</p>
</li>
<li><p>The client and server <strong>use the public and private keys to generate new session keys</strong> that will be used for further encryption.</p>
</li>
</ul>
</li>
<li><p><strong>Session Key Encryption</strong></p>
<ul>
<li><p>Instead of using the public/private key pair for every request, <strong>session keys</strong> are created.</p>
</li>
<li><p>These <strong>session keys</strong> are <strong>symmetric keys</strong>, meaning both the client and server use the same key for encryption and decryption.</p>
</li>
<li><p>This allows for <strong>faster and more efficient encryption</strong> of all HTTP requests and responses.</p>
</li>
</ul>
</li>
<li><p><strong>Encrypting HTTP Requests &amp; Responses</strong></p>
<ul>
<li><p>After the handshake, all HTTP data exchanged (requests and responses) is <strong>encrypted with the session key</strong>.</p>
</li>
<li><p>If a hacker intercepts this communication, they will only see <strong>random strings of characters</strong> rather than readable text.</p>
</li>
</ul>
</li>
</ol>
<p><strong>Why Is This Important?</strong></p>
<p>Without TLS/SSL encryption, <strong>hackers can easily read sensitive data</strong> like passwords, credit card details, and personal messages. By encrypting HTTP requests and responses, <strong>HTTPS protects users from cyber threats like eavesdropping, data tampering, and man-in-the-middle attacks</strong>.</p>
<h3 id="heading-ssltls-handshake">SSL/TLS Handshake</h3>
<p>The <strong>SSL/TLS handshake</strong> is a process that establishes a <strong>secure connection</strong> between a client (browser) and a server before any data is exchanged. It ensures <strong>confidentiality, integrity, and authentication</strong> in online communication.</p>
<p><strong>How the SSL/TLS Handshake Works:</strong></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740735577788/77c6de4f-ba7b-49e0-925c-7af1d5cdcdee.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Client Initiates Connection (“ClientHello”)</strong></p>
<ul>
<li><p>The client (browser) sends a <strong>“ClientHello”</strong> message to the server.</p>
</li>
<li><p>This message includes the <strong>supported encryption algorithms</strong> and other parameters.</p>
</li>
</ul>
</li>
<li><p><strong>Server Responds (“ServerHello”)</strong></p>
<ul>
<li><p>The server replies with a <strong>“ServerHello”</strong> message.</p>
</li>
<li><p>It selects an encryption algorithm and <strong>sends its SSL/TLS certificate</strong>, which contains its <strong>public key</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Client Verifies Certificate</strong></p>
<ul>
<li>The client checks if the SSL/TLS certificate is <strong>valid and issued by a trusted Certificate Authority (CA)</strong>.</li>
</ul>
</li>
<li><p><strong>Key Exchange &amp; Encryption Setup</strong></p>
<ul>
<li><p>A <strong>symmetric session key</strong> is generated to encrypt communication.</p>
</li>
<li><p>This key is securely exchanged using <strong>asymmetric encryption (public &amp; private keys)</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Handshake Completion (“Finished” Message)</strong></p>
<ul>
<li><p>Both client and server send a <strong>“Finished” message</strong>, confirming the handshake is successful.</p>
</li>
<li><p>From this point, all communication is <strong>encrypted using the agreed session key</strong>.</p>
</li>
</ul>
</li>
</ol>
<p><strong>Why Is the SSL/TLS Handshake Important?</strong></p>
<ul>
<li><p><strong>Prevents cyber threats</strong> like man-in-the-middle attacks.</p>
</li>
<li><p><strong>Encrypts data</strong> to keep sensitive information safe.</p>
</li>
<li><p><strong>Authenticates the server</strong>, ensuring users connect to the right website.</p>
</li>
</ul>
<h3 id="heading-how-does-https-help-authenticate-web-servers">How Does HTTPS Help Authenticate Web Servers?</h3>
<p><strong>Authentication</strong> makes sure that a website is <strong>legitimate</strong> and not an <strong>imposter</strong> created by attackers. Unlike HTTP, which operates purely on <strong>trust</strong>, HTTPS verifies a web server’s identity using <strong>SSL/TLS certificates</strong> and cryptographic mechanisms.</p>
<p><strong>How HTTPS Verifies a Server’s Identity:</strong></p>
<ol>
<li><p><strong>SSL/TLS Certificate &amp; Public-Private Key Pair</strong></p>
<ul>
<li><p>Every HTTPS-enabled website has an <strong>SSL/TLS certificate</strong> issued by a <strong>Certificate Authority (CA)</strong>.</p>
</li>
<li><p>This certificate contains a <strong>public key</strong>, while the server holds a matching <strong>private key</strong>.</p>
</li>
<li><p>When a browser connects to a website, it requests the SSL certificate and verifies its authenticity.</p>
</li>
</ul>
</li>
<li><p><strong>The Role of the Private Key</strong></p>
<ul>
<li><p>The <strong>private key</strong> is <strong>never shared</strong> and is known only by the legitimate web server.</p>
</li>
<li><p>If a server can <strong>decrypt a message</strong> encrypted with the <strong>public key</strong>, it proves it owns the <strong>private key</strong>—confirming its identity.</p>
</li>
</ul>
</li>
<li><p><strong>Certificate Authority (CA) Validation</strong></p>
<ul>
<li><p>The SSL certificate is <strong>digitally signed</strong> by a trusted CA.</p>
</li>
<li><p>Browsers <strong>verify the CA signature</strong> to ensure the certificate was issued to the correct website.</p>
</li>
</ul>
</li>
</ol>
<p><strong>What Attacks Does HTTPS Prevent?</strong></p>
<ul>
<li><p><strong>On-Path Attacks (Man-in-the-Middle Attacks)</strong> – Prevents hackers from intercepting and modifying data.</p>
</li>
<li><p><strong>DNS Hijacking</strong> – Ensures users connect to the real website instead of a fraudulent one.</p>
</li>
<li><p><strong>BGP Hijacking</strong> – Blocks attackers from rerouting traffic to malicious servers.</p>
</li>
<li><p><strong>Domain Spoofing</strong> – Verifies that the website is the legitimate owner of the domain.</p>
</li>
</ul>
<p><strong>Why is HTTPS Authentication Important?</strong></p>
<p>By proving that a server is <strong>who it claims to be</strong>, HTTPS helps protect users from phishing sites, identity theft, and financial fraud. This is why <strong>browsers flag HTTP websites as “Not Secure”</strong>, urging users to avoid them.</p>
<h3 id="heading-advantages-1">Advantages</h3>
<ol>
<li><p><strong>Protects Data During Transmission</strong> – Encrypts data, keeping it safe from hackers.</p>
</li>
<li><p><strong>Prevents Cyber Attacks</strong> – Shields your website from <strong>data breaches, phishing, and man-in-the-middle (MITM) attacks</strong>.</p>
</li>
<li><p><strong>Builds Trust</strong> – Visitors feel more secure knowing their information is protected.</p>
</li>
<li><p><strong>Removes “Not Secure” Warnings</strong> – Browsers show a <strong>padlock icon</strong>, signaling a safe connection.</p>
</li>
<li><p><strong>Boosts SEO Rankings</strong> – Google and other search engines rank <strong>HTTPS websites higher</strong> than HTTP ones.</p>
</li>
</ol>
<h3 id="heading-disadvantages-1">Disadvantages</h3>
<ol>
<li><p><strong>Requires an SSL Certificate</strong> – Website owners need to <strong>buy and renew</strong> an SSL certificate, which may cost money.</p>
</li>
<li><p><strong>More Processing Power Needed</strong> – Encrypting and decrypting data takes <strong>extra computing resources</strong>, slightly affecting speed.</p>
</li>
<li><p><strong>Caching Issues</strong> – Some <strong>public caching</strong> (storing data temporarily for faster access) doesn’t work the same way with HTTPS.</p>
</li>
<li><p><strong>Blocked by Some Firewalls &amp; Proxies</strong> – Certain networks (schools, workplaces) may <strong>restrict access to HTTPS websites</strong>.</p>
</li>
<li><p><strong>Configuration Problems</strong> – If not set up correctly, a website might still load <strong>some files over HTTP</strong>, causing security risks.</p>
</li>
</ol>
<h2 id="heading-evolution-of-web-protocols"><strong>Evolution of Web Protocols</strong></h2>
<p>The <strong>Hypertext Transfer Protocol (HTTP)</strong> has evolved over the years to improve <strong>speed, efficiency, and security</strong>. Each new version of HTTP introduces better ways to transfer data, reduce delays, and enhance the user experience.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740735619239/0d441e0c-a6bf-419b-919e-2c2a420b7454.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>HTTP/0.9 (1991) – The First Version</strong></p>
<ul>
<li><p>This was the <strong>earliest version</strong> of HTTP, designed only for <strong>retrieving HTML pages</strong>.</p>
</li>
<li><p>It supported <strong>only one request type</strong> (<strong>GET</strong>) and <strong>did not include headers</strong>.</p>
</li>
<li><p>There was <strong>no support for images, scripts, or stylesheets</strong>—only simple text-based web pages could be loaded.</p>
</li>
</ul>
</li>
<li><p><strong>HTTP/1.0 (1996) – More Features, But Still Limited</strong></p>
<ul>
<li><p>This version introduced <strong>headers</strong>, which allowed additional information to be included in requests and responses.</p>
</li>
<li><p>It supported <strong>multiple request methods</strong>, including <strong>POST and HEAD</strong>, making it possible to send and retrieve different types of data.</p>
</li>
<li><p>However, it still had a major limitation—<strong>each request required a new connection</strong>, which made loading web pages slow.</p>
</li>
</ul>
</li>
<li><p><strong>HTTP/1.1 (1997) – Faster &amp; More Efficient</strong></p>
<ul>
<li><p>Introduced <strong>persistent connections</strong>, meaning multiple requests could be sent over <strong>a single TCP connection</strong> instead of opening a new connection for each request.</p>
</li>
<li><p>Added <strong>chunked transfer encoding</strong>, allowing large content to be sent in smaller parts, reducing delays.</p>
</li>
<li><p>Introduced <strong>request pipelining</strong>, which allowed multiple requests to be sent <strong>without waiting</strong> for each response, improving page load speed.</p>
</li>
<li><p>This version remained the <strong>standard for nearly two decades</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>HTTP/2 (2015) – Speed &amp; Performance Boost</strong></p>
<ul>
<li><p>Switched from <strong>text-based format to a binary format</strong>, making data transfer <strong>faster and more efficient</strong>.</p>
</li>
<li><p>Introduced <strong>multiplexing</strong>, allowing multiple requests and responses to be sent at the <strong>same time</strong> over a single connection.</p>
</li>
<li><p>Enabled <strong>server push</strong>, allowing servers to send resources to the client <strong>before they are requested</strong>, improving load times.</p>
</li>
<li><p>Compressed headers to <strong>reduce data overhead</strong> and improve efficiency.</p>
</li>
<li><p>HTTP/2 is commonly used with <strong>SSL/TLS encryption</strong>, making it more secure.</p>
</li>
</ul>
</li>
<li><p><strong>HTTP/3 (2019) – The Future of Web Communication</strong></p>
<ul>
<li><p>Replaces <strong>TCP with QUIC</strong>, a faster protocol that reduces connection delays.</p>
</li>
<li><p><strong>Eliminates head-of-line blocking</strong>, meaning if one request is delayed, others can still be processed.</p>
</li>
<li><p>Provides <strong>built-in encryption by default</strong>, making it <strong>more secure</strong> than previous versions.</p>
</li>
<li><p>Improves <strong>real-time data streaming, gaming, and mobile browsing performance</strong>.</p>
</li>
</ul>
</li>
</ol>
<p><strong>HTTPS: The Secure Standard for the Web</strong></p>
<ul>
<li><p><strong>HTTPS (Hypertext Transfer Protocol Secure)</strong> is the secure version of HTTP that encrypts data using <strong>SSL/TLS</strong> to protect users from cyberattacks.</p>
</li>
<li><p>Today, most websites use <strong>HTTP/2 with HTTPS</strong> to ensure <strong>both security and speed</strong>.</p>
</li>
<li><p>As <strong>HTTP/3 adoption grows</strong>, it will become the standard for <strong>faster, more secure, and reliable web communication</strong>.</p>
</li>
</ul>
<h2 id="heading-differences-between-http-amp-https"><strong>Differences Between HTTP &amp; HTTPS</strong></h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Feature</strong></td><td><strong>HTTP</strong></td><td><strong>HTTPS</strong></td></tr>
</thead>
<tbody>
<tr>
<td><strong>Full Form</strong></td><td>HyperText Transfer Protocol</td><td>HyperText Transfer Protocol Secure</td></tr>
<tr>
<td><strong>URL Format</strong></td><td>Starts with <strong>“</strong><a target="_blank" href="http://xn--ivg"><strong>http://”</strong></a></td><td>Starts with <strong>“</strong><a target="_blank" href="https://xn--ivg"><strong>https://”</strong></a></td></tr>
<tr>
<td><strong>Port Number</strong></td><td>Uses <strong>port 80</strong> for communication</td><td>Uses <strong>port 443</strong> for communication</td></tr>
<tr>
<td><strong>Security</strong></td><td><strong>Not secure</strong></td><td><strong>Secure</strong> with encryption</td></tr>
<tr>
<td><strong>Encryption</strong></td><td>No encryption, data is sent in <strong>plain text</strong></td><td>Data is encrypted using <strong>SSL/TLS</strong>, sent in <strong>ciphertext</strong></td></tr>
<tr>
<td><strong>Data Protection</strong></td><td>Vulnerable to <strong>hacking, MITM attacks, and data interception</strong></td><td>Protects data from <strong>hackers, MITM attacks, and phishing</strong></td></tr>
<tr>
<td><strong>Verification</strong></td><td>Does not verify the <strong>server’s identity</strong></td><td>Uses <strong>SSL/TLS certificates</strong> to verify server identity</td></tr>
<tr>
<td><strong>Search Ranking (SEO)</strong></td><td>No impact on SEO ranking</td><td>Improves SEO ranking (<strong>preferred by search engines</strong>)</td></tr>
<tr>
<td><strong>Performance</strong></td><td><strong>Faster</strong> since there is no encryption</td><td><strong>Slightly slower</strong> due to encryption processes</td></tr>
<tr>
<td><strong>Usage</strong></td><td>Suitable for <strong>general browsing</strong> (non-sensitive data)</td><td>Required for <strong>login pages, banking, and sensitive data transfer</strong></td></tr>
<tr>
<td><strong>Data Transfer</strong></td><td>Sends data in <strong>plain text</strong>, easy to intercept</td><td>Encrypts data before sending, making it <strong>secure</strong></td></tr>
<tr>
<td><strong>Browser Indicator</strong></td><td>May show a <strong>“Not Secure”</strong> warning in modern browsers</td><td>Shows a <strong>padlock icon</strong> indicating a secure connection</td></tr>
<tr>
<td><strong>User Trust</strong></td><td>Users may <strong>hesitate</strong> to enter sensitive details</td><td>Users feel <strong>confident and safe</strong> sharing data</td></tr>
<tr>
<td><strong>SSL/TLS Certificate</strong></td><td><strong>Not required</strong></td><td><strong>Mandatory</strong> for encryption and authentication</td></tr>
<tr>
<td><strong>Use of Hashtags for Data Security</strong></td><td>Does not use data hashing</td><td>Uses <strong>hashing</strong> and encryption before sending data</td></tr>
</tbody>
</table>
</div><h2 id="heading-ssl-amp-tls-certificates"><strong>SSL &amp; TLS Certificates</strong></h2>
<h3 id="heading-what-is-an-ssl-certificate"><strong>What is an SSL Certificate?</strong></h3>
<p>An <strong>SSL (Secure Sockets Layer) Certificate</strong> is a <strong>digital security credential</strong> that provides <strong>encryption and authentication</strong> for websites. It ensures that any data exchanged between a <strong>user’s browser</strong> and a <strong>web server</strong> remains <strong>private and secure</strong>, preventing unauthorized access or interception.</p>
<p>To enable <strong>HTTPS</strong>, a website must have a <strong>valid SSL certificate</strong>. This certificate uses <strong>two cryptographic keys</strong>: a <strong>public key</strong> to encrypt data and a <strong>private key</strong> to decrypt it.</p>
<p>SSL certificates are issued by <strong>Certificate Authorities (CAs)</strong>, trusted organizations that verify a website’s identity before granting a certificate. When you visit a secure website, your browser checks for a valid SSL certificate. A <strong>padlock icon</strong> in the address bar indicates a secure connection, while an invalid or missing certificate triggers a <strong>security warning</strong>.</p>
<h3 id="heading-what-is-a-tls-certificate"><strong>What is a TLS Certificate?</strong></h3>
<p>A <strong>TLS (Transport Layer Security) Certificate</strong> is the <strong>successor to SSL certificates</strong> that provides <strong>better security</strong> for websites.  It <strong>encrypts and protects</strong> data sent between a user’s browser and a web server, keeping it safe from hackers.</p>
<p>TLS is the <strong>newer and stronger</strong> version of <strong>SSL</strong>, which is no longer used. It uses <strong>better encryption methods</strong> to prevent <strong>eavesdropping, data tampering, and cyberattacks</strong>. Even though people still say “SSL,” most websites today actually use <strong>TLS</strong> for security.</p>
<p>Websites with <strong>HTTPS</strong> use <strong>TLS certificates</strong> to keep user data <strong>safe, private, and secure</strong> while browsing or making online transactions.</p>
<h3 id="heading-what-are-the-different-types-of-ssltls-certificates"><strong>What are the different types of SSL/TLS certificates?</strong></h3>
<p>There are <strong>three main types</strong> of SSL/TLS certificates:</p>
<ol>
<li><p><strong>Domain Validated (DV) Certificates</strong></p>
<ul>
<li><p>The <strong>basic</strong> type of SSL/TLS certificate.</p>
</li>
<li><p><strong>Easiest and fastest</strong> to obtain, as it only requires domain ownership verification.</p>
</li>
<li><p>Best for <strong>personal websites, blogs, or small projects</strong> that don’t handle sensitive data.</p>
</li>
</ul>
</li>
<li><p><strong>Organization Validated (OV) Certificates</strong></p>
<ul>
<li><p>Provides <strong>more security</strong> than DV certificates.</p>
</li>
<li><p>Requires the <strong>Certificate Authority (CA) to verify the organization’s identity</strong> before issuing the certificate.</p>
</li>
<li><p>Suitable for <strong>business websites, e-commerce stores, and organizations</strong> that need <strong>extra trust and security</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Extended Validation (EV) Certificates</strong></p>
<ul>
<li><p>Offers the <strong>highest level of security and assurance</strong>.</p>
</li>
<li><p>Requires a <strong>thorough verification</strong> of the business or organization.</p>
</li>
<li><p>Used by <strong>banks, large corporations, and businesses handling sensitive information</strong> to build <strong>maximum trust</strong> with users.</p>
</li>
</ul>
</li>
</ol>
<h3 id="heading-why-are-ssltls-certificates-important"><strong>Why are SSL/TLS Certificates important?</strong></h3>
<p>SSL/TLS certificates help <strong>keep your information safe</strong> when it is sent over the internet. They use <strong>encryption</strong> to protect your data from hackers and identity thieves.</p>
<p>These certificates are issued by <strong>Certificate Authorities (CAs)</strong>. When you visit a website, your browser <strong>checks if the SSL/TLS certificate is valid</strong>. If it is, you will see a <strong>padlock icon</strong> in the address bar, showing that the site is secure.</p>
<p>Not all websites <strong>need</strong> an SSL/TLS certificate, but they are <strong>important</strong> for websites that handle <strong>sensitive information</strong>, such as:</p>
<ul>
<li><p><strong>Online shopping sites</strong> (to protect payment details)</p>
</li>
<li><p><strong>Social media sites</strong></p>
</li>
<li><p><strong>Websites with login pages</strong></p>
</li>
</ul>
<p>If you’re not sure if your website needs an SSL/TLS certificate, <strong>ask your web hosting provider or an IT expert</strong>. Having one <strong>keeps users safe and builds trust</strong>.</p>
<h2 id="heading-how-to-switch-from-http-to-https"><strong>How To Switch From HTTP To HTTPS?</strong></h2>
<p>Switching from <strong>HTTP to HTTPS</strong> makes your website <strong>more secure and trustworthy</strong>. To do this, you need an <strong>SSL/TLS certificate</strong> and some basic setup.</p>
<p>You need to follow these steps:</p>
<ol>
<li><p><strong>Install an SSL/TLS Certificate</strong></p>
<ul>
<li><p>Get an <strong>SSL/TLS certificate</strong> from a <strong>trusted Certificate Authority (CA)</strong> (e.g., Let’s Encrypt, GoDaddy, Namecheap).</p>
</li>
<li><p>Many web hosting providers offer <strong>free SSL certificates</strong> and allow <strong>one-click installation</strong> in their dashboard.</p>
</li>
<li><p>If needed, follow your hosting provider’s <strong>SSL installation guide</strong> for manual setup.</p>
</li>
</ul>
</li>
<li><p><strong>Force HTTPS on Your Server</strong></p>
<ul>
<li><p>After installing the SSL certificate, <strong>redirect all HTTP traffic to HTTPS</strong> so users always access the secure version of your site.</p>
</li>
<li><p><strong>For Apache servers</strong> (using .htaccess), add this code:</p>
<pre><code class="lang-plaintext">  RewriteEngine On  
  RewriteCond %{HTTPS} !=on  
  RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</code></pre>
</li>
<li><p>If using <strong>NGINX</strong>, modify the server settings to enforce HTTPS.</p>
</li>
<li><p>Some hosting providers (like <strong>SiteGround, Bluehost</strong>) offer an <strong>easy HTTPS switch</strong> in their settings.</p>
</li>
</ul>
</li>
<li><p><strong>Set Up HTTPS in Your Website Platform</strong></p>
<ul>
<li><p>Some platforms, like <strong>WordPress, Joomla, or Shopify</strong>, need additional setup to work correctly with HTTPS.</p>
</li>
<li><p><strong>Common issue: “Mixed Content Errors”</strong> – This happens when some images, scripts, or stylesheets still load over HTTP instead of HTTPS.</p>
</li>
<li><p><strong>How to Fix Mixed Content Issues:</strong></p>
<ul>
<li><p>Use <strong>a plugin</strong> (like Really Simple SSL for WordPress) to update all links to HTTPS.</p>
</li>
<li><p>Manually update <strong>internal links</strong> in your database using a <strong>Search &amp; Replace tool</strong>.</p>
</li>
</ul>
</li>
</ul>
</li>
<li><p><strong>Update All Links and Resources</strong></p>
<ul>
<li><p>Make sure that <strong>all images, scripts, and third-party services</strong> use <strong>HTTPS versions</strong> instead of HTTP.</p>
</li>
<li><p>Update your <strong>CDN (Content Delivery Network)</strong> settings to load content securely.</p>
</li>
</ul>
</li>
<li><p><strong>Test and Verify HTTPS is Working</strong></p>
<ul>
<li><p>Visit your website using <a target="_blank" href="https://yourwebsite.com"><strong>https://yourwebsite.com</strong></a> and check for the <strong>padlock icon</strong> in the browser’s address bar.</p>
</li>
<li><p>Use <strong>SSL Checker tools</strong> like SSL Labs to verify your SSL certificate is working correctly.</p>
</li>
<li><p>Check for <strong>mixed content errors</strong> using browser <strong>Developer Tools</strong> (Press F12 &gt; Console).</p>
</li>
</ul>
</li>
<li><p><strong>Update Search Engines &amp; External Links</strong></p>
<ul>
<li><p>Go to <strong>Google Search Console</strong> and <strong>update your website URL to HTTPS</strong>.</p>
</li>
<li><p>Update your <strong>Google Analytics settings</strong> with the new <strong>HTTPS version</strong> of your site.</p>
</li>
<li><p>Submit a new <strong>sitemap with HTTPS URLs</strong> to search engines.</p>
</li>
<li><p>Ask external websites linking to you to update their links to <a target="_blank" href="https://yourwebsite.com"><strong>https://yourwebsite.com</strong></a>.</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-is-https-setup-more-expensive-than-http"><strong>Is HTTPS Setup More Expensive than HTTP?</strong></h2>
<p>In the past, HTTPS cost money because SSL/TLS certificates had to be bought and renewed every year. But now, many providers offer free SSL certificates, making HTTPS affordable for everyone.</p>
<p><strong>Where Can You Get Free SSL Certificates?</strong></p>
<ul>
<li><p><strong>Let’s Encrypt</strong> – A free SSL provider used by many websites.</p>
</li>
<li><p><strong>Cloudflare</strong> – Offers free SSL with its services.</p>
</li>
<li><p><strong>AWS Certificate Manager (ACM)</strong> – Provides free SSL for websites hosted on AWS.</p>
</li>
<li><p><strong>Web Hosting Companies</strong> – Many hosting providers (like <strong>SiteGround, Bluehost, and Namecheap</strong>) include <strong>free SSL</strong> in their plans.</p>
</li>
</ul>
<p>In conclusion, HTTPS is <strong>no longer expensive</strong>—you can get an SSL certificate for free, and many services make it easy to set up and manage.</p>
<h2 id="heading-how-do-i-know-if-my-website-uses-http-or-https">How Do I Know If My Website Uses HTTP or HTTPS?</h2>
<p>You can easily check which protocol your website is using by looking at the <strong>address bar</strong> in your browser.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1740736489460/dfc6702f-7de0-42f1-aef1-311bd2f1b6bf.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p><strong>If the URL starts with</strong> http:// → The website is using <strong>HTTP</strong> (not secure).</p>
</li>
<li><p><strong>If the URL starts with</strong> https:// → The website is using <strong>HTTPS</strong> (secure and encrypted).</p>
</li>
</ul>
<p><strong>Tip:</strong> Some browsers, like <strong>Google Chrome</strong>, hide the http:// or https:// part in the address bar. To see the full URL, <strong>click twice on it</strong> and the full address will be visible.</p>
<h2 id="heading-why-choose-https-over-http"><strong>Why Choose HTTPS Over HTTP?</strong></h2>
<p><strong>Did you know?</strong> Over <strong>43% of cyberattacks</strong> target small businesses, and websites without HTTPS are <strong>prime targets</strong> for hackers. If a website still runs on <strong>HTTP</strong>, it’s like leaving your <strong>front door unlocked</strong>—making it easy for cybercriminals to <strong>steal sensitive data</strong>.</p>
<ol>
<li><p><strong>Secure Data Transmission</strong></p>
<ul>
<li><p><strong>HTTPS encrypts data</strong> exchanged between a website and its visitors.</p>
</li>
<li><p>Only the <strong>server and client</strong> can read the data; hackers <strong>cannot intercept</strong> it.</p>
</li>
<li><p>Makes <strong>online transactions, logins, and personal data processing safer</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Better SEO Ranking</strong></p>
<ul>
<li><p><strong>Search engines like Google rank HTTPS sites higher</strong> than HTTP sites.</p>
</li>
<li><p>Websites without HTTPS are often <strong>pushed back in search results</strong>.</p>
</li>
<li><p>HTTPS helps improve <strong>visibility, traffic, and credibility</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Builds Trust with Visitors</strong></p>
<ul>
<li><p>Online scams and frauds are increasing, making users more cautious.</p>
</li>
<li><p><strong>Web browsers display a padlock icon</strong> on HTTPS websites, showing they are secure.</p>
</li>
<li><p><strong>Without HTTPS, visitors see a “Not Secure” warning</strong>, which can scare them away.</p>
</li>
</ul>
</li>
<li><p><strong>Required for Online Payments</strong></p>
<ul>
<li><p>HTTPS is <strong>mandatory</strong> for <strong>e-commerce websites</strong> and online transactions.</p>
</li>
<li><p><strong>Payment processors will reject</strong> websites that <strong>don’t use HTTPS</strong>.</p>
</li>
<li><p>Without HTTPS, submitting payment details is <strong>risky</strong> and can lead to <strong>data theft</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Stronger Security &amp; Protection</strong></p>
<ul>
<li><p>HTTP sends <strong>plain text data</strong>, making it <strong>easy to hack</strong>.</p>
</li>
<li><p>HTTPS <strong>encrypts all messages</strong>, protecting personal details like <strong>credit cards, passwords, and addresses</strong>.</p>
</li>
<li><p>Prevents cyber threats like <strong>man-in-the-middle attacks and data breaches</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Increases Website Authority &amp; Reputation</strong></p>
<ul>
<li><p><strong>Search engines prefer HTTPS sites</strong> because they are <strong>more trustworthy</strong>.</p>
</li>
<li><p><strong>Users trust HTTPS websites more</strong>, leading to better engagement.</p>
</li>
<li><p>A <strong>padlock icon in the browser</strong> reassures visitors that the site is <strong>safe</strong>.</p>
</li>
</ul>
</li>
<li><p><strong>Faster Performance &amp; Better Analytics</strong></p>
<ul>
<li><p><strong>HTTPS websites load faster</strong> than HTTP ones.</p>
</li>
<li><p>Referral traffic (visitors from ads or social media) is <strong>better tracked</strong> with HTTPS.</p>
</li>
<li><p>Websites using HTTPS get <strong>more accurate analytics</strong>, helping businesses grow.</p>
</li>
</ul>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p><strong>The web is evolving, and so are cyber threats.</strong> If your website is still on <strong>HTTP</strong>, you’re not just losing trust—you’re also risking <strong>data breaches, SEO penalties, and lost customers</strong>. The good news? <strong>Switching to HTTPS is easier and more affordable than ever!</strong> Secure your website today, protect your visitors, and build <strong>a future-proof online presence</strong></p>
<p><strong>Secure your website, protect your users, and stay ahead—make the switch to HTTPS today!</strong></p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[TCP & UDP Protocols]]></title><description><![CDATA[Introduction
Every second, messages, videos, and files move across the internet, connecting people and devices everywhere. But how does all this data travel so smoothly? The answer lies in two important ways of communication—TCP (Transmission Control...]]></description><link>https://blog.devwithjay.com/tcp-udp</link><guid isPermaLink="true">https://blog.devwithjay.com/tcp-udp</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[TCP]]></category><category><![CDATA[UDP]]></category><category><![CDATA[ddos]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Sun, 16 Feb 2025 13:16:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947771674/271404cc-6743-439c-9437-b7d3fff67df0.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>Every second, messages, videos, and files move across the internet, connecting people and devices everywhere. But how does all this data travel so smoothly? The answer lies in two important ways of communication—<strong>TCP (Transmission Control Protocol) and UDP (User Datagram Protocol).</strong></p>
<p>Think of the internet like a busy road. Some vehicles follow strict traffic rules, making sure every passenger reaches safely—this is <strong>TCP</strong>. Others move fast, weaving through traffic without stopping too much—this is <strong>UDP</strong>.</p>
<p>These two methods decide how data moves from one place to another. <strong>TCP</strong> makes sure nothing gets lost, while <strong>UDP</strong> focuses on speed, getting data delivered as quickly as possible. Both are important but used for different things.</p>
<p>In this article, we’ll explore how TCP and UDP work, where they are used, how they function, their benefits, drawbacks, and real-life applications. We’ll also see why they are important for things like web browsing, video calls, and online gaming.</p>
<h2 id="heading-udp-user-datagram-protocol">UDP (User Datagram Protocol)</h2>
<h3 id="heading-what-is-udp">What Is UDP?</h3>
<p>UDP is a basic and widely used protocol for network communication. It works at Layer 4 (Transport Layer) of the OSI model, directly on top of the Internet Protocol (IP) layer.</p>
<p>Unlike other protocols, UDP doesn’t establish a connection before sending data, making it faster but also less reliable—some data packets might get lost along the way. It is also known as the <strong>"fire-and-forget"</strong> protocol as it sends the data and does not care whether the data is received or not.</p>
<h3 id="heading-why-it-is-used">Why It Is Used?</h3>
<p>UDP is great for situations where speed matters more than perfection. It’s used for things like online calls (VoIP) and video streaming because a little bit of missing data (like a quick glitch or static) is better than long delays. That’s why most internet-based phone calls use UDP—it’s better to have a slightly choppy conversation than one with annoying pauses.</p>
<p>The same goes for online gaming, where fast response times are crucial. If a few data packets get lost, it’s still better than lagging behind in the game. Even DNS (which helps your browser find websites) uses UDP because it needs to work quickly and efficiently.</p>
<p>Besides gaming and streaming, UDP is widely used in IoT (Internet of Things) devices, where sensors need to send data quickly and don’t require confirmation. It’s also used in real-time applications like stock market price updates, where speed is more critical than occasional missing data.</p>
<h3 id="heading-main-features-of-udp">Main features of UDP</h3>
<ul>
<li><p><strong>Stateless Protocol:</strong> UDP is stateless, meaning that it doesn't maintain a connection between the sender and receiver. Each datagram (packet) is sent independently, without knowing if the destination is ready or even exists.</p>
</li>
<li><p><strong>No Prior Communication Required:</strong> Since it’s stateless, UDP can send data immediately, making it faster than connection-based protocols like TCP.</p>
</li>
<li><p><strong>Simple and Minimal Header:</strong> UDP's header is only 8 bytes long, much smaller than TCP's header, which means less extra data is added, making it efficient and quick.</p>
</li>
<li><p><strong>Broadcast and Multicast Support:</strong> UDP allows data to be sent to multiple devices at once, making it ideal for applications like live streaming, online multiplayer games, and network discovery services (e.g., DHCP).</p>
</li>
</ul>
<h3 id="heading-udp-packet-format">UDP Packet Format</h3>
<p>A <strong>UDP packet</strong>, also called a <strong>datagram</strong>, has two main parts: a <strong>header</strong> and a <strong>data section</strong>. Its simple structure makes UDP fast and efficient.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947805955/e0c49adc-021b-41ec-a089-9b3916fb12d4.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p><strong>Header</strong> – This is the control information of the message and is <strong>8 bytes</strong> in size.</p>
</li>
<li><p><strong>Data</strong> – This is the actual content being sent and can be any size, up to <strong>65,535 bytes</strong>. It carries the main information, such as a DNS request or a video stream packet.</p>
</li>
</ul>
<h3 id="heading-udp-header-structure"><strong>UDP Header Structure</strong></h3>
<p>The <strong>UDP header</strong> is very small, only <strong>8 bytes long</strong>, which makes it fast and efficient.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947821134/d1b3d538-4259-4f64-987b-ba3d79e53aaa.png" alt class="image--center mx-auto" /></p>
<p><strong>UDP Header Fields:</strong></p>
<ol>
<li><p><strong>Source Port (16 bits)</strong> – Identifies the port of the sending application. This is used by the receiver to know where to send a response.</p>
</li>
<li><p><strong>Destination Port (16 bits)</strong> – Identifies the port of the receiving application. This tells the receiver’s system which application should process the incoming datagram.</p>
</li>
<li><p><strong>Length (16 bits)</strong> – Specifies the total length of the UDP datagram, including both the header and the data. This helps in determining the boundaries of the datagram.</p>
</li>
<li><p><strong>Checksum (16 bits)</strong> – <strong>:</strong> Used for error-checking of the header and data. This ensures the integrity of the data during transmission. It is <strong>optional in IPv4</strong> but <strong>mandatory in IPv6</strong>.</p>
</li>
</ol>
<p>The checksum makes sure that the data is not altered(changed) during transmission. It is calculated using the pseudo header, UDP header, and UDP payload.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947843671/05c5508f-6f6d-4249-89ae-6059252b70a5.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-udp-ports">UDP Ports</h3>
<p><strong>UDP Ports</strong> help applications and services communicate without needing a connection. Since UDP is <strong>connectionless</strong>, these port numbers allow data to be sent without a persistent link between sender and receiver.</p>
<p>UDP ports range from <strong>0 to 65,535</strong> and are divided into three types:</p>
<ol>
<li><p><strong>Well-Known Ports (0-1023)</strong> – Used for standard services like:</p>
<ul>
<li><p><strong>DNS (Port 53)</strong> – Resolves domain names.</p>
</li>
<li><p><strong>DHCP (Ports 67/68)</strong> – Assigns IP addresses.</p>
</li>
<li><p><strong>NTP (Port 123)</strong> – Synchronizes time.</p>
</li>
</ul>
</li>
<li><p><strong>Registered Ports (1024-49151)</strong> – Assigned to specific applications.</p>
</li>
<li><p><strong>Dynamic/Private Ports (49152-65535)</strong> – Used temporarily for short-lived connections, often within a system.</p>
</li>
</ol>
<p>Unlike TCP ports, which require a connection, UDP ports remain <strong>stateless</strong>, meaning there is no session tracking. This makes UDP <strong>faster</strong> but <strong>less reliable</strong>, as it does not confirm if data is received.</p>
<p><strong>Common Uses of UDP Ports:</strong></p>
<ul>
<li><p>Streaming (YouTube, Netflix)</p>
</li>
<li><p>VoIP (Skype, Zoom)</p>
</li>
<li><p>Online Gaming</p>
</li>
<li><p>DNS Queries</p>
</li>
<li><p>Time Synchronization</p>
</li>
</ul>
<h3 id="heading-working-of-udp">Working of UDP</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947854853/4ee05267-65af-4b47-bfbe-b2ac08b68c56.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Packaging the Data -</strong></p>
<ul>
<li><p>The process starts when an application decides to send data using UDP. This data could be anything from a <strong>DNS request</strong> to a <strong>video streaming packet</strong>.</p>
</li>
<li><p>The application <strong>packages</strong> the data into a <strong>UDP datagram</strong> to prepare it for transmission.</p>
</li>
</ul>
</li>
<li><p><strong>Adding Headers &amp; Creating the Datagram -</strong></p>
<ul>
<li><p>The <strong>UDP layer</strong> then adds a small header to this datagram.</p>
</li>
<li><p>This header contains:</p>
<ul>
<li><p><strong>Source Port and Destination Port</strong> – These ensure the data reaches the correct application.</p>
</li>
<li><p><strong>Length of the Datagram</strong> – Specifies the size of the data.</p>
</li>
<li><p><strong>Checksum</strong> – Helps detect errors during transmission.</p>
</li>
</ul>
</li>
<li><p>The <strong>UDP header is added to the application data</strong>, forming a complete UDP <strong>datagram</strong>. This datagram is then packed into an <strong>IP packet</strong> for delivery.</p>
</li>
</ul>
</li>
<li><p><strong>Passing Through the IP Layer &amp; Network Layer</strong></p>
<ul>
<li><p>The UDP datagram moves to the <strong>Internet Protocol (IP) layer</strong>, where another header is added.</p>
</li>
<li><p>This <strong>IP header</strong> contains:</p>
<ul>
<li><p><strong>Sender’s IP Address</strong> – Identifies where the data is coming from.</p>
</li>
<li><p><strong>Receiver’s IP Address</strong> – Specifies where the data needs to go.</p>
</li>
</ul>
</li>
<li><p>The <strong>IP packet</strong> is then wrapped inside a <strong>network frame</strong> (like Ethernet) so it can be sent over the physical network.</p>
</li>
</ul>
</li>
<li><p><strong>Sending the Data Over the Network</strong></p>
<ul>
<li>The network frame is <strong>sent across the internet</strong>, passing through routers and network segments until it reaches the final destination.</li>
</ul>
</li>
<li><p><strong>Receiving &amp; Processing the Data</strong></p>
<p> Once the data arrives at the destination:</p>
<ul>
<li><p>The <strong>network frame is removed</strong>, revealing the <strong>IP packet</strong>.</p>
</li>
<li><p>The <strong>IP layer</strong> processes the packet and extracts the <strong>UDP datagram</strong>.</p>
</li>
<li><p>The <strong>UDP layer</strong> verifies the checksum (if used) and checks the <strong>destination port</strong> to see which application needs the data.</p>
</li>
</ul>
</li>
<li><p><strong>Delivering Data to the Application</strong></p>
<ul>
<li><p>Finally, the <strong>receiving application</strong> extracts the original data from the UDP datagram and processes it.</p>
</li>
<li><p>This could mean:</p>
<ul>
<li><p>A video streaming app <strong>plays the video smoothly</strong>.</p>
</li>
<li><p>A game <strong>updates player actions in real-time</strong>.</p>
</li>
<li><p>A browser <strong>resolves a website address using DNS</strong>.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<h3 id="heading-advantages-of-udp">Advantages of UDP</h3>
<ol>
<li><p><strong>No Connection Needed</strong> – UDP does not require a connection between sender and receiver, making it faster and more efficient.</p>
</li>
<li><p><strong>Supports Broadcast and Multicast</strong> – It allows data to be sent to multiple devices at once, which is useful for streaming and gaming.</p>
</li>
<li><p><strong>Works on Various Networks</strong> – UDP can function across different types of networks, making it highly adaptable.</p>
</li>
<li><p><strong>Ideal for Real-Time Data</strong> – It is commonly used for live video, online gaming, and VoIP because of its low latency.</p>
</li>
<li><p><strong>Delivers Data Even If Some Parts Are Missing</strong> – Unlike TCP, UDP does not wait for all parts of the data before delivering it, making it faster in real-time scenarios.</p>
</li>
</ol>
<h3 id="heading-disadvantages-of-udp">Disadvantages of UDP</h3>
<ol>
<li><p><strong>No Acknowledgment of Delivery</strong> – There is no way to confirm whether the data was successfully received.</p>
</li>
<li><p><strong>No Order Guarantee</strong> – UDP does not track the sequence of packets, so data may arrive out of order.</p>
</li>
<li><p><strong>Unreliable Due to Being Connectionless</strong> – Since UDP does not establish a connection before sending data, some packets may get lost without any recovery mechanism.</p>
</li>
<li><p><strong>Packets Can Be Dropped in Collisions</strong> – In case of network congestion or packet collision, routers tend to drop UDP packets more often than TCP packets.</p>
</li>
<li><p><strong>No Built-in Error Handling</strong> – If an error is detected in a packet, UDP does not attempt to fix or resend it, which can lead to data loss.</p>
</li>
</ol>
<h3 id="heading-applications-of-udp">Applications of UDP</h3>
<ol>
<li><p><strong>Streaming Audio &amp; Video</strong> – UDP is widely used in platforms like YouTube Live, Netflix, and Spotify because it ensures smooth playback with minimal delay, even if some data is lost.</p>
</li>
<li><p><strong>Online Gaming</strong> – Multiplayer games like PUBG, Call of Duty, and Fortnite use UDP for fast communication between players, reducing lag.</p>
</li>
<li><p><strong>DNS (Domain Name System) Queries</strong> – When you type a website name, UDP helps quickly convert it into an IP address, allowing faster web browsing.</p>
</li>
<li><p><strong>Network Monitoring</strong> – Tools that track network performance use UDP for fast, lightweight data exchange without delays.</p>
</li>
<li><p><strong>Multicasting</strong> – UDP enables sending data to multiple users at once, making it useful for IPTV, live broadcasts, and real-time notifications.</p>
</li>
<li><p><strong>Routing Protocols</strong> – Some network routing protocols, like RIP (Routing Information Protocol), rely on UDP to exchange routing updates efficiently.</p>
</li>
</ol>
<h3 id="heading-how-is-udp-used-in-ddos-attacks"><strong>How is UDP used in DDoS attacks?</strong></h3>
<p>UDP has some risks, but they’re usually not a big deal in most cases. However, because UDP doesn’t need a handshake before sending data, attackers can misuse it to overwhelm a server with fake traffic. This is called a <strong>UDP flood attack</strong>.</p>
<p>In this, the attacker sends tons of UDP packets to random ports on a target computer. The target tries to respond with ICMP messages saying those ports are unreachable. Since this requires processing power, the server can get overloaded and stop working properly, blocking real users from accessing it.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947867595/87908274-3aa0-4ef5-b495-718e8f1e0da6.png" alt class="image--center mx-auto" /></p>
<p>To prevent this, organizations use different strategies. One way is to <strong>limit how many ICMP responses a server sends</strong>, though this can sometimes block legitimate traffic too. Another way is to <strong>route UDP traffic through a distributed network</strong> of multiple data centers, so no single server gets overwhelmed.</p>
<p>Another common UDP-based attack is the <strong>UDP amplification attack</strong>, where an attacker sends small requests to open UDP services like DNS or NTP with a spoofed source IP (the victim’s IP). These services respond with much larger data packets, overwhelming the victim’s bandwidth.</p>
<h2 id="heading-tcp-transmission-control-protocol">TCP (Transmission Control Protocol)</h2>
<h3 id="heading-what-is-tcp">What Is TCP?</h3>
<p>TCP (Transmission Control Protocol) is one of the most commonly used network protocols. It operates at Layer 4 (Transport Layer) of the OSI model, sitting directly on top of the Internet Protocol (IP) layer.</p>
<p>Unlike UDP, TCP establishes a connection before sending data, ensuring that every packet reaches its destination correctly and in the right order. This makes TCP highly reliable but also a bit slower compared to UDP.</p>
<h3 id="heading-why-it-is-used-1">Why It Is Used?</h3>
<p>TCP is used in situations where <strong>accuracy and reliability</strong> matter more than speed. It’s the backbone of internet communication when you need <strong>guaranteed</strong> data delivery.</p>
<p>For example, <strong>web browsing (HTTP/HTTPS)</strong> relies on TCP because when you load a webpage, you want <strong>every part</strong> of the page—text, images, and videos—to arrive <strong>intact and in order</strong>. Imagine reading an article where random paragraphs go missing—that’s what TCP prevents!</p>
<p>The same goes for <strong>file transfers (FTP, SFTP)</strong> and <strong>email (SMTP, IMAP, POP3)</strong>. If you’re downloading a file, you can’t afford to have missing chunks—it would corrupt the file. TCP makes sure every part is received properly, even if it has to <strong>retransmit</strong> some packets.</p>
<p>Another important use case is <strong>online banking and transactions</strong>. When you transfer money or send sensitive data, you don’t want <strong>even a single bit</strong> to be lost or arrive out of order. TCP ensures <strong>secure, complete, and error-free</strong> transmission.</p>
<p>Even video streaming platforms like <strong>Netflix and YouTube</strong> use TCP in certain cases, especially when buffering is preferred over missing video frames. This ensures that a high-quality stream is delivered without errors.</p>
<h3 id="heading-main-features-of-tcp">Main Features of TCP</h3>
<ul>
<li><p><strong>Reliable Transmission:</strong> TCP makes sure that all data is delivered correctly and in the right order.</p>
</li>
<li><p><strong>Error Detection and Correction:</strong> It checks for errors using checksums and resends data if something goes wrong.</p>
</li>
<li><p><strong>Three-Way Handshake:</strong> Before sending data, TCP sets up a connection using a three-step process (SYN, SYN-ACK, and ACK) to ensure both devices are ready to communicate.</p>
</li>
<li><p><strong>Stateful Protocol:</strong> TCP keeps track of the connection, making communication stable and reliable.</p>
</li>
<li><p><strong>Multiplexing:</strong> It allows multiple applications on the same device to communicate at the same time using different ports.</p>
</li>
<li><p><strong>Addressing:</strong> TCP uses both IP addresses and port numbers to create unique paths for data to travel.</p>
</li>
</ul>
<h3 id="heading-tcp-packet-format">TCP Packet Format</h3>
<p>A <strong>TCP segment</strong> is placed inside an <strong>IP packet</strong> before being sent over the network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947901935/51c89e49-0913-42c6-9d63-8c65e2633334.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Header – The header size starts at 20 bytes but can grow up to 60 bytes if extra options are added.</p>
</li>
<li><p>Data – The data section contains the actual information being sent, such as a webpage, file, or message, and can vary in size depending on the network conditions and TCP settings.</p>
</li>
</ul>
<h3 id="heading-tcp-header-structure">TCP Header Structure</h3>
<p>The TCP header starts at <strong>20 bytes</strong>, providing reliability and control but adding more overhead than UDP.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947912541/8d9b2154-f8ac-436b-89f0-a6a4a3874893.png" alt class="image--center mx-auto" /></p>
<p><strong>TCP Header Fields:</strong></p>
<ol>
<li><p><strong>Source Port (16 bits):</strong> Identifies the port number of the sender’s application.</p>
</li>
<li><p><strong>Destination Port (16 bits):</strong> Identifies the port number of the receiving application.</p>
</li>
<li><p><strong>Sequence Number (32 bits):</strong> Ensures that data packets are reassembled in the correct order upon arrival.</p>
</li>
<li><p><strong>Acknowledgment Number (32 bits):</strong> Indicates the next expected byte from the sender, confirming successful receipt of previous data.</p>
</li>
<li><p><strong>Data Offset (4 bits):</strong> Specifies the length of the TCP header in multiples of 32-bit words.</p>
</li>
<li><p><strong>Reserved (3 bits):</strong> Reserved for future use and always set to zero.</p>
</li>
<li><p><strong>Flags (9 bits):</strong> Control flags that help manage TCP communication, including:</p>
<ul>
<li><p><strong>URG:</strong> Indicates that the urgent pointer field contains important data.</p>
</li>
<li><p><strong>ACK:</strong> Confirms receipt of data and acknowledges the next expected byte.</p>
</li>
<li><p><strong>PSH:</strong> Requests immediate delivery of data to the receiving application.</p>
</li>
<li><p><strong>RST:</strong> Resets the connection if an error occurs or the communication is disrupted.</p>
</li>
<li><p><strong>SYN:</strong> Initiates a new connection and synchronizes sequence numbers.</p>
</li>
<li><p><strong>FIN:</strong> Indicates that the sender has no more data to transmit.</p>
</li>
<li><p><strong>ECE (Explicit Congestion Notification Echo):</strong> Alerts the sender that network congestion is occurring, allowing it to reduce transmission speed.</p>
</li>
<li><p><strong>CWR (Congestion Window Reduced):</strong> Informs the receiver that the sender has adjusted its data flow in response to congestion.</p>
</li>
<li><p><strong>NS (Nonce Sum):</strong> An experimental flag that helps prevent data tampering during transmission.</p>
</li>
</ul>
</li>
<li><p><strong>Window Size (16 bits):</strong> Specifies the amount of data (in bytes) the receiver is ready to accept at one time. The default maximum is <strong>65,535 bytes</strong>, but this can be increased using the window scaling option.</p>
</li>
<li><p><strong>Checksum (16 bits):</strong> Used to verify data integrity and detect transmission errors in the header and data.</p>
</li>
<li><p><strong>Urgent Pointer (16 bits):</strong> Points to urgent data if the <strong>URG flag</strong> is set, ensuring it is processed immediately.</p>
</li>
<li><p><strong>Options (variable length):</strong> Allows additional settings to enhance TCP functionality and performance. The header is padded to maintain proper alignment.</p>
</li>
<li><p><strong>Padding (variable length):</strong> Extra bits added to ensure the header length is a multiple of <strong>32 bits</strong> for proper data alignment.</p>
</li>
</ol>
<h3 id="heading-tcp-ports">TCP Ports</h3>
<p>TCP ports help applications and services communicate by establishing reliable connections. Since TCP is <strong>connection-oriented</strong>, these port numbers ensure that data is sent and received in an organized and error-free manner.</p>
<p>TCP ports range from <strong>0 to 65,535</strong> and are categorized into three types:</p>
<ol>
<li><p><strong>Well-Known Ports (0-1023):</strong> Reserved for standard services like:</p>
<ul>
<li><p><strong>HTTP (Port 80):</strong> Handles web traffic.</p>
</li>
<li><p><strong>HTTPS (Port 443):</strong> Secure web browsing.</p>
</li>
<li><p><strong>FTP (Port 21):</strong> File transfers.</p>
</li>
<li><p><strong>SSH (Port 22):</strong> Secure remote access.</p>
</li>
</ul>
</li>
<li><p><strong>Registered Ports (1024-49151):</strong> Assigned to specific applications and services.</p>
</li>
<li><p><strong>Dynamic/Private Ports (49152-65535):</strong> Used temporarily for short-lived connections, such as browsing sessions or streaming.</p>
</li>
</ol>
<p>Unlike <strong>UDP ports</strong>, which are <strong>stateless</strong>, TCP ports maintain a connection for <strong>session tracking</strong> and <strong>error handling</strong>, making TCP more reliable but slightly slower.</p>
<p><strong>Common Uses of TCP Ports:</strong></p>
<ul>
<li><p>Web Browsing (HTTP - Port 80, HTTPS - Port 443)</p>
</li>
<li><p>File Transfers (FTP - Port 21, SFTP - Port 22)</p>
</li>
<li><p>Email Services (SMTP - Port 25, IMAP - Port 143, POP3 - Port 110)</p>
</li>
<li><p>Remote Access (SSH - Port 22, Telnet - Port 23, RDP - Port 3389)</p>
</li>
<li><p>Database Communication (MySQL - Port 3306, PostgreSQL - Port 5432, SQL Server - Port 1433)</p>
</li>
<li><p>Online Transactions &amp; Banking</p>
</li>
<li><p>Cloud Services &amp; API Communications</p>
</li>
<li><p>Secure Communication (TLS/SSL - Port 443)</p>
</li>
</ul>
<h3 id="heading-tcp-working">TCP Working</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947924483/92710da2-3411-43ff-846a-07fb0b27b2c6.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Packaging the Data</strong></p>
<ul>
<li><p>The process begins when an application decides to send data using TCP. This data could be anything from a web page request to an email or a file transfer.</p>
</li>
<li><p>TCP breaks the data into segments and prepares it for transmission.</p>
</li>
</ul>
</li>
<li><p><strong>Adding Headers &amp; Creating the TCP Segment</strong></p>
<ul>
<li><p>The TCP layer adds a <strong>header</strong> to each segment, which contains:</p>
<ul>
<li><p><strong>Source Port and Destination Port</strong> – Ensure the data reaches the correct application.</p>
</li>
<li><p><strong>Sequence Number</strong> – Keeps track of the order of data packets.</p>
</li>
<li><p><strong>Acknowledgment Number</strong> – Confirms received data.</p>
</li>
<li><p><strong>Flags (SYN, ACK, FIN, etc.)</strong> – Controls the communication process.</p>
</li>
<li><p><strong>Checksum</strong> – Helps detect transmission errors.</p>
</li>
</ul>
</li>
<li><p>This <strong>TCP segment</strong> is then packed into an <strong>IP packet</strong> for delivery.</p>
</li>
</ul>
</li>
<li><p><strong>Establishing a Connection (Three-Way Handshake)</strong></p>
<p> Before sending data, TCP establishes a connection using a three-step handshake:</p>
<ol>
<li><p><strong>SYN</strong> – The client sends a SYN packet to the server to initiate a connection.</p>
</li>
<li><p><strong>SYN-ACK</strong> – The server sends a <strong>SYN-ACK packet</strong> to confirm it received the <strong>SYN packet</strong> and to set up its own sequence number for communication.</p>
</li>
<li><p><strong>ACK</strong> – The client sends an ACK packet, completing the handshake and establishing a connection.</p>
</li>
</ol>
</li>
<li><p><strong>Passing Through the IP &amp; Network Layers</strong></p>
<ul>
<li><p>The TCP segment moves to the <strong>IP layer</strong>, where another header is added.</p>
</li>
<li><p>The <strong>IP header</strong> contains:</p>
<ol>
<li><p><strong>Sender’s IP Address</strong> – Identifies the source.</p>
</li>
<li><p><strong>Receiver’s IP Address</strong> – Identifies the destination.</p>
</li>
</ol>
</li>
<li><p>The IP packet is then wrapped inside a <strong>network</strong> <strong>frame</strong> (like Ethernet) and sent over the physical network.</p>
</li>
</ul>
</li>
<li><p><strong>Sending Data Over the Network</strong></p>
<ul>
<li>The network frame travels across the internet, passing through <strong>routers and network segments</strong>, until it reaches the destination.</li>
</ul>
</li>
<li><p><strong>Receiving &amp; Processing the Data</strong></p>
<p> Once the data arrives at the destination:</p>
<ul>
<li><p>The <strong>network frame</strong> is removed, revealing the <strong>IP packet</strong>.</p>
</li>
<li><p>The <strong>IP layer</strong> processes the packet and extracts the <strong>TCP segment</strong>.</p>
</li>
<li><p>The <strong>TCP layer</strong> verifies the <strong>checksum</strong>, <strong>reorders segments</strong>, and <strong>removes duplicates</strong> if necessary.</p>
</li>
<li><p>The <strong>acknowledgment number</strong> confirms successful receipt.</p>
</li>
</ul>
</li>
<li><p><strong>Delivering Data to the Application</strong></p>
<ul>
<li><p>Finally, the receiving application extracts the <strong>original data</strong> and processes it.</p>
</li>
<li><p>This could mean:</p>
<ul>
<li><p>A web browser loads a page.</p>
</li>
<li><p>An email application displays a message.</p>
</li>
<li><p>A file transfer completes successfully.</p>
</li>
</ul>
</li>
</ul>
</li>
</ol>
<ol start="8">
<li><strong>Closing the Connection (Four-Way Handshake)</strong></li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947936124/baced4f4-3096-4679-b269-fff865f9774a.png" alt class="image--center mx-auto" /></p>
<ul>
<li><p>Once data transmission is complete, TCP <strong>gracefully closes the connection</strong> using a <strong>four-step process</strong>:</p>
<ol>
<li><p><strong>FIN</strong> – The sender requests to end the session.</p>
</li>
<li><p><strong>ACK</strong> – The receiver acknowledges the request.</p>
</li>
<li><p><strong>FIN</strong> – The receiver also requests closure.</p>
</li>
<li><p><strong>ACK</strong> – The sender confirms, and the connection is closed.</p>
</li>
</ol>
</li>
</ul>
<h3 id="heading-advantages-of-tcp">Advantages of TCP</h3>
<ul>
<li><p><strong>Reliable Transmission</strong> – TCP ensures data is delivered completely and in the correct order.</p>
</li>
<li><p><strong>Error Detection &amp; Correction</strong> – Uses checksums and retransmission to fix lost or corrupted data.</p>
</li>
<li><p><strong>Connection-Oriented</strong> – Establishes a connection before data transfer, ensuring communication is stable.</p>
</li>
<li><p><strong>Flow &amp; Congestion Control</strong> – Adjusts data flow to prevent overwhelming the receiver or network.</p>
</li>
<li><p><strong>Data Sequencing</strong> – Assigns sequence numbers to packets so they arrive in the correct order.</p>
</li>
<li><p><strong>Supports Acknowledgment</strong> – Confirms the receipt of data, reducing the chances of data loss.</p>
</li>
</ul>
<h3 id="heading-disadvantages-of-tcp"><strong>Disadvantages of TCP</strong></h3>
<ul>
<li><p><strong>Slower Than UDP</strong> – The extra reliability features make TCP slower.</p>
</li>
<li><p><strong>Higher Overhead</strong> – Larger headers and acknowledgments increase data size and processing time.</p>
</li>
<li><p><strong>Connection Setup Required</strong> – The three-way handshake adds a delay before data can be sent.</p>
</li>
<li><p><strong>Not Ideal for Real-Time Applications</strong> – Retransmissions can cause delays in gaming and live streaming.</p>
</li>
<li><p><strong>Consumes More Resources</strong> – TCP uses more system memory and processing power due to session tracking.</p>
</li>
</ul>
<h3 id="heading-applications-of-tcp"><strong>Applications of TCP</strong></h3>
<ul>
<li><p><strong>Web Browsing (HTTP/HTTPS)</strong> – Ensures web pages load completely and correctly.</p>
</li>
<li><p><strong>File Transfers (FTP, SFTP)</strong> – Guarantees files are transferred without errors.</p>
</li>
<li><p><strong>Email Services (SMTP, IMAP, POP3)</strong> – Ensures emails are sent and received properly.</p>
</li>
<li><p><strong>Remote Access (SSH, Telnet, RDP)</strong> – Provides secure and stable connections to remote devices.</p>
</li>
<li><p><strong>Online Transactions &amp; Banking</strong> – Ensures secure and error-free money transfers.</p>
</li>
<li><p><strong>Database Communication</strong> – Used by SQL-based databases for accurate data retrieval.</p>
</li>
<li><p><strong>Cloud Services &amp; APIs</strong> – Helps in reliable data exchange between applications.</p>
</li>
</ul>
<h3 id="heading-how-tcp-handles-congestion">How TCP Handles Congestion?</h3>
<p>TCP includes <strong>built-in congestion control</strong> to prevent network overload and ensure smooth data transmission. It uses the following methods:</p>
<ul>
<li><p><strong>Slow Start:</strong> TCP begins by sending small amounts of data and gradually increases the speed until it finds the network’s capacity.</p>
</li>
<li><p><strong>Congestion Avoidance:</strong> If congestion is detected, TCP slows down data transmission to prevent further delays or packet loss.</p>
</li>
<li><p><strong>Fast Retransmit &amp; Recovery:</strong> If a packet is lost, TCP quickly resends it instead of waiting for a timeout.</p>
</li>
<li><p><strong>Selective Acknowledgment (SACK):</strong> Instead of acknowledging each packet individually, TCP confirms multiple received packets at once, reducing unnecessary retransmissions.</p>
</li>
</ul>
<h3 id="heading-how-tcp-prevents-cyber-attacks"><strong>How TCP Prevents Cyber Attacks?</strong></h3>
<p>Although TCP is a reliable protocol, it is still vulnerable to certain <strong>cyber attacks</strong>.</p>
<p>Some common threats include:</p>
<ul>
<li><p><strong>SYN Flood Attacks:</strong> Attackers send a large number of SYN requests but never complete the handshake, causing the server to become overloaded.</p>
</li>
<li><p><strong>Session Hijacking:</strong> Hackers intercept active TCP connections to steal or modify sensitive data.</p>
</li>
<li><p><strong>TCP Reset Attacks:</strong> Attackers send fake <strong>RST (reset) packets</strong> to forcefully close connections.</p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1739947946106/1eeebaa4-a3f0-4f2c-a23c-9a7e59924a84.png" alt class="image--center mx-auto" /></p>
<p>To protect against these attacks, <strong>mitigation strategies</strong> include:</p>
<ul>
<li><p><strong>Firewalls &amp; Intrusion Prevention Systems (IPS):</strong> Monitor and block suspicious traffic.</p>
</li>
<li><p><strong>SYN Cookies:</strong> Prevent SYN flood attacks by delaying resource allocation until the handshake is complete.</p>
</li>
<li><p><strong>Encryption &amp; Secure Protocols (TLS/SSL):</strong> Protect data from interception and tampering.</p>
</li>
<li><p><strong>Rate Limiting:</strong> Restrict excessive requests from a single source to prevent server overload.</p>
</li>
</ul>
<h2 id="heading-conclusion">Conclusion</h2>
<p>TCP and UDP help data move across the internet in different ways. TCP is reliable and ensures that all data arrives correctly, making it great for web browsing, emails, and file downloads. UDP focuses on speed, which is useful for online games, video calls, and streaming, even if some data is lost.</p>
<p>Choosing the right one depends on the need—TCP for accuracy and UDP for fast delivery. Both work together to keep the internet running smoothly.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[The Internet Protocol]]></title><description><![CDATA[Introduction
Everyday, billions of devices—like computers, smartphones, and smart TVs—talk to each other over the internet. But how do they know where to send and receive data? The answer is Internet Protocol (IP).
Think of the internet like a huge p...]]></description><link>https://blog.devwithjay.com/internet-protocol</link><guid isPermaLink="true">https://blog.devwithjay.com/internet-protocol</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[ip address]]></category><category><![CDATA[IP]]></category><category><![CDATA[protocols]]></category><category><![CDATA[subnet]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Tue, 04 Feb 2025 16:22:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738864706537/6f3a77d0-1b60-4406-a040-848c7ce32b40.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>Everyday, billions of devices—like computers, smartphones, and smart TVs—talk to each other over the internet. But how do they know where to send and receive data? The answer is <strong>Internet Protocol (IP).</strong></p>
<p>Think of the internet like a huge postal system. Just as houses have unique addresses, every device connected to the internet has a unique IP address. When you send data (like a message or a video), it’s like mailing a letter. The internet uses IP to figure out where the letter needs to go and how to deliver it.</p>
<p>In this article, we’ll explore how the internet works, how IP addresses help devices communicate, and why this system is so important.</p>
<h2 id="heading-understanding-networks-and-the-internet"><strong>Understanding Networks and the Internet</strong></h2>
<h3 id="heading-what-is-a-network">What is a Network?</h3>
<p>A network is a group of computers that are connected and can share information with each other. It’s similar to a group of friends who stay in touch, share news, and work together on different activities.</p>
<p>Computers within a network can communicate with each other, and since networks are also connected to one another, a computer in one part of the world can send information to another computer far away.</p>
<p>Now that we know what a network is, let’s see how all these networks come together to form the <strong>internet</strong>.</p>
<h3 id="heading-what-is-the-internet">What is the Internet?</h3>
<p>The Internet is a huge <strong>network</strong> made up of millions of smaller networks that are all connected. It connects computers, smartphones, tablets, and other devices all over the world.</p>
<p>In fact, the word “Internet” comes from the idea of <strong>interconnected networks</strong>.</p>
<p>Computers connect to each other and to the Internet using <strong>wires, cables, radio waves, and other types of network technology</strong>. When data is sent over the Internet, it is converted into tiny signals of light or electricity, called <strong>bits</strong>. The receiving computer then reads and understands these bits.</p>
<p>The speed of the Internet depends on how many bits can pass through the wires, cables, or radio waves at the same time. The more bits that can travel at once, the faster the Internet works.</p>
<p>To make communication possible, the internet relies on a set of rules known as <strong>protocols</strong>.</p>
<h2 id="heading-protocols">Protocols</h2>
<p>In networking, a <strong>protocol</strong> is a set of rules that computers follow to communicate with each other. These rules make sure that information is sent and received correctly.</p>
<p>Even if two devices are different—like a Windows laptop and an iPhone—they can still communicate because they follow the same <strong>protocols</strong>.</p>
<p><strong>Examples of Protocols:</strong></p>
<ul>
<li><p><strong>IP (Internet Protocol)</strong> – Helps send data to the right place on a network.</p>
</li>
<li><p><strong>TCP (Transmission Control Protocol)</strong> – Makes sure data is delivered fully and in the correct order.</p>
</li>
<li><p><strong>UDP (User Datagram Protocol)</strong> – Sends data fast but doesn’t check if it was received.</p>
</li>
<li><p><strong>DNS (Domain Name System)</strong> – Changes website names into IP addresses so computers can find them.</p>
</li>
</ul>
<p>One of the most important protocols that keeps everything running smoothly is the Internet Protocol (IP).</p>
<h2 id="heading-understanding-ip-internet-protocol">Understanding IP (Internet Protocol)</h2>
<h3 id="heading-what-is-an-ip">What is an IP?</h3>
<p>The <strong>Internet Protocol (IP)</strong> is the system that allows computers and devices to send and receive data across networks.</p>
<p>When you send something over the internet—like an email or a website request—your data is broken into small pieces called <strong>packets</strong>. Each packet carries instructions (IP information) on where to go and how to get there.</p>
<h3 id="heading-why-do-we-need-an-ip">Why do we need an IP?</h3>
<p>Every device connected to the internet needs a <strong>unique IP address</strong> so that data knows where to go. Without IP addresses, sending information over the internet would be like mailing a letter <strong>without an address</strong>—it wouldn’t reach the right place!</p>
<p>When data is sent over the internet, the sender and receiver might be in different places, using networks with different speeds. To handle this, <strong>protocols</strong> manage the flow of data and decide which device can use the connection at a given time.</p>
<p>Since IP is the backbone of communication, let’s see how it works through IP addresses.</p>
<h2 id="heading-ip-addresses">IP Addresses</h2>
<p>An <strong>IP address</strong> is a unique number assigned to every device or website connected to the Internet. It looks like a series of numbers, such as <strong>192.168.1.1</strong>.</p>
<p>It is a <strong>Layer</strong> <strong>3</strong> property, meaning it helps devices communicate on a network.</p>
<p><strong>Types of IP Addresses:</strong></p>
<ol>
<li><p><strong>Dynamic IP Address</strong> – Assigned <strong>automatically</strong> by something called <strong>DHCP (Dynamic Host Configuration Protocol)</strong>. These addresses can change over time.</p>
</li>
<li><p><strong>Static IP Address</strong> – Manually assigned and does not change.</p>
</li>
</ol>
<p>Every IP address has <strong>two</strong> <strong>parts</strong>:</p>
<ol>
<li><p><strong>Network Portion</strong> - Identifies the network the device belongs to.</p>
</li>
<li><p><strong>Host Portion</strong> – Identifies the specific device within that network.</p>
</li>
</ol>
<p>Since these numbers are hard to remember, the <strong>DNS (Domain Name System)</strong> converts website names into IP addresses, as explained in one of my previous article on <a target="_blank" href="https://blog.devwithjay.com/dns-demystified"><strong>DNS</strong></a>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738575761535/d347c8d8-3e85-479d-9eec-ead1918d00ab.png" alt class="image--center mx-auto" /></p>
<p>To better manage networks, IP addresses are structured with subnet masks.</p>
<h2 id="heading-subnet-mask-and-its-importance">Subnet Mask and Its Importance</h2>
<h3 id="heading-what-is-a-subnet"><strong>What is a Subnet?</strong></h3>
<p>A subnet is a way to divide a big network into smaller, more manageable parts.</p>
<h3 id="heading-what-is-a-subnet-mask"><strong>What is a Subnet Mask?</strong></h3>
<p>A subnet mask determines which part of an IP address belongs to the network and which part belongs to the host.</p>
<p>For example: 1<strong>92.168.1.1/24</strong></p>
<ul>
<li><p><strong>/24</strong> means the first <strong>24 bits</strong> represent the <strong>network portion</strong>.</p>
</li>
<li><p>The remaining <strong>8 bits</strong> are used for the <strong>host portion</strong>, allowing multiple devices within that network.</p>
</li>
</ul>
<h3 id="heading-why-is-this-important"><strong>Why is this Important?</strong></h3>
<p>The subnet mask helps devices determine whether another IP address belongs to the <strong>same network</strong> or if it needs to communicate through a <strong>router</strong>.</p>
<p>If the destination IP is <strong>in the same subnet</strong>, data is sent <strong>directly</strong> using <strong>MAC addresses</strong>. If it is <strong>outside the subnet</strong>, the packet is sent to the <strong>default gateway</strong>.</p>
<h2 id="heading-default-gateway">Default Gateway</h2>
<h3 id="heading-what-is-it">What is It?</h3>
<p>The <strong>default gateway</strong> is the router that connects a subnet to other networks. Each network has a <strong>router</strong> (gateway) that knows how to forward packets to the correct destination.</p>
<p>A router has <strong>multiple interfaces</strong>, each belonging to a different subnet.</p>
<h3 id="heading-how-it-works"><strong>How It Works?</strong></h3>
<p>If a computer wants to communicate with another device in the same subnet, it sends the data directly.</p>
<p>If a computer needs to communicate with a device outside its subnet, the data is sent to the default gateway, which then forwards it to the correct destination.</p>
<h2 id="heading-ip-packets">IP Packets</h2>
<h3 id="heading-what-is-it-1">What is It?</h3>
<p>When we think about an <strong>IP packet</strong>, we usually see it as <strong>data with a source and destination IP address</strong>. However, there’s much more to it!</p>
<p>An IP packet has <strong>two main parts</strong>:</p>
<ol>
<li><p><strong>Header</strong> – Contains important details for routing and network control.</p>
</li>
<li><p><strong>Data</strong> – The actual information being sent.</p>
</li>
</ol>
<p>Although we mostly focus on the <strong>data</strong> being sent, the <strong>header</strong> is just as important because it helps with <strong>routing, troubleshooting, and error handling</strong>.</p>
<p>The <strong>header size</strong> can range from <strong>20 to 60 bytes</strong>, depending on whether optional fields are included. While this adds extra data, it ensures that packets are delivered <strong>smoothly and efficiently</strong>.</p>
<p>The <strong>data section</strong> can hold up to <strong>65,536 bytes</strong>, but in most cases, it is limited to <strong>around 1500 bytes</strong> due to network restrictions like the <strong>Maximum Transmission Unit (MTU)</strong>.</p>
<p>If a packet is too large, it may be <strong>broken into smaller pieces (fragments)</strong>, but this is usually avoided because it can make data transfer <strong>more complicated</strong>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738677796347/e805a5af-c486-455f-a408-7d68028e2ceb.png" alt class="image--center mx-auto" /></p>
<ol>
<li><p><strong>Version</strong> – Shows whether the packet is using <strong>IPv4</strong> or <strong>IPv6</strong>.</p>
</li>
<li><p><strong>Header Length</strong> – Indicates the size of the header.</p>
</li>
<li><p><strong>Type of Service</strong> – Helps decide how important the packet is compared to others. Some packets need to be sent quickly, like video calls, while others can wait.</p>
</li>
<li><p><strong>Total Length</strong> – The complete size of the packet, including both the <strong>header</strong> and <strong>data</strong>.</p>
</li>
<li><p><strong>Identification</strong> – A unique number given to a packet. If the packet is split into smaller parts, this number helps put them back together.</p>
</li>
<li><p><strong>Flags</strong> – Controls whether a packet can be broken into smaller parts or must stay whole.</p>
</li>
<li><p><strong>Fragment Offset</strong> – If a packet is split into smaller parts, this number helps place each part in the right order.</p>
</li>
<li><p><strong>Time to Live (TTL)</strong> – Limits how many times a packet can be passed between networks before it is removed. This prevents packets from traveling forever if something goes wrong.</p>
</li>
<li><p><strong>Protocol</strong> – Identifies what type of data is inside the packet. It could be <strong>TCP</strong> (for web pages and file transfers), <strong>UDP</strong> (for video calls and gaming), or <strong>ICMP</strong> (for network testing).</p>
</li>
<li><p><strong>Header Checksum</strong> – A number used to check if the header was damaged while traveling.</p>
</li>
<li><p><strong>Source and Destination IP Addresses</strong> – Show <strong>where the packet came from</strong> and <strong>where it needs to go</strong>.</p>
</li>
<li><p><strong>Explicit Congestion Notification (ECN)</strong> – Helps reduce congestion in the network by signaling the sender to slow down instead of losing data.</p>
</li>
</ol>
<h3 id="heading-why-does-this-matter"><strong>Why Does This Matter?</strong></h3>
<p>Understanding these details helps in <strong>troubleshooting network issues</strong>, <strong>optimizing data transfer</strong>, and making sure that packets reach their destination <strong>efficiently and securely</strong>.</p>
<p>The format of these packets depends on whether they use IPv4 or IPv6.</p>
<h2 id="heading-understanding-ipv4-and-ipv6"><strong>Understanding IPv4 and IPv6</strong></h2>
<h3 id="heading-ipv4">IPv4</h3>
<p>IPv4 (Internet Protocol version 4) was introduced in <strong>1983</strong> and is still widely used today. It follows a simple format with <strong>four sets of numbers</strong> separated by dots, like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738680105340/595ccaca-97c6-401b-9922-67d7ce761c8b.png" alt class="image--center mx-auto" /></p>
<p>IPv4 is a <strong>32-bit system</strong>, meaning it can create about <strong>4.3 billion unique IP addresses</strong>. At first, this seemed like plenty. But over time, as more devices connected to the internet—smartphones, computers, smart TVs, and even smart refrigerators—the number of available addresses started running out.</p>
<h3 id="heading-ipv6">IPv6</h3>
<p>To solve this, <strong>IPv6</strong> was introduced. It uses a <strong>128-bit system</strong>, meaning it can support an almost unimaginable number of addresses—<strong>a 39-digit number</strong>!</p>
<p>IPv6 looks different from IPv4. Instead of just numbers, it uses <strong>both numbers and letters</strong>, separated by colons. Here’s an example:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738681017764/759fcf91-a17c-4f25-8882-b956a0515cdf.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-why-ipv6-is-better">Why IPv6 is Better?</h3>
<p>Besides providing more IP addresses, IPv6 also has other benefits:</p>
<ul>
<li><p><strong>Better security</strong> – It keeps data safer with better encryption and authentication.</p>
</li>
<li><p><strong>Better privacy</strong> – It makes it harder for others to track users online.</p>
</li>
<li><p><strong>More efficient communication</strong> – It speeds up data transfer by making routing more efficient.</p>
</li>
</ul>
<h3 id="heading-ipv4-and-ipv6-work-together">IPv4 and IPv6 Work Together</h3>
<p>Even though IPv6 is better, <strong>many systems still use IPv4</strong>. This means both versions need to work together. To make sure IPv4 and IPv6 devices can still communicate, <strong>special techniques</strong> were developed to allow smooth interaction between the two systems.</p>
<p>For now, both IPv4 and IPv6 are being used side by side, but in the future, IPv6 will likely become the standard for all devices.</p>
<h2 id="heading-what-happened-to-ipv5">What happened to IPV5?</h2>
<p>You might be wondering—if we have <strong>IPv4 and IPv6</strong>, why is there no <strong>IPv5</strong>?</p>
<p>IPv5 was actually <strong>never officially released</strong>. It was created as an <strong>experimental protocol</strong> mainly for streaming data, like <strong>voice and video</strong>. However, it still used <strong>32-bit addressing</strong>, just like IPv4. This meant it couldn’t solve the problem of <strong>running out of IP addresses</strong>.</p>
<p>Because IPv5 wasn’t a long-term solution, it was <strong>abandoned</strong>, and <strong>IPv6</strong> was developed instead. Unlike IPv5, <strong>IPv6</strong> provides:</p>
<ul>
<li><p>A nearly unlimited number of IP addresses</p>
</li>
<li><p>Better security to protect online communication</p>
</li>
<li><p>More efficient data transfer</p>
</li>
</ul>
<p>That’s why the internet skipped IPv5 and moved straight to IPv6!</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>The <strong>Internet Protocol (IP)</strong> is what allows devices worldwide to communicate smoothly. It gives each device a unique address and helps direct data to the right place. <strong>IPv4 has worked well for years</strong>, but with more devices connecting, <strong>IPv6 is needed for the future</strong>.</p>
<p>Understanding basics like <strong>IP addresses, subnetting, and gateways</strong> helps us see how data moves online. As technology improves, <strong>networks will become faster, safer, and more efficient</strong>. Whether you’re <strong>fixing a connection or setting up a system</strong>, knowing how IP works is a important skill in today’s digital world.</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://blog.devwithjay.com">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[Client-Server Architecture]]></title><description><![CDATA[Introduction
The client-server architecture is a revolutionary concept that fundamentally changed how applications are built and deployed. It introduced the idea of separating the client and server into distinct components, allowing the core pieces o...]]></description><link>https://blog.devwithjay.com/client-server</link><guid isPermaLink="true">https://blog.devwithjay.com/client-server</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[client-server]]></category><category><![CDATA[RPC]]></category><category><![CDATA[peer to peer]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Thu, 23 Jan 2025 11:32:31 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1737631124188/1025169e-726c-4d3f-ba52-f651361c76f6.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>The client-server architecture is a revolutionary concept that fundamentally changed how applications are built and deployed. It introduced the idea of separating the client and server into distinct components, allowing the core pieces of code to exist in different locations. This innovation paved the way for modern distributed computing.</p>
<p>Previously, applications ran on large mainframes, which were expensive and resource-intensive. The client-server model addressed this by moving heavy workloads, such as computational tasks or database queries, to servers equipped with powerful resources. Clients, on the other hand, became lightweight, requiring only basic hardware to interact with the server</p>
<p>For example, consider a scenario where a server performs resource-intensive tasks like database queries or complex computations. A thin client device, like a tablet or desktop, sends requests to the server. The server processes these requests and sends the results back to the client. This separation improves scalability and reduces costs since multiple clients can use a single powerful server.</p>
<h2 id="heading-remote-procedure-calls-rpcs">Remote <strong>Procedure Calls (RPCs)</strong></h2>
<p>To enable communication between the client and server, <strong>Remote Procedure Calls (RPCs)</strong> were introduced. These allow a client to execute functions on a remote server as if they were local.</p>
<p>Early implementations lacked standardization, but over time, standards like <strong>gRPC</strong> (Google RPC) were developed. These standards provide efficient and universal communication between distributed components.</p>
<h2 id="heading-what-is-a-client">What is a Client?</h2>
<p>A client is a computer or device, also known as a <strong>host</strong>, that requests and uses services or receives information.</p>
<p>It is the part of an application that directly communicate with the users. Clients send requests to the server, process the server's responses, and display the results to the user.</p>
<p>Clients are designed to be <strong>lightweight</strong>, <strong>fast</strong> and <strong>simple</strong>.</p>
<p>Examples of a client are:</p>
<ul>
<li><p><strong>Web Browsers</strong>: Chrome, Firefox, Safari</p>
</li>
<li><p><strong>Mobile Applications</strong>: Instagram, WhatsApp, Facebook</p>
</li>
<li><p><strong>IoT Devices</strong>: Fitness trackers, Thermostats, Smart Speakers</p>
</li>
</ul>
<h2 id="heading-what-is-a-server">What is a Server?</h2>
<p>A <strong>server</strong> is a remote computer that provides access to data and services. It processes requests from clients, performs the required tasks, and sends the responses back to the clients.</p>
<p>Servers are typically physical devices, such as rack-mounted servers, but with the rise of cloud computing, <strong>virtual servers</strong> have become increasingly common.</p>
<p>Servers handle a variety of processes, such as:</p>
<ul>
<li><p><strong>Email services</strong>: Managing and sending emails efficiently.</p>
</li>
<li><p><strong>Application hosting</strong>: Hosting and Running software applications for users.</p>
</li>
<li><p><strong>Internet connections</strong>: Providing web hosting and data access.</p>
</li>
<li><p><strong>Printing services</strong>: Managing print jobs across a network.</p>
</li>
</ul>
<p>Examples of a server are:</p>
<ul>
<li><p><strong>Web Servers</strong>: Apache, Nginx</p>
</li>
<li><p><strong>Database Servers</strong>: MySQL, PostgreSQL</p>
</li>
<li><p><strong>Cloud Servers</strong>: AWS, Google Cloud</p>
</li>
</ul>
<h2 id="heading-client-server-architecture">Client-Server Architecture</h2>
<h3 id="heading-what-is-it">What Is It?</h3>
<p>Client-server architecture is a system where a <strong>server</strong> hosts and manages resources or services, and a <strong>client</strong> (like a computer, phone, or tablet) requests these services over a network. It’s also known as the <strong>client-server network</strong> or <strong>network computing model</strong>.</p>
<p>In simple words, this model splits tasks between the client and the server. The client sends a request, and the server processes it and sends back the result.</p>
<h3 id="heading-how-it-works">How It Works?</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737631842613/336a9ad4-4987-49d6-bea1-f1dedfd0a3b9.png" alt class="image--center mx-auto" /></p>
<p>In this model:</p>
<ul>
<li><p><strong>Clients</strong> send requests to <strong>servers</strong> for data like web pages or applications.</p>
</li>
<li><p><strong>Servers</strong> process these requests and send back the required responses to the clients.</p>
</li>
<li><p>This communication happens over a <strong>network</strong>, connecting the client and server.</p>
</li>
</ul>
<p>For example, when you open a website, your browser (the client) requests data from the web server. The server processes the request and sends the website's content back to the browser.</p>
<h3 id="heading-why-it-is-required">Why It Is Required?</h3>
<p>Today, many businesses depend heavily on technology to succeed. Client-server architecture helps them:</p>
<ul>
<li><p>Collect, process, and share data efficiently.</p>
</li>
<li><p>Manage networks and systems from a central point.</p>
</li>
<li><p>Scale operations easily as businesses grow.</p>
</li>
<li><p>Improve productivity by handling heavy tasks on powerful servers while keeping clients light and fast.</p>
</li>
</ul>
<h3 id="heading-characteristics">Characteristics</h3>
<ul>
<li><p>Clients and servers do different tasks and often use different hardware and software.</p>
</li>
<li><p>More devices can be added easily.</p>
</li>
<li><p>It uses stronger or multiple servers for bigger tasks.</p>
</li>
<li><p>A server can handle many tasks at the same time, but each task needs its own program.</p>
</li>
<li><p>Clients and servers follow specific rules (protocols) to share data.</p>
</li>
<li><p>Both clients and servers use all the necessary rules (protocols) to send and receive information correctly.</p>
</li>
</ul>
<h3 id="heading-advantages"><strong>Advantages</strong></h3>
<ol>
<li><p><strong>Centralized system</strong>: All data and services are stored in one place, making it easier to manage, update, and secure.</p>
</li>
<li><p><strong>Cost-efficient</strong>: Clients don’t need much hardware or software. They only need a network connection and an app or browser to access the server.</p>
</li>
<li><p><strong>High performance</strong>: The server can handle many client requests quickly and efficiently with low delays.</p>
</li>
</ol>
<h3 id="heading-disadvantages"><strong>Disadvantages</strong></h3>
<ol>
<li><p><strong>Limited scalability</strong>: The system depends on the server’s capacity. If the server is overloaded or breaks down, the system may not work properly.</p>
</li>
<li><p><strong>Network dependency</strong>: The system relies on the connection between the client and server. If the network is slow or unstable, it can cause delays or errors.</p>
</li>
<li><p><strong>Complex setup</strong>: The system has many parts that need to work together. This makes it harder to design, set up, and manage, with challenges like security, synchronization, and compatibility.</p>
</li>
</ol>
<h2 id="heading-microservices">Microservices</h2>
<p>Microservices architecture is a modern version of the client-server model. Instead of building one large application, it divides the application into smaller, independent parts that communicate using APIs or RPCs. This makes the system easier to scale and more flexible, but it can also make it more complex to manage.</p>
<h2 id="heading-how-do-server-side-processes-work-in-a-serverless-architecture"><strong>How Do Server-Side Processes Work In a Serverless Architecture?</strong></h2>
<p>In serverless computing, all backend processes still run on servers instead of client devices, but they are not deployed on any specific server or set of servers. Backend processes are broken up into functions, which run on demand, and automatically scale up to handle more load. Developers can still build all the functionality that normally runs server-side within a serverless architecture.</p>
<h2 id="heading-peer-to-peer-network">Peer-To-Peer Network</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737631170734/e6535a90-eb90-4b85-856b-77f821835822.png" alt class="image--center mx-auto" /></p>
<p>Peer-to-peer (P2P) networks are made up of groups of computers, called nodes or peers, connected in a network. In these networks, each peer acts as both a client and a server.</p>
<p>All peers have the same responsibilities and permissions to manage data. This is very different from the client-server model, where users and servers have specific and separate roles.</p>
<h2 id="heading-comparison-between-client-server-amp-peer-to-peer-network">Comparison between Client-Server &amp; Peer-To-Peer Network</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td><strong>Client-Server</strong></td><td><strong>Peer-to-Peer (P2P)</strong></td></tr>
</thead>
<tbody>
<tr>
<td>Needs a central server</td><td>No central server</td></tr>
<tr>
<td>Safer with better security</td><td>Users are responsible for security</td></tr>
<tr>
<td>Scalable and stable for many users</td><td>Performance drops with more users</td></tr>
<tr>
<td>Server failure stops the system</td><td>One failure doesn’t affect the network</td></tr>
<tr>
<td>Slower for file sharing</td><td>Faster for file sharing</td></tr>
</tbody>
</table>
</div><h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we understood that the client-server architecture is a strong and flexible way to manage network resources and applications. It helps IT professionals deal with the challenges of a fast-changing and competitive world by sharing tasks between clients and servers. This system also makes the network scalable, secure, reliable, and high-performing.</p>
<p>If you found this article helpful, share it with others and feel free to leave your feedback—I’d love to hear your thoughts!</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://hashnode.com/@learnwithjay">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[DNS Simplified]]></title><description><![CDATA[Introduction
The Domain Name System (DNS) is the backbone of the internet, which translates human-friendly domain names into machine-readable IP addresses. It simplifies navigation by allowing users to type names like google.com instead of rememberin...]]></description><link>https://blog.devwithjay.com/dns-demystified</link><guid isPermaLink="true">https://blog.devwithjay.com/dns-demystified</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[dns]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Sun, 19 Jan 2025 10:45:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1737283316214/b76cfca1-f98d-48a3-be96-25bab532bd03.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-introduction">Introduction</h2>
<p>The Domain Name System (DNS) is the backbone of the internet, which translates human-friendly domain names into machine-readable IP addresses. It simplifies navigation by allowing users to type names like <a target="_blank" href="http://google.com">google.com</a> instead of remembering complex numerical addresses.</p>
<p>In this article, we’ll explore domains, their structure, the concept of DNS, how it works, and its importance in making the internet user-friendly.</p>
<p>All Computers on the internet, from a smart phone, laptop, server, find and communicate with each other using numbers. These numbers are called as <strong>IP addresses</strong>. When you open a web browser and go to a website, you don't have to remember and enter a long number. Instead, you can enter a <strong>domain name</strong> like <strong>google.com</strong> and still end up in the right place.</p>
<p>Domain names make it easy to find and access resources across different systems, networks, and organizations. When we type a domain name, a resolver processes it to find and get the information linked to that name, such as IP addresses. To the user, it looks like a simple system—a single domain tree—but in reality, the resolver works with many name servers to make sure everything works smoothly.</p>
<h2 id="heading-structure-of-domain">Structure of Domain</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737283296813/be72f09c-c67e-431f-adfe-bc514fa248bd.png" alt class="image--center mx-auto" /></p>
<p>A domain is a string that users type into their browser, consisting of three parts:</p>
<ol>
<li><p><strong>Subdomain</strong>: The prefix, such as <strong>www.</strong> or <strong>blog.</strong></p>
</li>
<li><p><strong>2nd Level Domain</strong>: The main name, such as google in <a target="_blank" href="http://google.com">google.com</a>.</p>
</li>
<li><p><strong>Top-Level Domain (TLD)</strong>: The suffix, like .com, <strong>.org</strong>, or <strong>.edu</strong>.</p>
</li>
</ol>
<p>These parts are separated by dots, creating a fully qualified domain name (FQDN), such as <strong>www.devwithjay.com.</strong> This structure makes it easier for users to access websites by typing readable names instead of numerical IP addresses.</p>
<p>A domain name is <strong>not the same as a URL (Uniform Resource Locator)</strong>.</p>
<ul>
<li><p>A URL is the full web address of a site.</p>
</li>
<li><p>It includes the domain name and other details, like:</p>
<ul>
<li><p>The <strong>protocol</strong> (e.g., HTTP or HTTPS) used to access the page.</p>
</li>
<li><p>The path to a specific file or folder on the website (e.g., <a target="_blank" href="https://blog.devwithjay.com/journey-of-data"><strong>https://ww.blog.devwithjay.com/journey-of-data</strong>)</a>.</p>
</li>
</ul>
</li>
</ul>
<h2 id="heading-what-is-dns">What is DNS?</h2>
<p>DNS acts like the internet’s phonebook, translating domain names into IP addresses so that devices can locate and connect to servers. Just like we don’t memorize phone numbers anymore because our phone stores them under contact names, DNS helps us avoid memorizing IP addresses by linking them to domain names.</p>
<p>When new addressing systems are introduced, they always bring the challenge of creating a way to map one type of address to another. In the early days of networking, MAC (Media Access Control) addresses were the foundation. These unique identifiers worked well for local communication but weren’t designed for routing across large networks. To address this limitation, IP addresses were introduced. Even with this advancement, MAC addresses remain essential within local networks, which is why the Address Resolution Protocol (ARP) was developed. ARP bridges the gap by mapping IP addresses to their corresponding MAC addresses.</p>
<p>A similar challenge arises with domain names and IP addresses, which is where the <strong>Domain Name System</strong> (DNS) comes in. People know websites by their domain names, like <a target="_blank" href="http://Facebook.com">Facebook.com</a>, but computers need the corresponding IP address to connect to the server. DNS resolves this by acting as a translator. It typically uses the User Datagram Protocol (UDP) on Port 53, though it can operate on other ports. Once DNS provides the IP address for a domain, the device can establish communication with the server. If the connection is local, ARP may further resolve the IP address to a MAC address.</p>
<p>Every device on the Internet has a unique IP address, which other devices use to locate it. Thanks to DNS, people don’t need to remember complex IP addresses, such as 192.168.1.1 for IPv4 or longer alphanumeric addresses like 2400:cb00:2048:1::c629:d7a2 for IPv6. DNS is used to simplify this process, making the Internet easier to use.</p>
<h2 id="heading-why-do-we-need-dns">Why do we need DNS?</h2>
<p>Imagine having to memorize an IP address like 172.217.10.46 for every website you visit. That would be impractical!</p>
<p>DNS makes the internet easier to use by providing a layer of abstraction:</p>
<ul>
<li><p>Users only need to remember domain names, while DNS manages the mapping to IP addresses.</p>
</li>
<li><p>DNS also handles changes in IP addresses caused by server updates or load balancing, ensuring users always reach the correct destination.</p>
</li>
</ul>
<p>Without DNS, the internet would be far less user-friendly and scalable.</p>
<h2 id="heading-working-of-dns">Working of DNS</h2>
<p>DNS is not just a simple database where you query for a name and get an IP address. If it were built like that, the database would be <a target="_blank" href="http://google.com">massive,</a> containing millions of records. To handle this, DNS uses <strong>partitioning</strong> to divide the data into smaller, manageable sets. This is similar to splitting a large table into smaller parts in a database.</p>
<h3 id="heading-dns-works-in-layers"><strong>DNS works in layers</strong></h3>
<ul>
<li><p><strong>Root Servers</strong>: The top level of DNS, which directs queries to the next level.</p>
</li>
<li><p><strong>Top-Level Domain (TLD) Servers</strong>: These servers handle specific domains like <strong>.com</strong>, <strong>.org</strong>, <strong>.net</strong>, or country-specific domains like <strong>.in</strong>.</p>
</li>
<li><p><strong>Authoritative Name Servers (ANS)</strong>: These servers store the actual IP address for the requested domain, like <a target="_blank" href="http://www.google.com"><strong>google.com</strong></a>.</p>
</li>
</ul>
<p>When you connect to a network, your device gets a default DNS resolver (usually your router or a public resolver like <strong>8.8.8.8</strong> from Google or <strong>1.1.1.1</strong> from Cloudflare).</p>
<p>The resolver checks if it already has the answer (cached). If not, it starts querying other servers step by step.</p>
<h3 id="heading-querying-process"><strong>Querying Process</strong></h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737283259839/d8da87a8-5e87-46f9-9286-8a418375dc10.png" alt class="image--center mx-auto" /></p>
<p><strong>Step 1:</strong> The client sends a request to the resolver, asking for the IP address of a website (e.g., <a target="_blank" href="http://google.com">google.com</a>).</p>
<p><strong>Step 2:</strong> The resolver sends a query to a root server, asking for the TLD server of the domain (e.g., .com for <a target="_blank" href="http://google.com">google.com</a>).</p>
<p><strong>Step 3:</strong> The root server replies with the IP address of a TLD server that handles <strong>.com</strong> domains.</p>
<p><strong>Step 4:</strong> The resolver queries the TLD server, asking for the authoritative name server for <a target="_blank" href="http://google.com">google.com</a>.</p>
<p><strong>Step 5:</strong> The TLD server responds with the IP address of the authoritative name server.</p>
<p><strong>Step 6:</strong> The resolver asks the authoritative name server for the IP address of <a target="_blank" href="http://google.com">google.com</a>.</p>
<p><strong>Step 7:</strong> The authoritative name server responds with the IP address, which is then sent to the resolver.</p>
<p><strong>Step 8:</strong> Once the resolver gets the IP address of the domain, it sends this IP address to the client.</p>
<p><strong>Step 9:</strong> The client then uses this IP address to establish a connection with the server, such as initiating a TCP handshake.</p>
<h3 id="heading-why-this-long-process-is-required">Why this Long Process is Required?</h3>
<p>This layered approach reduces the size of individual databases and improves efficiency. Each server in the hierarchy only manages a specific part of the DNS structure, making it scalable and reliable.</p>
<h3 id="heading-caching">Caching</h3>
<p>To speed up responses, DNS resolvers and browsers temporarily store frequently accessed domains in their cache. This avoids repeatedly asking DNS servers for the same information, making responses faster and saving resources.</p>
<h3 id="heading-load-balancing">Load Balancing</h3>
<p>DNS can give multiple IP addresses for the same domain. This spreads traffic across different servers, preventing any one server from getting too much load. It makes websites faster and more reliable.</p>
<h3 id="heading-geo-dns">Geo-DNS</h3>
<p>DNS sends users to servers closest to their location. This reduces delays and makes websites load faster, especially for global users.</p>
<h3 id="heading-how-does-dns-match-responses-to-queries-if-it-uses-udp">How does DNS match responses to queries if it uses UDP?</h3>
<p>Each query contains a <strong>unique transaction ID</strong> to match responses with their respective requests. This ensures that the resolver can correctly identify which response corresponds to which query, even when multiple queries are processed simultaneously.</p>
<h2 id="heading-dns-challenges">DNS Challenges</h2>
<p><strong>Plaintext Queries</strong>: Traditional DNS queries are unencrypted, meaning your internet service provider (ISP) or other entities can see which websites you visit.</p>
<p><strong>Encryption Solutions</strong>: Technologies like DNS-over-HTTPS (DoH) and DNS-over-TLS (DoT) are being adopted to encrypt DNS queries.</p>
<p><strong>Vulnerabilities</strong>: DNS is vulnerable to attacks like:</p>
<ul>
<li><p><strong>DNS Cache Poisoning</strong>:  Attackers inject fake responses into a resolver’s cache.</p>
</li>
<li><p><strong>Hijacking</strong>: Attackers redirect users to malicious servers.</p>
</li>
</ul>
<h2 id="heading-what-is-ddns">What is DDNS?</h2>
<p>Many websites and online services, like APIs, run on internet connections with IP addresses that change frequently. This can be a problem for website owners who want their domain name to always point to the correct server. A domain name needs to be linked to an IP address in the Domain Name System (DNS), so if the IP address changes, the link breaks.</p>
<p>This is where Dynamic DNS (DDNS) comes in. DDNS is a service that automatically updates DNS records with the correct IP address, even if it keeps changing.</p>
<p>For example, imagine a small website called <a target="_blank" href="http://www.example.com"><strong>www.example.com</strong></a> with an IP address of <strong>192.0.2.0</strong>. Whenever someone types <a target="_blank" href="http://www.example.com"><strong>www.example.com</strong></a> into their browser, the DNS directs them to the server at that IP address. If the website’s internet provider changes the IP address to <strong>192.0.2.1</strong>, a DDNS service updates the DNS records automatically. This ensures visitors are always sent to the right server, no matter how often the IP changes.</p>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we understood that DNS is the backbone of the internet, bridging the gap between human-friendly domain names and machine-friendly IP addresses. It’s a decentralized, efficient, and robust system that allows the internet to function as we know it. Whether you’re browsing a website, sending an email, or using a cloud service, DNS is silently working in the background.</p>
<p>If you found this article helpful, share it with others and feel free to leave your feedback—I’d love to hear your thoughts!</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://hashnode.com/@learnwithjay">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item><item><title><![CDATA[The Hidden Journey Of Our Data]]></title><description><![CDATA[Have you ever wondered how your data travels from a browser on your computer to a server…?
It feels like magic, but it’s actually the result of a complex system working behind the scenes.
In this article, I’ll walk you through the hidden journey of y...]]></description><link>https://blog.devwithjay.com/journey-of-data</link><guid isPermaLink="true">https://blog.devwithjay.com/journey-of-data</guid><category><![CDATA[ChaiCode]]></category><category><![CDATA[internet]]></category><category><![CDATA[OSI Model]]></category><category><![CDATA[networking]]></category><category><![CDATA[data]]></category><dc:creator><![CDATA[Jay Kadlag]]></dc:creator><pubDate>Thu, 16 Jan 2025 09:03:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1738865470335/be80f798-fb8f-425f-8ebc-442864a5b8eb.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Have you ever wondered how your data travels from a browser on your computer to a server…?</p>
<p>It feels like magic, but it’s actually the result of a complex system working behind the scenes.</p>
<p>In this article, I’ll walk you through the hidden journey of your data — from your device to the server and back — and introduce the important parts that make it all work. From the client-server architecture to the OSI model, let’s dive in!</p>
<h2 id="heading-client-server-architecture">Client-Server Architecture</h2>
<p>Before diving into the process of data transfer, let’s understand the client-server architecture.</p>
<p>The client-server architecture revolutionized computing by separating client and server locations. A client is a device which sends a request and a server is a device which sends back the response. This communication between the client and server happens through a network.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737017953236/e5d65af4-7641-4a59-9e52-41d9295a8a8f.png" alt class="image--center mx-auto" /></p>
<p>This architecture has several benefits, such as, Resource Allocation, Scalability and Efficiency. It separates the application into multiple components. Microservices evolved from this model, breaking down monolithic services into smaller, interconnected services.</p>
<h2 id="heading-osi-open-system-interconnections">OSI → Open System Interconnections</h2>
<h3 id="heading-why-do-we-need-osi-model">Why do we need OSI Model ?</h3>
<p>The OSI Model is used as a standard to ensure smooth communication between systems. Without a common standard, different systems won’t be able to communicate with each other. In such case, we would need different versions of the same app for different network types like Wifi, Fiber, LTE and Ethernet.</p>
<p>When we use the OSI Model, apps do not need to know the type of network being used (Wifi, Ethernet, etc). Communication is smooth, no matter which type of network is used.</p>
<h3 id="heading-layers-of-the-osi-model">Layers of the OSI Model</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1737016556820/e89c562b-2506-4224-a322-8446e3d506c0.png" alt class="image--center mx-auto" /></p>
<p>At the client side, the data passes from the top layers to the bottom layers, each layer performing certain operation on the data.</p>
<ol>
<li><p><strong>Application Layer:</strong> When you type a link, consider <a target="_blank" href="https://www.google.com">https://www.google.com</a>, the browser initiates a request such as HTTP POST or GET. The request includes the data (e.g., form data, JSON payload), headers, and protocol (e.g., HTTPS).</p>
</li>
<li><p><strong>Presentation Layer:</strong> The data is <strong>encoded</strong> or <strong>serialized</strong> into a format suitable for transmission (e.g., JSON, XML). Encryption is applied if required (e.g., SSL/TLS for HTTPS).</p>
</li>
<li><p><strong>Session Layer:</strong> A <strong>session</strong> is established if the protocol is stateful, like, in case of TCP. The session manages connection states between the client and server. It handles starting, maintaining and ending connections.</p>
</li>
<li><p><strong>Transport Layer:</strong> The data is segmented into smaller chunks. The <strong>TCP</strong> protocol ensures reliable delivery by establishing a connection via the <strong>three-way handshake</strong> (SYN, SYN-ACK, ACK). The segments are labeled with <strong>source and destination port numbers</strong> (e.g., port 443 for HTTPS).</p>
</li>
<li><p><strong>Network Layer:</strong> Each segment is encapsulated in an <strong>IP packet</strong>. The <strong>source and destination IP addresses</strong> are then added to the packet header. Routing decisions are made based on the destination IP address.</p>
</li>
<li><p><strong>Data Link Layer:</strong> Each packet is encapsulated in a <strong>frame</strong> for transmission over the network. The frame contains the <strong>source and destination MAC addresses</strong>. The frame is prepared for the specific physical medium (e.g., Ethernet, Wi-Fi).</p>
</li>
<li><p><strong>Physical Layer:</strong> The frame is converted into a series of electrical signals, light pulses, or radio waves. These signals are transmitted through the physical medium (e.g., copper wire, fiber-optic cable, or airwaves).</p>
</li>
</ol>
<p>At the server side, the process is reversed. The data passes from the bottom layers to the top layers.</p>
<ol>
<li><p><strong>Physical Layer:</strong> Receives the signal and converts it back into bits.</p>
</li>
<li><p><strong>Data Link Layer</strong>: Extracts the frame and verifies the MAC address.</p>
</li>
<li><p><strong>Network Layer:</strong> Reads the IP packet and verifies the destination IP.</p>
</li>
<li><p><strong>Transport Layer:</strong> Reassembles the segments and verifies the ports and connection state.</p>
</li>
<li><p><strong>Session Layer:</strong> Ensures the session is valid.</p>
</li>
<li><p><strong>Presentation Layer:</strong> Decrypts and deserializes the data (e.g., JSON to an object).</p>
</li>
<li><p><strong>Application Layer:</strong> Processes the request and sends a response back to the client.</p>
</li>
</ol>
<h2 id="heading-conclusion">Conclusion</h2>
<p>In this article, we saw how the data transfers from your device to a server. The amount of hard work smart people have put in to make this underlying system is rarely acknowledged. So the next time you send a message to a friend or browse a website, take a moment to appreciate the work of great engineers who designed and implemented these communication protocols that power everything on the internet.</p>
<p>If you found this article helpful, share it with others and feel free to leave your feedback—I’d love to hear your thoughts!</p>
<h3 id="heading-want-more">Want More…?</h3>
<p>I write articles on <a target="_blank" href="https://hashnode.com/@learnwithjay">blog.devwithjay.com</a> and also post development-related content on the following platforms:</p>
<ul>
<li><p><a target="_blank" href="https://x.com/devwithjay"><strong>Twitter/X</strong></a></p>
</li>
<li><p><a target="_blank" href="https://www.linkedin.com/in/devwithjay"><strong>LinkedIn</strong></a></p>
</li>
</ul>
]]></content:encoded></item></channel></rss>