MongoDB Event Store Indices
Closed this issue · 0 comments
Let users configure the builtin indices that are created by the MongoDB event store.
Motivation
Currently, the MongoDB event store creates 8 indices that are more or less useful/applicable for different kinds of queries. Goal is to reduce the default amount of indices to a minimum, without creating performance issues. If needed, users should be able to enable additional, "named" indices that boost the performance of specific queries.
Proposal
Proposal is to separate indices into two kinds: core
and edge
. Core indices are always created because they are required by goes' components to be performant. Edge-case indices can be enabled by applications that do more uncommon queries, which wouldn't be able to use the core indices.
Core Indices
aggregate name + id + version
: query aggregates by name (+ id (+ version))id
: fetch a specific eventname
: query events by name- used in many projection startup queries
- e.g.
query.New(query.Name(FooEvent, BarEvent))
- e.g.
- used in many projection startup queries
name + time
: fetch all events of a given set of names, sorted by time- used in projection jobs when using the default query
aggregate name + version
: query events of a specific aggregate type, up to a specific version- used in projection startup queries
- e.g.
query.New(query.AggregateName("foo"), query.AggregateVersion(1))
to fetch the first event of each "foo" aggregate to extract the aggregates from a projection job in the most performant way
- e.g.
- used in projection startup queries
Edge Case Indices
aggregate id
: fetch a specific aggregate only by its idaggregate version
: useful when querying only by versionname + version
: query a given set of events, up to a given version- can be used in projection startup queries
- e.g.
query.New(query.Name(FooEvent, BarEvent), query.AggregateVersion(1))
to extract aggregates from projection jobs
- e.g.
- can be used in projection startup queries
Enabling Indices
Edge-case indices can be enabled individually using feature flags:
package example
func example(enc event.Encoding) {
store := mongo.NewEventStore(enc, mongo.WithIndices(
indices.EventStore.AggregateID,
indices.EventStore.AggregateVersion,
indices.EventStore.NameAndVersion,
))
}