<?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 Vinay Kumar on Medium]]></title>
        <description><![CDATA[Stories by Vinay Kumar on Medium]]></description>
        <link>https://medium.com/@muppanavinay?source=rss-a6ec4dd8dc93------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*RiHO7TgqgzOoQpV4.jpg</url>
            <title>Stories by Vinay Kumar on Medium</title>
            <link>https://medium.com/@muppanavinay?source=rss-a6ec4dd8dc93------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 04:36:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@muppanavinay/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[How a Simple Build Server Slowly Became a Distributed Build Platform]]></title>
            <link>https://medium.com/@muppanavinay/how-a-simple-build-server-slowly-became-a-distributed-build-platform-c6574dd39808?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/c6574dd39808</guid>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Sun, 17 May 2026 07:43:47 GMT</pubDate>
            <atom:updated>2026-05-17T07:43:47.061Z</atom:updated>
            <content:encoded><![CDATA[<p>A developer pushes code.<br>A build starts somewhere.<br>A few minutes later, a green checkmark appears.</p><p>From the outside, CI systems look almost boring.<br>Just pull code and run some scripts… right? That assumption is exactly where this story begins.</p><p>Over the last decade, I’ve worked on large-scale backend and platform systems, led engineering teams, and spent years around the messy realities of internal developer infrastructure. Somewhere along the way, I became deeply fascinated by build systems — not because they looked complicated at first, but because they <em>didn’t</em>.</p><p>This series is a journey through that evolution. <br>We’ll start with something deceptively simple — a tiny build server inspired by early tools like Jenkins and TeamCity — and slowly evolve it into something much closer to a real-world modern build platform.</p><p>But here’s the interesting part:</p><p>Most sophisticated engineering systems don’t begin with sophisticated architecture.</p><p>They begin with:</p><blockquote><em>“This should be easy.”</em></blockquote><h4>The Simplest CI System You Can Imagine</h4><p>How hard can it really be to build a small CI system for your team?<br>A webhook receives a git push.<br>Clone the repo.<br>Run a build script.<br>Stream the logs.<br>Show a green or red badge.<br>Done… right?</p><p>For a small team, this honestly feels like a weekend project. And that’s exactly why almost every engineer eventually underestimates build systems.<br>At first glance, tools like Jenkins almost feel over engineered.</p><p>Why would anyone need plugins, distributed workers, schedulers, pipelines, agents, or orchestration layers just to run a few scripts?</p><p>In the beginning, even our setup was painfully simple.</p><p>One machine.<br>One workspace.<br>One running build at a time.<br>And strangely enough… it worked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GWSqj5lju5jsAJNzZp_C8w.png" /></figure><h3>The First Version Felt Almost Too Easy</h3><p>The first version of the system barely deserved to be called a “platform.”<br>A small service listened for git events.</p><p>Whenever somebody pushed code:</p><ul><li>the repository was cloned,</li><li>a build script was executed,</li><li>logs were streamed to a tiny UI,</li><li>and the final status was stored somewhere in a database.</li></ul><p>That was enough to make the entire team happy. Until a simple question appeared:</p><blockquote><em>What happens when two developers push code at the same time?</em></blockquote><h3>The First Real Problem</h3><p>At first, the answer looked obvious: just queue the builds.</p><p>If one build was already running, the next build could simply wait until the machine became free. For a small team, this worked surprisingly well. The system stayed simple, predictable, and easy to debug.</p><p>But the moment builds started becoming longer, the cracks appeared.</p><p>A single slow build could block everyone behind it. One developer running a massive test suite suddenly meant the rest of the team had to wait 30 or 40 minutes just to get basic feedback on their changes.</p><p>Naturally, the next question appeared:</p><blockquote><em>Why not run multiple builds in parallel?</em></blockquote><h3>Parallel Builds Change Everything</h3><p>Running builds in parallel sounded like a tiny improvement.</p><p>Instead of one build at a time, the machine could execute multiple builds simultaneously and dramatically reduce waiting time for developers. On paper, it looked like the perfect solution.</p><p>Until the builds started interfering with each other.</p><p>One build updated dependencies while another was already compiling. Temporary files leaked across workspaces. Shared directories became unpredictable. Sometimes builds failed randomly, and rerunning the exact same commit magically fixed the issue.</p><p>Those failures were the worst kind:</p><ul><li>inconsistent,</li><li>difficult to reproduce,</li><li>and almost impossible to debug confidently.</li></ul><p>For the first time, the problem was no longer “running a script.”</p><p>The problem had quietly become isolation.</p><h3>The Isolation Fix</h3><p>The obvious fix was to isolate every build from every other build.</p><p>Instead of sharing the same workspace, each build would get its own clean environment. No shared dependencies. No leftover temporary files. No accidental interference from another running job.</p><p>This idea slowly pushed the industry toward tools like containers and dedicated build agents. Systems like Jenkins started making a lot more sense once you experienced these failures firsthand.</p><p>And honestly, isolation worked.</p><p>Builds became far more predictable. Random failures dropped dramatically. Developers trusted the system again.</p><p>But isolation introduced a completely different problem.</p><p>Every build now behaved like a fresh machine starting from scratch.</p><h3>Clean Environments Are Expensive</h3><p>At first, the slowdown felt acceptable.</p><p>A few extra seconds to create a clean environment didn’t seem like a big deal compared to the stability we gained. Most teams would happily trade a little performance for predictable builds.</p><p>But over time, those “few extra seconds” started multiplying.</p><p>Every build now had to:</p><ul><li>pull dependencies again,</li><li>initialize tooling again,</li><li>prepare the environment again,</li><li>and rebuild caches that already existed somewhere else minutes earlier.</li></ul><p>The system had become reliable.</p><p>But it had also become inefficient.</p><p>And naturally, the next idea appeared:</p><blockquote><em>What if builds could share some state safely?</em></blockquote><h3>The Beginning Of Accidental Complexity</h3><p>At this point, the system was still running on a single machine.</p><p>There were no distributed workers.</p><p>No orchestration layer.</p><p>No sophisticated schedulers.</p><p>And yet, the architecture was already becoming more complicated than we originally expected.</p><p>A system that started as:</p><ul><li>“clone repo,”</li><li>“run script,”</li><li>“show result”</li></ul><p>was now dealing with:</p><ul><li>concurrent execution,</li><li>workspace isolation,</li><li>dependency management,</li><li>and performance tradeoffs around shared state and caching.</li></ul><p>The interesting part is that none of this complexity was planned.</p><p>Every change was a reasonable reaction to a real problem:</p><ul><li>queues fixed contention,</li><li>parallelism fixed queues,</li><li>isolation fixed interference,</li><li>caching tried to fix isolation costs.</li></ul><p>And this pattern appears again and again in large engineering systems.</p><p>Sophisticated platforms rarely begin with sophisticated architecture.</p><p>They evolve into it, one production problem at a time.</p><p>In the next article, we’ll continue this journey by solving the next obvious bottleneck:</p><blockquote><em>what happens when one machine is no longer enough?</em></blockquote><p>And this was only the beginning.</p><p>What started as a tiny internal build server was already evolving into something far more complicated than we originally imagined.</p><p>In the next article, we’ll continue this journey by solving the next obvious problem:</p><blockquote><em>what happens when a single machine can no longer handle the entire engineering team?</em></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c6574dd39808" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building Kafka Architecture — A Common-Sense Approach]]></title>
            <link>https://medium.com/@muppanavinay/building-kafka-architecture-a-common-sense-approach-c24f242b9239?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/c24f242b9239</guid>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[streaming]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Sun, 08 Feb 2026 05:17:48 GMT</pubDate>
            <atom:updated>2026-02-08T05:17:48.405Z</atom:updated>
            <content:encoded><![CDATA[<h3>Building Kafka Architecture — A Common-Sense Approach</h3><p>Without going into too much background, let’s assume a few things. If you’ve started reading this article, you probably already have a basic idea of what a messaging or pub-sub system is.</p><p>In this article, we’ll build Kafka step by step — not by memorizing components, but by solving real problems as they naturally appear. Each time we hit a limitation, we’ll think through it using common sense and evolve our system, eventually arriving at what we now call <strong>Kafka</strong>.</p><p>Let’s begin.</p><p>Kafka is a messaging system, so two things are obvious — <strong>producers</strong> (send messages) and <strong>consumers</strong> (receive messages). <br>In the simplest setup, a producer sends a message directly to a consumer. The consumer immediately acknowledges receipt, while actual processing happens asynchronously.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mLYktWeGiqfSN-Gtn8l7zw.png" /></figure><p><strong>Problems appear quickly:</strong></p><ul><li>Consumer may crash after receiving the message but before processing it</li><li>Producer may crash before receiving the acknowledgement</li><li>Multiple consumers may need the same message</li><li>Direct connections between many producers and consumers do not scale</li></ul><p>Clearly, direct producer-to-consumer communication is fragile and not scalable. We need an intermediate system.</p><p>Thinking about this, a simple idea emerges — introduce another machine in between that temporarily holds the data.<br>Now, producers don’t send messages directly to consumers. Instead, they write messages to this intermediate system, which stores them durably — typically as an <strong>append-only log</strong> on disk (optionally cached in memory for faster reads).<br>With this setup, even if the <strong>producer crashes</strong> or the <strong>consumer crashes</strong>, the message safely exists in the middle system and can be processed later.</p><p>This middle machine is what we call a broker.</p><p>Now another thought: what if there are <strong>different types of messages</strong>?</p><p>We can categorize messages into logical groups called <strong>topics</strong> — similar to topics of discussion. Each topic contains messages of a specific type, and the <strong>broker</strong> manages the storage of these topics and their messages.</p><p><strong>Next concern:</strong> what if the <strong>broker itself goes down</strong>? The system must remain available.<br> To handle this, we introduce <strong>replication</strong> — each topic’s data is copied across multiple brokers so that if one broker fails, another can continue serving the data without interruption.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q9SMsHvGEXM5w5iR8k_QDA.png" /></figure><p>But wait… another problem shows up.</p><p>All producers are still writing to <strong>one growing log</strong>. As traffic increases, this single log becomes a bottleneck. One machine simply cannot keep up forever.</p><p>Then a simple idea strikes:</p><p><em>What if instead of one big log, we quietly split it into many smaller logs and spread them across machines?</em></p><p>Now messages don’t fight for the same space anymore. Each message can decide <strong>which smaller log to go to</strong>, using something like a key — for example, <em>userId</em>, <em>orderId</em>, or anything meaningful.</p><p>And that’s the moment we realize:</p><p><strong>This is what Kafka calls a <em>partition</em>.</strong></p><p>A topic is not a single log at all — it is a <strong>collection of partitions</strong>, and the key that decides where a message goes is called the <strong>partition key</strong>.</p><p>Nice… producers are finally relaxed.</p><p>But now the <strong>consumers start crying</strong>.</p><p>Traffic increases, messages pile up, and a single consumer cannot keep up. Adding more consumers seems obvious — but then a new question appears:</p><p><em>If multiple consumers read the same partition, who processes which message?</em><br> Chaos. Duplicate processing. Broken ordering. Not good.</p><p>Then another simple realization:</p><p><em>What if we divide the work the same way we divided the data?</em></p><p>Each partition can be assigned to <strong>one consumer</strong>, and we can group consumers together so they automatically share the work.</p><p>And that’s the “aha” moment:</p><p><strong>This is what Kafka calls a <em>consumer group</em>.</strong></p><ul><li>One consumer can handle <strong>multiple partitions</strong></li><li>But <strong>one partition is handled by only one consumer within the group</strong>, keeping ordering intact while still allowing the system to scale.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WaDN8Tjm3hewbYU4HsvSkw.png" /></figure><p>Producers are producing, partitions are scaling, consumer groups are sharing the work… life looks good.</p><p>But then a slightly uncomfortable question appears:</p><p><em>What happens if a consumer crashes in the middle of processing?</em><br> When it comes back, how does it know <strong>where to resume</strong>? Start from the beginning? That would reprocess everything. Start from the end? That would lose data. Both are terrible ideas.</p><p>Clearly, the system needs a way to <strong>remember the exact position up to which each consumer has already processed messages</strong>, and this position must survive consumer restarts, broker failures, and rebalances.</p><p>We’ll come back to how Kafka solves this in a moment.</p><p>So we needed a reliable bookmark — something that tells a consumer exactly <strong>where it stopped reading</strong>, even if it crashes and comes back later.</p><p>Kafka solves this very elegantly.</p><p>Inside every partition, messages are stored sequentially and automatically numbered:</p><p><strong>0, 1, 2, 3, 4…</strong></p><p>That sequence number is called the <strong>offset</strong> — essentially the message’s position inside the partition.<br> A consumer simply records the last message it has successfully processed and resumes from the next number when it restarts.</p><p>But another thought appears:</p><p><em>Where should this bookmark live? Inside the consumer? What if the machine running the consumer disappears?</em></p><p>Kafka keeps these committed positions safely inside Kafka itself (in an internal topic), so even if <strong>consumers restart, brokers fail, or rebalances happen</strong>, consumers can resume reading from the correct point without losing track.</p><p>And because each partition is an append-only log, <strong>message ordering is guaranteed within a partition</strong>, which means processing in offset order preserves correctness naturally.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/842/0*ch7PFpXJOzkVFklq.png" /></figure><p>Everything looks reliable now, but another practical problem appears:</p><p><em>Can Kafka store messages forever?</em><br> If every message stays permanently, disks will fill up very quickly, and our “infinite log” dream will end in a very finite outage.</p><p>So instead of storing messages forever, Kafka allows us to define a <strong>retention policy</strong>:</p><ul><li>Keep messages for a <strong>specific time</strong> (for example, 7 days), or</li><li>Keep messages until the <strong>log reaches a certain size</strong>, after which older data is automatically removed.</li></ul><p>For some use cases, we don’t even care about every historical value — we only care about the <strong>latest value per key</strong>. For those cases, Kafka provides <strong>log compaction</strong>, where older records for the same key are cleaned up while preserving the most recent one.</p><p><strong>Now comes the durability question</strong></p><p>We replicated partitions across brokers — great.<br> But another important question appears:</p><p><em>When can a producer safely assume that the message is truly written?</em><br> What if the leader broker writes the message and crashes <strong>before followers copy it</strong>?</p><p>Kafka solves this using <strong>acknowledgement levels (acks)</strong>:</p><ul><li><strong>acks=0</strong> → Producer does not wait for confirmation (fast, risky)</li><li><strong>acks=1</strong> → Leader confirms once it writes the message (safer, but leader crash may still lose data)</li><li><strong>acks=all</strong> → Leader waits until all <strong>in-sync replicas (ISR)</strong> confirm the write (safest option)</li></ul><p>Now naturally another realisation happens:</p><p><em>Not every replica should be trusted equally.</em><br> Only replicas that are fully caught up with the leader are considered part of the <strong>ISR (In-Sync Replica set)</strong>.<br> Kafka ensures durability by allowing the leader to acknowledge writes only after replicas in the <strong>ISR</strong> confirm the data.</p><p>But another question appears:</p><p><em>Who decides what happens when a broker dies? Who selects the new leader for a partition?</em></p><p>Kafka solves this using a <strong>cluster controller</strong> — a broker elected among all brokers whose job is to manage metadata, detect broker failures, and trigger <strong>leader elections</strong> for affected partitions.</p><p>When a leader broker goes down:</p><ol><li>The controller detects the failure</li><li>One of the <strong>in-sync replicas (ISR)</strong> is selected as the new leader</li><li>Producers and consumers automatically start communicating with the new leader</li></ol><p>From the outside, the system continues running, often without users even noticing that a failure happened.</p><p>Just when everything looks perfect, another distributed-systems problem quietly appears.</p><p>A producer sends a message… the network times out… the producer retries… and now the same message may be written <strong>twice</strong>.<br> Consumers suddenly start seeing duplicates, downstream systems behave strangely, and debugging becomes a detective story.</p><p>We clearly need a way to ensure that <strong>retries do not create duplicate records</strong>.</p><p>We can solves this by attaching sequence information to messages sent by a producer, allowing the broker to recognise retries and accept each message <strong>only once</strong>, even if it was sent multiple times.</p><p><strong>And voilà — this is what Kafka calls an <em>Idempotent Producer</em>.</strong></p><p>But the story doesn’t end there.</p><p>Another challenge appears:</p><p>A service reads from topic A, processes the data, and writes results to topic B.<br> What if the system crashes <strong>after writing to one partition but before writing to another</strong>? Now the system is in a half-completed state.</p><p>We need a way to ensure that <strong>multiple writes either all succeed together or none succeed at all</strong>.</p><p>Kafka introduces atomic multi-partition writes to solve this problem.</p><p><strong>And voilà — this is what Kafka calls <em>Transactions</em> (Exactly-Once Semantics).</strong></p><p>And that’s the final realisation:</p><p>Step by step, solving simple reliability and scaling problems using common sense, we didn’t just build a message queue — we built the foundation of a <strong>real-time streaming platform</strong>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c24f242b9239" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apache Flink Architecture — How One JAR Becomes Many Threads (Finally Explained)]]></title>
            <link>https://medium.com/@muppanavinay/apache-flink-architecture-how-one-jar-becomes-many-threads-finally-explained-24fc958e0f4f?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/24fc958e0f4f</guid>
            <category><![CDATA[design]]></category>
            <category><![CDATA[architecture]]></category>
            <category><![CDATA[deep-dives]]></category>
            <category><![CDATA[apache-flink]]></category>
            <category><![CDATA[deep-thoughts]]></category>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Fri, 30 Jan 2026 04:14:59 GMT</pubDate>
            <atom:updated>2026-01-30T04:14:59.310Z</atom:updated>
            <content:encoded><![CDATA[<h3>Apache Flink Architecture — How One JAR Becomes Many Threads (Finally Explained)</h3><p>For a long time, I used <strong>Apache Flink</strong> without being fully comfortable with <em>how</em> it actually works.</p><p>I could write:</p><pre>.keyBy(host)<br>.window(...)<br>.aggregate(...)</pre><p>But in my head, things felt vague:</p><ul><li>Where are the threads?</li><li>How does one JAR run in parallel?</li><li>Who decides which data goes where?</li><li>What does “shuffle” actually mean?</li></ul><p>I couldn’t accept “Flink handles it” as an answer.</p><p>So this article is my attempt to explain Flink <strong>the way it finally clicked for me</strong> — from the ground up, without skipping any architectural truth.</p><h3>1. What Flink Really Is</h3><p>Apache Flink is a <strong>stream processing engine</strong>.</p><ul><li>It can read from <strong>multiple sources</strong> (Kafka, DB, HTTP, files)</li><li>It can write to <strong>multiple sinks</strong></li><li>It processes <strong>bounded and unbounded streams</strong></li><li>Everything is modeled as a <strong>pipeline</strong></li></ul><p>A running Flink application is called a <strong>Job</strong>.</p><p>That job processes data through a pipeline called a <strong>Job Graph</strong>.</p><h3>2. The Most Important Realization</h3><blockquote><strong><em>A Flink JAR contains only code.<br> It contains no threads, no parallelism, no execution.</em></strong></blockquote><p>This single idea removes half the confusion.</p><p>Your JAR is just:</p><ul><li>operator definitions</li><li>business logic</li><li>serialization code</li></ul><p>Execution is decided <strong>later</strong>, by Flink itself.</p><h3>3. The Two Physical Components That Exist</h3><p>At runtime, only <strong>two real processes</strong> matter:</p><h3>1. JobManager (Control Plane)</h3><p>The JobManager:</p><ul><li>Runs your main() method</li><li>Reads your JAR</li><li>Discovers operators (map, keyBy, window, etc.)</li><li>Builds the <strong>logical DAG</strong></li><li>Converts it into an <strong>ExecutionGraph</strong></li><li>Schedules work</li></ul><p>The JobManager <strong>never processes data</strong>.</p><h3>2. TaskManagers (Execution Plane)</h3><p>TaskManagers:</p><ul><li>Are JVM processes</li><li>Execute the job</li><li>Run your code</li><li>Own threads and memory</li></ul><p>This is where all data processing happens.</p><h3>4. Operators vs Operator Subtasks (Critical Distinction)</h3><p>This was the biggest mental block for me.</p><h3>Operator (Logical)</h3><p>An operator is a <strong>template</strong>, not a running thing.</p><p>Examples:</p><ul><li>Map</li><li>Filter</li><li>Window</li><li>Aggregate</li></ul><p>They exist only in the DAG.</p><h3>Operator Subtask (Physical)</h3><p>When parallelism is applied, Flink creates <strong>operator subtasks</strong>.</p><p>If parallelism = 3:</p><pre>Map operator<br> ├── Map-1<br> ├── Map-2<br> └── Map-3</pre><p>Each subtask:</p><ul><li>Is a real execution unit</li><li>Processes a subset of data</li><li>Runs independently</li></ul><blockquote><strong><em>Operator subtasks are the smallest execution units in Flink.</em></strong></blockquote><h3>5. TaskManagers, Slots, and Threads (No More Confusion)</h3><p>Inside a TaskManager JVM:</p><pre>TaskManager (JVM)<br> ├── Slot 1 (resource container)<br> │     └── Thread → Operator Subtask(s)<br> ├── Slot 2<br> │     └── Thread → Operator Subtask(s)<br> └── Slot 3<br>       └── Thread → Operator Subtask(s)</pre><p>Key truths:</p><ul><li>A <strong>slot is NOT a thread</strong></li><li>A slot is a <strong>resource reservation</strong></li><li>Each operator subtask runs in <strong>exactly one thread</strong></li><li>Threads are long-lived</li></ul><blockquote><strong><em>Operator subtask = execution thread</em></strong></blockquote><p>That sentence is safe to memorize.</p><h3>6. Operator Chaining (Default Behaviour)</h3><p>If no data redistribution is needed, Flink <strong>chains operators</strong>.</p><p>Example:</p><pre>source.map().filter()</pre><p>Runtime execution:</p><pre>Thread:<br>  Source → Map → Filter</pre><p>This means:</p><ul><li>Same slot</li><li>Same thread</li><li>Just Java method calls</li><li>No serialization</li><li>No network</li></ul><p>This is the <strong>default and preferred</strong> execution model.</p><h3>7. What a Shuffle Actually Means</h3><p>This is where Flink becomes interesting.</p><h3>Definition (the one that finally worked for me)</h3><blockquote><strong><em>A shuffle is when data must move from one operator subtask thread to another operator subtask thread, based on a routing rule.</em></strong></blockquote><p>Nothing more. Nothing less.</p><h3>What causes a shuffle?</h3><p>The most common cause:</p><pre>.keyBy(host)</pre><p>Why?<br> Because Flink must guarantee:</p><blockquote><strong><em>All records with the same key go to the same thread.</em></strong></blockquote><p>That guarantee <strong>cannot</strong> be upheld without redistribution.</p><h3>8. What Happens During a Shuffle (Step-by-Step)</h3><ol><li>An event is processed upstream</li><li>Flink applies a partitioning rule:</li></ol><pre>targetSubtask = hash(key) % parallelism</pre><ol><li>The event is:</li></ol><ul><li>serialized</li><li>written to a network buffer</li><li>sent to the target TaskManager</li></ul><ol><li>A different thread receives it</li><li>Processing continues</li></ol><p>This breaks chaining.</p><p>So execution becomes:</p><pre>Thread A (Source → Map → Filter)<br>   ↓ shuffle<br>Thread B (Window/Aggregate)</pre><h3>9. Why Aggregation Happens After Shuffle</h3><p>Consider:</p><pre>.keyBy(host)<br>.window(...)<br>.aggregate(...)</pre><p>After keyBy:</p><ul><li>Each key is assigned to <strong>exactly one subtask</strong></li><li>That subtask:</li><li>owns the state</li><li>runs in one thread</li><li>aggregates safely</li></ul><p>There is:</p><ul><li>no locking</li><li>no shared state</li><li>no race conditions</li></ul><blockquote><strong><em>One key → one subtask → one thread</em></strong></blockquote><p>This is the core design of Flink.</p><h3>10. Scheduling Is About Resources, Not Semantics</h3><p>One important realization:</p><blockquote><em>An aggregate subtask runs in Slot 4 not because Slot 4 is “special”, but because the scheduler had capacity there.</em></blockquote><p>Slots do not represent meaning.<br> They represent <strong>available resources</strong>.</p><p>Semantics live in:</p><ul><li>operators</li><li>keys</li><li>routing rules</li></ul><h3>11. One JAR, Many Threads (The Final Picture)</h3><p>Even though I wrote:</p><pre>.aggregate(...)</pre><p>Once,<br> Flink runs it:</p><ul><li>in multiple threads</li><li>in multiple TaskManagers</li><li>for different keys</li><li>with isolated state</li></ul><p>Same code.<br> Many executions.</p><h3>12. The Mental Model That Finally Stuck</h3><pre>JAR           → code only<br>Operator      → logical template<br>Parallelism   → number of subtasks<br>Subtask       → execution instance<br>Thread        → runs the subtask<br>Slot          → resource container<br>Chaining      → same thread<br>Shuffle       → data redistribution + new thread</pre><p>If I remember this, I remember Flink.</p><h3>Closing Thought</h3><p>Apache Flink is sophisticated not because it hides complexity — <br> but because it <strong>contains</strong> complexity so you don’t have to manage it.</p><p>Once I understood:</p><ul><li>how DAGs become threads</li><li>why shuffles exist</li><li>how correctness is guaranteed</li></ul><p>Flink stopped being a black box.</p><p>It became an <strong>engine I can reason about</strong>.</p><p>And that, for me, was the real win.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24fc958e0f4f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CTR — Click through rate]]></title>
            <link>https://medium.com/@muppanavinay/ctr-click-through-rate-3be24acabe47?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/3be24acabe47</guid>
            <category><![CDATA[digital-marketing]]></category>
            <category><![CDATA[ctr]]></category>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Tue, 20 May 2025 11:36:25 GMT</pubDate>
            <atom:updated>2025-05-20T11:36:25.063Z</atom:updated>
            <content:encoded><![CDATA[<h3>CTR — Click through rate</h3><p>In the digital marketing era, CTR stands for click-through rate: a metric that measures the number of clicks advertisers receive on their ads per the number of views.</p><p>To get your PPC successful it is very important to get a high click-through rate , because both your Quality Score and how much you pay every time someone clicks your search ad gets directly effected.</p><h4>In Broader terms CTR is defined as : -</h4><p>Ad Clicks ÷ Ad Impressions = Click-Through Rate (CTR)</p><p>It is a calculation of number of users clicked on an ad(clicks) divided by the number of times the ad was shown (impressions).</p><h3>CTR is a key Metric — (Why does it matter anyway ?)</h3><p>Click-through rate is important to your account because it directly effects your Quality Score — (<a href="https://www.wordstream.com/quality-score">https://www.wordstream.com/quality-score</a>)</p><p>Image&lt;quality score vs ctr&gt;</p><p>Search marketing platforms like Google Ad Words and other offer pricing discounts for ads that offer high relevance. One means for doing this is to offer higher Quality Scores to ads with high Add words click through rates.</p><ul><li>High click-through rates = high Quality Scores.</li><li>High Quality Scores allow you to improve or maintain <a href="https://www.wordstream.com/ad-position">a</a>d positions for lower costs.</li></ul><p>Additionally, if you are advertising on relevant queries, achieving a high click-through rate means that you are driving the highest possible number of people to your offering.</p><h3>How Good is your CTR ?</h3><p>CTR means the number of people eventually visit your page by clicking on the Ad. The quality of the imagery, keywords, ad positioning and many other factors will impact your CTR</p><p>well there are some benchmark studies on average CTR to help marketers determine how good is the CTR, But there is no best way to determine a perfect and successful CTR because there are too many variables associated with it that comes into picture.</p><p>It’s hard to compare CTRs across campaigns, accounts, strategies or companies. But let’s look at some data-backed industry averages that can help us benchmark your current CTR against those of your competitors.</p><h3>Average CTR for Search, Display, Rich Media</h3><p>According to Wordstream, the average click-through rate on the Ad Words search network is <a href="https://blog.hubspot.com/agency/google-adwords-benchmark-data?__hstc=17269478.fd115503892343c806dd0e26a0125b23.1589560855390.1589560855390.1589560855390.1&amp;__hssc=17269478.1.1589560855394&amp;__hsfp=913035639">1.91% on search and 0.35%</a> on display, 2% will be considered as an above average click through rate.</p><p>The best source for display ad CTR benchmarks was originally Doubleclick (the display advertising part of Google) who had a regularly updated interactive Display Bench-marking tool as part of Rich Media Gallery. You could select by country, sector and ad format to create your own benchmarks.</p><p>This may have been removed by Google so we can only see the previous data.</p><p>So, this is just than 5 clicks per 10000 impressions showing the difficulty of driving direct response from online display or banner ads. Perhaps that is why Google no longer publishes this data…</p><p>&lt;Addwords-industry-benchmark-average.jpg&gt;</p><p>The average Facebook CTR in the news-feed is 1.11% and this trend showed a downfall of 0.37% compared to the previous year.</p><p>This cross-industry <a href="https://www.wordstream.com/blog/ws/2018/08/13/google-ads-mobile-benchmarks">Google Ads clickthrough rate and conversion benchmark from Wordstream</a> gives data comparing Google Ads CTRs for the search results against Google Ads display ad network which is typically an image or text-based banner format.</p><blockquote><em>The average click-through rate in Google Ads across all industries is 3.17% on the search network and 0.46% on the display network.</em></blockquote><p>There is no surprise that the CTR on the search network is much higher than in the display network since in the search network, searchers are typing in product and brand names when they have specific intent so the ads are more relevant. But generally this is not the case in display network.</p><p><a href="https://www.wordstream.com/click-through-rate">https://www.wordstream.com/click-through-rate</a> (refer)</p><p>Generally speaking, as we mentioned above, you want as high a click-through rate as possible.</p><p>Except when you don’t.</p><h3>Is Higher Click-Through Rates good for your Business ?</h3><p>If a keyword isn’t pertinent to your business or isn’t going to generate sales, leads, branding gains, etc. then <strong>a high click-through rate for that term is actually bad for business</strong>. The reasoning for this is fairly clear:</p><ul><li>You’re paying for every click.</li><li>A lot of clicks generate a lot of ad spend.</li><li>Some times you’re generating clicks on <a href="https://www.wordstream.com/keywords">keywords</a> that are <strong>priced too high, and won’t turn a profit even if they convert</strong>.</li><li>Irrelevant terms and clicks are just spending money without bringing in additional business.</li></ul><p>So you don’t <em>always </em>want higher click-through rates: what you want are high CTRs on keywords that are:</p><ul><li><strong>Relevant </strong>— Have to do with your ad text, your landing page, and your offering.</li><li><strong>Affordable </strong>— Keywords that aren’t going to be profit-prohibitive.</li></ul><p>So, in a nut shell, a good CTR means first targeting the right words, then getting as many people as you can to click on <em>those </em>ads.</p><h3>Achieving Strong Click-Through Rates For Your Ads</h3><p>Achieving strong click-through rates in PPC, then, depends on:</p><ul><li>Targeted keywords to bid on.</li><li>Cost-efficient clicks.</li><li>Tools and methodology for closely integrating keywords with ad text and landing pages.</li><li>The ability to quickly and efficiently segment <a href="https://www.wordstream.com/keyword-grouping">keyword groups</a> to generate closer targeting.</li></ul><p>Remember, the higher your click-through rate, the better your Quality Scores will likely be, and high Quality Scores are one of the single best predictors of success in PPC.</p><p>— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —</p><p>&lt;Take help from <a href="https://www.acquisio.com/blog/agency/what-is-a-good-click-through-rate-ctr/">https://www.acquisio.com/blog/agency/what-is-a-good-click-through-rate-ctr/</a> to write the below article .&gt;</p><p>Now lets see how we can improve out CTR, There are some industry proven ways than we can follow to achieve higher CTR. I will discuss here 4 different ways in this article.</p><h3>Target your audience</h3><p>Running a good PPC campaign demands target audience and this should be the top priority when it comes to higher CTR. There are other factors which also come into play, but if your audience targeting isn’t right then chances are you will loose your future inflow of cash.</p><p>Just imaging that you want a service for your business and the marketing agency is sending you SEO information, ebooks etc then you will end up having 0 clicks and eventually a click on unsubscribe button.</p><p>Audience targeting is still a huge pain point for most PPC advertisers. 2017 data shows that <a href="https://smallbiztrends.com/2017/01/do-facebook-ads-work.html">62% of small business advertisers</a> on Facebook miss their target market and, as a result, see poor performance metrics.</p><p>If you want to advertise on facebook then use deeper target audience like their income range, demographics, behaviors, interests etc and you can also exclude some of the demographics which are irrelevant.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3be24acabe47" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering the DP-on-Subsequence Pattern: How to Think Like a Pro]]></title>
            <link>https://medium.com/@muppanavinay/mastering-the-dp-on-subsequence-pattern-how-to-think-like-a-pro-be3798b6fb01?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/be3798b6fb01</guid>
            <category><![CDATA[recursion]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[dynamic-programming]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Tue, 20 May 2025 11:32:44 GMT</pubDate>
            <atom:updated>2025-05-20T11:34:51.369Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*Bvd3MXcuyMPJaco1kU52ug.jpeg" /></figure><p><strong>Mastering the DP-on-Subsequence Pattern: How to Think Like a Pro</strong></p><p>When approaching Dynamic Programming problems, especially in interviews, there’s one powerful and frequently used pattern that every FAANG aspirant must master: <strong>DP on Subsequences</strong>. Let’s break it down and learn how to spot and solve problems using this pattern.</p><h3>🧠 The Core Intuition</h3><p>At its heart, this pattern revolves around sequences (usually arrays or strings), where you are:</p><ul><li>Making decisions based on previously seen elements</li><li>Building solutions by considering each element in the sequence as a potential end of a valid solution</li></ul><p>We ask ourselves: <strong>Can I extend a previous solution by including this element?</strong></p><h3>🔄 Generic DP Transition</h3><p>The usual structure of this pattern looks like:</p><pre>for (int i = 0; i &lt; n; i++) {<br>    for (int j = 0; j &lt; i; j++) {<br>        if (condition to extend from j to i) {<br>            dp[i] = Math.max(dp[i], dp[j] + 1);<br>        }<br>    }<br>}</pre><ul><li>dp[i] = optimal answer ending at index i</li><li>j explores all previous candidates that could extend to i</li></ul><h3>🔹 Typical Use-Cases</h3><h3>1. Longest Increasing Subsequence (LIS)</h3><p><strong>Problem:</strong> Find the longest subsequence where every element is greater than the previous one.</p><pre>int[] dp = new int[n];<br>Arrays.fill(dp, 1);<br>for (int i = 1; i &lt; n; i++) {<br>    for (int j = 0; j &lt; i; j++) {<br>        if (nums[i] &gt; nums[j]) {<br>            dp[i] = Math.max(dp[i], dp[j] + 1);<br>        }<br>    }<br>}<br>int res = Arrays.stream(dp).max().getAsInt();</pre><h3>2. Maximum Sum Increasing Subsequence</h3><p><strong>Problem:</strong> Find a subsequence with increasing elements that yields the maximum possible sum.</p><pre>int[] dp = new int[n];<br>for (int i = 0; i &lt; n; i++) dp[i] = nums[i];<br>for (int i = 1; i &lt; n; i++) {<br>    for (int j = 0; j &lt; i; j++) {<br>        if (nums[i] &gt; nums[j]) {<br>            dp[i] = Math.max(dp[i], dp[j] + nums[i]);<br>        }<br>    }<br>}<br>int res = Arrays.stream(dp).max().getAsInt();</pre><h3>3. Longest Bitonic Subsequence</h3><p><strong>Problem:</strong> Find the longest subsequence that first increases and then decreases.</p><pre>int[] inc = new int[n];<br>int[] dec = new int[n];<br>Arrays.fill(inc, 1);<br>Arrays.fill(dec, 1);<br><br>for (int i = 1; i &lt; n; i++)<br>    for (int j = 0; j &lt; i; j++)<br>        if (nums[i] &gt; nums[j]) inc[i] = Math.max(inc[i], inc[j] + 1);<br>for (int i = n-2; i &gt;= 0; i--)<br>    for (int j = n-1; j &gt; i; j--)<br>        if (nums[i] &gt; nums[j]) dec[i] = Math.max(dec[i], dec[j] + 1);<br>int maxLen = 0;<br>for (int i = 0; i &lt; n; i++)<br>    maxLen = Math.max(maxLen, inc[i] + dec[i] - 1);</pre><h3>4. Russian Doll Envelopes</h3><p><strong>Problem:</strong> Given envelopes with width and height, find the max number of envelopes you can nest.</p><p><strong>Approach:</strong> Sort by width asc and height desc. Apply LIS on heights.</p><pre>jArrays.sort(envelopes, (a, b) -&gt; a[0] == b[0] ? b[1] - a[1] : a[0] - b[0]);<br>int[] heights = new int[envelopes.length];<br>for (int i = 0; i &lt; envelopes.length; i++) {<br>    heights[i] = envelopes[i][1];<br>}<br><br>List&lt;Integer&gt; lis = new ArrayList&lt;&gt;();<br>for (int h : heights) {<br>    int idx = Collections.binarySearch(lis, h);<br>    if (idx &lt; 0) idx = -idx - 1;<br>    if (idx == lis.size()) lis.add(h);<br>    else lis.set(idx, h);<br>}<br>return lis.size();</pre><h3>5. Longest String Chain</h3><p><strong>Problem:</strong> Find the longest chain of words where each word is a predecessor of the next.</p><pre>Arrays.sort(words, Comparator.comparingInt(String::length));<br>Map&lt;String, Integer&gt; dp = new HashMap&lt;&gt;();<br>int maxLen = 0;<br>for (String word : words) {<br>    int best = 0;<br>    for (int i = 0; i &lt; word.length(); i++) {<br>        String prev = word.substring(0, i) + word.substring(i + 1);<br>        best = Math.max(best, dp.getOrDefault(prev, 0) + 1);<br>    }<br>    dp.put(word, best);<br>    maxLen = Math.max(maxLen, best);<br>}</pre><h3>6. Longest Divisible Subset</h3><p><strong>Problem:</strong> Find the largest subset such that for every pair (Si, Sj), Si % Sj == 0 or Sj % Si == 0.</p><pre>Arrays.sort(nums);<br>int[] dp = new int[n];<br>int[] prev = new int[n];<br>Arrays.fill(dp, 1);<br>Arrays.fill(prev, -1);<br>int max = 0, lastIdx = 0;<br><br>for (int i = 1; i &lt; n; i++) {<br>    for (int j = 0; j &lt; i; j++) {<br>        if (nums[i] % nums[j] == 0 &amp;&amp; dp[j] + 1 &gt; dp[i]) {<br>            dp[i] = dp[j] + 1;<br>            prev[i] = j;<br>        }<br>    }<br>    if (dp[i] &gt; max) {<br>        max = dp[i];<br>        lastIdx = i;<br>    }<br>}</pre><h3>👁️ How to Spot This Pattern</h3><p>Ask yourself:</p><ul><li>Am I dealing with a sequence or set?</li><li>Is the solution dependent on comparing current with all previous?</li><li>Can I break the problem into subproblems ending at each index?</li><li>Am I trying to build up a result over time, extending solutions?</li></ul><p>If yes — this pattern might be your go-to!</p><h3>✅ Problem-Solving Steps</h3><h3>Problem-Solving Steps</h3><p><strong>Define dp[i] clearly</strong></p><p>What does it represent? (length, sum, count, etc.)</p><p><strong>Figure out the transition</strong></p><p>Under what condition can dp[i] be extended from dp[j]?</p><p><strong>Initialize base cases</strong></p><p>Usually dp[i] = 1 or the element itself if summing</p><p><strong>Track global best</strong></p><p>Since best answer may not be at the last index, maintain a max across all dp[i]</p><p><strong>Optimize if needed</strong></p><p>Many of these problems have O(n²) brute force, but can be optimized with binary search or special sorting</p><h3>🥇 Mindset for Mastery</h3><p>Instead of memorizing solutions, <strong>train your thinking</strong>:</p><p>Visualize the problem as a sequence</p><p>Think recursively first: “If I pick this, what options did I have before?”</p><p>Translate that to a loop comparing j to i</p><p>Keep asking: Can this subproblem help build the current one?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be3798b6fb01" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SSL certificates, all you need to know]]></title>
            <link>https://medium.com/@muppanavinay/ssl-certificates-all-you-need-to-know-4a66a3f898a8?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/4a66a3f898a8</guid>
            <category><![CDATA[decryption]]></category>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[certificate]]></category>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Sun, 18 Aug 2024 07:21:22 GMT</pubDate>
            <atom:updated>2024-08-18T07:21:22.935Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*znUBQ2Bv0Jurqa97NaGWOw.jpeg" /></figure><p>As a software developer, you’ve likely encountered terms like SSL, HTTPS, and TCP countless times. But have you ever stopped to wonder what they actually do or how they help keep your data safe from hackers? In this article, we’ll embark on a journey through the world of encryption — starting from the basics of scrambling data to exploring symmetric and asymmetric key encryption, and finally, unlocking the mystery of digital certificates. Discover how these technologies work together to protect your information every day, without you even realising it.</p><p>Consider the below image which shows how we communicate with a server, imagine you are at amazon.com and trying to login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*gl5cvyEEL_2gnOah1rEmSA.png" /></figure><p>In the image above, you see someone trying to log in to Amazon, while a sneaky character (let’s call them MMA — short for “<strong>Man in the Middle Attack</strong>”) tries to intercept their credentials. Of course, Amazon’s security is far more complex, but let’s simplify it for the sake of understanding. To keep things safe, I decided to scramble the data with a key — a process known as encryption. This key can then be used to unscramble it, or decrypt it, back into its original form.</p><p>This method, where the same key is used for both encryption and decryption, is called symmetric key encryption. While powerful, it’s not foolproof. If our friend MMA manages to sniff out the key, they can unlock the data just as easily.</p><p>Now, let’s see in the image below why this type of encryption alone isn’t enough to keep hackers at bay.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*NC2P6UGSBUD9nyUmrMrHQA.png" /></figure><p>Now, let’s take it up a notch with asymmetric key encryption — a game-changer in the world of security. Unlike symmetric encryption, where the same key is used to lock and unlock data, asymmetric encryption uses two different keys: a public key and a private key. Here’s the cool part: the public key is shared with everyone, but only the private key can unlock what the public key encrypts.</p><p>Imagine you want to send a secure message. You use the recipient’s public key to encrypt it. Even if MMA (our Man in the Middle Attacker) intercepts this message, they can’t decrypt it because they don’t have the private key — only the intended recipient does. This one-way lock mechanism makes asymmetric encryption far more secure against prying eyes.</p><p>This dual-key system is the backbone of many online security protocols, including SSL/TLS, which keeps your internet browsing safe. It ensures that even if a hacker gets their hands on the public key, your data remains locked away, protected by the private key that only you or the intended receiver possess.</p><p>Asymmetric encryption is like sending a package with a padlock that only the recipient can unlock. Even if someone intercepts it, without the right key, they’re out of luck. This method is what makes your transactions and communications over the internet truly secure, elevating it beyond the limitations of symmetric encryption.</p><p>Although this is better than symmetric key encryption still it falls apart for <strong>man in the middle attack, </strong>let’s see how.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*mbR6m78eblPdl1aUPMEICw.png" /></figure><p>Now it seems this asymmetric key encryption is magical and saved our lives and no hacker could ever hack these. If you think that then think again because even with strong encryption like RSA (leaving quantum computers breaking it just keeping it out of this) we can’t protect the system from man in the middle attack. Lets see how.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*_HMDXy_ROBC0Tm-ptrHpWw.png" /></figure><p>In the above diagram you see how our MMA even bypassed the asymmetric key encryption to get the data he wanted. This is a special man in the middle attack where the MMA attacker creates his own proxy layer in between the communication channel and exploits the users data.</p><p>Below is the step by step process</p><ol><li>The MMA attacker forms a proxy layer in between the user and the backend server.</li><li>Then the MMA attacker creates his own pair of public and private keys (blue keys)</li><li>Now when the server sends the public key (green key) the proxy layer saves it and instead sends the user it’s own blue public key.</li><li>User then believing the public key is legitimate encrypts the data with it and sends it.</li><li>The proxy layer again checks the encrypted data and decrypts it with his blue private key and then saves it, re encrypts it with green public key it has and sends to backend server.</li></ol><p>Now you see how you got attacked again.</p><h3>Certificates to the rescue</h3><p>In the digital world, where secure communication is paramount, certificates play the role of trusted guardians. At their core, certificates are like digital ID cards issued by a trusted authority known as a Certificate Authority (CA). When you visit a website, your browser checks the site’s certificate to verify that it’s legitimate and that the connection can be trusted. The certificate contains the website’s public key and information about the CA that issued it, along with a digital signature that ties it all together.</p><p>The magic of certificates lies in how they prevent man-in-the-middle attacks. When a website presents its certificate, your browser doesn’t just take it at face value. It checks the digital signature against a list of trusted CAs that come pre-installed in your browser. If everything checks out, the browser uses the public key in the certificate to establish a secure connection, ensuring that no one else can eavesdrop or tamper with the data being exchanged.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GZT4ckdTeDHh208VGByaqw.png" /></figure><p><strong>Below is the step by step process</strong></p><ol><li>amazon.com goes to a certificate authority (CA) which is a trusted one like google or lets encrypt and shared its public key</li><li>The CA then creates a certificate with CA’s address, amazon.com’s public key and a signature=(amazon.com’s public key + CA’s public key)</li><li>The CA gives this certificate to the server.</li><li>Now a user gets this certificate along with amazon.com’s public key when trying to initiate the communication.</li><li>The user now instead of directly encrypting with server’s public key, goes to the CA defined in the certificate and asks it’s public key.</li><li>Now after getting CA’s public key it decodes the signature gets amazon.com’s public key and matches it with the public key got from amazon.com, if both are same then it is verified that the public key instead belongs to amazon.com and not MMA.</li><li>Now user encrypts it’s client key with amazon.com’s public key and shares it.</li><li>Now you can see the client’s key is both with client and amazon.com thus creating symmetric key encryption.</li></ol><h3><strong>Conclusion</strong></h3><p>Without certificates, the internet would be a much riskier place. Attackers could easily impersonate websites by sending users fake public keys, tricking them into thinking they’re connected to a legitimate site. Certificates ensure that when you see that little padlock icon in your browser, you can trust that your data is encrypted and safe from prying eyes. It’s like having a personal bouncer at the door of your online interactions, ensuring only the right people get in.</p><p>In essence, certificates are the unsung heroes of online security. They create a foundation of trust that allows us to browse, shop, and communicate online with confidence. Whether you’re sending sensitive information or just browsing your favorite website, certificates are quietly working behind the scenes to keep your data safe, ensuring that the web remains a secure place for everyone.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4a66a3f898a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Boost Your PostgreSQL Performance: 5 Pro Tips You Can’t Miss]]></title>
            <link>https://medium.com/@muppanavinay/boost-your-postgresql-performance-5-pro-tips-you-cant-miss-dbb50c0f33ec?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/dbb50c0f33ec</guid>
            <category><![CDATA[partitioning]]></category>
            <category><![CDATA[postgresql]]></category>
            <category><![CDATA[indexing]]></category>
            <category><![CDATA[database-optimization]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Sun, 28 Jul 2024 06:40:09 GMT</pubDate>
            <atom:updated>2024-07-28T06:40:09.313Z</atom:updated>
            <content:encoded><![CDATA[<p>PostgreSQL is a robust, open-source database system that powers many of the world’s most demanding applications. However, even the best databases can hit performance bottlenecks. If you’re looking to turbocharge your PostgreSQL setup, here are five essential tips to optimise your database and ensure blazing-fast performance.</p><h3>1. Supercharge Your Queries with Prepared Statements</h3><p>When you execute a query for the first time, PostgreSQL must parse and plan it. This can be quite time-consuming, especially for complex queries. Prepared statements are your best friend here. By using prepared statements, you can store the parsed and planned query on the server. The next time you execute the prepared statement with different input values, PostgreSQL can reuse the existing plan, saving precious milliseconds.</p><p><strong>Example</strong>:</p><pre>PREPARE GetOrderById (INTEGER) AS<br>SELECT * FROM orders WHERE id = $1;<br><br>EXECUTE GetOrderById (10);</pre><p>In this example, the PREPARE statement creates a prepared statement named GetOrderById that takes an integer parameter. The EXECUTE statement then executes the prepared statement, passing in the value 10 for the parameter. This dramatically reduces query planning time for repeated queries.</p><h3>2. Speed Up Searches with Indexing</h3><p>Indexes are like the table of contents in a book. They allow PostgreSQL to quickly locate rows that match specific conditions. When you create an index on a column, PostgreSQL creates a sorted list of the values in that column. This can significantly enhance the performance of queries using WHERE clauses, particularly for large tables.</p><p><strong>Example</strong>:</p><pre>CREATE INDEX idx_orders_customer_id ON orders(customer_id);</pre><p>This example creates an index named idx_orders_customer_id on the customer_id column of the orders table. This index can be used to swiftly find orders for a specific customer.</p><h3>3. Manage Big Data with Partitioning</h3><p>Partitioning is a technique that allows you to split a large table into smaller, more manageable pieces. Each partition can be stored in a separate file or table-space, improving performance by reducing the amount of data PostgreSQL needs to scan during queries and enhancing the efficiency of operations like inserts and deletes.</p><p><strong>Example</strong>:</p><pre>CREATE TABLE orders_archive (LIKE orders) PARTITION BY RANGE (order_date);<br><br>CREATE TABLE SPACE orders_archive_space;<br><br>ALTER TABLE orders_archive SET TABLESPACE orders_archive_space;<br><br>ARCHIVE TABLE orders INTO orders_archive PARTITION (order_date) VALUES LESS THAN (CURRENT_DATE - INTERVAL &#39;1 year&#39;);</pre><p>In this example, a partitioned table named orders_archive is created, divided by the order_date column. This setup ensures that the table is split into partitions, one for each year. The ARCHIVE TABLE statement then moves old orders into the appropriate partition, keeping your data neatly organised.</p><h3>4. Bulk Load Data with the COPY Command</h3><p><strong>Explanation</strong>: The COPY command is a powerhouse for bulk loading data into PostgreSQL tables. It can load data from a file or from standard input, inserting multiple rows at once. This method is much faster than inserting data one row at a time using INSERT statements.</p><p><strong>Example</strong>:</p><pre>COPY orders (id, customer_id, order_date) FROM &#39;/path/to/orders.csv&#39; DELIMITER &#39;,&#39;;</pre><p>This example uses the COPY command to load data from a CSV file named orders.csv into the orders table. The DELIMITER clause specifies that the columns in the CSV file are separated by commas. Simple and efficient!</p><h3>5. Distribute Load with Read Replicas</h3><p><strong>Explanation</strong>: Read replicas are read-only copies of your PostgreSQL database. By creating read replicas, you can distribute the read load across multiple servers, enhancing the performance of read-only queries like SELECT statements. Read replicas are also a great fallback for disaster recovery, as you can failover to a read replica if your primary database goes down.</p><p><strong>Example</strong>: Setting up read replicas involves more steps than we can cover here, but numerous online resources can guide you through the process. Just remember, this strategy is invaluable for scaling your read operations and ensuring high availability.</p><h3>Final Thoughts</h3><p>These tips are just the tip of the iceberg when it comes to PostgreSQL performance tuning. Always consult the PostgreSQL documentation for detailed usage and further optimisation techniques. Implement these strategies, and you’ll be well on your way to running a lean, mean PostgreSQL machine.</p><p><strong>Ready to boost your PostgreSQL performance? Try these tips and let us know how they work for you!</strong></p><p>Feel free to follow me for more insights on database optimization and other tech tips. Happy optimising! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dbb50c0f33ec" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How does docker work (in 2 mins)]]></title>
            <link>https://medium.com/@muppanavinay/how-does-docker-run-in-5-mins-a2d1cade8ff1?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/a2d1cade8ff1</guid>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[deep-dives]]></category>
            <category><![CDATA[podman]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Sat, 18 Feb 2023 06:52:07 GMT</pubDate>
            <atom:updated>2023-02-18T07:13:55.604Z</atom:updated>
            <content:encoded><![CDATA[<p>Docker is a very popular containerization engine/tool available in the market right now. Although there are other alternatives which are also great like Podman, but Docker is still winning the battle to be the most popular.</p><p>This is a short documentation to give you very quick view of how it runs and how different components interact with each other to spin up a container for you.</p><p>Docker has broadly 5 components</p><ol><li>Docker client</li><li>Docker daemon</li><li>containerd (spelled as container-dee)</li><li>shim</li><li>runc</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*ZrbnCmhCNlcEmwZes6View.png" /></figure><p>Lets say, you have run the below command</p><pre>docker container run -name ctrl -it alpine:latest</pre><p>Here you are issuing docker CLI command to Docker Client, this is exactly like invoking shell script with some arguments.</p><h3>Docker Client</h3><p>The Docker client takes the above command to form a Post request and calls docker daemon API. (Docker daemon listens to “<strong>/var/run/docker.sock” </strong>on<strong> Linux </strong>and<strong> “\pipe\docker_engine” </strong>in <strong>Windows</strong>) It is just like any web server listening to a port.</p><h3>Docker Daemon</h3><p>The Docker daemon now calls the <strong>containerd </strong>to start a new container, this call is just like CRUD style API call which happens over gRPC protocol.</p><h3>Containerd</h3><p>Now containerd cannot create a container on it’s own. It uses <strong>runc</strong> to do the job. <strong>runc </strong>actually interfaces with the OS kernel to pull all the constructs needed for container creation.</p><h3>runc</h3><p>The container process starts as a child process of <strong>runc, </strong>once the container is created the <strong>runc </strong>process dies.</p><h3>shim</h3><p>You may be thinking then what the heck is <strong>shim</strong> — Now the containerd creates an instance of <strong>runc</strong> to create a container, and after the container is created, the <strong>runc</strong> instance exits making the containerd’s shim process, the parent of the newly created container.</p><p>Shim performs some actions like keeping the STDIN and STDOUT streams open, so that if the daemon is restarted, the container doesn’t terminate. It also reports the container status to the daemon etc.</p><p>We need to understand that earlier docker daemon was a huge monolithic software, now they have broken that down into smaller pieces, such that each piece has a dedicated job. For example, if you are upgrading the daemon, your running containers will not terminate. Isn’t it the ask of every app in prod environment !!!</p><p><strong><em>You may be thinking what is the daemon doing now, as every thing is taken care by other components</em></strong> .</p><p>Well there is work which is being done by the daemon. We don’t know if something gets added or something gets stripped off from it in the future.</p><p>Currently some jobs that are taken care by the daemon are — image management/build, REST API, authentication, authorization, security, networking and orchestration.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a2d1cade8ff1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Functional interfaces , Lambdas and streams … A short and quick guide.]]></title>
            <link>https://medium.com/@muppanavinay/getting-functional-interfaces-lambdas-and-streams-a-short-and-quick-guide-26f75983430a?source=rss-a6ec4dd8dc93------2</link>
            <guid isPermaLink="false">https://medium.com/p/26f75983430a</guid>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vinay Kumar]]></dc:creator>
            <pubDate>Mon, 04 Feb 2019 15:17:41 GMT</pubDate>
            <atom:updated>2019-02-05T19:06:48.338Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sr8NxC8nD_g5VZZm" /><figcaption>Photo by <a href="https://unsplash.com/@markusspiske?utm_source=medium&amp;utm_medium=referral">Markus Spiske</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Getting Functional interfaces , Lambdas and streams … A short and quick guide.</h3><h4>Functional Interfaces</h4><p><strong>What ?</strong></p><p>Functional interfaces are the interfaces which exposes only one method to the outside world to implement . It can have static or <strong>default </strong>methods in it. Functional interfaces are marked with <strong><em>@FunctionalInterface</em></strong> where this annotation will ensure you have only one abstract method in it (We also call these Markers)</p><p>ex → <strong><em>Runnable</em></strong>, <strong><em>ActionListener</em></strong>,<em> </em><strong><em>Comparable etc.</em></strong></p><pre>@FunctionalInterface</pre><pre>public interface MathOp</pre><pre>{</pre><pre>static int multiply(int a, int b) {</pre><pre>return a*b;</pre><pre>}</pre><pre>default double divide(int a, int b) {</pre><pre>return a/b;</pre><pre>}</pre><pre>public int add(int a, int b);</pre><pre>}</pre><p><strong>Why ?</strong></p><p>Now we know that functional interfaces contain only one exposed functionality to be overridden , the question comes why ? The answer to this is : functional interfaces are meant to be used mostly along with Lambdas and streams where we can just provide the code expression to be executed.</p><p>Lets go by some examples. Below we are creating a by-function which takes two arguments and returns the greater integer.</p><pre>@FunctionalInterface</pre><pre>public interface MaxFinder</pre><pre>{</pre><pre>int findMax(int a, int b);</pre><pre>}</pre><pre>MaxFinder max = (a, b) -&gt; a &gt; b ? a : b;</pre><pre>System.out.println(max.findMax(10, 15));</pre><h3><strong>Lambdas</strong></h3><p>Lambdas or lambda expressions also known as <em>“code as data”</em> helps us in writing functional programs in Java . Earlier in Java we used to pass fields or objects but there is a limitation in it.</p><p>Imagine if we can pass only the behaviour, not the whole object to a method. In real world, object has an existence and it contains properties along with behaviour, but some times, it is not reasonable to pass the whole object when only a single behaviour of it is needed. This is where lambdas come in where we pass functions instead of the whole object. Ex :</p><pre>(comma separated parameters) -&gt; (code expression or block)</pre><pre>(a, b) -&gt; return a*b;</pre><pre>parameters are optional you can use () is case there are no parameters to pass.</pre><p>Here Java came up with an arrow operator , don’t worry much its just a separation between parameters list and the code acting with those parameters. Do not confuse it with anonymous inner class, this is totally different it’s anonymous inner method instead.</p><pre>use javap tool to read the bytecode instructions to get more insight.</pre><pre>javap -c &lt;my_class&gt;.class</pre><p>Lets go by a concrete example for the above….</p><p>Below is the code which contains an interface <em>“MyString”</em> containing a method <em>“myStringFunction”</em> , we have given a implementation for this function in which it prints the the input in reverse order in upper case.</p><pre>package com.codeground.codeg.resources;</pre><pre>interface MyString {</pre><pre>    String myStringFunction(String str);</pre><pre>}</pre><pre>public class MyMain {</pre><pre>  public static void main(String[] args) {</pre><pre>      MyString reverseStr = (str) -&gt; {</pre><pre>          String result = &quot;&quot;;</pre><pre>          for(int i = str.length()-1; i &gt;= 0; i--)</pre><pre>               result += Character.toUpperCase(str.charAt(i));</pre><pre>               return result;</pre><pre>          };</pre><pre>     System.out.println(<br>         reverseStr.myStringFunction(&quot;lambda expression&quot;)<br>     );</pre><pre>  }</pre><pre>}</pre><pre>==&gt; NOISSERPXE ADBMAL</pre><h3>Streams….</h3><p>You can imagine streams as a pipeline for data. Collections in Java have this stream feature enabled. By collection, i mean “List” type of collection which you can imagine as items stored one after the other in a sequential manner.</p><p>Like a liquid flowing from one end to the other in a pipe, same ways in streams data is processed one after the other.</p><p>Let’s have a tour of the streams to understand it.</p><p>Before that let’s look at some examples of data processing that we used to do earlier.</p><p>Let’s say we have to change the first character of the names, present in a list to upper case</p><p>Naive way -</p><pre>String a[] = new String[]{&quot;john&quot;,&quot;kim&quot;,&quot;june&quot;,&quot;shaun&quot;};</pre><pre>List&lt;String&gt; normalList = Arrays.asList(a);</pre><pre>List&lt;String&gt; modifiedList = new ArrayList&lt;String&gt;();</pre><pre>for(int i = 0; i &lt; normalList.size() ; i++) {</pre><pre>String b = (String) normalList.get(i);</pre><pre>b = b.replace(b.charAt(0), Character.toUpperCase(b.charAt(0)));</pre><pre>modifiedList.add(b);</pre><pre>}</pre><pre>modifiedList.forEach(System.out::println);</pre><p>Stream way -</p><pre>modifiedList = normalList.stream()<br>                         .map(ele -&gt; ele.replace(ele.charAt(0),       Character.toUpperCase(ele.charAt(0))))<br>                         .collect(Collectors.toList());</pre><p>Let’s say we have to do a particular task 121 times —</p><pre>for(int i = 0; i&lt; 121 ; i++) {</pre><pre>    &lt;do some work&gt;<br>}</pre><p>In streams —</p><pre>IntStream.range(0, 121).forEach(index -&gt; {</pre><pre>    &lt;Do work&gt;</pre><pre>});</pre><p>Here you might have noticed that we are using forEach , this is nothing but an internal iterator, Java 8 on wards, in collections we have internal iterators. Anyways it’s logical for a collection to iterate itself instead of somebody iterating it. This excludes the pain of remembering all those Iterators and also removing verbose code.</p><p>Java 8 promotes writing declarative code instead of imperative programming.</p><p>Before going further and using streams we have to know 4 functional interfaces and two kinds of operations in streams.</p><p>Let’s go through functional interfaces first :</p><ul><li>Consumer (Accepts one argument but returns none)</li><li>Supplier (Takes an argument and returns a result)</li><li>Predicate (This returns either true or false)</li><li>BiConsumer ( Takes two arguments and do not return a result )</li></ul><p>There are two operations in streams one is intermediate operations and other is the terminal operations, a terminal operation can only produce results and the intermediate operations only produce streams again.</p><p>By default streams are lazy i.e without a terminal operation the intermediate operations won’t be called.</p><p>intermediate operations are like .map(), .reduce(), .filter() etc.</p><p>terminal operations include .forEach(), .collect() etc.</p><p>I will only go through some functions by examples as i intent to keep the blog short.</p><h4>.<strong>map(&lt;supplier&gt;)</strong></h4><pre>normalList.stream().map(ele -&gt; ele*3).forEach(System.out::println);</pre><pre>In the above we are multiplying each number in normalList by 3 and printing them. Again the :: operator we used above is known as method reference. </pre><h4>.reduce()</h4><pre>Employee e0 = new Employee(&quot;Jhon&quot;, 10000);</pre><pre>Employee e1 = new Employee(&quot;Shawn&quot;, 13000);</pre><pre>Employee e2 = new Employee(&quot;Shean&quot;, 13000);</pre><pre>Employee e3 = new Employee(&quot;Shaw&quot;, 10600);</pre><pre>Employee e4 = new Employee(&quot;Alex&quot;, 15000);</pre><pre>List&lt;Employee&gt; employees = Arrays.asList(e0, e1, e2, e3, e4);</pre><pre>employees.stream()<br>         .map(emp -&gt; emp.getSalary())<br>         .reduce(Integer::sum)<br>         .ifPresent(System.out::println); </pre><pre>** Here we are adding up the total salary of all employees</pre><h4>.filter(&lt;predicate&gt;)</h4><pre>employees.stream()<br>         .map( emp -&gt; emp.getSalary() )<br>         .filter( sal -&gt; sal &gt;= 13000 )<br>         .reduce(Integer::sum)<br>         .ifPresent(System.out::println);</pre><pre>** Here filter takes a Predicate which means it takes a input and returns true or false. here we are getting the sum of all salaries which are greater or equal to 13k.</pre><h4>.collect()</h4><pre>LinkedList&lt;Employee&gt; result =   employees.stream()<br>                 .collect(Collectors.toCollection(LinkedList::new));</pre><pre>** converting a list of Employee objects to Linked list</pre><pre>String allNames = employees.stream()<br>                           .map(emp -&gt; emp.getName())<br>                           .collect(Collectors.joining(&quot;,&quot;));</pre><pre>Output -&gt; Jhon,Shawn,Shean,Shaw,Alex</pre><pre>** Imagine writing this code in an imperative way, hell lot of pain to figure out boundary conditions for putting the &quot;,&quot;.</pre><p>Hopefully this article gives a head start towards functional programming. you can check more about the topics in more details.</p><p>happy coding……</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=26f75983430a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>