public function __construct(PostId $postId) {/**/}
// getters/setters…
public function getAggregateId() {/**/} public function update($title, $content) {/**/} private function applyPostWasPublished(PostWasPublished $event) {/**/} private function applyPostWasUpdated(PostWasUpdated $event) {/**/} public static function create($title, $content) {/**/} public static function reconstituteFrom( AggregateHistory $postAggregateHistory ) {/**/} }
Reconstituting aggregates • get aggregate history from the event storage • aggregate history is an ordered set of events affecting particular aggregate • reconstitute aggregate’s state: ‣ create new instance of the aggregate class ‣ replay events from aggregate history on it
Projections • data stored in the way it can be easily used for reading purposes • very simple structure • updated on every event affecting any of its data
Performance: event storage • append only, immutable • immutable data is very easy to scale up • can handle millions of events • but you can always make a snapshot
With event sourcing you will avoid • deleting something accidentally • problems with missing data that could have been saved • hard investigations of what has happened
TL;DR Event sourcing principles • do not store state of objects • store only facts that happened (events) • reconstitute state of aggregates from event storage • dispatch events to update projections • use projections for reading