<?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 sarath chandra on Medium]]></title>
        <description><![CDATA[Stories by sarath chandra on Medium]]></description>
        <link>https://medium.com/@iamsarathchandra?source=rss-fe3682084b83------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*cry9qejQoWwPRunj7jCP_A.jpeg</url>
            <title>Stories by sarath chandra on Medium</title>
            <link>https://medium.com/@iamsarathchandra?source=rss-fe3682084b83------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:07:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@iamsarathchandra/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[Schedulers in Akka using Scala — Use Case: Flipkart]]></title>
            <link>https://iamsarathchandra.medium.com/schedulers-in-akka-using-scala-use-case-flipkart-59e0c5530931?source=rss-fe3682084b83------2</link>
            <guid isPermaLink="false">https://medium.com/p/59e0c5530931</guid>
            <category><![CDATA[akka-actor]]></category>
            <category><![CDATA[akka]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[scheduler]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[sarath chandra]]></dc:creator>
            <pubDate>Mon, 31 Mar 2025 15:06:11 GMT</pubDate>
            <atom:updated>2025-03-31T15:06:11.640Z</atom:updated>
            <content:encoded><![CDATA[<h3>Schedulers in Akka using Scala — Use Case: Flipkart</h3><h3>Introduction</h3><p>Akka provides powerful scheduling capabilities to execute tasks at a fixed interval or after a certain delay. This feature is useful for scenarios like background tasks, periodic health checks, cache invalidation, and more. In this blog, we’ll explore <strong>Akka Schedulers</strong> using Scala and demonstrate how Flipkart (an e-commerce platform) can leverage them to enhance its operations.</p><h3>Why Use Schedulers in Akka?</h3><p>Schedulers in Akka help perform asynchronous and periodic operations without blocking threads. Some common use cases include:</p><ul><li><strong>Refreshing Cache:</strong> Refreshing frequently accessed product details, prices, or offers.</li><li><strong>Sending Notifications:</strong> Scheduling push notifications for order updates.</li><li><strong>Periodic Health Checks:</strong> Ensuring microservices are running efficiently.</li><li><strong>Retry Mechanism:</strong> Retrying failed tasks, like payment processing.</li></ul><h3>Flipkart Use Case: Auto-Refreshing Product Deals</h3><p>Consider Flipkart’s <strong>Deals of the Day</strong> feature, where top deals and discounts update every hour. Instead of manually refreshing deals, Flipkart can use an <strong>Akka Scheduler</strong> to update offers periodically.</p><h3>Implementing Akka Schedulers in Scala</h3><h3>Step 1: Setting Up Akka ActorSystem</h3><p>First, define an <strong>ActorSystem</strong> to handle scheduled tasks:</p><pre>import akka.actor.{Actor, ActorSystem, Props}<br>import scala.concurrent.ExecutionContext.Implicits.global<br>import scala.concurrent.duration._<br><br>object FlipkartScheduler extends App {<br>  // Create an ActorSystem<br>  implicit val system: ActorSystem = ActorSystem(&quot;FlipkartSystem&quot;)<br><br>  // Schedule periodic refresh<br>  system.scheduler.schedule(initialDelay = 0.seconds, interval = 1.hour) {<br>    println(&quot;Refreshing Deals of the Day...&quot;)<br>  }<br>}</pre><h3>Step 2: Using an Actor to Handle Scheduled Tasks</h3><p>Instead of printing, let’s use an <strong>Actor</strong> to refresh deals:</p><pre>class DealRefresher extends Actor {<br>  override def receive: Receive = {<br>    case &quot;refresh&quot; =&gt;<br>      println(&quot;Fetching latest deals from the database and updating the cache...&quot;)<br>      // Business logic to fetch &amp; update deals<br>  }<br>}<br><br>object FlipkartScheduler extends App {<br>  implicit val system: ActorSystem = ActorSystem(&quot;FlipkartSystem&quot;)<br>  val dealRefresher = system.actorOf(Props[DealRefresher], &quot;dealRefresher&quot;)<br><br>  // Schedule refresh every hour<br>  system.scheduler.schedule(0.seconds, 1.hour, dealRefresher, &quot;refresh&quot;)<br>}</pre><h3>Explanation</h3><ul><li>schedule: Executes the task at fixed intervals.</li><li>dealRefresher ! &quot;refresh&quot;: Sends a message to the actor, triggering the deal refresh logic.</li></ul><h3>Advanced Use Case: Dynamic Scheduling Based on Traffic</h3><p>Flipkart experiences <strong>high traffic</strong> during the <strong>Big Billion Days</strong> sales. To handle this, we can dynamically adjust the scheduling interval:</p><pre>import akka.actor.{ActorRef, Cancellable}<br><br>var refreshTask: Option[Cancellable] = None<br><br>def adjustScheduler(interval: FiniteDuration): Unit = {<br>  // Cancel the previous schedule if it exists<br>  refreshTask.foreach(_.cancel())<br>  <br>  // Start a new schedule with updated interval<br>  refreshTask = Some(system.scheduler.schedule(0.seconds, interval, dealRefresher, &quot;refresh&quot;))<br>}<br><br>// Example: Increase refresh frequency during sales<br>adjustScheduler(30.minutes) // Refresh deals every 30 minutes instead of 1 hour</pre><h3>Conclusion</h3><p>Akka Schedulers provide a <strong>reliable and non-blocking way</strong> to handle periodic tasks. Flipkart can leverage this for <strong>automated deal updates, order notifications, and dynamic scheduling</strong> based on traffic. This ensures a seamless shopping experience for millions of users.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59e0c5530931" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Currying in Scala: A Functional Programming Powerhouse]]></title>
            <link>https://iamsarathchandra.medium.com/mastering-currying-in-scala-a-functional-programming-powerhouse-ce88a3edf3ce?source=rss-fe3682084b83------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce88a3edf3ce</guid>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[currying]]></category>
            <category><![CDATA[functional-programming]]></category>
            <category><![CDATA[scala-programming]]></category>
            <dc:creator><![CDATA[sarath chandra]]></dc:creator>
            <pubDate>Sun, 02 Mar 2025 09:04:52 GMT</pubDate>
            <atom:updated>2025-03-02T09:05:58.521Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>Currying is a powerful functional programming concept that plays a crucial role in <strong>Scala</strong>. It allows us to break down functions with multiple parameters into a series of <strong>single-argument</strong> functions. But why should we care? In real-world applications, currying enables <strong>code reusability, modularity, and better function composition</strong>, making it a go-to technique for building scalable and readable systems.</p><p>In this blog, we’ll explore <strong>currying in Scala</strong>, understand its <strong>syntax</strong>, and uncover how it helps solve <strong>real-world problems</strong> in <strong>Big Data, API security, and Kafka-based processing</strong>. 🚀</p><h3>What is Currying in Scala?</h3><p>Currying is the process of transforming a function that takes multiple arguments into a series of <strong>functions that take one argument each</strong>.</p><h3>Syntax of Currying in Scala</h3><pre>// A curried function that adds two numbers<br>def add(a: Int)(b: Int): Int = a + b<br><br>// Partially applying the function<br>val addFive = add(5) _  <br>println(addFive(3))  // Output: 8</pre><p>In the above example:</p><ul><li>add takes two arguments separately.</li><li>We partially apply add(5) to create a new function that expects only one more parameter.</li></ul><h3>Why is Currying Useful?</h3><p>Currying brings several advantages: ✅ <strong>Partial Function Application</strong>: Create specialized functions without rewriting code. ✅ <strong>Better Readability &amp; Maintainability</strong>: Makes code more modular. ✅ <strong>Seamless Functional Composition</strong>: Helps in chaining functions. ✅ <strong>Implicit Parameter Support</strong>: Often used for dependency injection.</p><pre>def greet(name: String)(implicit greeting: String): String = s&quot;$greeting, $name!&quot;<br>implicit val defaultGreeting: String = &quot;Hello&quot;<br>println(greet(&quot;Scala&quot;)) // Output: Hello, Scala!</pre><h3>Real-World Problems Solved by Currying</h3><p>Now, let’s dive into practical use cases where <strong>currying shines</strong> in real-world applications. 🚀</p><h3>1. Configurable Logging System</h3><p><strong>Problem:</strong> Different modules in an application require different log levels (INFO, DEBUG, ERROR). Instead of passing the log level every time, we can use currying.</p><p><strong>Solution:</strong></p><pre>def log(level: String)(message: String): Unit = println(s&quot;[$level] $message&quot;)<br><br>val infoLog = log(&quot;INFO&quot;) _<br>val errorLog = log(&quot;ERROR&quot;) _<br>infoLog(&quot;System started&quot;)    // [INFO] System started<br>errorLog(&quot;Connection failed&quot;) // [ERROR] Connection failed</pre><p>✅ <strong>Benefit:</strong> Reusable loggers without redundant parameter passing.</p><h3>2. Big Data Processing Pipeline (Apache Spark)</h3><p><strong>Problem:</strong> Data transformations vary based on dynamic filters (e.g., filtering by country in Spark jobs).</p><p><strong>Solution:</strong></p><pre>def filterData(criteria: String)(data: List[String]): List[String] =<br>  data.filter(_.contains(criteria))<br><br>val filterByIndia = filterData(&quot;India&quot;) _<br>val records = List(&quot;India - 1000 users&quot;, &quot;USA - 2000 users&quot;, &quot;India - 500 users&quot;)<br>println(filterByIndia(records)) // Output: List(&quot;India - 1000 users&quot;, &quot;India - 500 users&quot;)</pre><p>✅ <strong>Benefit:</strong> Easily configurable data filters for different use cases.</p><h3>3. API Authorization Middleware</h3><p><strong>Problem:</strong> Instead of checking authentication in every function, currying helps <strong>enforce authentication centrally</strong>.</p><p><strong>Solution:</strong></p><pre>def authenticate(token: String)(operation: =&gt; String): String =<br>  if (token == &quot;valid_token&quot;) operation else &quot;Unauthorized access&quot;<br><br>val securedAction = authenticate(&quot;valid_token&quot;) _<br>println(securedAction(&quot;User data retrieved&quot;)) // Output: User data retrieved<br>println(authenticate(&quot;invalid_token&quot;)(&quot;Sensitive data&quot;)) // Output: Unauthorized access</pre><p>✅ <strong>Benefit:</strong> Centralized security handling.</p><h3>4. Kafka Message Processing (Scala + Kafka)</h3><p><strong>Problem:</strong> We process different Kafka topics dynamically. Instead of writing separate functions, we <strong>reuse processing logic</strong> via currying.</p><p><strong>Solution:</strong></p><pre>def processMessage(topic: String)(message: String): String =<br>  s&quot;Processing [$topic]: $message&quot;<br><br>val processPayments = processMessage(&quot;payments&quot;) _<br>val processOrders = processMessage(&quot;orders&quot;) _<br>println(processPayments(&quot;Transaction ID 123&quot;))  // Processing [payments]: Transaction ID 123<br>println(processOrders(&quot;Order ID 456&quot;))         // Processing [orders]: Order ID 456</pre><p>✅ <strong>Benefit:</strong> <strong>Scalable</strong> and <strong>modular Kafka processing</strong>.</p><h3>5. Dynamic Query Builder (PostgreSQL + Scala)</h3><p><strong>Problem:</strong> SQL queries often change based on filters (e.g., WHERE clauses). Currying helps build queries dynamically.</p><p><strong>Solution:</strong></p><pre>def buildQuery(baseQuery: String)(condition: String): String =<br>  s&quot;$baseQuery WHERE $condition&quot;<br><br>val userQuery = buildQuery(&quot;SELECT * FROM users&quot;) _<br>println(userQuery(&quot;status = &#39;active&#39;&quot;))   // SELECT * FROM users WHERE status = &#39;active&#39;<br>println(userQuery(&quot;subscription = &#39;premium&#39;&quot;))  // SELECT * FROM users WHERE subscription = &#39;premium&#39;</pre><p>✅ <strong>Benefit:</strong> Flexible query building <strong>without repetitive code</strong>.</p><h3>When to Use Currying?</h3><p>✔️ When designing <strong>reusable and modular</strong> functions. ✔️ When applying <strong>higher-order functions</strong> effectively. ✔️ When handling <strong>dependency injection</strong> cleanly. ✔️ When working with <strong>functional composition</strong> in Scala.</p><h3>Final Thoughts</h3><p>Currying is an <strong>essential technique in Scala</strong>, enabling <strong>functional composition, clean code, and modular design</strong>. Whether you’re building <strong>Big Data pipelines, secure APIs, or dynamic Kafka processors</strong>, <strong>currying helps write expressive and reusable Scala code</strong>.</p><p>Are you using currying in your Scala projects? Let me know in the comments! 💬</p><h3>Further Reading:</h3><p>🔹 <a href="https://www.scala-lang.org/">Scala Functional Programming</a> 🔹 <a href="https://docs.scala-lang.org/overviews/collections-2.13/introduction.html">Advanced Scala Collections</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce88a3edf3ce" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Real-Time Recommendations Using Apache Storm and Kafka in Scala]]></title>
            <link>https://iamsarathchandra.medium.com/real-time-recommendations-using-apache-storm-and-kafka-in-scala-d7d635720036?source=rss-fe3682084b83------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7d635720036</guid>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[apache-storm]]></category>
            <dc:creator><![CDATA[sarath chandra]]></dc:creator>
            <pubDate>Wed, 06 Nov 2024 20:13:49 GMT</pubDate>
            <atom:updated>2024-11-06T20:13:49.033Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, we will walk through the implementation of a real-time recommendation system using Apache Storm and Kafka in Scala. We’ll create a topology that reads user activity and inventory data from two separate Kafka topics, joins them, and emits real-time product recommendations. This example will showcase how you can use Apache Storm to process large streams of data in real-time.</p><h3>Prerequisites</h3><p>Before diving into the code, you’ll need:</p><ul><li><strong>Apache Storm</strong> running on your system.</li><li><strong>Kafka</strong> setup for the data streams (user activity and inventory updates).</li><li><strong>Scala</strong> and <strong>SBT</strong> installed for building the project.</li></ul><h3>Step 1: Setting Up the Project with SBT</h3><p>To manage dependencies and build the project, we’ll use <strong>SBT</strong> (Scala Build Tool). Here’s the build.sbt file to set up the necessary dependencies for Apache Storm, Kafka, and Jackson serialization.</p><pre>name := &quot;RealTimeRecommendation&quot;<br><br>version := &quot;1.0&quot;<br><br>scalaVersion := &quot;2.13.10&quot;<br><br>libraryDependencies ++= Seq(<br>  &quot;org.apache.storm&quot; % &quot;storm-core&quot; % &quot;2.3.0&quot;,   // Apache Storm dependency<br>  &quot;org.apache.kafka&quot; % &quot;kafka-clients&quot; % &quot;2.8.1&quot;, // Kafka client dependency<br>  &quot;com.fasterxml.jackson.core&quot; % &quot;jackson-databind&quot; % &quot;2.12.3&quot; // Jackson for serialization<br>)</pre><h3>Step 2: Defining Spouts to Read from Kafka Topics</h3><p>A <strong>Spout</strong> in Apache Storm is responsible for emitting tuples into the topology. In our case, we’ll define two spouts: one for reading user activity data and another for inventory updates from Kafka.</p><h4>User Activity Spout</h4><p>This spout will simulate reading user activity events from a Kafka topic and emit the user ID, product ID, and timestamp.</p><pre>import org.apache.storm.spout.SpoutOutputCollector<br>import org.apache.storm.topology.base.BaseRichSpout<br>import org.apache.storm.tuple.Fields<br>import org.apache.storm.topology.OutputFieldsDeclarer<br>import org.apache.storm.task.TopologyContext<br>import org.apache.storm.spout.SpoutContext<br><br>class UserActivitySpout(kafkaTopic: String, zookeeperHosts: String) extends BaseRichSpout {<br>  var collector: SpoutOutputCollector = _<br><br>  override def open(config: java.util.Map[String, Object], context: SpoutContext, collector: SpoutOutputCollector): Unit = {<br>    this.collector = collector<br>  }<br><br>  override def nextTuple(): Unit = {<br>    // Simulating user activity data<br>    val userActivity = Map(&quot;userId&quot; -&gt; &quot;user123&quot;, &quot;productId&quot; -&gt; &quot;prod456&quot;, &quot;timestamp&quot; -&gt; System.currentTimeMillis())<br>    collector.emit(new org.apache.storm.tuple.Values(userActivity(&quot;userId&quot;), userActivity(&quot;productId&quot;), userActivity(&quot;timestamp&quot;)))<br>  }<br><br>  override def declareOutputFields(declarer: OutputFieldsDeclarer): Unit = {<br>    declarer.declare(new Fields(&quot;userId&quot;, &quot;productId&quot;, &quot;timestamp&quot;))<br>  }<br>}</pre><h4>Inventory Update Spout</h4><p>Similarly, this spout will simulate reading inventory update data from a Kafka topic and emit the product ID and stock count.</p><pre>import org.apache.storm.spout.SpoutOutputCollector<br>import org.apache.storm.topology.base.BaseRichSpout<br>import org.apache.storm.tuple.Fields<br>import org.apache.storm.topology.OutputFieldsDeclarer<br>import org.apache.storm.task.TopologyContext<br>import org.apache.storm.spout.SpoutContext<br><br>class InventoryUpdateSpout(kafkaTopic: String, zookeeperHosts: String) extends BaseRichSpout {<br>  var collector: SpoutOutputCollector = _<br><br>  override def open(config: java.util.Map[String, Object], context: SpoutContext, collector: SpoutOutputCollector): Unit = {<br>    this.collector = collector<br>  }<br><br>  override def nextTuple(): Unit = {<br>    // Simulating inventory update data<br>    val inventoryUpdate = Map(&quot;productId&quot; -&gt; &quot;prod456&quot;, &quot;stockCount&quot; -&gt; 10, &quot;lastUpdated&quot; -&gt; System.currentTimeMillis())<br>    collector.emit(new org.apache.storm.tuple.Values(inventoryUpdate(&quot;productId&quot;), inventoryUpdate(&quot;stockCount&quot;)))<br>  }<br><br>  override def declareOutputFields(declarer: OutputFieldsDeclarer): Unit = {<br>    declarer.declare(new Fields(&quot;productId&quot;, &quot;stockCount&quot;))<br>  }<br>}</pre><h3>Step 3: The Join Bolt</h3><p>We now need to join data from the two streams: user activity and inventory updates. The <strong>JoinBolt</strong> will combine the data based on productId and emit recommendations when a product is available.</p><pre>import org.apache.storm.topology.base.BaseBasicBolt<br>import org.apache.storm.tuple.Tuple<br>import org.apache.storm.task.OutputCollector<br><br>class JoinBolt extends BaseBasicBolt {<br>  var userActivityCache: Map[String, Tuple] = Map()<br>  var inventoryCache: Map[String, Tuple] = Map()<br><br>  override def execute(input: Tuple, collector: OutputCollector): Unit = {<br>    val streamId = input.getSourceStreamId<br>    val productId = input.getStringByField(&quot;productId&quot;)<br><br>    streamId match {<br>      case &quot;userActivityStream&quot; =&gt;<br>        // Cache user activity by productId<br>        userActivityCache += (productId -&gt; input)<br>      case &quot;inventoryUpdateStream&quot; =&gt;<br>        // Cache inventory update by productId<br>        inventoryCache += (productId -&gt; input)<br>    }<br><br>    // Join logic: If both user activity and inventory update exist, emit the recommendation<br>    if (userActivityCache.contains(productId) &amp;&amp; inventoryCache.contains(productId)) {<br>      val userActivity = userActivityCache(productId)<br>      val inventoryUpdate = inventoryCache(productId)<br><br>      val userId = userActivity.getStringByField(&quot;userId&quot;)<br>      val stockCount = inventoryUpdate.getIntegerByField(&quot;stockCount&quot;)<br><br>      if (stockCount &gt; 0) {<br>        collector.emit(new org.apache.storm.tuple.Values(userId, productId, &quot;Recommended&quot;))<br>      }<br>    }<br>  }<br><br>  override def declareOutputFields(declarer: OutputFieldsDeclarer): Unit = {<br>    declarer.declare(new Fields(&quot;userId&quot;, &quot;productId&quot;, &quot;status&quot;))<br>  }<br>}</pre><h3>Step 4: The Recommendation Bolt</h3><p>The <strong>RecommendationBolt</strong> processes the joined data and outputs product recommendations. In this simplified example, it prints the recommendations to the console.</p><pre>import org.apache.storm.topology.base.BaseBasicBolt<br>import org.apache.storm.tuple.Tuple<br>import org.apache.storm.task.OutputCollector<br><br>class RecommendationBolt extends BaseBasicBolt {<br>  override def execute(input: Tuple, collector: OutputCollector): Unit = {<br>    val userId = input.getStringByField(&quot;userId&quot;)<br>    val productId = input.getStringByField(&quot;productId&quot;)<br>    val status = input.getStringByField(&quot;status&quot;)<br><br>    // Process the recommendation (e.g., store in a DB or print)<br>    println(s&quot;Recommendation: User $userId should be recommended product $productId. Status: $status&quot;)<br>  }<br><br>  override def declareOutputFields(declarer: OutputFieldsDeclarer): Unit = {<br>    // No output fields since this is the final bolt<br>  }<br>}</pre><h3>Step 5: Topology Definition</h3><p>Now, let’s tie everything together by creating the <strong>Topology</strong>. We define the spouts and bolts, set up the parallelism, and run the topology.</p><pre>import org.apache.storm.topology.TopologyBuilder<br>import org.apache.storm.Config<br>import org.apache.storm.LocalCluster<br><br>object RecommendationTopology {<br>  def main(args: Array[String]): Unit = {<br>    val builder = new TopologyBuilder()<br><br>    // Define Spouts<br>    builder.setSpout(&quot;userActivitySpout&quot;, new UserActivitySpout(&quot;user_activity&quot;, &quot;localhost:2181&quot;))<br>    builder.setSpout(&quot;inventoryUpdateSpout&quot;, new InventoryUpdateSpout(&quot;inventory_updates&quot;, &quot;localhost:2181&quot;))<br><br>    // Define Bolts<br>    builder.setBolt(&quot;joinBolt&quot;, new JoinBolt())<br>      .shuffleGrouping(&quot;userActivitySpout&quot;, &quot;userActivityStream&quot;)<br>      .shuffleGrouping(&quot;inventoryUpdateSpout&quot;, &quot;inventoryUpdateStream&quot;)<br>    <br>    builder.setBolt(&quot;recommendationBolt&quot;, new RecommendationBolt())<br>      .shuffleGrouping(&quot;joinBolt&quot;)<br><br>    // Configure and run the topology<br>    val config = new Config()<br>    config.setDebug(true)<br>    val cluster = new LocalCluster()<br>    cluster.submitTopology(&quot;RealTimeRecommendation&quot;, config, builder.createTopology())<br><br>    // Run for a fixed time for demo purposes<br>    Thread.sleep(10000)<br>    cluster.shutdown()<br>  }<br>}</pre><h3>Step 6: Running the Topology</h3><ol><li><strong>Start Apache Storm</strong> and ensure Kafka is running with the topics user_activity and inventory_updates created.</li><li><strong>Run the Topology</strong>: Execute the RecommendationTopology in your Scala project.</li></ol><p>This will process the data in real-time, join the streams based on productId, and emit recommendations when a product is in stock.</p><h3>Conclusion</h3><p>In this blog, we demonstrated how to use Apache Storm in Scala to read data from two Kafka topics, join the data, and generate real-time product recommendations. This use case can be extended for more complex applications such as fraud detection, real-time analytics, and personalized recommendations.</p><p>By combining <strong>spouts</strong> for different data sources, <strong>bolts</strong> for processing, and <strong>Storm’s parallel processing</strong> capabilities, you can build powerful real-time data pipelines to solve a wide variety of problems.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7d635720036" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Getting Started with GitHub Actions: Automating Your Workflow]]></title>
            <link>https://iamsarathchandra.medium.com/getting-started-with-github-actions-automating-your-workflow-c7124ca38539?source=rss-fe3682084b83------2</link>
            <guid isPermaLink="false">https://medium.com/p/c7124ca38539</guid>
            <category><![CDATA[github-actions]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[ci-cd-pipeline]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[sarath chandra]]></dc:creator>
            <pubDate>Fri, 06 Sep 2024 19:31:50 GMT</pubDate>
            <atom:updated>2024-09-06T19:31:50.119Z</atom:updated>
            <content:encoded><![CDATA[<p>GitHub Actions is a powerful feature integrated directly into GitHub that allows you to automate, customize, and execute your software development workflows right in your repository. Whether you need to automate your CI/CD pipeline, deploy code to production, run tests, or anything in between, GitHub Actions provides a robust and flexible solution. In this blog post, we’ll dive into the basics of GitHub Actions, explore its key components, and provide a step-by-step guide to creating your first workflow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*id5TGgy-4-V-w2sFnpmtBg.png" /></figure><h3>What is GitHub Actions?</h3><p>GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that lets you automate your build, test, and deployment pipeline. With GitHub Actions, you can define workflows in a YAML file stored in your repository. These workflows can be triggered by various events, such as pushing code, creating pull requests, or on a scheduled basis.</p><h3>Key Components of GitHub Actions</h3><ol><li><strong>Workflows</strong>: A workflow is an automated process defined in a YAML file, typically located in the .github/workflows directory of your repository. A workflow is triggered by events and can run on specified conditions.</li><li><strong>Events</strong>: Events are specific activities that trigger workflows. Examples include push, pull_request, issue, and schedule.</li><li><strong>Jobs</strong>: Jobs are a series of steps executed on the same runner. Jobs can run in parallel or sequentially.</li><li><strong>Steps</strong>: Steps are individual tasks within a job. Each step runs a script or an action.</li><li><strong>Runners</strong>: Runners are servers that run your workflows. GitHub provides hosted runners with various operating systems, or you can use self-hosted runners.</li></ol><h3>Setting Up Your First GitHub Actions Workflow</h3><p>Let’s create a simple workflow that runs a set of tests on your codebase every time you push code to the repository.</p><h3>Step 1: Create a Workflow File</h3><p>First, create a new directory in your repository named .github/workflows. Inside this directory, create a new file named ci.yml:</p><pre>name: CI<br><br>on:<br>  push:<br>    branches:<br>      - main<br><br>jobs:<br>  build:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v2<br><br>      - name: Set up JDK 11<br>        uses: actions/setup-java@v2<br>        with:<br>          java-version: &#39;11&#39;<br><br>      - name: Build with Gradle<br>        run: ./gradlew build<br><br>      - name: Run tests<br>        run: ./gradlew test</pre><h3>Step-by-Step Explanation</h3><ul><li><strong>name</strong>: Names the workflow “CI”.</li><li><strong>on</strong>: Specifies the events that trigger the workflow. In this case, the workflow runs on push events to the main branch.</li><li><strong>jobs</strong>: Defines a job named build.</li><li><strong>runs-on</strong>: Specifies the type of runner to use. Here, we’re using ubuntu-latest.</li><li><strong>steps</strong>: Lists the steps to be executed in the job:</li><li><strong>Checkout code</strong>: Uses the actions/checkout action to clone the repository.</li><li><strong>Set up JDK 11</strong>: Uses the actions/setup-java action to set up Java 11.</li><li><strong>Build with Gradle</strong>: Runs the Gradle build command.</li><li><strong>Run tests</strong>: Runs the Gradle test command.</li></ul><h3>Using Secrets in GitHub Actions</h3><p>Sometimes, you need to use sensitive data like API keys or passwords in your workflows. GitHub Actions allows you to store such secrets securely.</p><h3>Step 1: Add a Secret</h3><ol><li>Go to your GitHub repository.</li><li>Click on Settings.</li><li>In the left sidebar, click on Secrets and variables and then Actions.</li><li>Click on New repository secret.</li><li>Add your secret with a name and value.</li></ol><h3>Step 2: Use the Secret in Your Workflow</h3><p>Modify your ci.yml to use the secret:</p><pre>- name: Use Secret<br>  run: echo ${{ secrets.MY_SECRET }}</pre><h3>Example: Deploying to AWS S3</h3><p>Here’s an example of a workflow that deploys your application to an AWS S3 bucket every time code is pushed to the main branch:</p><pre>name: Deploy to S3<br><br>on:<br>  push:<br>    branches:<br>      - main<br><br>jobs:<br>  deploy:<br>    runs-on: ubuntu-latest<br><br>    steps:<br>      - name: Checkout code<br>        uses: actions/checkout@v2<br><br>      - name: Install AWS CLI<br>        run: sudo apt-get install -y awscli<br><br>      - name: Deploy to S3<br>        env:<br>          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}<br>          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}<br>        run: |<br>          aws s3 sync . s3://my-bucket --delete<br></pre><h3>Conclusion</h3><p>GitHub Actions provides a powerful way to automate your workflows directly from your GitHub repository. By defining workflows in YAML files, you can customize and automate tasks such as building, testing, and deploying your code. With support for secrets, multiple runners, and extensive community-contributed actions, GitHub Actions is a versatile tool for any development pipeline.</p><p>By following this guide, you should now have a good understanding of the basics of GitHub Actions and how to set up your first automated workflow. As you become more familiar with the platform, you can explore more advanced features and create more complex workflows to suit your project’s needs.</p><h3>Additional Resources</h3><ul><li><a href="https://docs.github.com/en/actions">GitHub Actions Documentation</a></li><li><a href="https://github.com/marketplace?type=actions">GitHub Actions Marketplace</a></li><li><a href="https://github.com/actions">GitHub Actions Examples</a></li></ul><p>Feel free to explore these resources to further enhance your understanding and capabilities with GitHub Actions. Happy automating!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c7124ca38539" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Why Storing Data as Byte Arrays is a Smart Choice]]></title>
            <link>https://iamsarathchandra.medium.com/why-storing-data-as-byte-arrays-is-a-smart-choice-646e6d75307e?source=rss-fe3682084b83------2</link>
            <guid isPermaLink="false">https://medium.com/p/646e6d75307e</guid>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[big-data]]></category>
            <category><![CDATA[data]]></category>
            <category><![CDATA[data-engineering]]></category>
            <dc:creator><![CDATA[sarath chandra]]></dc:creator>
            <pubDate>Wed, 31 Jul 2024 16:50:58 GMT</pubDate>
            <atom:updated>2024-07-31T16:50:58.848Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/541/1*ACTf6uweN_CFca8nd0Wl8Q.png" /></figure><p>When it comes to storing data, there are many formats you can choose from. Most people are familiar with storing data as integers, strings, or even more complex user-defined objects. However, there’s a less common but highly efficient method: storing data as byte arrays. Let’s explore why this method can be a smart choice.</p><h3>What is a Byte Array?</h3><p>A byte array is simply an array where each element is a byte. A byte is a unit of digital information that consists of 8 bits. It can represent values from 0 to 255. In programming, you might see a byte array written as Array[Byte].</p><h3>Benefits of Using Byte Arrays</h3><ol><li><strong>Performance Efficiency</strong></li></ol><ul><li><strong>Fast Access</strong>: Byte arrays are stored in contiguous blocks of memory. This means you can quickly access and manipulate data because there’s no need to jump around in memory.</li><li><strong>Low Overhead</strong>: Unlike more complex data structures, byte arrays don’t come with extra processing overhead. This can make your programs run faster.</li></ul><p><strong>2. Storage Efficiency</strong></p><ul><li><strong>Compact Representation</strong>: Byte arrays can be more space-efficient. For example, storing a 16-bit integer (which is 2 bytes) as a byte array takes up half the space compared to storing it as an integer (4 bytes in most systems).</li><li><strong>Minimal Metadata</strong>: Byte arrays don’t include extra information that some other data types carry, saving space.</li></ul><p><strong>3. Flexibility</strong></p><ul><li><strong>Binary Data Handling</strong>: Byte arrays are perfect for handling raw binary data. This is common with files like images, audio, or network packets, where data is naturally in a binary format.</li><li><strong>Serialization</strong>: Byte arrays are easy to serialize (convert to a format suitable for storage or transmission) and deserialize. This makes them ideal for saving data to disk or sending it over a network.</li></ul><p><strong>4. Interoperability</strong></p><ul><li><strong>Cross-Language Compatibility</strong>: Because byte arrays are a basic data type, they can be used across different programming languages. This is great for systems where different components might be written in different languages.</li><li><strong>Standard Encoding</strong>: Byte arrays can be easily converted to and from standard encodings like UTF-8 for strings. This makes them versatile for various data types.</li></ul><p><strong>5. Control Over Data</strong></p><ul><li><strong>Fine-Grained Manipulation</strong>: With byte arrays, you have precise control over every byte of data. This is essential for tasks like encryption, compression, or working with custom data formats.</li></ul><p><strong>6. Memory Management</strong></p><ul><li><strong>Predictable Memory Usage</strong>: Byte arrays have a fixed size, so you always know how much memory you’re using. This predictability can help in writing efficient programs.</li></ul><h3>Real-World Use Cases</h3><p>Here are a few examples where byte arrays shine:</p><ul><li><strong>Image Processing</strong>: Storing pixel data as byte arrays allows for efficient manipulation and processing of images.</li><li><strong>Networking</strong>: Network protocols often transmit data in binary format. Byte arrays are perfect for packing and unpacking these data packets.</li><li><strong>File I/O</strong>: Reading from and writing to binary files (like executables or media files) is naturally suited to byte arrays.</li><li><strong>Encryption</strong>: Cryptographic algorithms work on binary data, making byte arrays ideal for holding encrypted data.</li></ul><h3>Conclusion</h3><p>Storing data as byte arrays might seem a bit low-level compared to using integers, strings, or objects. However, the benefits in terms of performance, storage efficiency, flexibility, and control are significant. Whether you are dealing with binary data, need fast access to data, or require efficient memory usage, byte arrays can be a powerful tool in your programming toolkit.</p><p>Next time you’re deciding on a data storage format, consider whether byte arrays might be the right choice for your application. They might just be the key to making your programs run faster and more efficiently.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=646e6d75307e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>