<?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 Vishnu Prabu on Medium]]></title>
        <description><![CDATA[Stories by Vishnu Prabu on Medium]]></description>
        <link>https://medium.com/@vishnuprabu017?source=rss-8423db5ce3ca------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hxLebX1N6xvHtIZ-wZIy9A.jpeg</url>
            <title>Stories by Vishnu Prabu on Medium</title>
            <link>https://medium.com/@vishnuprabu017?source=rss-8423db5ce3ca------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 07:17:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vishnuprabu017/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[RDD Operations : Transformations and Actions]]></title>
            <link>https://medium.com/@vishnuprabu017/rdd-operations-transformations-and-actions-1957a9938785?source=rss-8423db5ce3ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/1957a9938785</guid>
            <dc:creator><![CDATA[Vishnu Prabu]]></dc:creator>
            <pubDate>Fri, 01 Nov 2024 05:32:17 GMT</pubDate>
            <atom:updated>2024-11-01T05:32:17.638Z</atom:updated>
            <content:encoded><![CDATA[<h3>RDD Operations : Transformations and Actions</h3><p>Now that we’ve unlocked the concept of RDDs in our previous article, let’s take it a step further. RDDs allow us to process massive amounts of data, but how exactly do we work with them? This is where <strong>Transformations</strong> and <strong>Actions</strong> come into play. Think of them as the <strong>tools</strong> you use to shape and retrieve data from your RDDs. Just like how you need a pair of scissors and glue for a school project, transformations and actions are your tools to <strong>modify</strong> and <strong>get results</strong> from your data.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PF-GyO37nZ69HBcOKfiXVQ.png" /></figure><h3>RDD Transformations: Shaping Your Data</h3><p><strong>Spark Transformation</strong> is like a tool that helps you create new RDDs (data sets) from the ones you already have. You take an existing RDD, apply a transformation, and you get a new RDD. However, the original RDD doesn’t change because RDDs can’t be altered (they are immutable).</p><p>Transformations are operations that allow you to modify or prepare your RDD. But here’s the cool part: they are <strong>lazy</strong>. This means that nothing actually happens when you apply a transformation. Spark just remembers what you want to do and waits until an action is called to actually process the data. It’s like telling Spark, “Hey, when you’re ready, filter out the even numbers” — but Spark won’t do it until you say, “Now, give me the results!”</p><p>There are two types of transformations:</p><ol><li><strong>Narrow transformation</strong> — In <em>Narrow transformation</em>, all the elements that are required to compute the records in single partition live in the single partition of parent RDD. A limited subset of partition is used to calculate the result. <em>Narrow transformations</em> are the result of <em>map(), filter().</em></li><li><strong>Wide transformation </strong>— In wide transformation, all the elements that are required to compute the records in the single partition may live in many partitions of parent RDD. The partition may live in many partitions of parent RDD. <em>Wide transformations</em> are the result of <em>groupbyKey()</em> and <em>reducebyKey()</em>.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*VuA3K5zuPZ7GOw6ApPcKgw.png" /></figure><h4>Function’s in RDD transformations :</h4><ul><li><strong>map(func)</strong>: Transformation applies a function to each element in the RDD and returns a new RDD with the results. Think of it as a way to change each item in your dataset one by one.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4])<br>doubled = numbers.map(lambda x: x * 2)<br>print(doubled.collect()) # [2, 4, 6, 8]</pre><ul><li><strong>flatMap()</strong>: It works like <em>map()</em>, but it can return multiple values for each input element. It’s useful when you want to break each element into multiple parts.</li></ul><pre>lines = sc.parallelize([&quot;hello world&quot;, &quot;welcome to spark&quot;])<br>words = lines.flatMap(lambda line: line.split(&quot; &quot;))<br>print(words.collect())  # [&#39;hello&#39;, &#39;world&#39;, &#39;welcome&#39;, &#39;to&#39;, &#39;spark&#39;]</pre><ul><li><strong>filter(func): </strong>It selects elements that meet a condition. If an element passes the condition (returns <em>True</em>), it stays in the new RDD.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4, 5, 6])<br>evens = numbers.filter(lambda x: x % 2 == 0)<br>print(evens.collect())  # [2, 4, 6]</pre><ul><li><strong>mapPartitions(func): </strong>This function applies a transformation to each partition of the RDD, rather than to each element. It’s useful when working with large datasets.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4], 2)<br>partitions = numbers.mapPartitions(lambda iterator: [sum(iterator)])<br>print(partitions.collect())  # [3, 7] (the sum of each partition (1+2),(3+4))</pre><ul><li><strong>mapPartitionsWithIndex(): </strong>It’s like <em>mapPartitions()</em>, but it also provides the index (position) of the partition, so you can know which chunk of data you’re working with.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4], 2)<br>indexed_sums = numbers.mapPartitionsWithIndex(lambda idx, it: [(idx, sum(it))])<br>print(indexed_sums.collect())  # [(0, 3), (1, 7)]</pre><ul><li><strong>union(): </strong>It<strong> </strong>combines two RDDs into one, containing all elements from both RDDs.</li></ul><pre>rdd1 = sc.parallelize([1, 2])<br>rdd2 = sc.parallelize([3, 4])<br>combined = rdd1.union(rdd2)<br>print(combined.collect())  # [1, 2, 3, 4]</pre><ul><li><strong>intersection(): </strong>It<strong> </strong>returns only the elements that are common between two RDDs.</li></ul><pre>rdd1 = sc.parallelize([1, 2, 3])<br>rdd2 = sc.parallelize([2, 3, 4])<br>common = rdd1.intersection(rdd2)<br>print(common.collect())  # [2, 3]</pre><ul><li><strong>groupByKey(): </strong>It groups values by their keys (similar to a dictionary), which is useful when working with key-value pairs.</li></ul><pre>pairs = sc.parallelize([(&#39;a&#39;, 1), (&#39;b&#39;, 2), (&#39;a&#39;, 3)])<br>grouped = pairs.groupByKey()<br>print([(k, list(v)) for k, v in grouped.collect()])<br># [(&#39;a&#39;, [1, 3]), (&#39;b&#39;, [2])]</pre><ul><li><strong>reduceByKey(func, [numTasks]): </strong>It<strong> </strong>merges values for each key using a function, like summing or multiplying values.</li></ul><pre>pairs = sc.parallelize([(&#39;a&#39;, 1), (&#39;b&#39;, 2), (&#39;a&#39;, 3)])<br>reduced = pairs.reduceByKey(lambda a, b: a + b)<br>print(reduced.collect())  # [(&#39;a&#39;, 4), (&#39;b&#39;, 2)]</pre><ul><li><strong>coalesce(numPartitions): </strong>It<strong> </strong>reduces the number of partitions in an RDD, which can help optimize performance.</li></ul><pre>rdd = sc.parallelize([1, 2, 3, 4, 5, 6], 4)<br>coalesced = rdd.coalesce(2)<br>print(coalesced.getNumPartitions())  # 2</pre><h3>RDD Actions: Getting the Results</h3><p>Spark <strong>Transformations</strong> help us create new RDDs from existing ones, but if we actually want to get a result from our data (like counting, collecting, or saving it), that’s where <strong>Actions</strong> come into play. Unlike transformations, actions don’t create new RDDs. Instead, they give us final values or results that we can use.</p><p>Actions are the step where Spark stops being “lazy” and actually processes the data. This is when the work starts happening! When an action is triggered, Spark sends the data from Executors (the workers that process your tasks) to the Driver (the program that manages and coordinates the work).</p><p><strong>Function’s in RDD Actions:</strong></p><ul><li><strong>count() : </strong>Returns the number of elements in an RDD. It’s like counting how many items you have in a list.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4, 5])<br>total = numbers.count()<br>print(total)  # Output: 5</pre><ul><li><strong>collect() : </strong>Retrieves all elements from the RDD and brings them to the driver (your main program). It’s like gathering all the data in one place.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4])<br>result = numbers.collect()<br>print(result)  # [1, 2, 3, 4]</pre><ul><li><strong>take(n) : </strong>Returns the first <em>n </em>elements from the RDD. It’s like peeking at the first few items in a list.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4])<br>first_two = numbers.take(2)<br>print(first_two)  # [1, 2]</pre><ul><li><strong>top(n) : </strong>Returns the top <em>n</em> elements from the RDD, but in descending order. It’s like grabbing the biggest items.</li></ul><pre>numbers = sc.parallelize([1, 5, 3, 4])<br>largest = numbers.top(2)<br>print(largest)  # [5, 4]</pre><ul><li><strong>countByValue()</strong> : Counts how often each unique value appears in the RDD. It’s like tallying up how many times each number shows up.</li></ul><pre>numbers = sc.parallelize([1, 2, 2, 3, 3, 3])<br>counted = numbers.countByValue()<br>print(counted)  # {1: 1, 2: 2, 3: 3}</pre><ul><li><strong>reduce(func)</strong> : Combines the elements of the RDD using a function, like adding them all together. It processes the RDD one pair at a time.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4])<br>total = numbers.reduce(lambda a, b: a + b)<br>print(total)  # 10</pre><ul><li><strong>foreach(func)</strong> : Applies a function to each element in the RDD. It’s useful when you want to perform an operation on each item, like saving them to a database or printing them.</li></ul><pre>numbers = sc.parallelize([1, 2, 3, 4])<br>numbers.foreach(lambda x: print(x))<br># 1 2 3 4 (each will be printed of new line)</pre><h3>Conclusion</h3><p>Transformations and Actions are the heartbeat of working with RDDs in Spark. <strong>Transformations</strong> allow you to shape and refine your data step by step. <strong>Actions</strong> are what finally trigger the processing, giving you the results you need — whether it’s counting, collecting, or saving your data. This combination allows Spark to handle massive datasets efficiently across multiple computers, giving you the power to work with big data like never before.</p><p>Thank you for reading! To stay connected and discover more about Spark and AI, don’t hesitate to follow me on <a href="https://medium.com/@vishnuprabu017">Medium</a> for future updates!</p><p>If you have any queries or any topic-related suggestions, feel free to reach out to Me via <a href="https://www.linkedin.com/in/vishnu-prabu-169855279/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1957a9938785" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unlocking RDDs: The Building Blocks of Spark Processing]]></title>
            <link>https://medium.com/@vishnuprabu017/unlocking-rdds-the-building-blocks-of-spark-processing-2aac56cfa321?source=rss-8423db5ce3ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/2aac56cfa321</guid>
            <category><![CDATA[data-engineering]]></category>
            <category><![CDATA[apache-spark]]></category>
            <category><![CDATA[big-data]]></category>
            <dc:creator><![CDATA[Vishnu Prabu]]></dc:creator>
            <pubDate>Mon, 28 Oct 2024 05:32:08 GMT</pubDate>
            <atom:updated>2024-10-28T05:32:08.174Z</atom:updated>
            <content:encoded><![CDATA[<p>Think of <strong>RDDs (Resilient Distributed Datasets)</strong> as a magical container that can hold data for you. Imagine you’re working with a huge pile of data — way too big for your computer to handle all at once. Wouldn’t it be cool if you could split this pile into smaller parts and store them across multiple computers? That’s what RDDs do!</p><h3>What is RDD</h3><p><strong>RDD (Resilient Distributed Dataset)</strong> is like a special type of container for data used in Apache Spark. It allows you to:</p><ol><li><strong>Store Data</strong>: Think of it as a big box where you can keep a lot of data, like numbers or words.</li><li><strong>Spread it Out</strong>: This data box can be split and stored across many computers, helping them work together to handle large amounts of data.</li><li><strong>Stay Safe</strong>: If something goes wrong (like if one computer crashes), RDDs can recover lost data from other computers, so your information stays safe.</li></ol><p><strong>Example</strong>:</p><p>Imagine you’re in a school science project. You and your friends each have a piece of paper with different parts of the project. Instead of one person doing all the work, you split it up and finish faster. If someone loses their paper, no problem! You have backups to fix it. RDDs work the same way!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*qG4FLHVH2ghOwBNPU72f1A.png" /></figure><h3>Creating RDD</h3><h4>Creating RDD from a Collection</h4><p>We can create an RDD directly from a collection of data you already have in your program, such as a list or an array. This is useful for smaller datasets or for testing.</p><pre>from pyspark.sql import SparkSession<br>spark = SparkSession.builder.appName(&quot;creating rdd&quot;).getOrCreate()<br><br>numbers = spark.sparkContext.parallelize([1, 2, 3, 4, 5])<br>print(&quot;Numbers in RDD:&quot;, numbers.collect())</pre><ul><li>The <em>SparkSession</em> is the entry point for working with DataFrames and SQL in Spark, and it also allows access to the underlying <em>SparkContext.</em></li><li><em>SparkContext </em>provides a more unified interface for working with DataFrames, SQL queries, and other functionalities. <em>SparkContext </em>is essential for lower-level operations and RDD manipulations.</li><li><em>parallelize</em> method takes a list (in this case, [1, 2, 3, 4, 5]) and converts it into an RDD. This is done by distributing the data across the available worker nodes in the cluster, allowing for parallel processing.</li></ul><h3>Creating RDD from a File</h3><p>We can also create an RDD by reading data from a file stored on your computer or a distributed file system (like HDFS). This is useful for larger datasets that don’t fit into memory.</p><pre>text_file_rdd = spark.sparkContext.textFile(&quot;path_to_your_file/data.txt&quot;)<br><br>output_lines = text_file_rdd.collect()<br>print(&quot;Lines in the text file:&quot;)<br>for line in output_lines:<br>    print(line)</pre><ul><li><em>textFile()</em> method reads a text file from the specified path and creates an RDD. Each line of the text file becomes an element in the RDD.</li></ul><h3>Creating RDD from Existing RDDs</h3><p>We can also create new RDDs from existing ones by transforming them. For example, you might want to filter out certain data or perform a map operation.</p><pre>numbers = spark.sparkContext.parallelize([1, 2, 3, 4, 5])<br>#createing RDD with even numbers only<br>even_numbers = numbers.filter(lambda x: x % 2 == 0)<br>print(&quot;Even numbers:&quot;, even_numbers.collect())</pre><ul><li><em>filter</em> operation creates a new RDD that only contains the elements that meet the condition (in this case, being even).</li></ul><h3>Conclusion</h3><p>In conclusion, RDDs (Resilient Distributed Datasets) are like special containers that help us work with large amounts of data in Apache Spark. By understanding RDDs, we unlock the ability to handle big data efficiently. They provide a strong foundation for diving deeper into more advanced tools and techniques in Spark.</p><p>Thank you for reading! Keep an eye out for my upcoming blog on<strong><em> Spark Transformation and Actions in RDD. </em></strong>To stay connected and discover more about Spark and AI, don’t hesitate to follow me on <a href="https://medium.com/@vishnuprabu017">Medium</a> for future updates!</p><p>If you have any queries or any topic-related suggestions, feel free to reach out to Me via <a href="https://www.linkedin.com/in/vishnu-prabu-169855279/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2aac56cfa321" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Decoding the Inner Workings of Apache Spark Architecture]]></title>
            <link>https://medium.com/@vishnuprabu017/decoding-the-inner-workings-of-apache-spark-architecture-5080748bf093?source=rss-8423db5ce3ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/5080748bf093</guid>
            <dc:creator><![CDATA[Vishnu Prabu]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 11:19:18 GMT</pubDate>
            <atom:updated>2024-10-25T07:07:10.417Z</atom:updated>
            <content:encoded><![CDATA[<p>Before diving into the detailed working of Spark’s architecture, make sure to check out my <strong>previous blog</strong>, where I introduced <a href="https://medium.com/@vishnuprabu017/from-data-overload-to-insight-exploring-apache-sparks-magic-1ebe88e0ceb8"><strong>Apache Spark</strong></a> and how it is transforming the world of Big Data.</p><p>Apache Spark’s architecture follows a <strong>master-slave model</strong>, designed to process vast amounts of data efficiently across multiple machines (nodes) in a cluster. This architecture ensures <em>scalability, fault-tolerance, and high performance,</em> which makes Spark an ideal platform for Big Data processing. When you submit a job in Spark, the <strong>driver program</strong> creates a <strong>DAG of tasks</strong>. These tasks are <strong>divided across RDDs</strong> and sent to worker nodes for execution. The spark architecture depends upon two main abstractions which are:</p><ol><li>Resilient Distributed Dataset (RDD)</li><li>Directed Acyclic Graph (DAG)</li></ol><h4>Resilient Distributed Dataset (RDD)</h4><p>An <strong>RDD</strong> is like a <strong>big collection of data</strong> that Spark splits across multiple computers (nodes). Think of it as a <strong>distributed list</strong> where each piece of data is stored in chunks on different machines.</p><p>The word <strong>“resilient”</strong> means that if something goes wrong (e.g., a node crashes), the data can be <strong>recreated or recovered</strong> without starting everything from scratch.</p><p><strong>Key Features of RDD:</strong></p><ul><li><strong>Immutable</strong>: Once created, the data in an RDD cannot change (you create a new RDD if you want to modify it).</li><li><strong>Distributed</strong>: The data is spread across multiple computers for parallel processing.</li><li><strong>Fault-tolerant</strong>: If part of the data is lost, Spark recomputes it automatically.</li></ul><p><strong>Example</strong> : Imagine you and your friends are working on a group project. Each person is responsible for researching different sections. If one friend loses their notes, someone else can quickly recreate them using shared resources (e.g., textbooks). Similarly, if part of an RDD is lost, Spark recreates it automatically to avoid data loss.</p><h4>Directed Acyclic Graph (DAG)</h4><p>A Directed Acyclic Graph (DAG) is like a <strong>map of tasks</strong> that tells Spark how to process data step-by-step.</p><ul><li><strong>Directed</strong>: The tasks flow in one direction, from start to finish.</li><li><strong>Acyclic</strong>: There are no loops or cycles; once a task is done, it won’t come back to it.</li></ul><p>Think of a DAG as a <strong>series of connected tasks</strong>, where the <em>output of one task becomes the input for the next</em>. Spark creates a DAG before executing a job to <strong>optimize the order</strong> of operations and make processing faster.</p><p>Example :</p><p>Imagine you’re following a <strong>recipe to bake a cake</strong>.</p><ol><li>First, you gather the ingredients.</li><li>Next, you mix them in a bowl.</li><li>Then, you bake the mixture in the oven.</li><li>Finally, you serve the cake.</li></ol><p>Each step must be done <strong>in a specific order</strong> (you can’t bake the ingredients before mixing them!). That’s how a DAG works — it lays out the sequence of operations, ensuring the right steps happen in the right order.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/526/1*JnleNpF7uS2Ez3R4Or7OpA.png" /></figure><p><strong>Driver Program ( The Master Controller )</strong></p><p>The <strong>Driver Program</strong> is where the Spark job begins. It runs the <strong>main() function</strong> and takes responsibility for:</p><ul><li><strong>Splitting the job into tasks</strong> and distributing them to different nodes (computers).</li><li><strong>Tracking the progress of tasks</strong> running on worker nodes (executors).</li><li><strong>Collecting results</strong> from workers once tasks are complete.</li></ul><p>The <strong>Spark Context</strong> is the entry point for any Spark functionality. It represents the connection to a Spark cluster and can be used to create RDDs, accumulators, and broadcast variables. SparkContext also coordinates the execution of tasks.</p><p><strong>Example</strong> : The driver program is like a <strong>project manager</strong> who assigns specific parts of a project to team members, monitors progress, and collects the final deliverables.</p><p><strong>Cluster Manager ( The Resource Allocator )</strong></p><p>The <strong>Cluster Manager</strong> handles <strong>resource management</strong>. It ensures each Spark job gets the <strong>right amount of memory and CPU</strong> required to complete its tasks. Spark can integrate with various cluster managers, such as:</p><ul><li><strong>Standalone Mode:</strong> Spark’s built-in manager, ideal for small setups.</li><li><strong>YARN:</strong> Used in Hadoop clusters to manage resources across multiple jobs.</li><li><strong>Apache Mesos:</strong> A general-purpose cluster manager.</li></ul><p><strong>Example</strong> : The cluster manager is like a <strong>traffic cop</strong>, directing tasks to available resources (memory and CPUs) within the cluster.</p><p><strong>Executors ( The Workers )</strong></p><p><strong>Executors</strong> are <strong>processes running on worker nodes</strong> that perform the actual data processing. Each worker node has <strong>one or more executors</strong>, which execute tasks assigned by the driver and <strong>store intermediate data</strong> in memory or on disk.</p><p><strong>Responsibilities of Executors:</strong></p><ol><li><strong>Run tasks:</strong> Each executor processes part of the data.</li><li><strong>Store intermediate results:</strong> Results can be stored in <strong>memory (for speed)</strong> or <strong>disk (for fault tolerance)</strong>.</li><li><strong>Communicate with the Driver:</strong> Executors report task completion or failures back to the driver program.</li></ol><p><strong>Example</strong> : Think of the executors as <strong>cooks in a restaurant kitchen</strong>. Each cook works on preparing one part of the meal (e.g., appetizers, main course) and sends the final dish back to the head chef (Driver Program).</p><p><strong>Distributed Storage</strong> (HDFS, S3, or Local Disks):</p><p>Spark reads data from <strong>distributed storage systems</strong>, such as:</p><ul><li><strong>HDFS (Hadoop Distributed File System):</strong> Common in Hadoop ecosystems.</li><li><strong>Amazon S3:</strong> A popular cloud storage option.</li><li><strong>Local disks:</strong> Useful in standalone or smaller setups.</li></ul><p>The data is <strong>split into partitions</strong> and distributed across multiple nodes in the cluster. This enables <strong>parallel processing</strong>, where multiple nodes work on their own partition of the data simultaneously.</p><h3><strong>Working of Spark Architecture</strong></h3><h4>Submitting the Job: Spark Takes Your Request</h4><p>The first step begins when you submit a <strong>job</strong> to Spark. This job can be anything from running a SQL query or Python or Scala to analyzing huge datasets or building machine learning models. This request is sent to the <strong>Driver Program</strong>, which initiates the process.</p><p><strong>Example:</strong> Imagine you have a file with <strong>10 million online sales transactions</strong> and you want to find out the <strong>total revenue</strong> generated in the year 2023.</p><h4>Building the DAG: Spark Creates a Plan</h4><p>After receiving your request, the <strong>Driver Program</strong> doesn’t immediately start processing. Instead, it <strong>breaks down the job into smaller stages and tasks</strong>. This sequence of steps is arranged into a <strong>DAG (Directed Acyclic Graph)</strong>.</p><p><strong>Example:</strong> If your job is to calculate the total revenue for 2023, the DAG might look like this:</p><ol><li><strong>Load</strong> the dataset from the storage (e.g., HDFS or S3).</li><li><strong>Filter</strong> the transactions for the year 2023.</li><li><strong>Sum</strong> the revenue of the filtered transactions.</li></ol><h4>Dividing the Job into Tasks Using RDDs</h4><p>Spark now <strong>splits the data into smaller pieces</strong> called <strong>partitions</strong>. These partitions are handled by a data structure called <strong>RDD (Resilient Distributed Dataset)</strong>. Each partition contains a <strong>chunk of your data</strong> and will be processed independently on different machines (nodes) in the cluster.</p><p><strong>Example: </strong>If your dataset has <strong>10 million rows</strong>, Spark might split it into <strong>10 partitions</strong>, each containing 1 million rows.</p><h4>Task Execution on Worker Nodes</h4><p>Once the driver creates the tasks and assigns them to different nodes, the <strong>worker nodes</strong> (executors) start working. Each executor <strong>processes the data in its partition</strong>, performing the assigned computations. Since all the nodes work simultaneously, the overall job completes faster.</p><p><strong>Example</strong> : Suppose one partition contains the transactions for January to March. An executor on that node will calculate the sum of the revenue for those months. Another executor will sum the revenue for April to June, and so on.</p><p><strong>How Executors Work :</strong></p><ul><li><strong>In-memory Processing:</strong> Spark keeps data in RAM as much as possible to speed up computations.</li><li><strong>Temporary Storage:</strong> If there isn’t enough memory, the executor stores data temporarily on disk.</li></ul><h4>Collecting Results and Returning the Final Output</h4><p>After all the worker nodes finish their tasks, they send the <strong>partial results back to the driver</strong>. The driver collects and combines these results to generate the final output.</p><p><strong>Example </strong>: Each worker node sends the <strong>partial sum of revenue</strong> it calculated from its partition. The driver collects all these partial sums and <strong>adds them together</strong> to get the total revenue for 2023.</p><h3><strong>Conclusion</strong></h3><p>Spark’s architecture is what makes it a powerhouse for <strong>Big Data processing</strong>. By <strong>splitting tasks across multiple nodes</strong> and leveraging in-memory computation, Spark ensures that jobs are completed efficiently, even for the largest datasets. With <strong>fault-tolerance and scalability</strong> built-in, Spark is the go-to platform for businesses handling Big Data.</p><p>Thank you for reading! To stay connected and discover more about Spark and AI, don’t hesitate to follow me on <a href="https://medium.com/@vishnuprabu017">Medium</a> for future updates!</p><p>If you have any queries or any topic-related suggestions, feel free to reach out to Me via <a href="https://www.linkedin.com/in/vishnu-prabu-169855279/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5080748bf093" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[From Data Overload to Insight: Exploring Apache Spark’s Magic]]></title>
            <link>https://medium.com/@vishnuprabu017/from-data-overload-to-insight-exploring-apache-sparks-magic-1ebe88e0ceb8?source=rss-8423db5ce3ca------2</link>
            <guid isPermaLink="false">https://medium.com/p/1ebe88e0ceb8</guid>
            <dc:creator><![CDATA[Vishnu Prabu]]></dc:creator>
            <pubDate>Mon, 21 Oct 2024 10:21:35 GMT</pubDate>
            <atom:updated>2024-10-21T10:21:35.163Z</atom:updated>
            <content:encoded><![CDATA[<p>Welcome to the exciting world of <strong>Big Data and Apache Spark</strong>! Imagine a place where companies handle data as vast and changing as the ocean — huge, always flowing, and full of possibilities<strong>.</strong> Trying to manage such a large amount of information manually would be like trying to catch waves with a net! That’s where <strong>Apache Spark</strong> comes in, acting like a turbocharger that makes processing Big Data faster and easier than ever before.</p><p>Through this blog, you’ll explore <strong>how Spark is changing the way businesses work</strong>, why so many organizations rely on it, and the amazing ways it’s being used. Are you ready for this exciting journey? Let’s get started!</p><p>In this article, we will explore the following topics:</p><ol><li>Why Apache Spark is Revolutionizing Big Data</li><li>Beyond Hadoop: The Next-Gen Engine for Distributed Computing</li><li>Key Components of Spark</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*wZ5_vRqTJTCObJvfxkwGVA.png" /></figure><h3><strong>Why Apache Spark is Revolutionizing Big Data</strong></h3><p>In today’s world, <strong>data is everywhere</strong> — from Instagram likes to weather updates and bank transactions. Companies generate <strong>terabytes of data</strong> every day, and they need tools to make sense of it. Traditional tools either take too long or can’t keep up with this massive flow of information.</p><p>Apache Spark is an <strong>open-source, distributed computing engine</strong> designed to <strong>process large amounts of data quickly</strong> and <strong>supporting parallel processing</strong>. Simply put, Spark acts like a <strong>super-fast brain</strong>, dividing tasks across multiple computers that work together to handle huge datasets.</p><p>Think of Spark as a <em>super-brain</em> that can read millions of social media comments in minutes. Imagine a company launching a new product: Spark can analyze reactions on Twitter, Instagram, and Facebook in real-time, helping the company understand whether customers love the product or if improvements are needed. Without Spark, gathering these insights could take days — by which time it might be too late to react. With Spark, businesses can <em>stay ahead of the curve</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/1*bdPDpNfjiSRLq5OyZsG9AQ.png" /></figure><h3><strong>Beyond Hadoop: The Next-Gen Engine for Distributed Computing</strong></h3><p>Before Spark became the go-to tool, <strong>Hadoop</strong> was the pioneer of Big Data processing. Hadoop is also an <strong>open-source platform</strong> that splits data across many computers. However, it processes data more slowly because it writes and <em>reads from disks instead of using memory</em> (RAM).</p><p>Think of <em>Hadoop as a mailman</em> who delivers letters one at a time by walking to each house. It gets the job done, but slowly. In contrast, <em>Spark is like a fleet of drones</em> delivering letters to multiple houses simultaneously. While Hadoop laid the foundation for Big Data processing, Spark has taken things to the next level with its <strong>speed </strong>and<strong> flexibility</strong>.</p><p><strong>Key Differences Between Hadoop and Spark:</strong></p><p><strong>Speed</strong>: <strong>Hadoop</strong> uses a slower method called <strong><em>MapReduce</em></strong> that reads from and writes to disk frequently, making it sluggish. <strong>Spark</strong> keeps everything <strong><em>in memory</em></strong> (RAM), making it up to <em>100 times faster</em> for certain tasks.</p><p><strong>Real-Time Capability</strong>: <strong>Hadoop</strong> processes data in <strong><em>batches</em></strong>, while <strong>Spark</strong> can handle <strong><em>real-time streaming</em></strong>.</p><ul><li><strong>Example</strong>: Spark helps Uber analyze incoming ride requests instantly, matching drivers and riders within seconds. Hadoop would only provide results <em>after</em> the event, which isn’t ideal for real-time services.</li></ul><p><strong>Processing</strong>: <strong>Hadoop</strong> supports only <strong><em>batch processing</em></strong> while <strong>Spark</strong> uses both the <strong><em>batch processing </em></strong>and<strong><em> </em></strong>the<strong><em> stream processing</em></strong>.</p><ol><li><strong>Batch Processing</strong>: Batch processing means collecting <strong>large amounts of data over a specific period</strong> and processing it in one go.</li></ol><p>Example of Batch Processing: <strong>Payroll System</strong></p><ul><li><strong>Scenario</strong>: A company processes the salaries of its employees at the end of every month.</li><li><strong>How it Works</strong>: Throughout the month, the system collects data about employees’ working hours, bonuses, and deductions. At the <strong>end of the month</strong>, the payroll system processes all the data in one go to calculate salaries, generate payslips, and initiate payments.</li><li><strong>Why Batch?</strong>: Salary processing doesn’t need to happen instantly. It’s okay to <strong>accumulate the data and process it once</strong> a month.</li></ul><p>2. <strong>Stream Processing:</strong> Stream processing means analyzing <strong>data as it arrives, in real time</strong> or near real-time.</p><p>Example of Stream Processing : <strong>Uber Ride Matching</strong></p><ul><li><strong>Scenario</strong>: When you open the Uber app and request a ride, Uber’s system needs to <strong>find a nearby driver instantly</strong>.</li><li><strong>How it Works</strong>: As soon as the ride request comes in, the system <strong>analyzes the data in real time</strong> — checking the location of drivers, traffic conditions, and estimated travel times. Within seconds, it matches you with the best available driver.</li><li><strong>Why Stream?</strong>: You can’t wait for Uber to batch all ride requests for the day — decisions need to be made <strong>on the spot</strong> to provide fast service.</li></ul><p><strong>Use Cases</strong>: <strong>Spark</strong> comes up with the <strong><em>live data handling </em></strong>and<strong><em> ML applications simultaneously</em></strong> as it overcomes the disadvantages of <strong>Hadoop</strong> because it only make use of the <strong><em>historical data.</em></strong></p><h3>Key Components of Spark</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/1*LqlyJvNAcyw6c02famB4DQ.png" /></figure><h4><strong>Spark Core</strong></h4><p><strong>Spark Core</strong> is the <strong>heart of the entire Spark framework</strong>. It handles the fundamental functions like task scheduling, memory management, fault recovery, and distributing tasks across the cluster (multiple computers). Without Spark Core, the other components wouldn’t work since it serves as the foundation for them.</p><p><strong>Key Responsibilities:</strong></p><ul><li><strong>Task distribution</strong>: Divides big jobs into smaller tasks and assigns them to worker nodes.</li><li><strong>Memory management</strong>: Optimizes the use of RAM, making the processing faster.</li><li><strong>Fault tolerance</strong>: If a task fails, Spark Core reruns it to ensure the process completes.</li><li><strong>Data abstraction using RDDs (Resilient Distributed Datasets)</strong>: Spark Core creates RDDs to store data distributed across nodes while ensuring data can be recovered if something goes wrong.</li></ul><p><strong>Example</strong> : Think of Spark Core as a coach who assigns specific tasks to team members and ensures that even if one player fails, someone else takes over.</p><h4>Spark SQL</h4><p>Spark SQL provides tools to <strong>work with structured data</strong> (such as tables, rows, and columns) using <strong>SQL-like syntax</strong>. It integrates with traditional SQL databases and makes querying Big Data <strong>easy for analysts and developers</strong> without requiring deep programming knowledge.</p><p><strong>Key Features :</strong></p><ul><li><strong>DataFrames</strong>: Just like tables in SQL, DataFrames store data in rows and columns.</li><li><strong>Compatibility with SQL</strong>: You can use SQL queries to analyze data stored in Spark.</li><li><strong>Hive integration</strong>: Spark SQL can access Hive tables directly, making it easier to work with existing data warehouses.</li></ul><p><strong>Example : </strong>Spark SQL is like <strong>Google for data</strong> — you ask it questions, and it finds answers from the data. Suppose if A bank uses Spark SQL to run queries like, “What is the total loan amount approved for customers with a credit score above 700?”. It will perform SQL operations to fetch data’s.</p><h4>Spark Streaming</h4><p>Spark Streaming enables <strong>processing data in real time</strong> as it flows in. This is essential for applications that require quick responses — for example, <em>fraud detection, live monitoring, or recommendation engines</em>.</p><p><strong>How It Works :</strong></p><ul><li>Spark Streaming breaks incoming data into micro-batches (small chunks of data).</li><li>Each micro-batch is processed almost instantly, giving the appearance of real-time processing.</li></ul><p><strong>Example : </strong>Think of a <strong><em>ride-hailing service like Uber or Rapido</em></strong>. Spark Streaming continuously processes driver locations and ride requests as they come in, matching drivers with customers within seconds.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*K6hb6nieswKLlupQYiOXWA.png" /></figure><h4>MLlib (Machine Learning Library)</h4><p>MLlib provides a wide range of <strong>machine learning algorithms and tools</strong> that can run at scale. It allows users to build predictive models using Big Data, making it easy to perform <strong><em>classification, regression, clustering, and more</em></strong>.</p><p><strong>Key Features :</strong></p><ul><li>Supports linear regression, decision trees, clustering, and recommendation algorithms.</li><li>Works seamlessly with DataFrames and RDDs for data input.</li><li>Handles large datasets efficiently across multiple nodes.</li></ul><p><strong>Example</strong> : An e-commerce website can use MLlib to predict which customers are likely to make a purchase. By analyzing historical data, the system can recommend products like “<em>People who bought smartphones also bought earphones</em>.”</p><h4>GraphX</h4><p>GraphX allows users to work with <strong>graph data</strong> — that is, data with relationships, such as <strong><em>social networks</em></strong> or <strong><em>supply chains</em></strong>. With GraphX, users can model data as graphs with <em>nodes</em> (points) and <em>edges</em> (connections) to uncover patterns and relationships.</p><p><strong>Key Features :</strong></p><ul><li>Supports <strong>graph algorithms</strong> like PageRank, which measures the importance of web pages (used by Google’s search engine).</li><li>Allows users to <strong>merge graph computations with other data processing tasks.</strong></li></ul><p><strong>Example</strong> : Instagram could use GraphX to <strong><em>identify influencers</em></strong> by finding users with the most followers and interactions. This helps brands identify the best people to promote their products.</p><h3>Conclusion</h3><p>Apache Spark is a <strong>game-changer</strong> for companies working with Big Data. With <strong>blazing-fast processing</strong>, real-time capabilities, and easy-to-use APIs, Spark is <strong>revolutionizing industries</strong> — from entertainment to finance to healthcare. Whether you’re <strong>recommending songs on Spotify</strong> or <strong>detecting fraud in a bank</strong>, Spark is working behind the scenes to make things happen faster and smarter.</p><p>Thank you for reading! If you enjoyed this article and If you’ve ever been curious about how data drives the world, now is a great time to dive deeper into Spark.</p><p>Keep an eye out for my upcoming blog on <strong><em>Spark Architecture and its Working. </em></strong>To stay informed about Spark and AI, feel free to follow me on <a href="https://medium.com/@vishnuprabu017">Medium</a> for more exciting content!</p><p>If you have any queries or any topic-related suggestions, feel free to reach out to Me via <a href="https://www.linkedin.com/in/vishnu-prabu-169855279/">LinkedIn</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1ebe88e0ceb8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>