<?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 Akshay Havale on Medium]]></title>
        <description><![CDATA[Stories by Akshay Havale on Medium]]></description>
        <link>https://medium.com/@akshayhavale?source=rss-b24c7cfe5344------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*SIUkGG3QhG7xMR-0</url>
            <title>Stories by Akshay Havale on Medium</title>
            <link>https://medium.com/@akshayhavale?source=rss-b24c7cfe5344------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 17:21:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@akshayhavale/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[Use of @Async asynchronous method + @Transactional transaction processing]]></title>
            <link>https://akshayhavale.medium.com/use-of-async-asynchronous-method-transactional-transaction-processing-499f6d7889a8?source=rss-b24c7cfe5344------2</link>
            <guid isPermaLink="false">https://medium.com/p/499f6d7889a8</guid>
            <dc:creator><![CDATA[Akshay Havale]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 17:32:13 GMT</pubDate>
            <atom:updated>2021-03-22T17:32:13.231Z</atom:updated>
            <content:encoded><![CDATA[<p>Sometimes some methods or services need to be executed asynchronously to save time</p><p>First of all, it is best to propose the method for asynchronous execution separately to form a class. Write your method in the class. You can add @Async annotation to the method to be asynchronous to indicate the method to be executed asynchronously, or it can be on the head of this class. Add @Async this annotation, but this means that all the methods in this class are executed asynchronously, then the methods in this class will appear asynchronous methods called asynchronous methods. So I suggest that asynchronous Annotate on the method</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pakHpyoKPtR2aZLt.png" /></figure><p>Then there is another point to note that the class you define must be injected into the spring container to become a Bean of spring, so you need to add @Component, otherwise you will not find this class during execution!!</p><p>This will save time happily asynchronously!!! — — however</p><p>When you execute it, you will find -_-!! It seems that there is no change, and asynchronous is also the case!! Actually-you know, you did not execute asynchronous at all</p><p>We need to add a comment @EnableAsync on the main startup class to turn on the asynchronous. This is the moment to go asynchronous!!!</p><p>So pay attention to when using asynchronous:</p><p>1. The separately proposed class must become annotated @Component to become a Spring Bean</p><p>2. Add a comment @EnableAsync on the main startup class to start the asynchronous moment</p><p>Asynchronous use with transactions:</p><p>We must ensure consistency and atomicity when performing business…</p><p>Then you need to add @Transactional transaction processing, rollback processing is performed when an exception is encountered,</p><p>Now method A calls method B. For efficiency, method B is asynchronous. In order to ensure data consistency, atomicity…</p><p>Results in the following situations:</p><p>1. Added @Transactional transaction to method A, not added to method B,</p><p>Then at this time, A throws an exception during execution (remember that B is asynchronous), then the business executed in A is rolled back, and no rollback occurs in B.</p><p>AB is abnormal only A rolls back</p><p>B is abnormal, A is executed normally, B does not end abnormally and no rollback occurs</p><p>2. Added @Transactional transaction to A and B methods:</p><p>At this time, A is abnormal, then A has rolled back, and B executes normally</p><p>Only B is abnormal, A executes normally and B rolls back</p><p>By the way, using asynchronous is equivalent to multiple threads of execution. If method B is called during the execution of method A, method B is executed after method B is executed. This is a single thread, so in order to save time, method B is asynchronous, which is done at the same time. There are two things, this is the operation of multiple threads.</p><p>Conclusion: The transactions between different threads are completely isolated, and asynchronous threads can still be called asynchronous</p><p><em>Originally published at </em><a href="https://www.programmersought.com/article/20984469580/"><em>https://www.programmersought.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=499f6d7889a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to Make Microservices Communicate]]></title>
            <link>https://akshayhavale.medium.com/how-to-make-microservices-communicate-ce7718c9d35b?source=rss-b24c7cfe5344------2</link>
            <guid isPermaLink="false">https://medium.com/p/ce7718c9d35b</guid>
            <dc:creator><![CDATA[Akshay Havale]]></dc:creator>
            <pubDate>Mon, 22 Mar 2021 17:07:27 GMT</pubDate>
            <atom:updated>2021-03-22T17:07:27.261Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ozr1iymS_C00V31p.jpg" /></figure><p>I’m sure you want to <a href="https://spaceuptech.com/blog/how-to-build-scalable-apps">build scalable apps</a>, right? Who doesn’t? If so, you must have come across the words “Cloud Native.” This approach is like an angel which can resolve most of your scaling challenges. So, what exactly is cloud native?</p><p>Cloud native is an approach used to build apps which can harness all the capabilities of the cloud.</p><p>Yup, you got that right. It’s an approach. Not a framework. Not a bunch of steps to follow. And due to this, there are a million different approaches to go cloud native and achieve cloud computing “Moksha.”</p><p>One key principle of cloud native is microservices. Microservices are tiny (sometimes not so tiny) modules which can work independently of each other. They could have dependencies on other microservices or even a data persistence layer like a database. But the key is to use <a href="https://en.wikipedia.org/wiki/Loose_coupling">loose-coupling</a>. Microservices coordinate by means of “communication.”</p><p>This means each microservice sits in a different repository and is being deployed independently. For the DevOps folks out there, you have an independent continuous delivery pipeline dedicated to each microservice.</p><p>But that brings me to the most important question.</p><h4>How can we make microservices talk?</h4><p>Keeping aside the difficulties in deciding on a “ <a href="https://en.wikipedia.org/wiki/Forward_compatibility">forward compatible</a> “ API for microservices, just making them talk isn’t as simple as it looks. There are multiple parameters you need to consider. These are throughput, latency, and scalability.</p><p>Now there are many ways to classify the different modes of communication. Synchronous (blocking) and asynchronous (non-blocking) are used quite often, but I feel these are mostly the characteristics of a programing language. I’m also going to disregard half vs. full duplex modes since these days it’s very easy to use either (or even both) in most cloud architectures.</p><p>So let’s dive in.</p><h3>The Brokerless Design</h3><p>What it is: In here we make our microservices talk to each other directly. You could use HTTP for traditional request-response or use websockets (or HTTP2) for streaming.</p><p>There is absolutely no intermediary nodes (except routers and load balancers) between two or more microservices. You can connect to any service directly, provided you know their service address and the API used by them.</p><p>Sounds pretty basic right? It pretty much is. There are wonderful protocols like <a href="https://grpc.io/">GRPC</a> to make life much easier.</p><p>The Pros:</p><ul><li>Low Latency: This method has the lowest latency possible. There is no middle man here. It’s fast. The limitations are imposed mostly due to poor API implementations. But again, tools like GRPC make sure you get maximum performance at the API layer.</li><li>Easy to Implement: A brokerless design is easy to visualise and implement. This makes life much easier and the world a happier place to live in.</li><li>Easy Debugging: This method is fairly easy to debug, especially from the next one I’m going to talk about. Debugging or tracing where the errors are is a super important topic in distributed systems. This becomes even more important when you are releasing new updates multiple times a day.</li><li>High Throughput: In this mechanism more CPU cycles are actually spent on doing work rather than routing. It may not be that apparent now, but a broker design would make this a bit more clear. It’s not a surprise that most of the database APIs actually use a brokerless design.</li></ul><p>The Cons:</p><ul><li>Service Discovery: In such a design, service discovery has utmost importance. The service discovery mechanism needs to be responsive and scalable enough to reflect the latest state of the cluster.</li><li>Connection Nightmare: Imagine if all the microservices need to connect to each other. That would be a lot of connections. Most of these connections are fairly idle. As a result, a lot of resources are wasted due to this.</li><li>Tightly Coupled: By nature, brokerless designs are tightly coupled. Imagine you have a microservice to process online payments. Now you want another microservice to give you a real-time update of number of payments happening per minute. This will require you to make modifications in multiple microservices which is undesirable.</li></ul><p>In many cases a brokerless design just doesn’t work. You often have requirements to simply publish the message once and have multiple subscribers consume it. This is where a broker design comes into the picture.</p><h3>The Messaging Bus (Broker) Design</h3><p>What it is: In this architecture, all communication is routed via a group of brokers. Brokers are server programs running some advanced routing algorithms.</p><p>Each microservice connects to a broker. The microservice can send and receive messages via the same connection. The service sending messages is called a publisher and receiver is called a subscriber. Messages are published to a particular “topic.” A subscriber receives those messages for topics to which it has subscribed.</p><p>The Pros:</p><ul><li>Load Balancing: Most messaging brokers support load balancing out of the box. This makes the overall architecture much simpler and highly scalable. Some brokers (like <a href="https://www.rabbitmq.com/">RabbitMQ</a>) have built-in retries and more for making the communication channel more reliable.</li><li>Service Discovery: Service discovery is not required when using a messaging backend. All microservices act as clients. The only service which needs to be discoverable is the message broker.</li><li>Fan In and Fan Out: A messaging backend makes it easier to distribute workload and aggregate the results. The best part is that adding worker microservices can be done transparently without having to update the other microservices.</li><li>Stream Based Design: Such an approach also gives birth to a concept of streams. Each topic is essentially a stream of messages. Any subscriber can tap into these streams as and when required. The possibilities of modeling a system design using streams is endless.</li></ul><p>The Cons:</p><ul><li>Scaling the brokers: While the advantages are amazing, scaling the brokers themselves becomes a challenge for highly distributed systems. It’s just another piece to maintain alongside your microservices.</li><li>Higher Latency: The number of hops in a message bus increases the overall latency. This is especially true for a RPC-like use case. In mission critical apps, this might not be a feasible solution.</li><li>Higher Resource Utilization: The brokers need CPU, memory, and storage resources to run. These resources could otherwise be utilized for running other microservices. The overheads associated with a broker design could be too much for a small cluster.</li></ul><p>Just knowing the advantage and disadvantage of various architectures isn’t enough. It is important to know when to use what.</p><p>You must always default to a brokerless design. Make the switch if you need the flexibility of streams or need to leverage the pub-sub semantics of a message bus. If you’re starting off fresh, it would make sense to start with a brokerless design and then switch once the need rises.</p><p>It’s not necessary to choose just one. You can use both. For our tool, we are using a broker design to implement the RPC calls. The communication with our database layer is brokerless to provide lower latencies.</p><h3>Wrapping Up</h3><p><strong>If you are opting for a microservices based architecture, I always recommend going event driven. </strong><a href="https://blog.spaceuptech.com/posts/building-event-driven-microservices-that-scale/"><strong>Event driven architectures</strong></a><strong> can be seen as having an advanced broker at its core which has a a ton of capabilities (like task scheduling) built in.</strong></p><p>Using the right approach for the job is important. Choosing the mode of communication is a fundamental decision which needs to be taken with great care.</p><p><em>Did this article help you? How do you make sure your apps are cloud native? Share your experiences below.</em></p><p>There are multiple options for both. Sticking to a well established framework almost always makes more sense than making something from scratch. There are so many options out there. For message brokers you’ve got RabbitMQ, <a href="https://nats.io/">Nats</a>, <a href="https://kafka.apache.org/">Kafka</a>, etc., and each one is built for particular messaging semantics.</p><p>Another awesome way is to use a Backend as a Service like <a href="https://spaceuptech.com/space-cloud">Space Cloud</a>. Space Cloud will automate the entire backend so you can focus on the business logic rather than the the cloud architecture.</p><p><em>Originally published at </em><a href="https://dzone.com/articles/how-to-make-microservices-communicate"><em>https://dzone.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ce7718c9d35b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>