My take on CQRS is when followed strictly your commands don't return anything (return type void), so my example is really straight forward: How do you retrieve an ID when creating something?
For example, when creating a credit card transaction it seems rather important to return a transaction ID, or when creating a customer it would be much easier if you got the customer you created or the customer ID back so a browser could navigate automatically to that customer page for example.
One solution could be to first ask for an ID and then create the customer or transaction with that ID, but it seems pretty weird.
Does anyone have any experience with this or know how it should be done in the most effective way? Maybe I have misunderstood something?
CQRS separates reads and writes into different models, using commands to update data, and queries to read data. Commands should be task-based, rather than data centric. ("Book hotel room", not "set ReservationStatus to Reserved").
What is CQRS? CQRS stands for Command and Query Responsibility Segregation. It is a command query pattern and can separate the read and write operations for a data store. CQRS uses a command and query pattern in which the command functionality only updates or writes data and the query functionality returns the data.
Understanding the CRQS pattern The Command Query Responsibility Segregation (CQRS) pattern separates a service's write tasks from its read tasks. While reading and writing to the same database is acceptable for small applications, distributed applications operating at web-scale require a segmented approach.
CQRS is all about fire-and-forget, and since GUIDs are very reliable (low risk of collision) there is no problem sending in a GUID that you generate your self.
The steps would basically be:
Read more about GUIDs on Wikipedia
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With