es4j icon indicating copy to clipboard operation
es4j copied to clipboard

Problem: querying for aggregates is expensive

Open yrashk opened this issue 9 years ago • 1 comments

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.

yrashk avatar Nov 06 '16 16:11 yrashk

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.

yrashk avatar Nov 09 '16 18:11 yrashk