<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Prerna Mishra on Medium]]></title>
        <description><![CDATA[Stories by Prerna Mishra on Medium]]></description>
        <link>https://medium.com/@prernahimanshu2?source=rss-85f0c9ab9d7d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ZNogCDLYHX8Vh54d</url>
            <title>Stories by Prerna Mishra on Medium</title>
            <link>https://medium.com/@prernahimanshu2?source=rss-85f0c9ab9d7d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 02:09:34 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prernahimanshu2/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Your Router Doesn’t Know Where Google Is. Neither Does Mine.]]></title>
            <link>https://medium.com/@prernahimanshu2/your-router-doesnt-know-where-google-is-neither-does-mine-4bddc2896189?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/4bddc2896189</guid>
            <category><![CDATA[ip-routing]]></category>
            <category><![CDATA[network-layer]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[osi-model]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Fri, 04 Sep 2026 13:02:21 GMT</pubDate>
            <atom:updated>2026-09-04T13:02:21.757Z</atom:updated>
            <content:encoded><![CDATA[<p>And yet, packets cross the planet in milliseconds. Here’s how.</p><p><em>Here’s what broke my brain a little: no single router on Earth knows where google.com is.</em></p><p>Not yours. Not your ISP’s. Not even Google’s backbone routers. And yet, every single request works, every single time, in milliseconds.</p><p>The magic isn’t in knowing the map. The magic is in asking the right question, over and over, at every hop.</p><h3>Welcome to Layer 3: The Network Layer (OSI Model)</h3><p>Layer 2 only cares about your immediate neighbors — it’s all about MAC addresses and local delivery. The Data Link Layer works at the speed of your local network.</p><p>But Layer 3 is different. Its entire job is answering one question, asked millions of times per second: where does this packet go next?</p><p>Not “where does it end up?” Not “what’s the full path?” Just: <em>next.</em></p><h3>The Postal Analogy That Clicked</h3><p>You’re mailing a letter from Delhi to a small town in Portugal. Your local postman has no idea where that town is. None. But he knows one thing:</p><p>Not local → send to the city office</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C-q7guMO8rs5rUUYXv6U_Q.png" /></figure><p>Nobody knew the full route. Each one only knew the next hop.</p><h3>MAC vs IP: The Core Difference</h3><p>To understand routing, you need to understand the difference between the two addressing schemes that power the internet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*awSDjgQupE7o7ZBIK0UU3A.png" /></figure><h3>The Routing Table: Deceptively Simple :</h3><p>=====================================================</p><p>Your home router doesn’t know much. In fact, it’s almost comically simple:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*h7gknYjVtouq7CkSxWOeng.png" /></figure><p>That’s it. Two rules. Your router sees an IP, checks if it’s local (on your home network), and if not, sends it out to your ISP. The ISP’s job is to figure out the next hop.</p><h3>Backbone routers: More complex, same principle</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Jc0-60XPb50ntx1iiixgGA.png" /></figure><h3>The Packet’s Journey</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9zrPOw43MGcZaOBa80lzPA.png" /></figure><p>The packet starts as a MAC address (local delivery on your network), becomes an IP address (Layer 3 routing across the internet), and arrives at the destination. Each router along the way asks the same question: <em>where’s the next hop?</em></p><h3>The Unsettling Part: No Guarantees</h3><p>Layer 3 makes no promises. This is genuinely unsettling when you first learn it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gcDOtOUDUzlNPlLuxL4IwQ.png" /></figure><h3>How It Works: The Algorithm</h3><p>Every router, billions of times a second, does the same thing:</p><ol><li>Look at the destination IP</li><li>Check the routing table</li><li>Pick the best matching entry</li><li>Forward to the next hop</li><li><strong>Forget</strong></li></ol><p>That’s it. That’s how packets cross continents. No central authority. No complete map. Just dumb, stateless decisions chained together.</p><p>A packet might take a different route tomorrow. It might take a different route from the next packet you send. The network doesn’t care — it just keeps moving packets closer to their destination, one hop at a time.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4bddc2896189" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[I Thought I Knew How Wi-Fi Worked. I Didn’t.]]></title>
            <link>https://medium.com/@prernahimanshu2/i-thought-i-knew-how-wi-fi-worked-i-didnt-9ec6e1fff03c?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ec6e1fff03c</guid>
            <category><![CDATA[wifi]]></category>
            <category><![CDATA[mac-address]]></category>
            <category><![CDATA[ip-address]]></category>
            <category><![CDATA[data-link-layer]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Wed, 02 Sep 2026 18:21:07 GMT</pubDate>
            <atom:updated>2026-09-02T18:21:07.468Z</atom:updated>
            <content:encoded><![CDATA[<p>It started with a dumb question I couldn’t shake.</p><p>I was sitting at my desk, phone connected to Wi-Fi like it has been every day for years, and I suddenly wondered — how does my router actually know it’s <em>me</em>? Like, what’s stopping my neighbor’s phone from just… walking in?</p><p><em>I assumed I knew the answer. Something about MAC addresses. I’d read that somewhere. Turns out I was mostly wrong, and figuring out why sent me down a rabbit hole for an entire evening.</em></p><p>Here’s what I found, explained the way I eventually had to explain it to myself: as a story about a gated society and a very organized security guard.</p><p><strong>The guard at the gate</strong></p><p>Picture your router as a security guard sitting at the gate of a housing society. Every device that wants in has to get past him first.</p><p><em>You walk up. He asks for ID. You give him the Wi-Fi password.</em></p><p><em>That’s it. That’s the actual security check.</em></p><p>This was my first surprise — it’s not your MAC address doing the verification. Your MAC address isn’t checked against some global registry of legitimate devices (there isn’t one). The password is the lock and key. On mobile networks it’s your SIM card doing the same job, with secret keys baked into the chip.</p><p>MAC filtering exists on some routers, sure, but it’s trivially spoofable and mostly security theater. The password is what matters.</p><p><strong>Then he hands you a house number</strong></p><p>Once you’re through the gate, the guard says: <em>“Alright, you’re House #42.”</em></p><p>That’s your IP address. You didn’t pick it — it was handed to you the second you walked in. There’s a protocol behind this called DHCP, but honestly, “guard hands you a house number” covers it.</p><p>And then he writes something in his notebook:</p><p>Code</p><p><em>A4:5E:60:F2:3B:9C → House #42</em></p><p>That first bit is your MAC address — a permanent ID your device was born with at the factory. It’s not a credential. It’s a name tag. The guard only uses it <em>after</em> you’ve already proven yourself, so he can keep track of who lives where.</p><p>That distinction took me embarrassingly long to internalize.</p><p><strong>Sending a letter</strong></p><p>Now you want to message a friend who lives outside the society.</p><p>You don’t walk out and deliver it yourself. You hand it to the guard: <em>“Send this out for me.”</em></p><p>He takes it, and — this is the important part — makes a mental note: <em>if a reply comes back, it belongs to House #42.</em></p><p>Later, the reply shows up at the gate. Guard checks his notebook. Finds #42. Delivers it. Done.</p><p>That’s the whole local loop, and it happens thousands of times a second without you ever thinking about it.</p><p><strong>But here’s what I hadn’t considered</strong></p><p>The guard doesn’t know every address on Earth.</p><p>So how does <em>your</em> little society connect to the rest of the world? This is where I realized my mental model had a giant hole in it.</p><p><strong>If you’re on home Wi-Fi:</strong> your router isn’t floating in space. There’s a physical cable — fiber or coax — running out of your building into your ISP’s network. Your router hands the letter to that line, and your ISP takes over.</p><p>Your ISP is basically a regional postal hub. It doesn’t know every address either. It just knows the <em>next</em> hub to forward to. And that hub knows the next one. And so on, hopping across the planet — this is routing, driven by routing tables and a protocol called BGP — until your letter reaches whatever server your friend’s messages live on.</p><p><strong>If you’re on mobile data:</strong> there’s no Wi-Fi guard. Your phone talks straight to a cell tower over radio. No password — your SIM proves who you are instead, using cryptographic keys stored inside it.</p><p>That tower is wired (usually fiber) back to your carrier’s core network — their own enormous sorting facility. From there? Exactly the same story. Hand off to the wider internet, hop, hop, hop, arrive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ovf9PkEqTP-SBsLkeAg_Rw.png" /><figcaption>Connection paths diverge, then converge</figcaption></figure><p>That last row is the part I find genuinely beautiful. Once your data leaves your house or leaves the tower, <strong>the rest of the journey is the same.</strong> Wi-Fi, 5G, fiber, doesn’t matter. It’s all just routers passing packets to other routers using IP addresses, over and over, until it lands.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*lIhrPRuRhCB69fBkSqwN6g.png" /></figure><p><strong>So, back to the original question</strong></p><p><em>Does my router know my MAC address is legit?</em></p><p>No. It doesn’t verify legitimacy at all. It trusts the password, then uses the MAC as a label to keep its records straight. The gate is the security. The name tag is just bookkeeping.</p><p>Which, when you think about it, is a pretty reasonable design — you don’t need every layer to be a security checkpoint. You just need the right one to be.</p><p><strong>The bit I keep thinking about</strong></p><p>None of this is magic. It’s a chain of small, boring, extremely well-defined handoffs — prove who you are, take an address, pass it up, pass it along — repeated a few billion times a second across the world.</p><p>I’ve been using Wi-Fi for fifteen years and never once wondered about any of it. Now I can’t stop noticing it.</p><p>Anyway — if you also assumed MAC addresses were doing the security work, you’re not alone. That’s genuinely why I wrote this down.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ec6e1fff03c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Data Link Layer & MAC ID: The Secret Language Your Devices Speak Before the Internet Gets Involved]]></title>
            <link>https://medium.com/@prernahimanshu2/data-link-layer-mac-id-the-secret-language-your-devices-speak-before-the-internet-gets-involved-a9fbaf8ed84e?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a9fbaf8ed84e</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[osi-model]]></category>
            <category><![CDATA[data-link-layer]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Tue, 01 Sep 2026 16:49:50 GMT</pubDate>
            <atom:updated>2026-09-01T16:49:50.489Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Ever wonder what happens before your message even leaves your house? There’s a quiet, local conversation happening between your phone and your Wi-Fi router — and it’s called the </em><strong><em>Data Link Layer</em></strong><em>.</em></p><p><strong>Data Link Layer</strong> Layer 2 of the OSI model. Moves data between nearby devices (not across the internet).</p><p><strong>MAC Address</strong> A permanent, unique ID burned into every device’s network hardware at the factory.</p><p><strong>Example MAC</strong> A4:5E:60:F2:3B:9C</p><p><strong>Scope</strong> Works only locally (same Wi-Fi/network) — not across the internet.</p><p><strong>Compared to IP</strong> MAC = permanent local ID 🪪 · IP = changeable global address 🌍</p><h3>The Story: Sending “Hi!” on WhatsApp</h3><p>You hit send on WhatsApp 💬</p><p>Your phone doesn’t know or care about WhatsApp’s server or your friend’s phone yet</p><p>It only asks: <strong>“Who’s nearest to me?”</strong> → Answer: your Wi-Fi router</p><p>So your phone basically shouts:</p><blockquote><strong>“Hey Router, it’s me — A4:5E:60:F2:3B:9C — here’s some data, please pass it on!”</strong></blockquote><p>Router recognizes the MAC address ✅</p><p>Accepts the data, hands it off to the Network Layer (where IP addresses take over for the long-distance journey)</p><h3>💡 Why It Matters</h3><ul><li>Every single message — no matter how far it travels — starts with this same local shout</li><li>It’s the first trust handshake in a chain that spans the entire internet</li><li>Small step, but nothing else works without it</li></ul><h3>TL;DR</h3><ul><li>MAC address = permanent local ID card</li><li>Data Link Layer = handles the local handoff between nearby devices</li><li>Next stop: Network Layer, where IP addresses take over for the global journey 🌍</li></ul><p>More OSI layer breakdowns coming soon — let me know if MAC addresses finally click for you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a9fbaf8ed84e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Day I Fell in Love with the OSI Model (Again)]]></title>
            <link>https://medium.com/@prernahimanshu2/the-day-i-fell-in-love-with-the-osi-model-again-fbecf513b4cd?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/fbecf513b4cd</guid>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[networking]]></category>
            <category><![CDATA[osi-model]]></category>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Sat, 29 Aug 2026 15:19:02 GMT</pubDate>
            <atom:updated>2026-08-29T15:19:02.620Z</atom:updated>
            <content:encoded><![CDATA[<p>I was digging into the internals of the Network Layer recently, when something pulled me back — <strong>the OSI Model</strong>. That old 7-layer diagram from college textbooks, the one I memorized once and never really <em>understood</em>.</p><p>This time, I wanted it to actually stick. So instead of theory, I turned it into a story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BXiQK9hziZgY2Ral" /><figcaption><a href="http://www.network-supply.com/">www.network-supply.com</a></figcaption></figure><p>Imagine you’re texting a friend “Hi!” 👋</p><p>Here’s what really happens, one layer at a time — remembered with a simple mnemonic:</p><blockquote><em>“</em><strong>Please Do Not Throw Sausage Pizza Away</strong><em>” 🍕</em></blockquote><p>P — Physical Your “Hi!” becomes electrical signals or radio waves, racing through cables or the air. No meaning yet — just raw bits.</p><p>D — Data Link Your phone shakes hands with the nearest tower or router using MAC addresses. Local trust, established.</p><p>N — Network Your message gets an IP address — like a destination stamped on an envelope — so it knows <em>where</em> to go.</p><p>T — Transport Your “Hi!” is broken into small packets, numbered, and promised safe delivery. Nothing gets lost. Nothing arrives out of order.</p><p>S — Session A conversation “thread” stays open between your phone and the server — so you’re not saying hello all over again for every message.</p><p>P — Presentation Your message gets dressed up — encrypted, formatted — so only your friend can read it.</p><p>A — Application Finally, it lands where you actually see it — the chat app itself, showing “Hi!” on your friend’s screen.</p><p>Seven layers. Milliseconds. One tiny message.</p><p>That’s the quiet magic of networking — nothing feels complicated once you follow the story, layer by layer.</p><p><em>What’s your favorite way to remember the OSI layers? Drop it in the comments 👇</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fbecf513b4cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview PySpark Problem 2 : Combining Data]]></title>
            <link>https://medium.com/@prernahimanshu2/interview-pyspark-problem-2-combining-data-7650969bafc8?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/7650969bafc8</guid>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Thu, 17 Jul 2025 13:10:26 GMT</pubDate>
            <atom:updated>2025-07-17T18:38:25.227Z</atom:updated>
            <content:encoded><![CDATA[<h3>Interview PySpark Problem 2 : Combine and Aggregate Text Data by ID</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*BNXASlOGcxmYIBlH.png" /></figure><h3>Interview Question:</h3><p>You’re given a dataset with duplicate id values and unique description values. Your task is to:</p><p><strong>Group descriptions by ID</strong> into a single space-separated string.</p><p><strong>Reverse the process</strong>: split a combined string back into individual rows.</p><p>Let’s walk through this using PySpark, just like you would in a real-world data engineering pipeline.</p><h3>Sample Dataset</h3><pre>data = [<br>    (1, &quot;hello&quot;),<br>    (1, &quot;hi&quot;),<br>    (1, &quot;bye&quot;)<br>]<br>columns = [&quot;id&quot;, &quot;description&quot;]</pre><h3>Task 1: Group Descriptions by ID</h3><p>We want to turn this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3-c0C11BuE8-VFLCG-xDNg.png" /></figure><h3>PySpark Code</h3><pre>from pyspark.sql import SparkSession<br>from pyspark.sql.functions import collect_list, concat_ws</pre><pre>spark = SparkSession.builder.appName(&quot;CombineDescriptions&quot;).getOrCreate()</pre><pre>df = spark.createDataFrame(data, columns)</pre><pre># Group descriptions for each ID into a single string<br>combined_df = df.groupBy(&quot;id&quot;) \<br>    .agg(concat_ws(&quot; &quot;, collect_list(&quot;description&quot;)).alias(&quot;combined_description&quot;))</pre><pre>combined_df.show(truncate=False)</pre><h3>Output</h3><pre>+---+--------------------+<br>|id |combined_description|<br>+---+--------------------+<br>|1  |hello hi bye        |<br>+---+--------------------+</pre><h3>Task 2: Split Combined Descriptions Back into Rows</h3><p>Let’s reverse the previous transformation — convert the grouped table back to individual records:</p><pre>combined_data = [(1, &quot;hello hi bye&quot;)]<br>combined_columns = [&quot;id&quot;, &quot;combined_description&quot;]<br>combined_df = spark.createDataFrame(combined_data, combined_columns)</pre><p>We want to get:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GNh0IUU7woIkpDy3tyddrg.png" /></figure><h3>PySpark Code</h3><pre>from pyspark.sql.functions import split, explode</pre><pre># Split the string into an array, then explode into separate rows<br>split_df = combined_df.withColumn(&quot;description&quot;, explode(split(&quot;combined_description&quot;, &quot; &quot;))) \<br>                      .select(&quot;id&quot;, &quot;description&quot;)</pre><pre>split_df.show()</pre><h3>✅ Output</h3><pre>+---+-----------+<br>| id|description|<br>+---+-----------+<br>|  1|     hello |<br>|  1|        hi |<br>|  1|       bye |<br>+---+-----------+</pre><p>I hope you discovered something valuable today :)<br>Keep exploring and enjoy the journey of learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7650969bafc8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Interview PySpark Problem 1: Real Estate Data Cleaning]]></title>
            <link>https://medium.com/@prernahimanshu2/interview-pyspark-problem-1-real-estate-data-cleaning-84907005e30c?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/84907005e30c</guid>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Tue, 15 Jul 2025 13:35:49 GMT</pubDate>
            <atom:updated>2025-07-15T13:37:31.276Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*145mQUZkaXz3upnY.png" /></figure><h3>Interview Question:</h3><p>You are given a Real Estate dataset with the following schema:</p><pre>data = [<br>   (1001, &quot;2025-01-15&quot;, 250000, 1200, 3, 2, &quot;New York&quot;, &quot;sold&quot;),<br>   (1002, &quot;2025-02-20&quot;, None, 1500, 4, 3, &quot;Los Angeles&quot;, &quot;available&quot;),<br>   (1003, &quot;2025-01-30&quot;, 320000, -500, 2, 1, &quot;Chicago&quot;, &quot;sold&quot;),<br>   (1004, &quot;2025-03-10&quot;, 450000, 2000, None, 3, None, &quot;sold&quot;),<br>   (1002, &quot;2025-02-20&quot;, None, 1500, 4, 3, &quot;Los Angeles&quot;, &quot;available&quot;),  # duplicate<br>   (1005, &quot;invalid_date&quot;, 380000, 1800, 3, 2, &quot;Houston&quot;, &quot;sold&quot;)<br>]</pre><pre>columns = [&quot;property_id&quot;, &quot;sale_date&quot;, &quot;price&quot;, &quot;area_sqft&quot;, &quot;bedrooms&quot;, &quot;bathrooms&quot;, &quot;city&quot;, &quot;status&quot;]</pre><p>Perform the following data cleaning steps using PySpark:</p><ol><li>Remove duplicate records.</li><li>Convert sale_date to proper date format; filter out rows with invalid dates.</li><li>Handle missing values in price, bedrooms, and city.</li><li>Remove rows with invalid or negative area_sqft.</li><li>Impute missing bedrooms with the median of valid values.</li><li>Filter to only include rows where status == &#39;sold&#39;.</li><li>Return the final cleaned DataFrame.</li></ol><h3>Answer:</h3><pre>from pyspark.sql import SparkSession<br>from pyspark.sql.functions import col, to_date, when, isnan, count, lit, udf<br>from pyspark.sql.types import IntegerType<br>import pyspark.sql.functions as F</pre><pre># Initialize Spark<br>spark = SparkSession.builder.appName(&quot;RealEstateCleaning&quot;).getOrCreate()</pre><pre># Create initial DataFrame<br>data = [<br>   (1001, &quot;2025-01-15&quot;, 250000, 1200, 3, 2, &quot;New York&quot;, &quot;sold&quot;),<br>   (1002, &quot;2025-02-20&quot;, None, 1500, 4, 3, &quot;Los Angeles&quot;, &quot;available&quot;),<br>   (1003, &quot;2025-01-30&quot;, 320000, -500, 2, 1, &quot;Chicago&quot;, &quot;sold&quot;),<br>   (1004, &quot;2025-03-10&quot;, 450000, 2000, None, 3, None, &quot;sold&quot;),<br>   (1002, &quot;2025-02-20&quot;, None, 1500, 4, 3, &quot;Los Angeles&quot;, &quot;available&quot;),<br>   (1005, &quot;invalid_date&quot;, 380000, 1800, 3, 2, &quot;Houston&quot;, &quot;sold&quot;)<br>]</pre><pre>columns = [&quot;property_id&quot;, &quot;sale_date&quot;, &quot;price&quot;, &quot;area_sqft&quot;, &quot;bedrooms&quot;, &quot;bathrooms&quot;, &quot;city&quot;, &quot;status&quot;]</pre><pre>df = spark.createDataFrame(data, columns)</pre><pre># 1. Remove duplicates<br><strong>df = df.dropDuplicates()</strong></pre><pre># 2. Convert sale_date to DateType and remove invalid dates<br><strong>df = df.withColumn(&quot;sale_date&quot;, to_date(&quot;sale_date&quot;, &quot;yyyy-MM-dd&quot;))<br>df = df.filter(col(&quot;sale_date&quot;).isNotNull())</strong></pre><pre># 3. Remove rows with null price or null city<br><strong>df = df.filter(col(&quot;price&quot;).isNotNull() &amp; col(&quot;city&quot;).isNotNull())</strong></pre><pre># 4. Remove rows with invalid or negative area_sqft<br><strong>df = df.filter(col(&quot;area_sqft&quot;) &gt; 0)</strong></pre><pre># 5. Impute missing bedrooms with median<br># First calculate median<br><strong>bedroom_median = df.approxQuantile(&quot;bedrooms&quot;, [0.5], 0.01)[0]<br>df = df.withColumn(&quot;bedrooms&quot;, when(col(&quot;bedrooms&quot;).isNull(), bedroom_median).otherwise(col(&quot;bedrooms&quot;)))</strong></pre><pre># 6. Filter only sold properties<br><strong>df_cleaned = df.filter(col(&quot;status&quot;) == &quot;sold&quot;)</strong></pre><pre># Show final cleaned DataFrame<br><strong>df_cleaned.show()</strong></pre><h3>Expected Output:</h3><pre>+-----------+----------+------+---------+--------+---------+--------+-----+<br>|property_id| sale_date| price|area_sqft|bedrooms|bathrooms|    city|status|<br>+-----------+----------+------+---------+--------+---------+--------+-----+<br>|       1001|2025-01-15|250000|     1200|     3.0|        2|New York| sold|<br>|       1003|2025-01-30|320000|      500|     2.0|        1| Chicago| sold|<br>|       1004|2025-03-10|450000|     2000|     3.0|        3|    null| sold|<br>+-----------+----------+------+---------+--------+---------+--------+-----+</pre><p>I hope you discovered something valuable today :)<br>Keep exploring and enjoy the journey of learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84907005e30c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Core Concept : EXISTS vs NOT EXISTS in SQL - What’s the Difference?]]></title>
            <link>https://medium.com/@prernahimanshu2/sql-core-concept-exists-vs-not-exists-in-sql-whats-the-difference-b15c38805744?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/b15c38805744</guid>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Tue, 20 May 2025 12:32:44 GMT</pubDate>
            <atom:updated>2025-05-20T12:32:44.066Z</atom:updated>
            <content:encoded><![CDATA[<h3>SQL Core Concept : EXISTS vs NOT EXISTS in SQL - What’s the Difference?</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8VtqcnlrK4u2pMI_Pro_8A.png" /></figure><p>Both EXISTS and NOT EXISTS are used with <strong>subqueries</strong> (a query inside another query).</p><p>❗<strong>VERY IMPORTANT </strong>— They check <strong>if something exists</strong> in the database — but they work in <strong>opposite ways</strong>.</p><h3>✅ EXISTS: &quot;Do it if something IS there.&quot;</h3><pre>SELECT * FROM products<br>WHERE EXISTS (<br>    SELECT * FROM products WHERE name = &#39;Apple&#39;<br>);</pre><blockquote><em>🔍 This will return all products — </em><strong><em>only if</em></strong><em> there is a product called “Apple”.</em></blockquote><h3>1. Scenario: Checking if a Product is in Stock</h3><p>Imagine you work at an e-commerce company, and you need to check if a product with a specific ID is currently in stock. You have a table products with product details and another table inventory with stock details.</p><pre>SELECT * FROM products<br>WHERE EXISTS (<br>    SELECT * FROM inventory WHERE product_id = products.id AND stock &gt; 0<br>);</pre><p><strong>Explanation</strong>:</p><ul><li>You want to list all the products that are in stock.</li><li>The query checks if there’s an entry in the inventory table where the stock of a product is greater than 0.</li><li><strong>If the product has stock</strong>, EXISTS returns <strong>true</strong>, and the product is included in the result.</li></ul><h3>2. Layman Example: EXISTS</h3><h4>Example: Checking for the Presence of Pizza on the Menu</h4><p>Let’s say you own a restaurant and want to see if <strong>Pizza</strong> is available on the menu. You have a table menu that lists all the items.</p><pre>SELECT * FROM menu<br>WHERE EXISTS (<br>    SELECT * FROM menu WHERE item_name = &#39;Pizza&#39;<br>);</pre><p><strong>Layman Explanation</strong>:</p><ul><li>“If <strong>Pizza</strong> is on the menu, then show all the items on the menu.”</li><li>This query checks if <strong>Pizza</strong> exists in the menu. If it does, the <strong>entire menu</strong> is displayed.</li></ul><h3>3. Filtering Active Users in a System</h3><ul><li>Imagine a system where users can <strong>create posts</strong>. You want to show all active users who have posted at least once.</li><li>You can use EXISTS to check if a user has <strong>any posts</strong> associated with their account.</li></ul><pre>SELECT * FROM users<br>WHERE EXISTS (<br>    SELECT * FROM posts WHERE posts.user_id = users.id<br>);</pre><p><strong>Use Case Explanation</strong>:</p><ul><li>The query filters out users who have not created any posts and only shows those who have at least one post. It uses EXISTS to confirm the presence of posts.</li></ul><h3>❌ NOT EXISTS: &quot;Do it if something is NOT there.&quot;</h3><pre>SELECT * FROM products<br>WHERE NOT EXISTS (<br>    SELECT * FROM products WHERE name = &#39;Apple&#39;<br>);</pre><blockquote><em>🔍 This will return all products — </em><strong><em>only if</em></strong><em> there is </em><strong><em>no</em></strong><em> product called “Apple”.</em></blockquote><h3>1. Finding Employees Without Assignments</h3><ul><li>You’re managing a project and want to identify employees who haven’t been assigned any tasks yet.</li><li>Using NOT EXISTS, you can find all employees who do <strong>not</strong> have any task assignments.</li></ul><pre>SELECT * FROM employees<br>WHERE NOT EXISTS (<br>    SELECT * FROM tasks WHERE tasks.employee_id = employees.id<br>);</pre><p><strong>Use Case Explanation</strong>:</p><ul><li>This query helps you find employees who haven’t been given any tasks, so you can assign new projects to them.</li></ul><h3>2. Show All Customers Who Have Never Placed an Order</h3><p>You work at a retail company, and you need a list of customers who haven’t placed any orders yet. You have a customers table and an orders table.</p><pre>SELECT * FROM customers<br>WHERE NOT EXISTS (<br>    SELECT * FROM orders WHERE orders.customer_id = customers.id<br>);</pre><p><strong>Explanation</strong>:</p><ul><li>The query checks if a customer has placed any order by looking for matching customer_id in the orders table.</li><li><strong>If there are no orders</strong>, NOT EXISTS returns <strong>true</strong>, meaning the customer has never placed an order.</li><li>Only customers who <strong>have never placed an order</strong> are included in the result.</li></ul><h3>3. Checking if You Don’t Have Pizza on the Menu</h3><p>Let’s say you want to see the entire menu, but <strong>only if there’s no pizza</strong> on it. If <strong>pizza exists</strong>, you don’t want to show the menu.</p><pre>SELECT * FROM menu<br>WHERE NOT EXISTS (<br>    SELECT * FROM menu WHERE item_name = &#39;Pizza&#39;<br>);</pre><p><strong>Layman Explanation</strong>:</p><ul><li>“Show me the whole menu <strong>only if</strong> there is <strong>no pizza</strong> on it.”</li><li>If <strong>Pizza</strong> is already on the menu, it returns <strong>nothing</strong>; otherwise, it shows everything.</li></ul><h3>Think of it Like This:</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*U5eySchFph7SzVQqDiq0Og.png" /></figure><p>I hope you discovered something valuable today :)<br>Keep exploring and enjoy the journey of learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b15c38805744" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Problem 2: Return a Product Name or the Full List Based on ID]]></title>
            <link>https://medium.com/@prernahimanshu2/sql-problem-2-return-a-product-name-or-the-full-list-based-on-id-809348383b9e?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/809348383b9e</guid>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Tue, 20 May 2025 11:45:33 GMT</pubDate>
            <atom:updated>2025-05-20T11:45:33.284Z</atom:updated>
            <content:encoded><![CDATA[<p>Let’s say you have a list of products stored in a database table like this:</p><h3>📦 Product Table (products)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Mu2ccr7a3CyVDsDHWxHMHg.png" /></figure><p>Now, here’s the logic you want:</p><blockquote><em>🧠 If a product with a given </em><em>id exists, return </em><strong><em>only that product’s name and id</em></strong><em>.<br> ❌ If the product doesn’t exist, return the </em><strong><em>entire product list</em></strong><em>.</em></blockquote><h3>SQL Query</h3><p>Here’s a simple SQL query that does exactly that:</p><pre>-- Change 2 to any product id you want to look for<br>SELECT <br>    id,<br>    name<br>FROM products<br>WHERE id = 2<br><br>UNION ALL<br><br>SELECT <br>    id,<br>    name<br>FROM products<br>WHERE NOT EXISTS (<br>    SELECT 1 FROM products WHERE id = 2<br>);</pre><h3>How It Works</h3><ul><li>The <strong>first part</strong> tries to get the product with id = 2.</li><li>The <strong>second part</strong> checks if that ID <strong>doesn’t exist</strong>, and if so, returns the full product list.</li></ul><p>Thanks to UNION ALL, you’ll either:</p><ul><li>Get <strong>one row</strong> (if the ID is found), or</li><li>Get the <strong>full table</strong> (if the ID is not found).</li></ul><h3>Example Results</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KegGIP1uu38iNYzBAyBjiA.png" /></figure><p><strong>💡 Use Cases</strong></p><ul><li>Building a product lookup tool</li><li>Creating fallback behavior for invalid IDs</li><li>Simplifying logic in APIs or dashboards</li></ul><p>I hope you discovered something valuable today :)<br>Keep exploring and enjoy the journey of learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=809348383b9e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL Problem 1: Find Starting Point and Final Destination for Each Customer]]></title>
            <link>https://medium.com/@prernahimanshu2/sql-problem-1-find-starting-point-and-final-destination-for-each-customer-2e9d8e2c6c6d?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/2e9d8e2c6c6d</guid>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Tue, 20 May 2025 08:54:40 GMT</pubDate>
            <atom:updated>2025-05-20T11:47:23.300Z</atom:updated>
            <content:encoded><![CDATA[<p>Given a list of flights taken by each customer, can you figure out:</p><ul><li><strong>Where did their journey begin?</strong></li><li><strong>Where did it end?</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vx5lg9o53TOCWbYPP54Q7g.png" /></figure><h3>Visualizing Customer 1’s Journey</h3><p>Think of each flight as an arrow pointing from the origin city to the destination city. For cust_id = 1, the journey looks like this:</p><p>New York ➡️ Chicago ➡️ Denver ➡️ San Diego</p><ul><li><strong>Start:</strong> New York (this is the first place they took off from)</li><li><strong>End:</strong> San Diego (this is their final destination)</li></ul><h3>Visualizing Customer 2’s Journey</h3><p>Similarly, for cust_id = 2, the journey is:</p><p>Miami ➡️ Atlanta ➡️ Boston</p><ul><li><strong>Start:</strong> Miami</li><li><strong>End:</strong> Boston</li></ul><p>This graph-style view helps us understand each customer’s travel path clearly, making it easier to identify where they started and where they ended.</p><p>We just saw the flight paths like arrows on a map. Now, how can SQL help us find the <strong>first origin</strong> and <strong>last destination</strong> for each customer?</p><h3>Method 1: Using Flight Order (ROW_NUMBER())</h3><p>If the flights have IDs that show their order, we can:</p><ul><li>Assign a number to each flight per customer, starting from the earliest flight (ROW_NUMBER() by ascending flight_id).</li><li>The flight with number 1 is the <strong>first flight</strong> → so its origin is the start.</li><li>Similarly, the flight with the highest number is the <strong>last flight</strong> → so its destination is the end.</li></ul><pre>WITH ordered_flights AS (<br>    SELECT *,<br>           ROW_NUMBER() OVER (PARTITION BY cust_id ORDER BY flight_id ASC) AS rn_start,<br>           ROW_NUMBER() OVER (PARTITION BY cust_id ORDER BY flight_id DESC) AS rn_end<br>    FROM Flights<br>),<br>first_flight AS (<br>    SELECT cust_id, origin AS first_origin<br>    FROM ordered_flights<br>    WHERE rn_start = 1<br>),<br>last_flight AS (<br>    SELECT cust_id, destination AS last_destination<br>    FROM ordered_flights<br>    WHERE rn_end = 1<br>)<br>SELECT f.cust_id, f.first_origin, l.last_destination<br>FROM first_flight f<br>JOIN last_flight l ON f.cust_id = l.cust_id;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z4y2kvsW9nakZ7w1XqazSg.png" /></figure><h3>Method 2: Using Graph Traversal (No Order Needed)</h3><p>Sometimes, flight IDs might not be reliable. Instead, we use a graph logic:</p><ul><li>The <strong>start point</strong> is the city that appears as an origin but never as a destination.</li><li>The <strong>end point</strong> is the city that appears as a destination but never as an origin.</li></ul><p>SQL uses LEFT ANTI JOIN to find these:</p><pre>WITH origin AS (<br>    SELECT f1.cust_id, f1.origin AS startpoint<br>    FROM Flights f1<br>    LEFT ANTI JOIN Flights f2<br>        ON f1.cust_id = f2.cust_id<br>       AND f1.origin = f2.destination<br>),<br>destination AS (<br>    SELECT f1.cust_id, f1.destination AS endpoint<br>    FROM Flights f1<br>    LEFT ANTI JOIN Flights f2<br>        ON f1.cust_id = f2.cust_id<br>       AND f1.destination = f2.origin<br>)<br>SELECT o.cust_id, startpoint, endpoint<br>FROM origin o<br>JOIN destination d ON o.cust_id = d.cust_id;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z4y2kvsW9nakZ7w1XqazSg.png" /></figure><h3>Summary</h3><ul><li><strong>Method 1</strong> works well if you trust flight order.</li><li><strong>Method 2</strong> works even if flight order is missing, by thinking of flights as graph edges.</li></ul><p>Either way, you get a clear view of where each customer’s journey began and ended!</p><p>I hope you discovered something valuable today :)<br>Keep exploring and enjoy the journey of learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2e9d8e2c6c6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Lambda vs. Kappa Architecture Explained with Real-Life Examples]]></title>
            <link>https://medium.com/@prernahimanshu2/lambda-vs-kappa-architecture-explained-with-real-life-examples-8090d4cbccf4?source=rss-85f0c9ab9d7d------2</link>
            <guid isPermaLink="false">https://medium.com/p/8090d4cbccf4</guid>
            <dc:creator><![CDATA[Prerna Mishra]]></dc:creator>
            <pubDate>Wed, 07 May 2025 17:18:17 GMT</pubDate>
            <atom:updated>2025-05-07T17:18:17.264Z</atom:updated>
            <content:encoded><![CDATA[<p>As big data continues to grow in <strong>volume</strong> and <strong>velocity</strong>, companies need smarter ways to handle <strong>both real-time</strong> and <strong>historical data</strong>. This is where <strong>Lambda</strong> and <strong>Kappa architectures</strong> step in.</p><p>Although they might sound complex, let’s break them down using <strong>simple analogies and real-world use cases</strong>.</p><ol><li>What is <strong>Lambda Architecture?</strong></li></ol><p><strong>Think of it like a two-lane highway.</strong></p><ul><li><strong>One lane (Batch Layer)</strong> moves slowly but safely — it processes all the data with full accuracy.</li><li><strong>The other lane (Speed Layer)</strong> zooms fast — it catches real-time data quickly but may miss some details.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*dcmhy4RMpgg80TUy.png" /><figcaption>Image by InterviewBit</figcaption></figure><h3>Real-Life Example: Fraud Detection in Banking</h3><ul><li>Think of banks like <strong>HSBC</strong> or <strong>PayPal</strong>.</li><li><strong>Speed Layer</strong>: Detects immediate fraud signals — e.g., a sudden $1,000 transfer from an unknown location triggers a red flag.</li><li><strong>Batch Layer</strong>: Periodically reviews all transactions in bulk to refine fraud detection algorithms and retrain ML models.</li></ul><p>🔁 This <strong>dual-layer approach</strong> ensures both <strong>speed</strong> and <strong>accuracy</strong>.</p><p><strong>2. What is Kappa Architecture?</strong></p><p><strong>Think of it like a one-lane express train.</strong></p><ul><li>All data flows through a single real-time stream.</li><li>If something goes wrong or needs to be reprocessed? Just <strong>replay the stream</strong>!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-O-MNGRElH01yH0C.png" /><figcaption>Image by InterviewBit</figcaption></figure><h3>Real-Life Use Case: Uber Ride Matching</h3><p>Companies like <strong>Uber</strong> rely heavily on <strong>real-time data</strong>, such as:</p><ul><li>Driver and rider locations</li><li>Trip requests</li><li>Traffic conditions</li></ul><p>The system continuously processes these inputs to <strong>match riders and drivers</strong>, <strong>estimate arrival times</strong>, and <strong>adjust prices</strong> — all in real time.</p><p>🆚 <strong>Lambda vs. Kappa — At a Glance</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VOKCQG2w5k6LBVnYcWHi2A.png" /></figure><h3>Which One Should You Choose?</h3><ul><li><strong>Choose Lambda</strong> when you need <em>historical accuracy and fast insights</em>.<br> ➤ Example: Financial systems, healthcare analytics</li><li><strong>Choose Kappa</strong> for <em>simpler, real-time-heavy applications</em>.<br> ➤ Example: Logistics, social media, ride-sharing platforms</li></ul><p><strong>Final Thought:</strong><br> Lambda offers <strong>depth + speed</strong>; Kappa offers <strong>simplicity + immediacy</strong>. Your choice depends on your system’s <strong>data needs</strong>, <strong>latency tolerance</strong>, and <strong>complexity budget</strong>.</p><p>I hope you discovered something valuable today :)<br>Keep exploring and enjoy the journey of learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8090d4cbccf4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>