<?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 Erik Ashepa on Medium]]></title>
        <description><![CDATA[Stories by Erik Ashepa on Medium]]></description>
        <link>https://medium.com/@erikash?source=rss-a79f49d0df5d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*n39kV92iRW7B9sLQNx4oXg.png</url>
            <title>Stories by Erik Ashepa on Medium</title>
            <link>https://medium.com/@erikash?source=rss-a79f49d0df5d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 06:39:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@erikash/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[Kafka Topic per Bounded Context]]></title>
            <link>https://medium.com/@erikash/kafka-topic-per-bounded-context-320e1c8e0474?source=rss-a79f49d0df5d------2</link>
            <guid isPermaLink="false">https://medium.com/p/320e1c8e0474</guid>
            <category><![CDATA[stream-processing]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[bounded-context]]></category>
            <category><![CDATA[ddd]]></category>
            <category><![CDATA[kafka]]></category>
            <dc:creator><![CDATA[Erik Ashepa]]></dc:creator>
            <pubDate>Mon, 25 Feb 2019 16:57:19 GMT</pubDate>
            <atom:updated>2019-02-25T16:57:19.540Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/769/1*hEk9UC5JUqSppdFeGEa8KA.png" /></figure><p>Although the title sounds a bit strange, Bounded Context is part of the Problem Domain and a Kafka Topic is definitely part of the Solution domain it captures the intent of presented approach better.</p><p>If you have a 1:1 mapping between a Bounded Context to a Microservice feel free to use Bounded Context and Microservice interchangeably.</p><p>At Fiverr we use Kafka as our data hub.</p><p>Every state change to our source systems is captured as a Typed “State change event” and is dual-written to Kafka in addition to the source database.</p><p>In this post I’ll refer only to the “public” Kafka topics which are meant to be consumed by our entire service eco-system, not private topics which are used by the source system.</p><p>The subject of this post is how to assign those messages into topics.</p><p>At Fiverr similar to other e-commerce business we have the holy trio of User, Gig (Product) and Order entities. <br>Most user facing experiences (website &amp; mobile views) require some data from the trio above for rendering.</p><h3>Our current approach</h3><p>A few years ago when we got started using Kafka as a data hub we didn’t have much knowledge nor attention for mapping our Bounded Contexts and our main code base was still very Monolithic.</p><p>So we got started with a simple Topic per Entity approach, unsurprisingly our first 3 topics were: USER, GIG, ORDER.</p><p>A few billion events later we added more topics matching other entities but this trio still remained the backbone of our event driven architecture and by far the most trafficked topics.</p><h3>Example use cases:</h3><p><strong>Attachments - </strong>The Fiverr platform supports attachments on a number of different entities such as Order Messages, Order Deliveries and Instant Messaging (Chat, A.K.A Fiverr’s Inbox) Messages.</p><p>We decided to route attachment related events to their entity’s related topic.</p><p>For example: Order Message Attachments and Order Delivery attachments were routed to the ORDER topic and Instant Messaging Message Attachments were routed to the INBOX topic.</p><p><strong>Collaboration - </strong>In order to facilitate better collaboration between the Buyer and Seller of a service, Fiverr created a collaboration tool which allows highlighting and commenting on Visually Oriented Deliveries such as Images and Video.</p><p>Similarly to Attachments<strong>, </strong>we decided to route the collaboration comments and highlights to their entity’s related topic: ORDER (Collaboration on Order Deliveries) and INBOX (Collaboration on Inbox Attachments).</p><h3><strong>Suggested Alternative:</strong></h3><p>Attachments and Collaboration are clearly their own Bounded Contexts and an alternative implementation would be to create a separate topic for each: ATTACHMENT and COLLABORATION respectively.</p><p><strong>Pros:</strong></p><ol><li><em>Single Writer</em> — It’s easier to reason about a topic which has a single producer. It has very clear semantics for message production/consumption frequency and is much easier to monitor.</li><li><em>Monotonically increasing message timestamp — </em><a href="https://cwiki.apache.org/confluence/display/KAFKA/KIP-353%3A+Improve+Kafka+Streams+Timestamp+Synchronization">Kafka Streams</a> and <a href="https://towardsdatascience.com/watermarking-in-spark-structured-streaming-9e164f373e9">Spark Structured Streaming</a> use the message timestamp to control from which topic partition to consume next. (Consuming from the TP with the oldest messages first in order to try to synchronize the consumption order across multiple topics in a deterministic way on a best effort basis)</li><li><em>Team Ownership</em> — A single team owns a Microservice implementing a Bounded Context and thus it’s related Kafka topic. The team could own it’s metrics and alerts similarly to the databases it uses.</li></ol><p><strong>Cons:</strong></p><ol><li><em>A lot more Topics — </em>A Topic per Microservice is by far a more fine grained, which means a lot more topics. I’m sure there are drawbacks to having lots of topics? anyone?</li></ol><p><strong>Tradeoffs</strong>:</p><p>When considering the performance characteristics of both solutions one needs to take into account the consumption patterns across all the consumers.</p><p>For example: Routing attachment events to their related entity topic ( USER and INBOX), would save the Order page Kafka consumer from iterating over the attachment related events in theINBOX topic at a price that other consumers which are not interested in attachments at all will still need to iterate over all the of them when consuming from the ORDER topic.</p><h3>Join the conversation!</h3><p>My reason for posting this (quick and dirty) post is to get your feedback! so please leave some in the comments below :)</p><p>P.S: You can clap a couple dozen times as well.. don’t be shy!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=320e1c8e0474" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>