<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: shweta naik</title>
    <description>The latest articles on DEV Community by shweta naik (@shweta_kawale).</description>
    <link>https://dev.to/shweta_kawale</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1652227%2F9409caca-d7cc-4a22-bc72-6784e37cddea.jpg</url>
      <title>DEV Community: shweta naik</title>
      <link>https://dev.to/shweta_kawale</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/shweta_kawale"/>
    <language>en</language>
    <item>
      <title>How to Handle BufferExhaustedException in Kafka</title>
      <dc:creator>shweta naik</dc:creator>
      <pubDate>Thu, 27 Jun 2024 07:07:22 +0000</pubDate>
      <link>https://dev.to/shweta_kawale/how-to-handle-bufferexhaustedexception-in-kafka-177p</link>
      <guid>https://dev.to/shweta_kawale/how-to-handle-bufferexhaustedexception-in-kafka-177p</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In distributed systems, message queues like Apache Kafka are essential for decoupling services and handling large streams of data. However, when dealing with high-volume data streams, you might encounter the dreaded BufferExhaustedException. This exception signifies that the internal buffers used by Kafka producers or consumers have reached their capacity, leading to data loss or processing delays.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding BufferExhaustedException&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When producing messages to Kafka, the producer maintains a buffer to hold data waiting to be sent to the Kafka brokers. BufferExhaustedException occurs when this buffer runs out of space before the data can be sent, typically because the producer is generating messages faster than they can be transmitted.&lt;/p&gt;

&lt;p&gt;Here’s what happens in a typical scenario:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Buffer Configuration&lt;/strong&gt;: The producer is configured with a buffer of a certain size.&lt;br&gt;
&lt;strong&gt;Asynchronous Production&lt;/strong&gt;: Messages are produced asynchronously, meaning the producer does not wait for confirmation before sending the next message.&lt;br&gt;
&lt;strong&gt;Buffer Exhaustion&lt;/strong&gt;: If the production rate is higher than the transmission rate, the buffer fills up, leading to BufferExhaustedException.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Use Case: Building and Sending Data to Kafka (Asynchronous vs. Synchronous)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario 1: Asynchronous Kafka Template&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data Building: Your application constructs large batches of data (e.g., sensor readings, and financial transactions) to send to Kafka.&lt;br&gt;
Asynchronous Sending: You leverage the asynchronous send method of the Kafka template, which doesn't block your application's main thread, allowing it to continue building more data.&lt;br&gt;
Buffer Overflow Risk: If the data production rate is significantly higher than Kafka's message processing capacity, the producer buffers might fill up, resulting in a BufferExhaustedException.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Scenario 2: Synchronous Kafka Template&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Data Building: You follow the same approach as in Scenario 1.&lt;br&gt;
Synchronous Sending: Here, you employ the synchronous send method. This method waits for the producer to acknowledge the message before returning control to your application.&lt;br&gt;
Reduced Overflow Risk: Synchronous sending offers a safeguard against buffer overflows since the application thread pauses until the message is accepted by Kafka. However, it can introduce latency due to the wait time.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Choosing the Right Approach: A Balancing Act&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;While synchronous sending minimizes the risk of buffer overflows, asynchronous sending provides better throughput if carefully managed. Here are some factors to consider:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Message Size&lt;/strong&gt;: Larger message sizes increase the buffer usage and the probability of overflows.&lt;br&gt;
&lt;strong&gt;Production Rate&lt;/strong&gt;: High production rates with relatively slow message processing can lead to overflows.&lt;br&gt;
&lt;strong&gt;Latency Tolerance&lt;/strong&gt;: If latency is critical, asynchronous sending might be preferred, but with careful monitoring and overflow handling strategies in place.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Strategies to Mitigate BufferExhaustedException&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Configure Buffer Sizes (Producer and Consumer)&lt;/strong&gt;: Kafka provides configuration options (producer.buffer.memory and consumer.buffer.memory) to fine-tune buffer sizes. However, setting them too high might impact overall memory usage, and too low could increase overflow occurrences.&lt;br&gt;
&lt;strong&gt;Optimize Message Batching&lt;/strong&gt;: Batching messages can improve efficiency, but excessively large batches might contribute to overflows. Experiment with batch sizes to find a sweet spot.&lt;br&gt;
&lt;strong&gt;Backpressure Mechanisms&lt;/strong&gt;: Kafka producers can apply backpressure to upstream systems (e.g., databases) when buffers are nearing capacity, preventing further data production until some space is available.&lt;br&gt;
Monitoring and Alerting: Regularly monitor buffer usage and configure alerts to notify you of potential overflows.&lt;br&gt;
&lt;strong&gt;Data Compression&lt;/strong&gt;: Consider compressing data before sending it to Kafka to reduce buffer footprint. However, compression adds processing overhead, so evaluate its impact on performance.&lt;br&gt;
&lt;strong&gt;Synchronous Sending as a Last Resort&lt;/strong&gt;: If asynchronous approaches lead to frequent overflows despite optimization, switching to synchronous sending can be a solution, but be mindful of potential latency implications.&lt;br&gt;
Conclusion&lt;/p&gt;

