title: Right design in akka. - Message delivery
body: <p>I have gone through some posts on how and why akka does not guarantee message delivery. The <a href="http://doc.akka.io/docs/akka/2.0.2/general/message-send-semantics.html" rel="noreferrer">documentation</a>, this <a href="https://groups.google.com/forum/#!msg/akka-user/Ih9HqTbI9NM/p0-Br_UXJ3EJ" rel="noreferrer">discussion</a> and the other discussions on group do explain it well.</p>
  
  <p>I am pretty new to akka and wish to know the appropriate design for a case. For example say I have 3 different actors all on different machines. One is responsible for cookbooks, the other for history and the last for technology books.</p>
  
  <p>I have a main actor on another machine. Suppose there is a query to the main-actor to search if we have some book available. The main actor sends requests to the 3 remote actors, and expects the result. So I do this:</p>
  
  <pre><code>  val scatter = system.actorOf(
          Props[SearchActor].withRouter(ScatterGatherFirstCompletedRouter(
                routees=someRoutees, within = 10 seconds)), "router")
    implicit val timeout = Timeout(10 seconds)
    val futureResult = scatter ?  Text("Concurrency in Practice")
    //      What should I do here?.
    //val result = Await.result(futureResult, timeout.duration) line(a)
  </code></pre>
  
  <p>In short, I have sent requests to all 3 remote actors and expect the result in 10 seconds. </p>
  
  <p>What should be the action?</p>
  
  <ol>
  <li>Say I do not get the result in 10 seconds, should I send a new request to all of them again?</li>
  <li>What if <code>within</code> time above is premature. But I do not know pre-hand on how much time it might take.</li>
  <li>What if <code>within</code> time was sufficient but the message got dropped.</li>
  </ol>
  
  <p>If i dont get response in <code>within</code> time and resend the request again. Something like this, it remain asynchronous:</p>
  
  <pre><code>futureResult onComplete{
    case Success(i) =&gt; println("Result "+i)
    case Failure(e) =&gt; //send again
  }
  </code></pre>
  
  <p>But under too many queries, wont it be too many threads on the call and bulky? If I uncomment <code>line(a)</code>, it becomes synchronous and under load might perform badly. </p>
  
  <p>Say I dont get response in 10 seconds. If <code>within</code> time was premature, then its a heavy useless computation happening again. If messsage got dropped, then <code>10</code> seconds of valuable time wasted. In case, say I knew that the message got delivered, I would probably wait for longer duration without being <em>skeptical.</em></p>
  
  <p>How do people solve such issues? <code>ACK</code>? But then I have to store the state in actor of all queries. It must be a common thing and I am looking for right design.</p>