Search code examples
cqrsevent-sourcing

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?


Solution

  • 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

    .