0

In a CQRS/Event Sourcing system you have current state in the Read Model (as projections). But what if I need to get data at specific (older) date? In the Write Model you can replay events until the date you want but you shouldn't query the Write Model (using it as Read Model).
I think storing projections by date is not an option because of potential size of data.

What is the best approach to solve this? Any suggestions?

Jose Alonso Monge
  • 1,014
  • 1
  • 16
  • 29

1 Answers1

2

The events written as the write model are themselves also a read model. There's therefore not necessarily any problem with querying those events for all events up to some point in time and, to use the FP term, folding over them to derive the state at a point in time.

If one doesn't want to query the same datastore as used for processing commands, the most trivial projection is one to essentially create a replica of the event store for querying:

  • for each event, write that event to a database (perhaps enriching with timestamp, entity ID, tag, etc. columns)

This query over the persisted events (whether you query the write-side's event store or some replica of the event store for querying) can be the basis for any read model: read models with their own databases are just an optimization so repeated queries aren't always replaying the events and applying the same function in the fold.

Levi Ramsey
  • 18,884
  • 1
  • 16
  • 30