Problem: querying for aggregates is expensive
Querying for things like:
- latest (as in, biggest TIMESTAMP) event for a certain scope (say, reference=R1)
- sum/avg/max/min for a certain scope (say, reference=R1)
is quite expensive as it involved a lot of scanning (as can be seen in https://github.com/eventsourcing/es4j/blob/master/eventsourcing-queries/src/main/java/com/eventsourcing/queries/IsLatestEntity.java and https://github.com/eventsourcing/es4j/blob/master/eventsourcing-queries/src/main/java/com/eventsourcing/queries/LatestAssociatedEntryQuery.java)
Proposed solution: designate and formalize an aggregate indexing system.
Proposed solution: implement aggregates as query subscribers that manipulate necessary indices manually.
Pros: relatively easy to implement, can be available very soon.
Cons: eventual index consistency — even though this will be executed before publishing future completes, it will be done after all other indices are available, causing a delay. This could be alleviated if in the future, entity subscribers will be in the same transactional context as all other updates.