<?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 Artem OBOTUROV on Medium]]></title>
        <description><![CDATA[Stories by Artem OBOTUROV on Medium]]></description>
        <link>https://medium.com/@oboturov?source=rss-7fbee93e21f9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*cSzogdyHY9flpVL9siv3pg.jpeg</url>
            <title>Stories by Artem OBOTUROV on Medium</title>
            <link>https://medium.com/@oboturov?source=rss-7fbee93e21f9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 06:17:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@oboturov/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[Golang <-time.After() is not garbage collected]]></title>
            <link>https://medium.com/@oboturov/golang-time-after-is-not-garbage-collected-4cbc94740082?source=rss-7fbee93e21f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4cbc94740082</guid>
            <category><![CDATA[memory-leak]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[profiling]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Artem OBOTUROV]]></dc:creator>
            <pubDate>Thu, 07 Feb 2019 14:33:01 GMT</pubDate>
            <atom:updated>2019-02-11T11:18:38.515Z</atom:updated>
            <content:encoded><![CDATA[<h3>Golang &lt;-time.After() is not garbage collected before expiry</h3><p>Recently I was investigating a memory leak problem in a Go application that boiled down to me not reading the documentation properly. Here’s a piece of code that caused memory consumption of multiple Gbs:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/309ddfa767a627ddee9b95c25b76e4af/href">https://medium.com/media/309ddfa767a627ddee9b95c25b76e4af/href</a></iframe><p>Below is the memory metrics graph from the app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gJ9dKrHbtvwJ5BKavylaYQ.png" /></figure><p>On the left side one can see the memory consumption before the fix, and on the right — after. The profiler showed that the &lt;-time.After was the reason for the memory leak. I was really surprised until I read the doc which says:</p><blockquote>The underlying Timer is not recovered by the garbage collector until the timer fires.</blockquote><p>So the 9Gb of RAM that was periodically GCed suddenly made sense. We have 60K messages per second in the channel that would be about 18 million timers allocated at every given moment plus some indeterminate number waiting to be GCed.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9027e4cf9760fd0e2bdcb8b34dbd2a1a/href">https://medium.com/media/9027e4cf9760fd0e2bdcb8b34dbd2a1a/href</a></iframe><p>Trivial refactoring helped to reduce memory consumption by a factor of 20.</p><p>RTFM</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4cbc94740082" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Avro schema full compatibility via optionality and its application in Kafka ecosystem]]></title>
            <link>https://medium.com/@oboturov/avro-schema-full-compatibility-via-optionality-and-its-application-in-kafka-ecosystem-f1c9f0cd2e8b?source=rss-7fbee93e21f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/f1c9f0cd2e8b</guid>
            <category><![CDATA[kafka]]></category>
            <category><![CDATA[kafka-streams]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Artem OBOTUROV]]></dc:creator>
            <pubDate>Mon, 07 Jan 2019 15:20:25 GMT</pubDate>
            <atom:updated>2019-01-07T15:20:25.562Z</atom:updated>
            <content:encoded><![CDATA[<p>Consider the notion of schema compatibility for an Avro schema. One could have <a href="https://docs.confluent.io/current/schema-registry/docs/avro.html#compatibility-types">seven different compatibility types</a> depending on changes performed to the schema. The safest compatibility type is <em>full</em> because it allows consumers and producers to use all the schema versions at the same time, while others would require orchestration of releases tangled to particular versions.</p><h3>Monadic do/for comprehension over optional fields</h3><p>Suppose we would like to perform operations over data in a way that would prevent consumers from breaking due to changes to the document schema (both backwards and forwards). Let’s consider how a document where all the fields are optional will be handled. Here’s an example schema:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/218682ad07a2fd55dbd22dcf1e186599/href">https://medium.com/media/218682ad07a2fd55dbd22dcf1e186599/href</a></iframe><p>When all fields are optional, the only thing that matters are the fields which are actually required for a particular computation. And in the case of Kafka Streams, we could <em>flatMapValues</em> over Optional monad for comprehension:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e217c3dd7874a55040b08b72fbba84b6/href">https://medium.com/media/e217c3dd7874a55040b08b72fbba84b6/href</a></iframe><p>The example above shows that <em>InstrumentUpdate,</em> which has all it’s fields defined as Optional values, could simply filter out stream elements that it is not suited to handle. One could perform some complex computations instead of just checking if that object has all values defined in all fields.</p><h3>Coercing auto-generated schemas to have full compatibility</h3><p>One nasty surprise I have encountered while working with <a href="https://www.confluent.io/connector/kafka-connect-jdbc/">Kafka Connect JDBC</a> is that it makes all <em>non-nullable columns</em> to be <em>required</em> in the auto-generated schema. This will be true for all key fields for example. There’s a reasonable way to work around it: one could create a view with non-null columns exported as nullable.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/875ee58f7cb9662a21ea60f229e25b5f/href">https://medium.com/media/875ee58f7cb9662a21ea60f229e25b5f/href</a></iframe><p>Note that the <em>NULLIF</em> was used with a sensible default value to be considered as <em>NULL.</em></p><p>In addition, one should change the <em>“table.types”</em> connector configuration attribute to <em>“VIEW” </em>instead of default <em>“TABLE”</em>, otherwise the view would not be found<em>.</em></p><h3>Accumulating field values changes in a snapshot view</h3><p>With some help from generic programming one could implement an accumulator of field changes:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e21ba1148de710125756c88cb9e3b87/href">https://medium.com/media/2e21ba1148de710125756c88cb9e3b87/href</a></iframe><p>Here we have a semigroup that implements sum as the selection of the most recent non-empty value for each field. Having this type class we could write by-key aggregation that would make a snapshot and accumulate all the fields values in just a few lines of Scala code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9d1a97df5836a019e1ac599298870bae/href">https://medium.com/media/9d1a97df5836a019e1ac599298870bae/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f1c9f0cd2e8b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kafka Streams & Confluent Schema registry data interoperability]]></title>
            <link>https://medium.com/@oboturov/kafka-streams-confluent-schema-registry-data-interoperability-d4e0ec45ee1?source=rss-7fbee93e21f9------2</link>
            <guid isPermaLink="false">https://medium.com/p/d4e0ec45ee1</guid>
            <category><![CDATA[kafka-streams]]></category>
            <category><![CDATA[avro]]></category>
            <category><![CDATA[scala]]></category>
            <category><![CDATA[confluent]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Artem OBOTUROV]]></dc:creator>
            <pubDate>Tue, 11 Dec 2018 15:22:36 GMT</pubDate>
            <atom:updated>2018-12-12T08:47:46.516Z</atom:updated>
            <content:encoded><![CDATA[<p>To run a Kafka Streams setup one should prepare a couple of components and properly configure them. Let’s check out what could be done for a simple case where we have some data ingested into Kafka by a microservice written in Go and processed by a Kafka Streams Scala app.</p><h3>Confluent Schema registry</h3><p>To start, a common data exchange format supported out of the box by Kafka Streams is Avro (although the binary payload of Kafka messages could be interpreted with any semantics). Consider for example the following schema:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/218682ad07a2fd55dbd22dcf1e186599/href">https://medium.com/media/218682ad07a2fd55dbd22dcf1e186599/href</a></iframe><p>It represents a price at some point in time for a hypothetical financial instrument. In order to use it with Kafka Streams, we should initially upload it to the Schema registry. The registry has a <a href="https://docs.confluent.io/current/schema-registry/docs/api.html">REST API</a>. Below is an example of how to do this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88a15cd71c0eb9046c06bc92f8255bfb/href">https://medium.com/media/88a15cd71c0eb9046c06bc92f8255bfb/href</a></iframe><p>Take note of the new schema ID attributed to it by the Schema registry. It would also make sense to set up authorization in front of the Schema registry. The easiest way to do it would be by wrapping it with a proxy that can handle authorization process (the plugin from Confluent requires one to pay a subscription fee). Now, we turn to the ingestion component.</p><h3>Go Avro codec and Schema registry interoperability</h3><p>There’s a quirk with the <a href="https://docs.confluent.io/current/schema-registry/docs/serializer-formatter.html#wire-format">wire format</a> of Schema registry Avro serializer: it allocates the first 5 bytes to define a record header, in which the first byte is 0 and the following 4 bytes define the schema ID. The codec written in Go is as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/176d874aa9ef06c63643ad4181c549c4/href">https://medium.com/media/176d874aa9ef06c63643ad4181c549c4/href</a></iframe><p>Once the Kafka connection is initialized in the publisher component, the codec could be used to push data to the topics.</p><h3>Kafka Streams Scala app</h3><p>One could use a very handy SBT plugin called <a href="https://github.com/julianpeeters/sbt-avrohugger">Avrohugger</a>. It is able to generate case classes from Avro schemas which would implement <em>org.apache.avro.specific.SpecificRecordBase</em> and could be used in Kafka Streams out of the box.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d4e0ec45ee1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>