title: Ask vs Tell or forward for Actors using Akka Streams
body: <p>Hi I am working with <code>akka streams</code> along with <code>akka-stream-kafka</code>. I am setting up a Stream with the below setup:</p>
  
  <pre><code>Source (Kafka) --&gt; | Akka Actor Flow | --&gt; Sink (MongoDB)
  </code></pre>
  
  <p><code>Actor Flow</code> basically by Actors that will process data, below is the hierarchy:</p>
  
  <pre><code>                                      System
                                           | 
                                       Master Actor  
                                        /       \
                            URLTypeHandler     SerializedTypeHandler
                               /       \                   |
                       Type1Handler   Type2Handler     SomeOtherHandler
  </code></pre>
  
  <p>So Kafka has the message, I write up the consumer and run it in <code>atMostOnceSource</code> configuration and use </p>
  
  <pre><code>Consumer.Control control =
              Consumer.atMostOnceSource(consumerSettings, Subscriptions.topics(TOPIC))
                      .mapAsyncUnordered(10, record -&gt; processAccessLog(rootHandler, record.value()))
                      .to(Sink.foreach(it -&gt; System.out.println("FinalReturnedString--&gt; " + it)))
                      .run(materializer);
  </code></pre>
  
  <p>I've used a print as a sink initially, just to get the flow running. </p>
  
  <p>and the <code>processAccessLog</code> is defined as:</p>
  
  <pre><code>private static CompletionStage&lt;String&gt; processAccessLog(ActorRef handler, byte[] value) {
  
      handler.tell(value, ActorRef.noSender());
  
      return CompletableFuture.completedFuture("");
  }
  </code></pre>
  
  <p>Now, from the definition <code>ask</code> must be used when an actor is expecting a response, makes sense in this case since I want to return values to be written in the sink.</p>
  
  <p>But everyone (including docs), mention to avoid <code>ask</code> and rather use <code>tell</code> and <code>forward</code>,  an amazing blog is written on it <a href="https://bartoszsypytkowski.com/dont-ask-tell-2/" rel="nofollow noreferrer">Don't Ask, Tell</a>.</p>
  
  <p>In the blog he mentions, in case of nested actors, use <code>tell</code> for the first message and then use <code>forward</code> for the message to reach the destination and then after processing directly send the message back to the root actor. </p>
  
  <p><a href="https://i.stack.imgur.com/ljZBK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ljZBK.png" alt="from the blog"></a></p>
  
  <p>Now here is the problem, </p>
  
  <ol>
  <li>How do I send the message from D back to A, such that I can still use the sink. </li>
  <li>Is it good practice to have open ended streams? e.g. Streams where Sink doesn't matter because the actors have already done the job. (I don't think it is recommend to do so, seems flawed). </li>
  </ol>