Patrick Wood
Patrick Wood

Reputation: 45

Akka.net Persistence Query -Events by Tag- stream order guarantee

I am working on building a solution with Akka.net that will allow for a persistence query that queries multiple tags. One of the ways i thought of doing this was to simply materialize 1 stream for each tag and then use akka.net stream abstractions to merge the streams with ordering.

However, Getakka.net (https://getakka.net/articles/persistence/persistence-query.html#eventsbytag-and-currenteventsbytag) guidance on the pre-defined queries that journals may have available indicates that queries snapping multiple PersistenceIds have no Ordering guarantee. I was wondering if this was because akka.net leaves read journal implementation up to the individual plugins or if there was inherently an issue with ordering and akka.net streams?

Were i to use a SQL based event store, it looks like the base abstract QueryExecutor allows for creating an ordered stream:

ByTagSql =
          $@"
          SELECT {allEventColumnNames}, e.{Configuration.OrderingColumnName} as Ordering
          FROM {Configuration.FullJournalTableName} e
          WHERE e.{Configuration.OrderingColumnName} > @Ordering AND e. 
          {Configuration.TagsColumnName} LIKE @Tag

          ***ORDER BY {Configuration.OrderingColumnName} ASC";***

Can anyone confirm if the lack of a "SelectByTag" query order guarantee is related to the underlying akka.net streaming platform OR the fact that each journal plugin is independently created by someone other than the akka.net team (or something else that i'm not thinking of) ?

Thanks!!

Upvotes: 1

Views: 204

Answers (1)

Aaronontheweb
Aaronontheweb

Reputation: 8404

I was wondering if this was because akka.net leaves read journal implementation up to the individual plugins or if there was inherently an issue with ordering and akka.net streams?

It's the former - for most journal implementations we work very hard to make sure that global order is preserved across all persistence ids through the use of a separate "Ordering" column, which is what typically get used in the Offset in Akka.Persistence.Query. However, we can't guarantee that DatabaseWeHaveNeverHeardOf will necessarily honor that in terms of how it internally produces reads / writes.

Meaning, that Akka.Persistence.Query doesn't enforce an ordering guarantee in its C# code - rather, we rely on the database to do that for us. Some are more consistent about it than others.

Can anyone confirm if the lack of a "SelectByTag" query order guarantee is related to the underlying akka.net streaming platform OR the fact that each journal plugin is independently created by someone other than the akka.net team (or something else that i'm not thinking of) ?

Most SelectByTag queries will be ordered if they've been developed by the Akka.NET team and if that's supported in the underlying database. Akka.Persistence.Azure / Akka.Persistence.*SQL / Akka.Persistence.Linq2Db all being good examples ones that preserve orering.

Upvotes: 2

Related Questions