<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="316999" data-post-id="316999">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="nivertech" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nivertech/120/7361_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  nivertech
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>IMO, Command Sourcing/Replay is necessary for proper Audit Trail and for recording/replaying realistic test scenarios, instead of writing integration tests manually.</p>
<p>I think the simplest solution is for every command to emit a special audit trail event with the command in the payload, or maybe Commanded has some hooks or middleware that allows this to be done without boilerplate code?</p>
<hr>
<p>Links relevant to this discussion:</p>
<p>Event Sourcing vs Command Sourcing (2013)</p><aside class="onebox allowlistedgeneric" data-onebox-src="https://thinkbeforecoding.com/post/2013/07/28/Event-Sourcing-vs-Command-Sourcing">
  <header class="source">
      <img src="https://thinkbeforecoding.com/content/favicon.ico" class="site-icon" alt="" width="32" height="32">

      <a href="https://thinkbeforecoding.com/post/2013/07/28/Event-Sourcing-vs-Command-Sourcing" target="_blank" rel="noopener nofollow ugc">thinkbeforecoding.com</a>
  </header>

  <article class="onebox-body">
    <img width="480" height="480" src="https://thinkbeforecoding.com/content/thinkbeforecoding-social.jpg" class="thumbnail onebox-avatar" alt="">

<h3><a href="https://thinkbeforecoding.com/post/2013/07/28/Event-Sourcing-vs-Command-Sourcing" target="_blank" rel="noopener nofollow ugc">// thinkbeforecoding</a></h3>

  <p>think - code - repeate - Jérémie Chassaing</p>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Jean Paliès - How video games taught me event sourcing<br>
<a href="https://vimeo.com/338573331" class="onebox" target="_blank" rel="noopener nofollow ugc">https://vimeo.com/338573331</a></p>
<p>Game Replay</p><aside class="onebox wikipedia" data-onebox-src="https://en.wikipedia.org/wiki/Game_replay">
  <header class="source">

      <a href="https://en.wikipedia.org/wiki/Game_replay" target="_blank" rel="noopener nofollow ugc">en.wikipedia.org</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://en.wikipedia.org/wiki/Game_replay" target="_blank" rel="noopener nofollow ugc">Game replay</a></h3>

<p>
 A game replay, also known as a demo, is a form of user-generated content. In most instances, a game replay is a recording of a battle or race between opponents in a video game which can then be viewed by other players. However, game replays are also used for single-player gameplay, especially for speedruns. Some games, such as TrackMania, Doom, and N, use size-efficient replay files that record inputs to get a 1:1 replay in lossless fidelity.
 It is most common in real-time strategy games like ...</p>

  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>

<p>Command Sourcing</p><div class="youtube-onebox lazy-video-container" data-video-id="-YSEpvyEfG8" data-video-title="Command Sourcing" data-video-start-time="" data-provider-name="youtube">
  <a href="https://www.youtube.com/watch?v=-YSEpvyEfG8" target="_blank" class="video-thumbnail" rel="noopener nofollow ugc">
    <img class="youtube-thumbnail" src="https://img.youtube.com/vi/-YSEpvyEfG8/maxresdefault.jpg" title="Command Sourcing" width="690" height="388">
  </a>
</div>

<p>Command Sourcing vs Event Sourcing</p><aside class="onebox githubgist" data-onebox-src="https://gist.github.com/eulerfx/11227933">
  <header class="source">

      <a href="https://gist.github.com/eulerfx/11227933" target="_blank" rel="noopener nofollow ugc">gist.github.com</a>
  </header>

  <article class="onebox-body">
    <h4><a href="https://gist.github.com/eulerfx/11227933" target="_blank" rel="noopener nofollow ugc">https://gist.github.com/eulerfx/11227933</a></h4>

  <h5>CSvsES.md</h5>
  <pre><code class="Markdown">Both command sourcing (CS) and event sourcing (ES) rely on determinism for correctness.

The correctness condition for ES is the determinism (purity) of the function `State -&gt; Event -&gt; State`. Given that this function is deterministic, aka it always maps the same inputs to the same ouputs, we can rely on it to reconstitute state at any point in time. Determinism is typically achieved by ensuring that the `Event` has all required information to make the state transition, ie no side effects. The `Event` then is a sort of "closure" of all pertinent information about the event.

The correctness condition for CS is the determinism of the function `State -&gt; Command -&gt; Event`. Herein lies one of the distinctions between command sourcing and event sourcing - a program can control its output, but it not its input. Since one can't control the input, aka command, one can't in general, enrich it with all required information to make the above function deterministic. A consequence of this is that you can't simply replay a stream of logged commands at some arbitrary time and hope to get the same outputs as you would if they were handled immediatly. The other difference of course is that the mentioned ES function is used for reconstituting the state and the CS function is used to react to an incoming command.

Disregard the semantic distinction between commands and events and consider instead the more abstract notion of input and output. In this sense, a service, an aggregate, a projection, etc can all be though of as a programs mapping input to output. In other words, they are all state machines - a finite state transducers in particular. Command sourcing is just `State -&gt; Input -&gt; Output`. The input need not be thought of as a command and indeed, a command can be thought of as an interpretation of an event as discussed [here](https://gist.github.com/eulerfx/9762362).

As a practical example, I'm currently building fully event sourced system using EventStore. Output streams produced by some programs are used as input streams of other programs. In this sense, I have both command sourcing and event sourcing. </code></pre>


  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="316999" data-batch-url="/posts/batch_likers">
                        3
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/to-commanded-or-not-to/56568/22">Post #21</a>
	                </div>
	            </div>
              <div id="likers-container-316999" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="316999"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>