modernice / goes

goes is an event-sourcing framework for Go.
https://goes.modernice.dev
Apache License 2.0
134 stars 12 forks source link

MongoDB Event Store Indices #38

Closed bounoable closed 2 years ago

bounoable commented 2 years ago

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

Edge Case Indices

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,
  ))
}