title: Concurrency of Kafka streams topology with multiple output topics
body: <p>Given a Kafka streams topology which publishes messages to two different topics, are there any guarantees in which order various steps will be executed in these two branches or are those branches separated completely and executed in parallel?</p>
  <h2>Example</h2>
  <pre class="lang-java prettyprint-override"><code>    KStream&lt;..., ...&gt; filteredStream = builder.stream(&quot;input-topic&quot;, ...).filter(...)...;
  
      filteredStream.mapValues(this::mapOne).to(&quot;output-topic-one&quot;, ...);
      filteredStream.flatMap(this::mapTwo).to(&quot;output-topic-two&quot;, ...);
  </code></pre>
  <p>In this example, will <code>mapOne</code> executed and publishing to <em>output-topic-<strong>one</strong></em> be done <strong>before</strong> <code>mapTwo</code> is even getting called or messages are published to <em>output-topic-<strong>two</strong></em>? In other words, is there a guarantee that <code>mapOne</code> will be finished <strong>before</strong> messages are published to <em>output-topic-<strong>two</strong></em>?</p>
  <h2>Topology Visualization</h2>
  <p>When looking at the visualization of the topology description (see at the bottom; made with <a href="https://zz85.github.io/kafka-streams-viz/" rel="nofollow noreferrer">https://zz85.github.io/kafka-streams-viz/</a>) you can see the two branches. But you can also see these numbers in each bubble which might also indicate that there is an order of execution (1-4, then 5-6-7, then 8-9).</p>
  <p><a href="https://i.stack.imgur.com/l9Oss.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l9Oss.png" alt="kafka streams topology" /></a></p>
  <h2>Topology Description</h2>
  <pre><code>Topologies:
     Sub-topology: 0
      Source: KSTREAM-SOURCE-0000000000 (topics: [input-topic])
        --&gt; KSTREAM-FILTER-0000000001
      Processor: KSTREAM-FILTER-0000000001 (stores: [])
        --&gt; KSTREAM-FILTER-0000000002
        &lt;-- KSTREAM-SOURCE-0000000000
      Processor: KSTREAM-FILTER-0000000002 (stores: [])
        --&gt; KSTREAM-MAP-0000000003
        &lt;-- KSTREAM-FILTER-0000000001
      Processor: KSTREAM-MAP-0000000003 (stores: [])
        --&gt; KSTREAM-FILTER-0000000004
        &lt;-- KSTREAM-FILTER-0000000002
      Processor: KSTREAM-FILTER-0000000004 (stores: [])
        --&gt; KSTREAM-MAPVALUES-0000000005, KSTREAM-FLATMAP-0000000008
        &lt;-- KSTREAM-MAP-0000000003
      Processor: KSTREAM-MAPVALUES-0000000005 (stores: [])
        --&gt; KSTREAM-FILTER-0000000006
        &lt;-- KSTREAM-FILTER-0000000004
      Processor: KSTREAM-FILTER-0000000006 (stores: [])
        --&gt; KSTREAM-SINK-0000000007
        &lt;-- KSTREAM-MAPVALUES-0000000005
      Processor: KSTREAM-FLATMAP-0000000008 (stores: [])
        --&gt; KSTREAM-SINK-0000000009
        &lt;-- KSTREAM-FILTER-0000000004
      Sink: KSTREAM-SINK-0000000007 (topic: output-topic-one)
        &lt;-- KSTREAM-FILTER-0000000006
      Sink: KSTREAM-SINK-0000000009 (topic: output-topic-two)
        &lt;-- KSTREAM-FLATMAP-0000000008
  </code></pre>