Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages to storing commands in a CQRS/ES system?

I am working on a CQRS/event store system. At the moment, the pattern that I use is for commands to be synchronous. That is, the user interface does not show an operation as completed until the command is complete, and the success/failure is shown to the user. During execution of the commands, all events generated (e.g., action X occurred on aggregate root Y) are stored in durable storage.

All of the descriptions of CQRS that I have read implement command storage. I am wondering if this is needed in my situation.

One other note - there are a lot of long running command type actions, so I have broken up operations into a command that generates events, and the events in turn issue more commands. The commands are idempotent, based on the state of the aggregate root. I don't know how this would impact the answer, but it is worth pointing out.

like image 764
Erick T Avatar asked Apr 18 '12 15:04

Erick T


People also ask

What is the command and query responsibility segregation CQRS pattern?

Command query responsibility segregation (CQRS) is a programming design pattern that treats retrieving data and changing data differently. CQRS uses command handlers to simplify the query process and hide complex, multi-system changes.

What is the difference between CQS and CQRS?

CQRS takes the defining principle of CQS and extends it to specific objects within a system, one retrieving data and one modifying data. CQRS is the broader architectural pattern, and CQS is the general principle of behaviour.

Are CQRS commands part of the domain model?

CQRS commands and the onion architectureCommands belong to the core domain (just like domain events). They play an important role in the CQRS architecture - they explicitly represent what the clients can do with the application. Just like events represent what the outcome of those actions could be.

Can we use CQRS without Event Sourcing?

Of course, CQRS can also be used without event sourcing or DDD, just as these concepts work without CQRS. However, there is no denying that the three concepts complement each other very well.

What is CQRS and Event Sourcing?

CQRS is by far the most common way that event sourcing is implemented in real-world applications. A CQRS system always has two sides, a write side and a read side: In the write side (shown on the left side of the diagram), you send commands or events, which are stored reliably.

Which is responsible for saving the events for Event Sourcing?

Instead of saving latest status of data into database, Event Sourcing pattern offers to save all events into database with sequential ordered of data events. This events database called event store. Instead of updating the status of a data record, it append each change to a sequential list of events.


2 Answers

  1. Regression testing After every dev iteration you can grab command log from production environment, re-execute it and compare event stream produced with one on production. If they different - you have regression in your logic.

  2. Message flow visualization and analysis.

like image 141
Yevhen Bobrov Avatar answered Sep 21 '22 19:09

Yevhen Bobrov


The examples of Cqrs that i've seen without event sourcing are usual relational databases that store the state of the system rather than Events which show how the state of the data came about. "Command sourcing" is a new concept for me and doesn't seem right since command handlers can change over time. Any changes to the command handlers logic would probably result in commands failing when replayed. Replaying events doesn't have this problem since your objects properties are directly set.

like image 29
Chris Moutray Avatar answered Sep 20 '22 19:09

Chris Moutray