title: What does a Materialized value means and why it is different in below logic for same graph?
body: <p>I am new to <code>Akka Stream</code> and have only started reading its docs as of last week. I am able to understand most of the concepts but I am finding it hard to understand what <code>Materialized Value</code> means in Akka stream and what its significance is?.</p>
  
  <p>If somebody could explain this to me with a real world example that would help a lot in co-relating it and its use cases in Akka Stream.</p>
  
  <p><strong>Update</strong></p>
  
  <p>I was going through below example and wanted to understand the two different kind of output that we get for the same graph. I know it has direct relation with the <code>Materialized Value</code> and that's why I asked the above question.</p>
  
  <pre><code>  implicit val system = ActorSystem("PlainSinkProducerMain")
    implicit val materializer = ActorMaterializer()
    val source = Source(1 to 10)
    val sink = Sink.fold[Int, Int](0)(_ + _)
    val runnable: RunnableGraph[Future[Int]] =
    source.toMat(sink)(Keep.right)
    val sum1: Future[Int] = runnable.run()
    val sum2: Future[Int] = runnable.run()
     println(sum1.value)
     println(sum2.value)
  </code></pre>
  
  <p>When I run this I get below output :</p>
  
  <pre><code>None
  Some(Success(55))
  </code></pre>
  
  <p>The above example is from the <a href="http://doc.akka.io/docs/akka/2.4.9/scala/stream/stream-flows-and-basics.html" rel="noreferrer">docs</a> and below is the explanation of it.</p>
  
  <blockquote>
    <p>Since a stream can be materialized multiple times, the materialized value will also be calculated anew for each such materialization, usually leading to different values being returned each time. In the example below we create two running materialized instance of the stream that we described in the runnable variable, and both materializations give us a different Future from the map even though we used the same sink to refer to the future. </p>
  </blockquote>
  
  <p>I have 2 questions here:
  1) Why the 2 different Materialized Instance of same graph have 2 different output values? Although the materialized value is calculated twice but under the hood both the calculation are for same graph.</p>
  
  <p>2) Why the return type is <code>Some(Success(55))</code> instead of a plain <code>55</code> for successful execution and <code>Failure Exception</code> for failed cases? (This might be dumb questions but I want to understand what problem/advantage does this special return value solves/gives.)</p>