DDD \ CQRS \ Event Sourcing and Querying Historical Data

2 answers


If I understand your question correctly, you want to request data. Within CQRS, there is a separation between retrieving data (via queries) and writing / configuring data (via commands). Every time you want to change data (via a command), you fire an event and store it in the EventStore. You can use Projection to create the presentation you want for the data, you can even save it to another database.

I will try to give an example for your example:



  • every hour an event is triggered in the EventStore with the current weather conditions and measurement time date (this could be a solution to import old data).
  • eventstore, launches a projection (with your own desired presentation), which is stored in another database (which you can easily query)
  • this database is accessible through queries.

It might be possible to leave another database, but this might be a solution to offer queries faster, because this database (with its replicas) is only responsible for reading in your application, while your eventstore does all the heavy lifting (writes ).

+1


source


Typically, to get a historical view, you only load an aggregate with events up to the time period of interest. This will give you a snapshot view at that time.

How do you get the current weather forecast? Downloading all weather events of all time for the requested location?



If the whole graphic drawing, etc. is done by clients and you are just delivering events, then you can simply allow clients to request part of the event flow through your api. You would not "publish" these events again to all clients as it has already happened. Clients will either call your api to be notified of "new" events, or receive "historical" events, or receive events from the moment following new events.

At least that's my understanding of how it will work.

0


source







All Articles