ruby-on-railsrubycqrsevent-sourcingrails-event-store

Persistent relational projections in RailsEventStore


I am trying to build a CQRS and event sourced Rails 5.2.x application using RailsEventStore.

Now I would like to project my event stream into a relational model, ideally just using ActiveRecord and the PostgreSQL database I also used for my event store.

In the documentation of RailsEventStore I only found on-the-fly, non-persistent projections.

Is there any infrastructure available to continuously build and update a relational representation of an event stream? It needs to remember which events have already been applied to the relational model across restarts of the application.

In case you know how to do it, please let me know.


Solution

  • There is no out-of-the-box background process in RailsEventStore to support persistent projections the same way EventStore database does them.

    There are however pieces you can fit together to achieve something similar — event handlers and linking.

    My colleague Rafał put together a few posts documenting this approach:

    If you'd like to implement such projection as a separate background process rather to rely on event handlers (whether synchronous or not) then Distributed RailsEventStore with PgLinearizedRepository might be a good starting point.