Search⌘ K
AI Features

Aggregate Repositories and Event Stores

Explore how to manage aggregates in event-driven Golang applications using aggregate repositories and event stores. Learn the Load and Save methods, efficient serialization and deserialization, and how a type registry helps handle concrete types safely during event sourcing.

Because we will be dealing with aggregates that, regardless of their structure, will be decomposed down to a stream of events, we can create and reuse a single repository and store.

AggregateRepository and related interfaces

Let us look at AggregateRepository and the interfaces involved in the following figure:

AggregateRepository and related interfaces
AggregateRepository and related interfaces

The Load() and Save() methods are the only methods we will use with event-sourced aggregates and their event streams. There are occasions when we would need to delete or alter events in the event store for reasons related to privacy or security concerns. This repository is not going to be capable of that and is not meant for that work. We would have some other specialized implementation we would use to gain access to the additional functions necessary. When working with event stores, securing them, and ensuring that they are in accordance with relevant legislation, ...