Search code examples
cassandraakkaevent-sourcinglagomakka-persistence

Akka: Events by tag and creation time


I have an application that uses Akka along with Cassandra for Event Sourcing. As part of an API response, I need to show the number of events of a specific type/tag (say UpdateEvent) that happened at a specific time range. Does there exists any near capability to achieve this?

I have read through "eventsByTag" query from Query Plugin and from what I understand the provide a stream of events and usage of which can have drastic impact for a client facing backend. Correct if I am wrong.

I think what I will be needing is someway to query the messages table to extract events by timeline or should I be using the stream to populate a new set of read-side table to achieve functionality.


Solution

  • Cassandra (and the schema used by Akka Persistence Cassandra) is not generally well-suited to this query, not least because it will involve a scan of the whole keyspace, so will be rather inefficient.

    Accordingly, the ideal way to go will be to project the events (e.g. using Lagom's projections or Akka Projection) into a time-series database (that's one of the advantages of CQRS: the ability to use a query model that's maximally well-suited to answering the question). If you don't happen to have a time-series database readily available, with some effort you can implement the functionality in a more general purpose database like Cassandra or a relational DB.