-
Notifications
You must be signed in to change notification settings - Fork 3
/
path---docs-snapshotting-bd0d6a40db6befede356.js.map
1 lines (1 loc) · 48.8 KB
/
path---docs-snapshotting-bd0d6a40db6befede356.js.map
1
{"version":3,"sources":["webpack:///path---docs-snapshotting-bd0d6a40db6befede356.js","webpack:///./.cache/json/docs-snapshotting.json"],"names":["webpackJsonp","423","module","exports","data","allPostTitles","edges","node","frontmatter","title","lesson","category","chapter","type","fields","slug","postBySlug","html","timeToRead","excerpt","cover","date","tags","pathContext"],"mappings":"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","file":"path---docs-snapshotting-bd0d6a40db6befede356.js","sourcesContent":["webpackJsonp([252523778511558],{\n\n/***/ 423:\n/***/ (function(module, exports) {\n\n\tmodule.exports = {\"data\":{\"allPostTitles\":{\"edges\":[{\"node\":{\"frontmatter\":{\"title\":\"Getting Started\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":1,\"type\":\"docs\"},\"fields\":{\"slug\":\"/getting-started\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Primitives\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/primitives\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Walkthrough Introduction\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/walkthrough-introduction\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Sagas\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/sagas\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Tips and Tricks\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":5,\"type\":\"docs\"},\"fields\":{\"slug\":\"/tips-and-tricks\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Aggregates\",\"lesson\":2,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/aggregates\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Aggregate\",\"lesson\":2,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-aggregate\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Snapshotting\",\"lesson\":2,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/snapshotting\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Articles\",\"lesson\":2,\"category\":\"akkatecture\",\"chapter\":5,\"type\":\"docs\"},\"fields\":{\"slug\":\"/articles\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Events\",\"lesson\":3,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/events\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Commands\",\"lesson\":3,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-commands\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Clustering\",\"lesson\":3,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/clustering\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Videos\",\"lesson\":3,\"category\":\"akkatecture\",\"chapter\":5,\"type\":\"docs\"},\"fields\":{\"slug\":\"/videos\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Commands\",\"lesson\":4,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/commands\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Events\",\"lesson\":4,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-events\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Production Readiness\",\"lesson\":4,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/production-readiness\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Specifications\",\"lesson\":5,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/specifications\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Specifications\",\"lesson\":5,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-specifications\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Event Upgrading\",\"lesson\":5,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/event-upgrading\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Subscribers\",\"lesson\":6,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/subscribers\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Aggregate Test\",\"lesson\":6,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-aggregate-test\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Testing Aggregates\",\"lesson\":6,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/testing-aggregates\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Scheduled Jobs\",\"lesson\":7,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/scheduled-jobs\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Aggregate Saga\",\"lesson\":7,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-aggregate-saga\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Akka\",\"lesson\":8,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/akka\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Subscribers\",\"lesson\":8,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-subscribers\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Configuration\",\"lesson\":9,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/configuration\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Projections\",\"lesson\":9,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-projections\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Walkthrough Ending\",\"lesson\":10,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/walkthrough-ending\"}}}]},\"postBySlug\":{\"html\":\"<p>State snapshotting is an optimization that you can use to reduce the amount of events that are replayed upon aggregate instantiation. The affect of snapshotting is to limit the 'at most amount of events to replay' for your aggregates. Snapshotting works in the following way; if your aggregate has comitted <code class=\\\"language-text\\\">N</code> events, and your last aggregate snapshot was at <code class=\\\"language-text\\\">N - x</code> events ago, instead of replaying all N events from the event journal (<code class=\\\"language-text\\\">[1 to N]</code>), Akka will hydrate your aggregate with your snapshot and then will replay the remaining journaled events from offset <code class=\\\"language-text\\\">[N-x to N]</code>, thus completing your aggregate recovery process. So the optimisation here is that you do not need to load all the comitted events that precede <code class=\\\"language-text\\\">N - x</code>. In cases where your aggregate has thousands of events this can be a worthwhile optimisation to reduce replay time and the load on your event journal.</p>\\n<p>Snapshotting can be applied to both aggregates and sagas. Since, in Akkatecture sagas are modelled similarly to aggregates, the same documentation here applies to sagas, ie the mechanics of snapshotting is the same in both aggregates and sagas.</p>\\n<p>In Akkatecture there is a notion of an <code class=\\\"language-text\\\">ISnapshotStrategy</code> which is a model that describes when a snapshot should be made. By default, Akkatecture aggregates and sagas use the snapshot strategy of <code class=\\\"language-text\\\">SnapshotNeverStrategy</code>. This tells the framework that the aggregate never snapshots, and thus, on recovery, will never use the snapshot store. There are a few other strategies namely:</p>\\n<ul>\\n<li><code class=\\\"language-text\\\">SnapshotEveryFewVersionsStrategy</code> - The most common snapshot strategy. The strategy models the case where you want a snapshot to occur every N versions.</li>\\n<li><code class=\\\"language-text\\\">SnapshotAlwaysStrategy</code> - Useful for scenarios where you have low throughput and temporally long running aggregates or sagas.</li>\\n<li><code class=\\\"language-text\\\">SnapshotNeverStrategy</code> - This is the default snapshot strategy, which tells the aggregate to never snapshot.</li>\\n</ul>\\n<p>You can implement your own SnapshotStrategy by implementing the <code class=\\\"language-text\\\">ISnapshotStrategy</code> interface.</p>\\n<h1 id=\\\"wiring-it-all-up\\\"><a href=\\\"#wiring-it-all-up\\\" aria-hidden=\\\"true\\\" class=\\\"anchor\\\"><svg aria-hidden=\\\"true\\\" height=\\\"16\\\" version=\\\"1.1\\\" viewBox=\\\"0 0 16 16\\\" width=\\\"16\\\"><path fill-rule=\\\"evenodd\\\" d=\\\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\\\"></path></svg></a>Wiring It All Up</h1>\\n<p>Lets say we have an <code class=\\\"language-text\\\">OrderAggregate</code>. And we want to set its snapshot strategy. We can do the following.</p>\\n<div class=\\\"gatsby-highlight\\\">\\n <pre class=\\\"language-csharp\\\"><code class=\\\"language-csharp\\\"><span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">class</span> <span class=\\\"token class-name\\\">OrderAggregate</span> <span class=\\\"token punctuation\\\">:</span> <span class=\\\"token class-name\\\">AggregateRoot</span><span class=\\\"token operator\\\"><</span>OrderAggregate<span class=\\\"token punctuation\\\">,</span> OrderId<span class=\\\"token punctuation\\\">,</span> OrderState<span class=\\\"token operator\\\">></span>\\n<span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token function\\\">OrderAggregate</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token class-name\\\">OrderId</span> aggregateId<span class=\\\"token punctuation\\\">)</span>\\n <span class=\\\"token punctuation\\\">:</span> <span class=\\\"token keyword\\\">base</span><span class=\\\"token punctuation\\\">(</span>aggregateId<span class=\\\"token punctuation\\\">)</span>\\n <span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">var</span> snapshotStrategy <span class=\\\"token operator\\\">=</span> <span class=\\\"token keyword\\\">new</span> <span class=\\\"token class-name\\\">SnapshotEveryFewVersionsStrategy</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token number\\\">10</span><span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n <span class=\\\"token function\\\">SetSnapshotStrategy</span><span class=\\\"token punctuation\\\">(</span>snapshotStrategy<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n <span class=\\\"token punctuation\\\">}</span>\\n<span class=\\\"token punctuation\\\">}</span></code></pre>\\n </div>\\n<blockquote>\\n<p>SetSnapshotStrategy can also be used during the aggregates lifetime, ie you can change the strategy as the aggregate evolves during runtime by codifying this behaviour in the aggregates command handlers.</p>\\n</blockquote>\\n<h2 id=\\\"setting-up-the-aggregate-state\\\"><a href=\\\"#setting-up-the-aggregate-state\\\" aria-hidden=\\\"true\\\" class=\\\"anchor\\\"><svg aria-hidden=\\\"true\\\" height=\\\"16\\\" version=\\\"1.1\\\" viewBox=\\\"0 0 16 16\\\" width=\\\"16\\\"><path fill-rule=\\\"evenodd\\\" d=\\\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\\\"></path></svg></a>Setting Up The Aggregate State</h2>\\n<p>We have to now make our aggregate state aware of the fact that it can be hydrated from a snapshot (as well as being hydrated from a stream of event apply methods).</p>\\n<div class=\\\"gatsby-highlight\\\">\\n <pre class=\\\"language-csharp\\\"><code class=\\\"language-csharp\\\"><span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">class</span> <span class=\\\"token class-name\\\">OrderState</span> <span class=\\\"token punctuation\\\">:</span> <span class=\\\"token class-name\\\">AggregateState</span><span class=\\\"token operator\\\"><</span>OrderAggregate<span class=\\\"token punctuation\\\">,</span> OrderId<span class=\\\"token operator\\\">></span>\\n IApply<span class=\\\"token operator\\\"><</span>OrderPlaced<span class=\\\"token operator\\\">></span><span class=\\\"token punctuation\\\">,</span>\\n IApply<span class=\\\"token operator\\\"><</span>OrderShipped<span class=\\\"token operator\\\">></span><span class=\\\"token punctuation\\\">,</span>\\n IHydrate<span class=\\\"token operator\\\"><</span>OrderSnapshot<span class=\\\"token operator\\\">></span><span class=\\\"token punctuation\\\">,</span>\\n<span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token class-name\\\">CustomerId</span> CustomerId <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span> <span class=\\\"token keyword\\\">private</span> <span class=\\\"token keyword\\\">set</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token class-name\\\">Address</span> ShippingAddress <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span> <span class=\\\"token keyword\\\">private</span> <span class=\\\"token keyword\\\">set</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">void</span> <span class=\\\"token function\\\">Apply</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token class-name\\\">OrderPlaced</span> aggregateEvent<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">{</span><span class=\\\"token comment\\\">/* omitted for brevity */</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">void</span> <span class=\\\"token function\\\">Apply</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token class-name\\\">OrderShipped</span> aggregateEvent<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">{</span><span class=\\\"token comment\\\">/* omitted for brevity */</span><span class=\\\"token punctuation\\\">}</span>\\n\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">void</span> <span class=\\\"token function\\\">Hydrate</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token class-name\\\">OrderSnapshot</span> aggregateSnapshot<span class=\\\"token punctuation\\\">)</span>\\n <span class=\\\"token punctuation\\\">{</span>\\n CustomerId <span class=\\\"token operator\\\">=</span> CustomerId<span class=\\\"token punctuation\\\">.</span><span class=\\\"token function\\\">With</span><span class=\\\"token punctuation\\\">(</span>aggregateSnapshot<span class=\\\"token punctuation\\\">.</span>CustomerId<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n\\n ShippingAddress <span class=\\\"token operator\\\">=</span> <span class=\\\"token keyword\\\">new</span> <span class=\\\"token class-name\\\">Address</span><span class=\\\"token punctuation\\\">(</span>\\n aggregateSnapshot<span class=\\\"token punctuation\\\">.</span>ShippingAddressLine<span class=\\\"token punctuation\\\">,</span>\\n aggregateSnapshot<span class=\\\"token punctuation\\\">.</span>ShippingAddressPostalCode<span class=\\\"token punctuation\\\">,</span>\\n aggregateSnapshot<span class=\\\"token punctuation\\\">.</span>ShippingAddressTown<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n <span class=\\\"token punctuation\\\">}</span>\\n<span class=\\\"token punctuation\\\">}</span>\\n\\n<span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">class</span> <span class=\\\"token class-name\\\">OrderSnapshot</span> <span class=\\\"token punctuation\\\">:</span> <span class=\\\"token class-name\\\">IAggregateSnapshot</span><span class=\\\"token operator\\\"><</span>OrderAggregate<span class=\\\"token punctuation\\\">,</span> OrderId<span class=\\\"token operator\\\">></span>\\n<span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">string</span> CustomerId <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">string</span> ShippingAddressLine<span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">string</span> ShippingAddressPostalCode <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">string</span> ShippingAddressTown <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token function\\\">OrderSnapshot</span><span class=\\\"token punctuation\\\">(</span>\\n <span class=\\\"token keyword\\\">string</span> customerId<span class=\\\"token punctuation\\\">,</span>\\n <span class=\\\"token keyword\\\">string</span> shippingAddressline<span class=\\\"token punctuation\\\">,</span>\\n <span class=\\\"token keyword\\\">string</span> shippingAddressPostalCode<span class=\\\"token punctuation\\\">,</span>\\n <span class=\\\"token keyword\\\">string</span> shippingAddressTown<span class=\\\"token punctuation\\\">)</span>\\n <span class=\\\"token punctuation\\\">{</span>\\n CustomerId <span class=\\\"token operator\\\">=</span> customerId<span class=\\\"token punctuation\\\">;</span>\\n ShippingAddressLine <span class=\\\"token operator\\\">=</span> shippingAddressLine<span class=\\\"token punctuation\\\">;</span>\\n ShippingAddressPostalCode <span class=\\\"token operator\\\">=</span> shippingAddressPostalCode<span class=\\\"token punctuation\\\">;</span>\\n ShippingAddressTown <span class=\\\"token operator\\\">=</span> shippingAddressTown<span class=\\\"token punctuation\\\">;</span>\\n <span class=\\\"token punctuation\\\">}</span>\\n<span class=\\\"token punctuation\\\">}</span></code></pre>\\n </div>\\n<p>Now all that is left is to override the <code class=\\\"language-text\\\">AggregateRoot.CreateSnapshot()</code> method so that Akkatecture can use this model to persist to the snapshot-store.</p>\\n<div class=\\\"gatsby-highlight\\\">\\n <pre class=\\\"language-csharp\\\"><code class=\\\"language-csharp\\\"><span class=\\\"token comment\\\">//within OrderAggregate.cs</span>\\n\\n<span class=\\\"token keyword\\\">protected</span> <span class=\\\"token keyword\\\">override</span> IAggregateSnapshot<span class=\\\"token operator\\\"><</span>OrderAggregate<span class=\\\"token punctuation\\\">,</span> OrderId<span class=\\\"token operator\\\">></span> <span class=\\\"token function\\\">CreateSnapshot</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token punctuation\\\">)</span>\\n<span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">return</span> <span class=\\\"token keyword\\\">new</span> <span class=\\\"token class-name\\\">OrderSnapshot</span><span class=\\\"token punctuation\\\">(</span>\\n State<span class=\\\"token punctuation\\\">.</span>CustomerId<span class=\\\"token punctuation\\\">.</span>Value<span class=\\\"token punctuation\\\">,</span>\\n State<span class=\\\"token punctuation\\\">.</span>ShippingAddress<span class=\\\"token punctuation\\\">.</span>Line<span class=\\\"token punctuation\\\">,</span>\\n State<span class=\\\"token punctuation\\\">.</span>ShippingAddress<span class=\\\"token punctuation\\\">.</span>PostalCode<span class=\\\"token punctuation\\\">,</span>\\n State<span class=\\\"token punctuation\\\">.</span>ShippingAddress<span class=\\\"token punctuation\\\">.</span>Town<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n<span class=\\\"token punctuation\\\">}</span></code></pre>\\n </div>\\n<h1 id=\\\"in-summary\\\"><a href=\\\"#in-summary\\\" aria-hidden=\\\"true\\\" class=\\\"anchor\\\"><svg aria-hidden=\\\"true\\\" height=\\\"16\\\" version=\\\"1.1\\\" viewBox=\\\"0 0 16 16\\\" width=\\\"16\\\"><path fill-rule=\\\"evenodd\\\" d=\\\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\\\"></path></svg></a>In Summary</h1>\\n<p>To get snapshots working in Akkatecture you need to:</p>\\n<ul>\\n<li>Define your snapshot strategy and set your aggregate to use that particular strategy.</li>\\n<li>Define the snapshot model that closely resembles your aggregate state.</li>\\n<li>Make your aggregate state model implement <code class=\\\"language-text\\\">IHydrate<></code></li>\\n<li>Override the <code class=\\\"language-text\\\">Aggregate.CreateSnapshot()</code> which maps the aggregates state to the aggregates snapshot model.</li>\\n</ul>\\n<blockquote>\\n<p>The snapshot model should be treated as an invariant since it gets stored by akka.net's snapshot store. The same versioning strategies used in event sourcing for events, are applicable to snapshots as well. If the snapshot loading fails. The aggregate will be reloaded from the event journal and not the snapshot store. The take away from this mechanic is that snapshots are an aggregate derivative of events. Your domain model should not reply on snapshots by any means.</p>\\n</blockquote>\",\"timeToRead\":4,\"excerpt\":\"State snapshotting is an optimization that you can use to reduce the amount of events that are replayed upon aggregate instantiation. The…\",\"frontmatter\":{\"title\":\"Snapshotting\",\"cover\":\"https://unsplash.it/400/300/?random?BoldMage\",\"date\":\"01/07/2018\",\"category\":\"akkatecture\",\"tags\":[\"advanced-concepts\",\"akkatecture\",\"csharp\",\"dotnet\"]},\"fields\":{\"slug\":\"/snapshotting\"}}},\"pathContext\":{\"slug\":\"/snapshotting\",\"category\":\"akkatecture\"}}\n\n/***/ })\n\n});\n\n\n// WEBPACK FOOTER //\n// path---docs-snapshotting-bd0d6a40db6befede356.js","module.exports = {\"data\":{\"allPostTitles\":{\"edges\":[{\"node\":{\"frontmatter\":{\"title\":\"Getting Started\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":1,\"type\":\"docs\"},\"fields\":{\"slug\":\"/getting-started\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Primitives\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/primitives\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Walkthrough Introduction\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/walkthrough-introduction\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Sagas\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/sagas\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Tips and Tricks\",\"lesson\":1,\"category\":\"akkatecture\",\"chapter\":5,\"type\":\"docs\"},\"fields\":{\"slug\":\"/tips-and-tricks\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Aggregates\",\"lesson\":2,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/aggregates\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Aggregate\",\"lesson\":2,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-aggregate\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Snapshotting\",\"lesson\":2,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/snapshotting\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Articles\",\"lesson\":2,\"category\":\"akkatecture\",\"chapter\":5,\"type\":\"docs\"},\"fields\":{\"slug\":\"/articles\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Events\",\"lesson\":3,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/events\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Commands\",\"lesson\":3,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-commands\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Clustering\",\"lesson\":3,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/clustering\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Videos\",\"lesson\":3,\"category\":\"akkatecture\",\"chapter\":5,\"type\":\"docs\"},\"fields\":{\"slug\":\"/videos\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Commands\",\"lesson\":4,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/commands\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Events\",\"lesson\":4,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-events\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Production Readiness\",\"lesson\":4,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/production-readiness\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Specifications\",\"lesson\":5,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/specifications\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Specifications\",\"lesson\":5,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-specifications\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Event Upgrading\",\"lesson\":5,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/event-upgrading\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Subscribers\",\"lesson\":6,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/subscribers\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Aggregate Test\",\"lesson\":6,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-aggregate-test\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Testing Aggregates\",\"lesson\":6,\"category\":\"akkatecture\",\"chapter\":4,\"type\":\"docs\"},\"fields\":{\"slug\":\"/testing-aggregates\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Scheduled Jobs\",\"lesson\":7,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/scheduled-jobs\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Aggregate Saga\",\"lesson\":7,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-aggregate-saga\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Akka\",\"lesson\":8,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/akka\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Subscribers\",\"lesson\":8,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-subscribers\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Configuration\",\"lesson\":9,\"category\":\"akkatecture\",\"chapter\":2,\"type\":\"docs\"},\"fields\":{\"slug\":\"/configuration\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Your First Projections\",\"lesson\":9,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/your-first-projections\"}}},{\"node\":{\"frontmatter\":{\"title\":\"Walkthrough Ending\",\"lesson\":10,\"category\":\"akkatecture\",\"chapter\":3,\"type\":\"docs\"},\"fields\":{\"slug\":\"/walkthrough-ending\"}}}]},\"postBySlug\":{\"html\":\"<p>State snapshotting is an optimization that you can use to reduce the amount of events that are replayed upon aggregate instantiation. The affect of snapshotting is to limit the 'at most amount of events to replay' for your aggregates. Snapshotting works in the following way; if your aggregate has comitted <code class=\\\"language-text\\\">N</code> events, and your last aggregate snapshot was at <code class=\\\"language-text\\\">N - x</code> events ago, instead of replaying all N events from the event journal (<code class=\\\"language-text\\\">[1 to N]</code>), Akka will hydrate your aggregate with your snapshot and then will replay the remaining journaled events from offset <code class=\\\"language-text\\\">[N-x to N]</code>, thus completing your aggregate recovery process. So the optimisation here is that you do not need to load all the comitted events that precede <code class=\\\"language-text\\\">N - x</code>. In cases where your aggregate has thousands of events this can be a worthwhile optimisation to reduce replay time and the load on your event journal.</p>\\n<p>Snapshotting can be applied to both aggregates and sagas. Since, in Akkatecture sagas are modelled similarly to aggregates, the same documentation here applies to sagas, ie the mechanics of snapshotting is the same in both aggregates and sagas.</p>\\n<p>In Akkatecture there is a notion of an <code class=\\\"language-text\\\">ISnapshotStrategy</code> which is a model that describes when a snapshot should be made. By default, Akkatecture aggregates and sagas use the snapshot strategy of <code class=\\\"language-text\\\">SnapshotNeverStrategy</code>. This tells the framework that the aggregate never snapshots, and thus, on recovery, will never use the snapshot store. There are a few other strategies namely:</p>\\n<ul>\\n<li><code class=\\\"language-text\\\">SnapshotEveryFewVersionsStrategy</code> - The most common snapshot strategy. The strategy models the case where you want a snapshot to occur every N versions.</li>\\n<li><code class=\\\"language-text\\\">SnapshotAlwaysStrategy</code> - Useful for scenarios where you have low throughput and temporally long running aggregates or sagas.</li>\\n<li><code class=\\\"language-text\\\">SnapshotNeverStrategy</code> - This is the default snapshot strategy, which tells the aggregate to never snapshot.</li>\\n</ul>\\n<p>You can implement your own SnapshotStrategy by implementing the <code class=\\\"language-text\\\">ISnapshotStrategy</code> interface.</p>\\n<h1 id=\\\"wiring-it-all-up\\\"><a href=\\\"#wiring-it-all-up\\\" aria-hidden=\\\"true\\\" class=\\\"anchor\\\"><svg aria-hidden=\\\"true\\\" height=\\\"16\\\" version=\\\"1.1\\\" viewBox=\\\"0 0 16 16\\\" width=\\\"16\\\"><path fill-rule=\\\"evenodd\\\" d=\\\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\\\"></path></svg></a>Wiring It All Up</h1>\\n<p>Lets say we have an <code class=\\\"language-text\\\">OrderAggregate</code>. And we want to set its snapshot strategy. We can do the following.</p>\\n<div class=\\\"gatsby-highlight\\\">\\n <pre class=\\\"language-csharp\\\"><code class=\\\"language-csharp\\\"><span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">class</span> <span class=\\\"token class-name\\\">OrderAggregate</span> <span class=\\\"token punctuation\\\">:</span> <span class=\\\"token class-name\\\">AggregateRoot</span><span class=\\\"token operator\\\"><</span>OrderAggregate<span class=\\\"token punctuation\\\">,</span> OrderId<span class=\\\"token punctuation\\\">,</span> OrderState<span class=\\\"token operator\\\">></span>\\n<span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token function\\\">OrderAggregate</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token class-name\\\">OrderId</span> aggregateId<span class=\\\"token punctuation\\\">)</span>\\n <span class=\\\"token punctuation\\\">:</span> <span class=\\\"token keyword\\\">base</span><span class=\\\"token punctuation\\\">(</span>aggregateId<span class=\\\"token punctuation\\\">)</span>\\n <span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">var</span> snapshotStrategy <span class=\\\"token operator\\\">=</span> <span class=\\\"token keyword\\\">new</span> <span class=\\\"token class-name\\\">SnapshotEveryFewVersionsStrategy</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token number\\\">10</span><span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n <span class=\\\"token function\\\">SetSnapshotStrategy</span><span class=\\\"token punctuation\\\">(</span>snapshotStrategy<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n <span class=\\\"token punctuation\\\">}</span>\\n<span class=\\\"token punctuation\\\">}</span></code></pre>\\n </div>\\n<blockquote>\\n<p>SetSnapshotStrategy can also be used during the aggregates lifetime, ie you can change the strategy as the aggregate evolves during runtime by codifying this behaviour in the aggregates command handlers.</p>\\n</blockquote>\\n<h2 id=\\\"setting-up-the-aggregate-state\\\"><a href=\\\"#setting-up-the-aggregate-state\\\" aria-hidden=\\\"true\\\" class=\\\"anchor\\\"><svg aria-hidden=\\\"true\\\" height=\\\"16\\\" version=\\\"1.1\\\" viewBox=\\\"0 0 16 16\\\" width=\\\"16\\\"><path fill-rule=\\\"evenodd\\\" d=\\\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\\\"></path></svg></a>Setting Up The Aggregate State</h2>\\n<p>We have to now make our aggregate state aware of the fact that it can be hydrated from a snapshot (as well as being hydrated from a stream of event apply methods).</p>\\n<div class=\\\"gatsby-highlight\\\">\\n <pre class=\\\"language-csharp\\\"><code class=\\\"language-csharp\\\"><span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">class</span> <span class=\\\"token class-name\\\">OrderState</span> <span class=\\\"token punctuation\\\">:</span> <span class=\\\"token class-name\\\">AggregateState</span><span class=\\\"token operator\\\"><</span>OrderAggregate<span class=\\\"token punctuation\\\">,</span> OrderId<span class=\\\"token operator\\\">></span>\\n IApply<span class=\\\"token operator\\\"><</span>OrderPlaced<span class=\\\"token operator\\\">></span><span class=\\\"token punctuation\\\">,</span>\\n IApply<span class=\\\"token operator\\\"><</span>OrderShipped<span class=\\\"token operator\\\">></span><span class=\\\"token punctuation\\\">,</span>\\n IHydrate<span class=\\\"token operator\\\"><</span>OrderSnapshot<span class=\\\"token operator\\\">></span><span class=\\\"token punctuation\\\">,</span>\\n<span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token class-name\\\">CustomerId</span> CustomerId <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span> <span class=\\\"token keyword\\\">private</span> <span class=\\\"token keyword\\\">set</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token class-name\\\">Address</span> ShippingAddress <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span> <span class=\\\"token keyword\\\">private</span> <span class=\\\"token keyword\\\">set</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">void</span> <span class=\\\"token function\\\">Apply</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token class-name\\\">OrderPlaced</span> aggregateEvent<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">{</span><span class=\\\"token comment\\\">/* omitted for brevity */</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">void</span> <span class=\\\"token function\\\">Apply</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token class-name\\\">OrderShipped</span> aggregateEvent<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">{</span><span class=\\\"token comment\\\">/* omitted for brevity */</span><span class=\\\"token punctuation\\\">}</span>\\n\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">void</span> <span class=\\\"token function\\\">Hydrate</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token class-name\\\">OrderSnapshot</span> aggregateSnapshot<span class=\\\"token punctuation\\\">)</span>\\n <span class=\\\"token punctuation\\\">{</span>\\n CustomerId <span class=\\\"token operator\\\">=</span> CustomerId<span class=\\\"token punctuation\\\">.</span><span class=\\\"token function\\\">With</span><span class=\\\"token punctuation\\\">(</span>aggregateSnapshot<span class=\\\"token punctuation\\\">.</span>CustomerId<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n\\n ShippingAddress <span class=\\\"token operator\\\">=</span> <span class=\\\"token keyword\\\">new</span> <span class=\\\"token class-name\\\">Address</span><span class=\\\"token punctuation\\\">(</span>\\n aggregateSnapshot<span class=\\\"token punctuation\\\">.</span>ShippingAddressLine<span class=\\\"token punctuation\\\">,</span>\\n aggregateSnapshot<span class=\\\"token punctuation\\\">.</span>ShippingAddressPostalCode<span class=\\\"token punctuation\\\">,</span>\\n aggregateSnapshot<span class=\\\"token punctuation\\\">.</span>ShippingAddressTown<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n <span class=\\\"token punctuation\\\">}</span>\\n<span class=\\\"token punctuation\\\">}</span>\\n\\n<span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">class</span> <span class=\\\"token class-name\\\">OrderSnapshot</span> <span class=\\\"token punctuation\\\">:</span> <span class=\\\"token class-name\\\">IAggregateSnapshot</span><span class=\\\"token operator\\\"><</span>OrderAggregate<span class=\\\"token punctuation\\\">,</span> OrderId<span class=\\\"token operator\\\">></span>\\n<span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">string</span> CustomerId <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">string</span> ShippingAddressLine<span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">string</span> ShippingAddressPostalCode <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token keyword\\\">string</span> ShippingAddressTown <span class=\\\"token punctuation\\\">{</span><span class=\\\"token keyword\\\">get</span><span class=\\\"token punctuation\\\">;</span><span class=\\\"token punctuation\\\">}</span>\\n\\n <span class=\\\"token keyword\\\">public</span> <span class=\\\"token function\\\">OrderSnapshot</span><span class=\\\"token punctuation\\\">(</span>\\n <span class=\\\"token keyword\\\">string</span> customerId<span class=\\\"token punctuation\\\">,</span>\\n <span class=\\\"token keyword\\\">string</span> shippingAddressline<span class=\\\"token punctuation\\\">,</span>\\n <span class=\\\"token keyword\\\">string</span> shippingAddressPostalCode<span class=\\\"token punctuation\\\">,</span>\\n <span class=\\\"token keyword\\\">string</span> shippingAddressTown<span class=\\\"token punctuation\\\">)</span>\\n <span class=\\\"token punctuation\\\">{</span>\\n CustomerId <span class=\\\"token operator\\\">=</span> customerId<span class=\\\"token punctuation\\\">;</span>\\n ShippingAddressLine <span class=\\\"token operator\\\">=</span> shippingAddressLine<span class=\\\"token punctuation\\\">;</span>\\n ShippingAddressPostalCode <span class=\\\"token operator\\\">=</span> shippingAddressPostalCode<span class=\\\"token punctuation\\\">;</span>\\n ShippingAddressTown <span class=\\\"token operator\\\">=</span> shippingAddressTown<span class=\\\"token punctuation\\\">;</span>\\n <span class=\\\"token punctuation\\\">}</span>\\n<span class=\\\"token punctuation\\\">}</span></code></pre>\\n </div>\\n<p>Now all that is left is to override the <code class=\\\"language-text\\\">AggregateRoot.CreateSnapshot()</code> method so that Akkatecture can use this model to persist to the snapshot-store.</p>\\n<div class=\\\"gatsby-highlight\\\">\\n <pre class=\\\"language-csharp\\\"><code class=\\\"language-csharp\\\"><span class=\\\"token comment\\\">//within OrderAggregate.cs</span>\\n\\n<span class=\\\"token keyword\\\">protected</span> <span class=\\\"token keyword\\\">override</span> IAggregateSnapshot<span class=\\\"token operator\\\"><</span>OrderAggregate<span class=\\\"token punctuation\\\">,</span> OrderId<span class=\\\"token operator\\\">></span> <span class=\\\"token function\\\">CreateSnapshot</span><span class=\\\"token punctuation\\\">(</span><span class=\\\"token punctuation\\\">)</span>\\n<span class=\\\"token punctuation\\\">{</span>\\n <span class=\\\"token keyword\\\">return</span> <span class=\\\"token keyword\\\">new</span> <span class=\\\"token class-name\\\">OrderSnapshot</span><span class=\\\"token punctuation\\\">(</span>\\n State<span class=\\\"token punctuation\\\">.</span>CustomerId<span class=\\\"token punctuation\\\">.</span>Value<span class=\\\"token punctuation\\\">,</span>\\n State<span class=\\\"token punctuation\\\">.</span>ShippingAddress<span class=\\\"token punctuation\\\">.</span>Line<span class=\\\"token punctuation\\\">,</span>\\n State<span class=\\\"token punctuation\\\">.</span>ShippingAddress<span class=\\\"token punctuation\\\">.</span>PostalCode<span class=\\\"token punctuation\\\">,</span>\\n State<span class=\\\"token punctuation\\\">.</span>ShippingAddress<span class=\\\"token punctuation\\\">.</span>Town<span class=\\\"token punctuation\\\">)</span><span class=\\\"token punctuation\\\">;</span>\\n<span class=\\\"token punctuation\\\">}</span></code></pre>\\n </div>\\n<h1 id=\\\"in-summary\\\"><a href=\\\"#in-summary\\\" aria-hidden=\\\"true\\\" class=\\\"anchor\\\"><svg aria-hidden=\\\"true\\\" height=\\\"16\\\" version=\\\"1.1\\\" viewBox=\\\"0 0 16 16\\\" width=\\\"16\\\"><path fill-rule=\\\"evenodd\\\" d=\\\"M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z\\\"></path></svg></a>In Summary</h1>\\n<p>To get snapshots working in Akkatecture you need to:</p>\\n<ul>\\n<li>Define your snapshot strategy and set your aggregate to use that particular strategy.</li>\\n<li>Define the snapshot model that closely resembles your aggregate state.</li>\\n<li>Make your aggregate state model implement <code class=\\\"language-text\\\">IHydrate<></code></li>\\n<li>Override the <code class=\\\"language-text\\\">Aggregate.CreateSnapshot()</code> which maps the aggregates state to the aggregates snapshot model.</li>\\n</ul>\\n<blockquote>\\n<p>The snapshot model should be treated as an invariant since it gets stored by akka.net's snapshot store. The same versioning strategies used in event sourcing for events, are applicable to snapshots as well. If the snapshot loading fails. The aggregate will be reloaded from the event journal and not the snapshot store. The take away from this mechanic is that snapshots are an aggregate derivative of events. Your domain model should not reply on snapshots by any means.</p>\\n</blockquote>\",\"timeToRead\":4,\"excerpt\":\"State snapshotting is an optimization that you can use to reduce the amount of events that are replayed upon aggregate instantiation. The…\",\"frontmatter\":{\"title\":\"Snapshotting\",\"cover\":\"https://unsplash.it/400/300/?random?BoldMage\",\"date\":\"01/07/2018\",\"category\":\"akkatecture\",\"tags\":[\"advanced-concepts\",\"akkatecture\",\"csharp\",\"dotnet\"]},\"fields\":{\"slug\":\"/snapshotting\"}}},\"pathContext\":{\"slug\":\"/snapshotting\",\"category\":\"akkatecture\"}}\n\n\n//////////////////\n// WEBPACK FOOTER\n// ./~/json-loader!./.cache/json/docs-snapshotting.json\n// module id = 423\n// module chunks = 252523778511558"],"sourceRoot":""}