<?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 Bhuvaneshwar Venkatraman on Medium]]></title>
        <description><![CDATA[Stories by Bhuvaneshwar Venkatraman on Medium]]></description>
        <link>https://medium.com/@bhuvaneshwar.venkatraman?source=rss-dad7c6a5e16f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*jtjxr3qMWyLtu_aC</url>
            <title>Stories by Bhuvaneshwar Venkatraman on Medium</title>
            <link>https://medium.com/@bhuvaneshwar.venkatraman?source=rss-dad7c6a5e16f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 16:30:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@bhuvaneshwar.venkatraman/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[Rethinking Kafka: A Hidden Metadata Store Like a Database]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@bhuvaneshwar.venkatraman/rethinking-kafka-a-hidden-metadata-store-like-a-database-77b19d312529?source=rss-dad7c6a5e16f------2"><img src="https://cdn-images-1.medium.com/max/720/1*3cKTwARHrVS9pP5w6xA9NQ.png" width="720"></a></p><p class="medium-feed-snippet">Use this link to read this content for free: Rethinking Kafka: A Hidden Metadata Store</p><p class="medium-feed-link"><a href="https://medium.com/@bhuvaneshwar.venkatraman/rethinking-kafka-a-hidden-metadata-store-like-a-database-77b19d312529?source=rss-dad7c6a5e16f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@bhuvaneshwar.venkatraman/rethinking-kafka-a-hidden-metadata-store-like-a-database-77b19d312529?source=rss-dad7c6a5e16f------2</link>
            <guid isPermaLink="false">https://medium.com/p/77b19d312529</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[distributed-ledgers]]></category>
            <category><![CDATA[metadata]]></category>
            <category><![CDATA[event-sourcing]]></category>
            <category><![CDATA[database]]></category>
            <dc:creator><![CDATA[Bhuvaneshwar Venkatraman]]></dc:creator>
            <pubDate>Tue, 05 Aug 2025 09:43:23 GMT</pubDate>
            <atom:updated>2025-08-05T10:20:07.334Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Build a solid Event-driven architecture using Kafka]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@bhuvaneshwar.venkatraman/build-a-solid-event-driven-architecture-using-kafka-27b6debb6a59?source=rss-dad7c6a5e16f------2"><img src="https://cdn-images-1.medium.com/max/1013/1*j9BlGlWvD-VFmUOmFFP-xg.png" width="1013"></a></p><p class="medium-feed-snippet">Introduction</p><p class="medium-feed-link"><a href="https://medium.com/@bhuvaneshwar.venkatraman/build-a-solid-event-driven-architecture-using-kafka-27b6debb6a59?source=rss-dad7c6a5e16f------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@bhuvaneshwar.venkatraman/build-a-solid-event-driven-architecture-using-kafka-27b6debb6a59?source=rss-dad7c6a5e16f------2</link>
            <guid isPermaLink="false">https://medium.com/p/27b6debb6a59</guid>
            <category><![CDATA[kafka-connect]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[back-pressure-regulator]]></category>
            <category><![CDATA[event-driven-architecture]]></category>
            <category><![CDATA[thundering-herd]]></category>
            <dc:creator><![CDATA[Bhuvaneshwar Venkatraman]]></dc:creator>
            <pubDate>Wed, 18 Sep 2024 16:45:20 GMT</pubDate>
            <atom:updated>2024-09-18T16:57:46.306Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Dance of Throughput vs Idempotency with Kafka]]></title>
            <link>https://medium.com/@bhuvaneshwar.venkatraman/dance-of-throughput-vs-idempotency-with-kafka-76905ff22780?source=rss-dad7c6a5e16f------2</link>
            <guid isPermaLink="false">https://medium.com/p/76905ff22780</guid>
            <category><![CDATA[tuning]]></category>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[throughput]]></category>
            <category><![CDATA[idempotency]]></category>
            <dc:creator><![CDATA[Bhuvaneshwar Venkatraman]]></dc:creator>
            <pubDate>Sat, 27 Jul 2024 16:49:25 GMT</pubDate>
            <atom:updated>2024-07-27T16:49:25.483Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*p2Op1sIOyyjdizupkFQMTQ.png" /><figcaption>powered by Kafka and knowledge</figcaption></figure><h3>Introduction</h3><p>From my experience in working with Kafka, I have observed various trade-offs when implementing an event driven architecture across the organisation. It is substantial that this architecture supports different kinds of requirements involving multiple applications. Some applications require low latency and high throughput while others expect consistency and reliability. In this blog post, I have summarised different methods available to have an impactful and robust implementation of a system driven by Kafka.</p><blockquote>Let’s plunge into the depths of Kafka and rise to the surface as champions!</blockquote><h3>Common Throughput Bottlenecks</h3><p>Before proceeding to explore throughput in Kafka, let’s try to understand throughput and its bottlenecks. The simple definition of throughput is “the amount of data passes through a system or process.” In broadly, it is a measure of number of units of information a system can process in a stipulated time. The maximum throughput a system can process and output is called bottleneck. When the input rate is very high but relative output rate by the system is low it causes a ripple effect in the ecosystem.</p><p>The root cause of a bottleneck could be anything stemming from improper architecture design, inefficient algorithms, bad coding practices. Although these are potential reasons the major bottleneck reasons are pertinent to the hardware on which the system relies on. The following are common bottlenecks faced in a Kafka ecosystem,</p><h4>Factors affecting throughput</h4><ol><li>Network latency and Bandwidth : Latency is the amount of time used by data to complete the process and response back to its source. Network latency can significantly reduce the throughput of Kafka.</li><li>Disk I/O performance : Slow disk performance can hinder Kafka’s ability to write logs efficiently.</li><li>CPU Utilisation : High CPU usage under heavy load can become a bottleneck.</li><li>Memory Utilisation : Insufficient memory allocation can lead to high I/O operations and slower performance.</li><li>Broker Configuration : Misconfigured brokers can lead to inefficient resource utilisation. Specifically number of network threads, number of I/O threads, buffer size and replications if not configured properly can lead to ineffectual Kafka.</li><li>Producer Configuration : Substandard producer settings can limit throughput.</li><li>Consumer Configuration : Inefficient consumer settings can lead to slower message consumption.</li><li>Topic Partitioning : Insufficient number of partitions can limit concurrency.</li><li>Cluster Performance : In a distributed environment, such as zookeeper or MSk can impact Kafka’s performance.</li><li>Client and Broker Compatibility : Although not so significant like others, compatibility issues between Kafka clients and brokers can cause performance issues.</li></ol><h3>Enhancing Kafka throughput</h3><p>Now that we have understood throughput, lets explore the options to increase Kafka’s performance. Kafka provides some properties, that when configured correctly can substantially increase the throughput.</p><p><strong>Producer Configurations</strong><br>1. <em>Batching Messages</em> : By increasing linger.ms the producer can batch more messages together. An optimal setting would be 5-100 ms. Having bigger batch.size allow larger batches. A decent value to begin is between 32 KB and 64 KB.<br>Caution: Keeping the above settings may increase Kafka&#39;s performance, but then the bottleneck shifts to consumer which should process a large number of messages efficiently.<br>2. <em>Compression</em> : Enable message compression to reduce the amount of data sent over the network. Use snappy or lz4 for balanced compression speed and efficiency.<br>3. <em>Asynchronous sends</em> : By default Kafka expects all brokers to acknowledge every message which may impact performance of the system. Allow the producer to send messages asynchronously by having acks to 1. This improves throughput at the cost of potential data loss.<br>4. <em>Buffer memory</em> : Increase the buffer memory to accept more messages before sending to Kafka. A setting of 64 MB would be a good starting point.<br>5. <em>Tuning</em> : Having the max.in.flight.requests.per.connection to 5 or more, the producer can send more requests before responses are received.</p><p><strong>Consumer Configurations</strong><br>1. <em>Fetch Size</em> : Increase fetch.min.bytes and fetch.max.wait.ms to allow consumers to fetch larger batches of messages. For beginning try having min bytes as 1 MB and max wait time as 500 ms.<br>2. <em>Poll Records</em> : Set max.poll.records to a higher value to allow consumers to process more records in each poll.<br>3. <em>Consumer Group size</em> : Increase the number of partitions and consumers in a consumer group to concurrently process message.</p><p><strong>Broker Configurations</strong><br>1. <em>Network and I/O Threads</em> : Tune the num.network.threads and num.io.threads to handle higher concurrency.<br>2. <em>Socket Buffer Size</em> : Adjust socket.send.buffer.bytes and socket.receive.buffer.bytes to optimize network throughput.<br>3. <em>Replication and Acknowledgement</em> : Reduce the replication factor for topics where high availability is less critical, to improve throughput. For instance, default.replication.factor=2 and min.insync.replicas=1.<br>4. <em>Log Settings</em> : Adjust log.segment.bytes and log.segment.ms to control the frequency of log segment rolling. Larger segment sizes reduce the overhead of frequent log segment creation.</p><h3>Exploring Kafka Idempotency</h3><p>In Kafka idempotency is the ability to produce messages while ensuring duplicate messages are not introduced even if the producer retries sending the same message multiple times. This assure that the effect of multiple identical write operations is the same as a single operation, which is central for maintaining data integrity and consistency, especially in distributed systems where network failures and retries are common.</p><h4>How Idempotency Works in Kafka</h4><p>Kafka uses the following mechanisms to achieve idempotency,</p><ol><li>Producer ID : Each Kafka producer instance is assigned a unique producer ID when it starts. This ID is used to track the producer’s state and message sequence numbers.</li><li>Sequence Number : Each message sent by the producer is assigned an increasing sequence number. This is different from offset which guarantees ordering within a partition. The combination of the producer ID and sequence number allows Kafka brokers to identify messages.</li></ol><h4>Configure Idempotent Producer</h4><ol><li>Idempotency is enabled in the Kafka producer by setting the enable.idempotence property to true.</li><li>To ensure all brokers have received a message, Kafka expects an acknowledgement from them. By configuring acks to all or -1, producer waits for the full acknowledgment from all in-sync replicas.</li><li>Idempotent producers handle retries automatically and ensure data consistency and integrity. By having retries to a higher value, Kafka producer can attempt resending messages multiple times thus data integrity is fortified. However, it is to note that every request is bound by a delivery time out. Meaning a message is not retried indefinitely. So setting a high value may not be beneficial unless the time out duration is adjusted.</li><li>Having max.in.flight.requests.per.connectionto 1 preserves the ordering of messages and increases durability.</li></ol><h4>Configure Idempotent Consumer</h4><ol><li>Set the enable.auto.commit property to false to control when offsets are committed. When auto-commit is enabled, offsets are committed automatically at regular intervals based on auto.commit.interval.ms. If a consumer crashes before processing messages, those messages may be lost.</li><li>Set the consumer’s isolation.level to read_committed to make sure that it only reads messages that have been successfully committed.</li><li>Utilise Kafka’s transactional capabilities by starting a transaction before sending messages and committing the transaction only after processing is complete. This ensures that either all messages are processed and committed, or none are, maintaining consistency. Once a transaction is committed, the changes are durable and will survive broker failures.</li><li>Manually control offsets using the commitSync() method to ensure offsets are committed after processing is complete.</li><li>For better durability and data integrity, it is advised to keep track of the processed messages (stored in database or distributed cache) either by their key or by having custom UUID.</li></ol><h3>Balancing Throughput vs Idempotency</h3><p>You should have some understanding about throughput and idempotency, how it works in Kafka, what are the configurations and settings required to achieve desired result. Most often knowing and configuring these properties may help, but in reality each stakeholders in the Kafka ecosystem have different expectations.</p><p>For instance, a payment transaction service relying on Kafka for processing and tracking of transactions require idempotency, low latency, exactly-once delivery. This requirement necessitates to setup the broker, producer and consumer for idempotent configurations. Lets say these transactions are also required for analytics purpose by a new service to identify key insights. Is it wise to set idempotent configurations for the new service? Even if we do not configure idempotency for consumer, the producer is still going to follow idempotent configurations resulting in lower throughput. What happens when an another new service want to consume the transactions for auditing purpose? Or you want to build a common platform using Kafka for your entire organisation to control and smoothen the flow of messages across business units.</p><p>Therefore, it is critical to strike a balance between throughput and idempotency. Especially if you wish to develop a common platform for multiple business units. Balance between throughput and idempotency arises with some trade-offs. Here, I have described some common safe approaches that we can take and try to reach a balance with limited trade-offs.</p><ol><li>We know that by setting max.in.flight.requests.per.connection to 1, ensures durability and preserves the order of messages. But starting from Kafka version 3.0 strongest delivery is guaranteed by default. This means that users now get ordering and durability without compromising on throughput. It is recommended to have this property &lt;=5 in idempotent producer.</li><li>Adjust linger.ms to batch records together to improve throughput without affecting idempotency.</li><li>The property acks=all protects the producer from losing any messages in case of brief broker failure. But waiting for acknowledgement from all brokers affects the throughput. So we can have min.in.sync.replicas to a value less than the brokers count for acknowledgement. This ensures idempotency yet allowing us to have improved throughput.</li><li>Though manual offset management gives control, it should be implemented after considering various factors, for example, average processing time. Thoroughly analyse and detect places where potential throughput are compromised.</li><li>Increase the max.poll.records to process more messages per poll call, which can enhance throughput but requires sufficient memory.</li><li>Continuously monitor key metrics such as throughput, latency, and error rates to identify and address bottlenecks. Use tools like Prometheus, Grafana, and Kafka’s built-in metrics. Fine-tune configurations based on observed performance and workload.</li><li>Increase the number of partitions for topics to allow greater parallelism. More partitions enable better utilisation of broker resources and allow more consumers to read data in parallel.</li><li>Set producer and consumer quotas client.quota.callback=quotaCallbackClass to prevent any single client from overwhelming the cluster.</li><li>Add more consumers to the consumer group to increase parallel processing. Each consumer in a group processes data from different partitions.</li><li>Implement robust error handling to manage timeouts and retries, ensuring consumers remain responsive and resilient to transient issues.</li><li>Use mechanisms to control back pressure, such as limiting the rate of data processing to prevent consumers from being overwhelmed.</li></ol><h3>Conclusion</h3><p>Balancing throughput and idempotency with Kafka should be achieved after careful analysis. It is suggested to let data that flows through the Kafka to dictate the necessary steps. Use features available in Kafka to fine tune the system. Robust and carefully crafted architecture enhances the system’s reliability and durability. Hope this blog helps you to build a more resilient and better applications.</p><p>Thank you for reading. Please consider clapping and share the blog with others.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=76905ff22780" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating Dynamic Kafka Producers and Listeners]]></title>
            <link>https://medium.com/@bhuvaneshwar.venkatraman/creating-dynamic-kafka-producers-and-listeners-6313d2124a35?source=rss-dad7c6a5e16f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6313d2124a35</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Bhuvaneshwar Venkatraman]]></dc:creator>
            <pubDate>Wed, 08 May 2024 16:34:08 GMT</pubDate>
            <atom:updated>2024-05-08T16:53:46.743Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9J5U3gsPFCX3OTuFP6xMyg.jpeg" /></figure><p>In this blog, we explore into the creation of dynamic Kafka producers and listeners. Imagine an application tasked with tracking apparel sales, refunds, and their status across various retail stores using Kafka and event tracking. While this setup suffices for regular operations, it may struggle to cope with heightened demands during festivals or events like Black Friday. While adding more instances could be a solution, it’s not always optimal. A more efficient approach involves scaling up by creating multiple producers and listeners for Kafka, maximizing instance capacity without the need for vertical scaling or instance setup delays.</p><p>This flexibility is crucial not only for apparel tracking but also for various industries such as taxi services, route details, payments for services like Uber, or managing surges in payment processing demands for FinTech and e-commerce platforms during peak periods.</p><p>Despite the significance of this dynamic Kafka feature, I found scant resources covering it comprehensively. Existing articles often focus on specific topics like RoutingKafkaTemplate, dynamic listeners, or SSL connections in Kafka. Thus, I’ve compiled this blog to consolidate all necessary information in one place.</p><p>Before delving further, readers should be familiar with Kafka basics, including Kafka listeners, producer templates, partitioning, consumer grouping, Zookeeper, and the Spring framework along with Spring bean context.</p><h3>Dynamic Producer Factories</h3><p>In a typical producer application, we create a producer template bean in a configuration class to send messages to a topic. However, if the application requires multiple producers with unique configurations to send messages to different topics, the traditional approach becomes cumbersome and time-consuming.</p><p>A more efficient method involves using a LinkedHashMap with the topic pattern as keys and producer factories as associated values to define a RoutingKafkaTemplate. The send method of RoutingKafkaTemplate takes the topic and message payload as arguments. Based on the provided topic name, it selects the associated producer factory from the LinkedHashMap. Refer to the code snippet for RoutingKafkaTemplate below.</p><p>With this setup, the application can effortlessly create multiple producers with different configurations, simplifying the process significantly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fAMF4cfF4qwBwfIo_zq1Bg.png" /></figure><h3>Dynamic Listeners</h3><p>To subscribe a simple Kafka listener to a topic, we annotate a method with @KafkaListener, specifying the topic, groupId, and listenerId. However, achieving dynamic listeners requires more effort than what the @KafkaListener annotation offers.</p><p>To initiate dynamic listeners, we create a KafkaListenerEndpoint object, defining its groupId, Id (listenerId), topic, and consumer properties necessary for our container factory to connect to the bootstrap server. Notably, the KafkaListenerEndpoint requires a bean that implements the MessageListener interface. In the onMessage method of the MessageListener instance, the consumer factory delivers the records consumed from the server.</p><p>Once we’ve defined the KafkaListenerEndpoint, we register it along with an instance of KafkaListenerContainerFactory (which can be autowired) in the KafkaListenerEndpointRegistry’s registerListenerContainer method to start listening to a topic. The method also accepts a boolean parameter, startImmediately, specifying whether the listener should commence listening immediately upon registration.</p><p>Now, armed with dynamic listeners, the application can scale up Kafka listeners as per the defined logic. Refer to the code snippet below for dynamic listener registration.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tNLcQ-EHkGCE6nuU-yp4JQ.png" /></figure><p>In my example project “dynamic-kafka” available at <a href="https://github.com/bhuvnsh/dynamic-kafka">GitHub</a>, I’ve utilized a REST API call to create producer and consumer listeners dynamically. I hope this provides valuable insights into building dynamic producers and consumers to scale up on demand.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cfOEA7sLb5qBPnLw5fDklQ.png" /></figure><p><strong>#Kafka #KafkaProducers #KafkaConsumers #Springboot #DynamicListeners #RoutingKafkaTemplate</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6313d2124a35" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>