Data persistence using Event sourcing

Asked

Viewed 235 times

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?

1 answer

1

The type of database you use to implement Event Sourcing is indifferent. I believe that this is the fact of the doubt on this subject: it is not about applying different tools to solve new problems but rather seeing old problems differently and modelling them differently. This is independent of the tool used.

Despite the recent hype, the idea of Event Sourcing is not new. It already existed in 2000 and was published in 2005 by Martin Fowler: http://martinfowler.com/eaaDev/EventSourcing.html

His website explains very well the conception of the idea:

inserir a descrição da imagem aqui

Looking on the internet I also saw this presentation where, in practice, explains well the problems and advantages of Event Sourcing and makes this parallel between events and mapping relational objects.

https://ookami86.github.io/event-sourcing-in-practice/

I hope it helps!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.