Hello everyone.
I'm fairly new to CQRS/event sourcing and I'm struggling a bit with many different implementation details. One such detail is about the structure of event storage. While all the events in the system share many similar properties, at the core they contain different details pertaining to a particular occurrence or state transition. This means that essentially each event is modeled differently from the others. Now, I'm quite confused as to how to go about storing such data. My original idea is to define an Event class with timestamp, id, etc. and to represent the actual event details a JSON formatted string. However, I felt as if representing the event data as a blob of JSON-formatted string can make the processing code cumbersome.
Now, what I'm considering is to model events in such a way that it's easy to keep track of them chronologically, while keeping the details in their own buckets so to speak. There will be an Event class that holds timestamp and some essential metada about the event, but ultimately the details will be kept separate. Something like the following (Java code):
class Event {
private String id;
private Instant timestamp;
private String type; //mostly a string representation of the actual event
private String eventDetailsId;
}
class OrderCreated {
private String id;
private String orderId;
private List<LineItem> lineItems;
}
These are simplified models to convey the general idea. I'm not sure if it's necessary to create a specific value objects to represent the id's, but yeah, this is how I think the model will be. Essentially Event objects are just pointers to actual event details. When rebuilding the query database for example, the first step is to get all the Event objects then one by one process them by retrieving the details from specific buckets. However, I'm not so sure if anyone has tried this approach and found some critical hurdles that I should be aware of this early. How are others approaching this problem?