<?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 Ramya L on Medium]]></title>
        <description><![CDATA[Stories by Ramya L on Medium]]></description>
        <link>https://medium.com/@aymar99?source=rss-dafffae09171------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*xcPk_qQPzXx-3EBmd5wYsw.jpeg</url>
            <title>Stories by Ramya L on Medium</title>
            <link>https://medium.com/@aymar99?source=rss-dafffae09171------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 14:28:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@aymar99/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[Letters from a  stoic — My favorite bits]]></title>
            <link>https://medium.com/@aymar99/letters-from-a-stoic-my-favorite-bits-55e4eff6ce7e?source=rss-dafffae09171------2</link>
            <guid isPermaLink="false">https://medium.com/p/55e4eff6ce7e</guid>
            <category><![CDATA[philosophy]]></category>
            <category><![CDATA[stoic-philosophy]]></category>
            <category><![CDATA[stoicism]]></category>
            <category><![CDATA[seneca]]></category>
            <category><![CDATA[stoic]]></category>
            <dc:creator><![CDATA[Ramya L]]></dc:creator>
            <pubDate>Tue, 02 May 2023 03:57:33 GMT</pubDate>
            <atom:updated>2023-11-18T11:58:58.542Z</atom:updated>
            <content:encoded><![CDATA[<h3>Letters from a stoic — My favorite bits</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*V6Zi0NwvHSUZG-mbLwpN8w.jpeg" /><figcaption>Seneca</figcaption></figure><p>Back when I was a teenager, I stumbled upon a short thought-provoking quote over the internet,</p><blockquote>We suffer more in our imagination more often than in reality.</blockquote><p>Little did I bother who wrote it.</p><p>Fast forward to my twenties, I came across stoicism, which talks about deriving joy from fair and skillful conduct during the passage of life instead of stressing over achievements that may or may not be the outcome due to the tough odds. It’s a way of life where our happiness is well secured from misfortunes. I started searching for authors to read more and I came across Seneca, a Roman philosopher who lived around 4 BC. He wrote about stoicism and other philosophical thoughts on how to lead a virtuous life. And coincidentally, he was the one who had written the quote I mentioned.</p><p>I started with “Letter from a Stoic”, a collection of letters written by Seneca to his friend Lucilius translated by Robin Campbell covering practical methodologies and philosophies for finding tranquility. Being my first book on ancient philosophy, it took me a while to get comfortable with the way of writing. Once I got through that phase, there were many instances where his writing resonated with me on a profound level. (I had bookmarked all the best quotations which I will be sharing in different categories in the following sections). Hope it will give a peek into Seneca’s way of thinking.</p><h3><strong>Sense of happiness</strong></h3><blockquote>You might think you want a fancy car or a nice watch. But what you probably want is respect and admiration.</blockquote><p>The above words are from the book, the psychology of Money. From my personal experience, whenever someone appreciates and admires me for the abilities I’ve built, it makes me feel valued. Admiration can’t be something that we chase; it’s a second-order effect of personal growth. But it fuels us to do better. Seneca adds another perspective to this idea, He says,</p><blockquote>Happy the man who improves other people not merely when he is in their presence but even when he is in their thoughts.</blockquote><blockquote>— Letter XI</blockquote><p>I realized, this is something very few people are capable of achieving, and this has been a capability of people I really admire.</p><h3>Envy</h3><blockquote>If you shape your life according to nature, you will never be poor. If according to Peoples’s opinions, you will never be rich.</blockquote><blockquote>— Letter XVI</blockquote><p>Obvious, isn’t it? Somehow, it’s never that obvious during the experience of envy. It may not be entirely bad. When you envy the right thing, it nudges you into becoming the right thing. Seneca also recognizes the importance of healthy envy. He says,</p><blockquote>There is a need, in my view, for someone as a standard against which our characters can measure themselves. Without a ruler to do it against, you won’t make the crooked straight.</blockquote><blockquote>— Letter XI</blockquote><h3>Self-control</h3><blockquote>Barley, porridge, or a crust of barley bread and water do not make a cheerful diet, but nothing gives one keener pleasure than the ability to derive pleasure even from that, and the feeling of having arrived at something which one cannot be deprived of by any unjust stroke of fortune.</blockquote><blockquote>— Letter XVIII</blockquote><p>Try to recall instances where you were able to say no to something that would have brought you joy, but you had better reasons to say no. Saying no to a social activity sometimes makes you a contrarian in front of others, but other times, you are respected since it is not an easy choice to make. Either way, aligning your actions based on what you feel is right, brings a sense of confidence and empowerment. Some of you may have a YOLO mindset to justify your actions. For those people, I recommend following what Seneca prescribes as the first step.</p><blockquote>A consciousness of wrongdoing is the first step to salvation.</blockquote><blockquote>— Letter XXVIII</blockquote><h3>Self-realization</h3><p>Growing up, as children, we had a lot of questions about the existence of things that make up the universe. However, somehow this curiosity faded away as we grew up. There are many reasons for this, and my reasoning is that as children, we had a lot of time and inner peace to let our minds wander. But as we grew up, we got locked into the small world of handling and fulfilling responsibilities. Losing curiosity is sad, but what’s even sadder is losing the ability to appreciate the marvels that make up the universe. Amidst the commotion of today’s life, Seneca’s description of nature’s divinity was so refreshing to me. Here it goes,</p><blockquote>If you have ever come across a dense wood of ancient trees that have risen to an exceptional height, shutting out all sight of the sky with one thick screen of branches upon another, the loftiness of the forest, the seclusion of the spot, your sense of wonderment at finding so deep and unbroken a gloom out of doors, will persuade you of the presence of a deity. Any cave in which the rocks have been eroded deep into the mountain resting on it, its hollowing out into a cavern of impressive extent not produced by the labors of men but the result of processes of nature, will strike into your soul some king of inkling of the divine.</blockquote><blockquote>— Letter XLI</blockquote><h3>Suffering</h3><p>Recollection of vivid memories of sufferings feels easier than the recollection of the happy ones. Negative emotions are felt much stronger than the positive ones leaving memory footprints that are deeper. Here’s what Seneca says,</p><blockquote>What’s the good of dragging up sufferings which are over, of being unhappy now just because you were then? what is more, doesn’t everyone add a good deal to his tale of hardships and deceive himself in the matter? Besides, there is a pleasure in having succeeded in enduring something the actual enduring of which was far from pleasant. When some trouble or other comes to an end the natural thing is to be glad. And when a man is in the grip of difficulties he should say</blockquote><blockquote>“There may be pleasure in the memory of even these events one day”</blockquote><blockquote>— Letter LXXVIII</blockquote><h3>Death</h3><p>The thought of ceasing to exist after a period of time creates uneasiness in me occasionally. There is a notion that even immortality gradually loses its appeal and creates a desire to die. But we don’t have the liberty to experience both and choose one. We are destined to die someday (anxiety kicks in). Here’s how Seneca perceives death!</p><blockquote>What is death? Either a transition or an end, I am not afraid of coming to an end, this being the same as never having begun, nor of transition, for I shall never be in confinement quite so cramped anywhere else as I am here.</blockquote><blockquote>— Letter LXV</blockquote><p>My feeling of uneasiness about death toned down reading this perception. Philosophy is soothing. ❤</p><p>If you liked reading my curated blog, do give a like!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55e4eff6ce7e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to the Actor-based concurrency model]]></title>
            <link>https://medium.com/@aymar99/introduction-to-the-actor-based-concurrency-model-f8677a3f141b?source=rss-dafffae09171------2</link>
            <guid isPermaLink="false">https://medium.com/p/f8677a3f141b</guid>
            <category><![CDATA[concurrency]]></category>
            <category><![CDATA[actor-model]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[akka]]></category>
            <dc:creator><![CDATA[Ramya L]]></dc:creator>
            <pubDate>Fri, 27 Jan 2023 12:54:44 GMT</pubDate>
            <atom:updated>2023-11-18T05:17:46.021Z</atom:updated>
            <content:encoded><![CDATA[<p>In software development, performance benefits from multi-core processors can be leveraged to the maximum through concurrent programming. Concurrent programming is designed to create independent processes working parallelly in a specific composition without affecting the desired outcome. Various concurrency models are being used such as threads and locks, Futures, coroutines, Communicating Sequential Processes, Actor model etc. In this blog, we will focus on the actor model and try to understand its working, pros and cons.</p><h3>What is an Actor?</h3><p>An actor is a lightweight high-level abstraction for asynchronous message passing and computation. Actors are isolated from each other and do not share memory. An actor is considered the universal primitive in the actor model (i.e.) all possible operations with the data like processing, storing and communication happen only through actors.</p><h4>An actor comprises of</h4><ul><li>Mailbox: A message queue-like data structure for storage.</li><li>Mailing address: For identifying and communicating with other actors.</li><li>State: Certain variables contained within the actor constitute its state of it.</li><li>Behavior: Decided upon by incoming message which could be a simple function to be applied to the input.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yZqxlLO2vU-4LhZ5rsPdrA.jpeg" /><figcaption>Visual representation of state isolation and message passing with actor system.</figcaption></figure><h3>What can an Actor do?</h3><ul><li>Communicate with other actors by exchanging messages asynchronously.</li><li>Change its own internal behavior/state.</li><li>Process the received messages in the mailbox in a FIFO fashion.</li><li>Create multiple actors, supervise other actors etc.</li></ul><h3>How does the Actor model work?</h3><p>Computation of tasks is a result of communication happening in the system. The tasks are received by an actor in the form of messages in linear order and processed in a FIFO fashion. Based on the incoming messages, the actor’s behavior is configured, and the necessary action is performed on the received message to produce the desired response. The response is then passed on to the actor of interest. An actor can either process the task by itself or create new actors and new tasks for the completion of the same. The creation of new actors for the execution of tasks is where concurrency comes into the picture. Depending on the requirement and hardware specs, any number of actors can be created and since the actors do not share their internal state, tasks can be processed by actors concurrently. Completed tasks and unused actors will be safely removed from the actor model without impacting the execution of other tasks.</p><h3>Message delivery in the Actor model</h3><p>The actor model offers at most one message delivery guarantee when it comes to message passing. This means that any message being sent from one actor to another might either be delivered once or not delivered at all. At most one delivery is chosen for its high-performance benefits because of reduced overhead compared to at least once or exactly once which might require retries to achieve them. Usage of the at most delivery pattern is highly desirable in various use cases where performance takes the upper hand and occasional loss of messages doesn’t disrupt the functioning of the system.</p><h3>Error handling in the Actor model</h3><p>Most actor model implementations use the notion `<strong>Let it crash`</strong> wherein failure of actors is an allowed phenomenon. However, the failure of an actor doesn’t go unnoticed. The actor model follows a hierarchical structure where every actor has a supervising actor. The supervising actor is notified of the failure of the subordinate actor and is primarily responsible for handling the same. Whenever the supervisor actor receives a notification of failure, it executes the error handling mechanism specified in the actor model implementation on the failed subordinate actors. Common error handling mechanisms include ignoring the error, restarting the actor, escalating the error to the supervisor of the supervising actor, killing the actor in case of unrecoverable failures etc.</p><h3>How Actor model is different from other concurrency models?</h3><p>In most concurrency models, one thread per concurrency primitive approach is used. In the actor model of concurrency, Actors aren’t restricted to single thread usage for the completion of a task. Subsequent invocations of instructions for a task from an actor can happen on different threads. Also, a single thread can be used for task execution from multiple actors. In this way, actors don’t hold ownership of the running thread. This makes actors lightweight entities compared to threads and opens possibilities for the creation of a huge number of actors for concurrency.</p><h3>Popular Actor model implementations</h3><p>The actor model is not just a conceptual model. There are various popular frameworks/libraries existing in the majority of the languages achieving the actor model concepts mentioned in this blog. Let’s look at two of the most popular implementations of the actor model.</p><h4>Erlang</h4><p><a href="https://www.erlang.org/">Erlang</a> is a language designed by Ericsson to program large highly reliable fault-tolerant telecommunications systems. The Erlang virtual machine is designed to manage many lightweight processes on top of the OS processes. These lightweight processes have all the characteristics of an actor such as immutable state, message passing, and fault tolerance. The Erlang Virtual Machine (BEAM) itself manages the concurrency, monitoring and garbage collection for these process-based actors providing built-in support for actor-based concurrency.</p><h4>AKKA</h4><p>Akka is an actor-based concurrency framework for JVM-based languages. JVM doesn’t have inherent support for actors. <a href="https://docs.scala-lang.org/overviews/core/actors.html">Scala Actors</a> was the pioneer in bringing the erlang model of actors into JVM. Scala actor model was built by efficiently multiplexing actors to OS threads. <a href="https://akka.io/">AKKA </a>is based on Scala actors and was more actively developed compared to the scala actors to provide better performance benefits. AKKA is actively being used to build highly scalable production-ready applications. Akka actors can communicate with actors with actor references within as well as across systems which enables support for distributed microservices architecture. AKKA cluster infrastructure provides features like discoverability, load balancing, sharding, and node monitoring that in many ways eliminates the complexity and cost involved in setting up the microservices architecture. Efficient load and performance testing tools like <a href="https://gatling.io/">Gatling </a>have also been built from AKKA.</p><h3>Understanding a simple Actor system with AKKA:</h3><p>Let’s build a simple system for detecting and tracking palindrome words in a given paragraph. This requirement can be further broken down into simpler tasks as follows,</p><ul><li>Tokenize a paragraph into words.</li><li>Identify whether the words are palindrome or not.</li><li>Keep track of the palindrome occurrences.</li></ul><p>There are going to be multiple words in a paragraph. Determining whether a word is a palindrome or not is an independent task determined by the input word alone. This makes this task suitable for concurrency. Let’s try to use the actor model for achieving this concurrency in our system.</p><p>The AKKA actor system for our problem statement comprises a StringProcessor actor that gets a Request message as a paragraph. The StringProcessor tokenises the paragraph into words and spawns PalindromePrintor actors for each word in the paragraph and sends the single word as an Input message to the spawned actors. The PalindromePrinter actors execute the required logic and find if the string is palindrome or not and print the same. Additionally, whenever a palindrome string is encountered, the PalindromePrinter actors send a PalindromeEvent message to the PalindromeCountTracker. The PalindromeCountTracker actor simply increments the counter and prints it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Gu2WsPOaNp6GgLuMfrfuUA.png" /><figcaption>Visual representation of actor model for our problem statement</figcaption></figure><h4>Implementing the Actor model for the above example with AKKA</h4><p>For using AKKA in our project we need to include the maven dependency from <a href="https://mvnrepository.com/artifact/com.typesafe.akka/akka-actor_3">Maven Repository: com.typesafe.akka » akka-actor (mvnrepository.com)</a> Once added we will be able to use the AKKA implementation to use actors for building our distributed concurrent system.</p><ul><li>The first step is to create the system for the actors to exist which will allocate the threads for processing. While creating the actor system, a top-level actor called the guardian actor is expected as a parameter. This Guardian actor should be able to handle the messages being sent into the actor system.</li></ul><pre>ActorSystem system = ActorSystem.create(StringProcessor.create(),&quot;palindrome-system&quot;);</pre><p>In our system, the StringProcessor is the guardian actor. The StringProcessor will accept the request containing a paragraph and spawn the words in the paragraph as Input messages to various child PalindromePrinter actors for further processing.</p><ul><li>We need to define three actor classes (StringProcessor, PalindomePrinter, PalindromeCountTracker) for the above system. To keep it simple we will look at the PalindromePrinter class definition alone. The other two classes can be defined in a similar fashion. For creating an actor-based class, we need to extend the AbstractBehaviour class of AKKA with a template parameter as the type of message the actor can accept.</li></ul><pre>public class PalindromePrinter extends AbstractBehavior&lt;PalindromePrinter.Input&gt; {<br><br>    public static final class Input {<br>        String message;<br>        ActorRef&lt;PalindromeCountTracker.PalindromeEvent&gt; replyTo;<br><br>        public Input(String message,ActorRef&lt;PalindromeCountTracker.PalindromeEvent&gt; replyTo) {<br>            this.message=message;<br>            this.replyTo=replyTo;<br>        }<br>    }<br><br>    public static Behavior&lt;Input&gt; create() {<br>        return Behaviors.setup(PalindromePrinter::new);<br>    }<br><br>    @Override<br>    public Receive&lt;Input&gt; createReceive() {<br>        return newReceiveBuilder().onMessage(Input.class,this::checkAndPrintIfPalindrome).build();<br>    }</pre><p>The PalindromePrinter class can be defined as above. Here Input is a static nested class that defines the type of message the PalindromePrinter actor accepts. Input class is having data members message of type string and replyTo of type ActorRef to store the reference of any actor that it needs to send a message. Once the actor class and input type are defined we need to override createReceive() method of the AbstractBehaviour to specify how the actor will process the message. Here we are specifying the function checkAndPrintIfPalindrome to be used for processing any Input message received.</p><ul><li>The function checkAndPrintIfPalindrome is applied to any Input object received by PalindromePrinter. The PalindromePrinter uses the IsPaindrome function on the input message to decide and print if the string is palindrome or not. The PalindromPrinter also sends a PalindromeEvent to the PalindromeCountTracker Actor whenever the isPalindrome function returns true. The PalindromeEvent can be sent by invoking the tell(message) method on the recipient actor ref as shown below.</li></ul><pre>private Behavior&lt;Input&gt; checkAndPrintIfPalindrome(Input input) {<br>    if (isPalindrome(input.message)) {<br>        input.replyTo.tell(new PalindromeCountTrack-er.PalindromeEvent(true));<br>        getContext().getLog().info(&quot;\&quot;{}\&quot; is a palindrome&quot;, input.message);<br>    } else {<br>        getContext().getLog().info(&quot;\&quot;{}\&quot; is not a palindrome&quot;, input.message);<br>    }<br>    return Behaviors.same();<br>}</pre><p>On receiving this PalindromeEvent message the PalindromeCountTracker increments its internal counter and prints the same.</p><ul><li>After the other two actors are defined in a similar way, we can send the first message to the guardian actor of our system using the following code.</li></ul><pre>system.tell(new StringProcessor.Request(&quot;Wow, It is a beautiful day.&quot;));</pre><p>Upon sending the paragraph as message to the StringProcessor actor, each word is processed by the actors in the system asynchronously and the result is printed as shown below.</p><pre>[2022-07-11 10:15:28,647] [INFO] [com.custom.StringProcessor] [palindrome-system-akka.actor.default-dispatcher-3] [akka://palindrome-system/user] - Processing paragraph....Wow, It is a beautiful day.<br>[2022-07-11 10:15:28,666] [INFO] [com.custom.PalindromePrinter] [palindrome-system-akka.actor.default-dispatcher-7] [akka://palindrome-system/user/It0.142426711304806] - &quot;It&quot; is not a palindrome<br>[2022-07-11 10:15:28,666] [INFO] [com.custom.PalindromePrinter] [palindrome-system-akka.actor.default-dispatcher-8] [akka://palindrome-system/user/is0.6628995083209714] - &quot;is&quot; is not a palindrome<br>[2022-07-11 10:15:28,666] [INFO] [com.custom.PalindromePrinter] [palindrome-system-akka.actor.default-dispatcher-6] [akka://palindrome-system/user/Wow0.34866621520695096] - &quot;Wow&quot; is a palindrome<br>[2022-07-11 10:15:28,667] [INFO] [com.custom.PalindromePrinter] [palindrome-system-akka.actor.default-dispatcher-8] [akka://palindrome-system/user/a0.29580985088847256] - &quot;a&quot; is a palindrome<br>[2022-07-11 10:15:28,667] [INFO] [com.custom.PalindromeCountTracker] [palindrome-system-akka.actor.default-dispatcher-7] [akka://palindrome-system/user/palindromeTracker] - Until now 1 palindrome events have occurred<br>[2022-07-11 10:15:28,667] [INFO] [com.custom.PalindromeCountTracker] [palindrome-system-akka.actor.default-dispatcher-7] [akka://palindrome-system/user/palindromeTracker] - Until now 2 palindrome events have occurred<br>[2022-07-11 10:15:28,667] [INFO] [com.custom.PalindromePrinter] [palindrome-system-akka.actor.default-dispatcher-8] [akka://palindrome-system/user/beautiful0.22490422686520395] - &quot;beautiful&quot; is not a palindrome<br>[2022-07-11 10:15:28,668] [INFO] [com.custom.PalindromePrinter] [palindrome-system-akka.actor.default-dispatcher-8] [akka://palindrome-system/user/day0.1723735260989474] - &quot;day&quot; is not a palindrome</pre><blockquote><strong>Note:</strong> The above code snippets are just for understanding core concepts. Fully functional implementation can be viewed in <a href="https://github.com/aymar99/Akka-simple-example">aymar99/Akka-simple-example: This repository consists of a small example to depict the actor concurrency model. (github.com)</a></blockquote><h3>Benefits of using the Actor model</h3><ul><li>Low-level concurrency programming involves handling shared mutable states. Race conditions, deadlocks and many other concurrency problems need to be addressed for the same. Locking, blocking and various synchronisation mechanisms need to be used to address the mentioned problems in low-level concurrency programming. The actor model provides a high-level abstraction with all these problems addressed in the most efficient way providing thread-safe concurrency with minimal programming effort.</li><li>The actor is a lightweight concurrency primitive with an isolated state. Hence, hundreds and thousands of actors can be spawned for creating highly concurrent and performant software applications.</li><li>Actors can pass messages to actors outside of the system over the network same as it does within the system. This paves way for scaling concurrency both within and across the systems with ease.</li><li>Fault tolerance is provided in the actor model by organising the actors in a tree structure where every actor has another supervisor actor on top of its hierarchy. The supervising actors have provision to specify the error handling mechanisms to be executed in case of unexpected failures. This hierarchical structure creates self-healing systems with the capability to easily detect and react to failures.</li></ul><h3>Caveats of using the Actor model</h3><ul><li>The message passing is asynchronous hence the order of messages cannot be guaranteed. This makes it not suitable for use cases where the sequencing of tasks is important.</li><li>Debugging of production failures might be complex without necessary logging since actors are abstractions and are not tied to any specific thread.</li></ul><h3>Reference links</h3><ol><li><a href="https://www.youtube.com/watch?v=1zVdhDx7Tbs">(626) Hewitt, Meijer and Szyperski: The Actor Model — YouTube</a></li><li><a href="https://dspace.mit.edu/handle/1721.1/6952">ACTORS: A Model of Concurrent Computation in Distributed Systems (mit.edu)</a></li><li><a href="https://doc.akka.io/docs/akka/current/typed/actor-lifecycle.html">Actor lifecycle • Akka Documentation</a></li><li><a href="https://developer.lightbend.com/docs/akka-platform-guide/microservices-tutorial/index.html">Implementing Microservices with Akka :: Akka Platform Guide (lightbend.com)</a></li><li><a href="https://developer.lightbend.com/docs/akka-platform-guide/concepts/akka-management.html">Akka Management :: Akka Platform Guide (lightbend.com)</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f8677a3f141b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>