CQRS with an Event Log and without Event Sourcing

cqrsdomain-driven-designevent-sourcing

I am trying to understand the difference between an event log and event store in the context of event sourcing.

A really nice explanation I found is that an event store is the single source of truth for the write model and an event log is the single source of truth for the read model.

Therefore say I wanted to use CQRS without Event Sourcing, then the way I understand it is that I would have an event log write model (Domain Objects serialised to an SQL database) and a NoSQL (MongoDB) read model. The two databases could be in separate API projects communicating using a RabbitMQ.

On that basis it is not a bad idea to use an EventLog when using CQRS without Event Sourcing i.e. when the business is not interested in replaying historic events (in my case the system only has one event).

Is it acceptable for the EventLog to be the write database? i.e. it would contain serialized domain objects.

Have I understood this correctly?

Best Answer

I can't find any authoritative answer between the difference between the two terms: "event log" and "event store". Martin Fowler uses both terms in this post but it's not clear if there is a difference. I think one cannot compare them, they are somewhat orthogonal or from different domains. An Event store is an Event log, that is, a log/list of all events that happened, ordered by the time they occurred.

An Event store is an event persistence that should have the following characteristics:

  • it contains a list of events
  • the events are logically grouped into streams
  • the events in a stream are appended in the order they occurred
  • it can detect/prevent concurrent appending of events on the same stream
  • it is optimised for loading of events on a given stream, in the order they occurred and from a specific point-in-time/stream-version

An Event log is just a list of events that could have the following characteristics:

  • the events could be totally ordered
  • it could fetch all events in the order they occurred and from a specific point in time

So, one could have an event persistence that is an Event store and an Event log, at the same time, at the cost of scalability, of course.

We can notice that an Event log is something that is needed more by the ReadModels because it's easier to design a ReadModel that processes the events in the order they occurred, across all streams.

A really nice explanation I found is that an event store is the single source of truth for the write model and an event log is the single source of truth for the read model.

The "source of truth" is the entity that owns the data, that can guarantee the correctness of the data. For example, the source of truth for the number of items in stock showed on the UI of an online store is the physical warehouse, not it's Event store/database. You cannot say that a something is a source of truth for some consumer; it is or it is not a source of truth, a producer of some truth; it's irrelevant who consumes the truth when deciding that some source is the source of truth.

Related Topic