Important Indices
If you have generated the tables automatically using your JPA implementation (for example, Hibernate), you probably do not have all the right indexes set on your tables. Different usages of the event store require different indexes to be set for optimal performance. This list suggests the indexes that should be added for the different types of queries used by the default EventStorageEngine
implementation:
Normal operational use (storing and loading events)
-
Table
DomainEventEntry
, columnsaggregateIdentifier
andsequenceNumber
(unique index) -
Table
DomainEventEntry
,eventIdentifier
(unique index)
Snapshotting
-
Table
SnapshotEventEntry
,aggregateIdentifier
column. -
Table
SnapshotEventEntry
,eventIdentifier
(unique index)
Sagas
-
Table
AssociationValueEntry
, columnssagaType
,associationKey
andassociationValue
, -
Table
AssociationValueEntry
, columnssagaId
andsagaType
,
The default column lengths generated by, for example, Hibernate may work, but won’t be optimal. A UUID, for example, will always have the same length. Instead of a variable length column of 255 characters, you could use a fixed length column of 36 characters for the aggregate identifier.
The timestamp
column in the DomainEventEntry
table only stores ISO 8601 timestamps. If all times are stored in the UTC timezone, they need a column length of 24 characters. If you use another timezone, this may be up to 28. Using variable length columns is generally not necessary, since time stamps always have the same length.
It is highly recommended to store all timestamps in UTC format. In countries with daylight saving time, storing timestamps in local time may result in sorting errors for events generated around and during the timezone switch. This does not occur when UTC is used. Some servers are configured to always use UTC. Alternatively, you should configure the event store to convert timestamps to UTC before storing them. |
The type
column in the DomainEventEntry
stores the type identifiers of aggregates. Generally, these are the 'simple name'
of the aggregate. Even the infamous AbstractDependencyInjectionSpringContextTests
in Spring only counts 45 characters. Here, again, a shorter (but variable) length field should suffice.