&lt;p&gt;By understanding the causes and handling strategies for BufferExhaustedException in Kafka, you can ensure your data pipelines operate smoothly and efficiently. Remember to choose an approach that balances throughput with overflow prevention, and constantly monitor your system to identify and address potential issues before they disrupt your data flow.&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>kafka</category>
    </item>
    <item>
      <title>Spring Modulith: Modularization of a monolithic application</title>
      <dc:creator>shweta naik</dc:creator>
      <pubDate>Wed, 19 Jun 2024 16:31:15 +0000</pubDate>
      <link>https://dev.to/shweta_kawale/spring-modulith-modularization-of-a-monolithic-application-16nn</link>
      <guid>https://dev.to/shweta_kawale/spring-modulith-modularization-of-a-monolithic-application-16nn</guid>
      <description>&lt;ul&gt;
&lt;li&gt;Modular Monolith is an architectural style where our source code is structured on the concept of modules&lt;/li&gt;
&lt;li&gt;A monolithic application is broken up into distinct modules while still maintaining a single codebase and deployment.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp7hvi7ba6694z702cf5k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fp7hvi7ba6694z702cf5k.png" alt="Image description" width="800" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Features&lt;/strong&gt;: &lt;br&gt;
&lt;strong&gt;Application module dependencies&lt;/strong&gt;: Other modules should not access internal implementation components.&lt;br&gt;
&lt;strong&gt;Application Events&lt;/strong&gt;: To keep application modules as decoupled as possible from each other, their primary means of interaction should be event publication and consumption.&lt;br&gt;
&lt;strong&gt;Integration Testing Application Module&lt;/strong&gt;: Allows to run integration tests bootstrapping individual application modules in isolation or combination with others&lt;br&gt;
&lt;strong&gt;Documentation&lt;/strong&gt;:  Can create documentation snippets in Asciidoc. Can produce C4 and UML component diagrams describing the relationships between the individual application modules.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advantages of Spring Modulith&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;Improved Maintainability&lt;/strong&gt;: Modular architecture promotes cleaner code, simplifies understanding, and facilitates easier maintenance as the application grows.&lt;br&gt;
&lt;strong&gt;Enhanced Testability&lt;/strong&gt;: Well-defined modules enable developers to write more focused and isolated unit and integration tests, leading to higher code quality.&lt;br&gt;
&lt;strong&gt;Scalability&lt;/strong&gt;: While not as horizontally scalable as microservices, Spring Modulith allows for vertical scaling by adding more resources to the application server.&lt;br&gt;
&lt;strong&gt;Faster Development&lt;/strong&gt;: Compared to the complexity of managing multiple services in microservices architecture, Spring Modulith offers a streamlined development process with a single codebase and deployment.&lt;br&gt;
&lt;strong&gt;Reduced Complexity&lt;/strong&gt;: For applications with tightly coupled functionalities that interact frequently, a single codebase in Spring Modulith can be more efficient.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Further Reading&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://docs.spring.io/spring-modulith/reference/index.html"&gt;Spring Doc&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Spring Modulith vs Microservices: *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frevlq1kxvd09s88y1ael.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frevlq1kxvd09s88y1ael.png" alt="Image description" width="800" height="685"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>opensource</category>
      <category>spring</category>
    </item>
  </channel>
</rss>
