Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Event Store / CQRS architecture, why are events stored instead of commands?

Presumably we could resurrect state by applying the same set of commands, so why not simply store commands rather than events?

like image 363
James L Avatar asked Feb 01 '13 22:02

James L


People also ask

What is difference between command and event?

Both are messages. They convey specific information; a command about the intent to do something, or an event about the fact that happened.

How do you store event sourcing data?

Instead of storing just the current state of the data in a domain, use an append-only store to record the full series of actions taken on that data. The store acts as the system of record and can be used to materialize the domain objects.

What is the difference between CQRS and event sourcing?

CQRS is implemented by a separation of responsibilities between commands and queries, and event sourcing is implemented by using the sequence of events to track changes in data.

What benefits do we get when we use event sourcing with CQRS?

Event sourcing is a powerful pattern and brings a lot of benefits to an application architecture if used appropriately: Makes write operations much faster as there is no read, update, and write required; write is merely appending an event to a log.


1 Answers

Events, communicate "this happened in our system". Events occur when a command has been accepted and processed. No one can reject or change the fact that it happened. It's the only authoritative source of changes in the system

Commands are just a way for a part of the system (like a UI) to tell the component in charge of making changes to the system (the "command handler") what it wants done. However, the command handler can choose not to process the command for various reasons. The UI could have stale information and processing the command wouldn't make business sense or the user could have not had the privileges to perform that action. Either way, the command is really just a request & have no bearing on the state of a system

.

like image 80
Jonathan Matheus Avatar answered Nov 03 '22 18:11

Jonathan Matheus