Aggregate Event Stream Lifetimes
Get a brief overview of the types of aggregates and snapshots.
Types of aggregates
In an event-sourced system, there are two kinds of aggregates:
Short-lived aggregates
Long-lived aggregates
Short-lived aggregates
Short-lived aggregates will not see many events in their short lifetime. Examples of a short-lived aggregate would be Order
from the Ordering module and Basket
from the Shopping Baskets module. Both exist for a short amount of time, and we do not expect them to see many events.
The performance of short-lived aggregates and streams with few events in general will not be a problem. The small number of events can be read and processed quickly.
Long-lived aggregates
Long-lived aggregates will see many events over their very long lifetime. Examples of long-lived aggregates are Store
from the Store Management module and Customer
from the Customers module. These entities will be around for a long time and can end up seeing many events.
Larger streams would take longer to read and process; the larger it is, the longer it would take.
Taking periodic snapshots of the event stream
When we know that we will be dealing with a larger stream, we can use snapshots to improve performance by reducing the number of events we will load and process. In the below figure, the state of the stream is saved along with the aggregate version.
Get hands-on with 1400+ tech skills courses.