best event sourcing db strategy

SharpNoiZy picture SharpNoiZy · Feb 23, 2015 · Viewed 32.4k times · Source

I want to setup a small event sourcing lib. I read a few tutorials online, everything understood so far.

The only problem is, in these different tutorials, there are two different database strategies, but without any comments why they use the one they use.

So, I want to ask for your opinion. And important, why do you prefer the solution you choose.

  1. Solution is the db structure where you create one table for each event.

  2. Solution is the db structure where you create only one generic table, and save the events as serialized string to one column.

In both cases I'm not sure how they handle event changes, maybe they create a whole new one.

Kind regards

Answer

Codescribler picture Codescribler · Feb 23, 2015

I built my own event sourcing lib and I opted for option 2 and here's why.

  • You query the event stream by aggregate id not event type.
  • Reproducing the events in order would be a pain if they are all in different tables
  • It would make upgrading events a bit of pain

There is an argument to say you can store events on a per aggregate but that depends of the requirements of the project.

I do have some posts about how event streams are used that you may find helpful.