title: Error kernel and supervision in Akka: will messages from stale children be delivered to restarted actor?
body: <p>I am trying to follow best practices and apply error kernel pattern in Akka. According to this quote from <a href="http://doc.akka.io/docs/akka/snapshot/general/actor-systems.html" rel="nofollow">here</a>:</p>
  
  <blockquote>
    <p>If one actor carries very important data (i.e. its state shall not be lost if avoidable), this actor should source out any possibly dangerous sub-tasks to children it supervises and handle failures of these children as appropriate. Depending on the nature of the requests, it may be best to create a new child for each request, which simplifies state management for collecting the replies. This is known as the “Error Kernel Pattern” from Erlang.</p>
  </blockquote>
  
  <p>... it is a good idea to create children and delegate error prone work to them, concentrating important state in parent/supervisor actor.</p>
  
  <p>In this scenario if actor with important state gets restarted for some reason, do I need to handle messages from it's stale children (that was created before restart)?</p>
  
  <p>Lets illustrate this with example.</p>
  
  <p>Lets asuume I have actors 3 actors: <code>A</code> (is parent/supervisor of <code>B</code>), <code>B</code> (is parent/supervisor of <code>C</code>, contains important state) and <code>C</code>.</p>
  
  <p><code>A</code>'s supervision strategy is configured to restart it's children on exception.</p>
  
  <p><code>C</code> gets created in <code>B</code>'s constructor.</p>
  
  <p>Lets then assume that message <code>bc</code> is sent form <code>B</code> to <code>C</code>. <code>C</code> starts to process it (lets imagine that it runs long running computation there) and, once done will reply to <code>B</code> with <code>cb</code>.</p>
  
  <p>Now, lets assume that <strong>before</strong> <code>cb</code> is sent to and processed by <code>B</code> <code>A</code> sends message <code>ab</code> to <code>B</code>. This message causes <code>B</code> to throw an exception and as a result of <code>A</code>'s supervision strategy decision <code>B</code> will be restarted.</p>
  
  <p>As a child of <code>B</code> <code>C</code> will be stopped during <code>B</code>'s restart (new <code>C'</code> will be created in <code>B</code>'s constructor).</p>
  
  <p>Will restarted <code>B</code> receive <code>cb</code> from <code>C</code> that was sent before <code>B</code> got restarted?</p>
  
  <p>If yes, will <code>sender</code> of <code>cb</code> (<code>C</code>) be considered a child of restarted <code>B</code>? And will actor ref's of <code>C</code> and <code>C'</code> be equal (assuming <code>C</code> and <code>C'</code>s names are equal)?</p>