1
Recently I heard about Event Soucring in a video by Greg Young and I found an idea that seems to be very useful in various systems where having a data history is important.
What I understood is that instead of persisting the state of the system entities and updating as the state changes, we persist events, which correspond to the state modifications.
As I understand it, the events corresponding to each aggregate present in the domain model persist, which makes sense, since the aggregates are treated as a whole in the field.
My only question is, how does one persist in events? Persisting status is no longer trivial in relational databases, but we can handle this by mapping properties to table columns.
On the other hand, is it not clear to me how to persist events in practice? Do we use relational banks, or do we have to use a different type of specific bank for that?
The only thing I thought would be to have a relational database, with a table for each event of each aggregate. So if an aggregate is Pedido
representing a request, we would have tables PedidoCriado
, PedidoAlterado
, PedidoCancelado
with data related to the event.
But that doesn’t seem like the right way, because it looks like it could get a little messy over time. Also, when you change an order, many properties stay the same. If the idea is to save only the deltas, only the event itself, many columns would be blank.
Anyway, if I want to use Event Sourcing and persist the events instead of persisting the state, how should I persist these events? What is the right mechanism to do this?