Reputation: 6364
What does it mean when someone says store event itself in the journal but not the state/data? such that one can replay the events to build the state. Can someone explain how the data in journal look like since there is no storing of state? Does one store the functions itself?
Upvotes: 0
Views: 132
Reputation: 17683
It means that you persist only what has changed in the state and not all the state. I will give you and example.
Let's suppose that you have an InventoryAggregate
that stores items, like Products
. Internally, this Aggregate
stores a list of all items but when a command to add the item X arrives (AddItemXCommand
) it produces the event that item x was added (ItemXWasAddedEvent
). Next time a similar command arrives, the Aggregate Repository
loads from the Event Store
(from the Journal if you want) all the previous generated events and apply them one-by-one onto the Aggregate in order to build the state (in this particular example, to build the list of all added items).
So, after the command arrives and is executed, the state
changes (an item is added to the list) but you don't persist it (you don't persist the item list), you persist only the generated event (that an item was added). After you persist that event you can discard the Aggregate
and its internal state
.
As an optimization, you can persist the internal state, so when a command arrives, you don't have to load+apply all the events, only the events that were generated after the state was cached. This state at a particular moment is know as Snapshot
.
Upvotes: 1