hai detto cqrs a chi ?!?!?!
TRANSCRIPT
![Page 1: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/1.jpg)
…WHAT’S THAT CQRS THING?
introduction for adopters
effect
free!
![Page 2: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/2.jpg)
COMMAND QUERY RESPONSIBILITY
SEGREGATION PATTERN
![Page 3: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/3.jpg)
ORIGINAL SIN
CREATE
READ
UPDATE
DELETE
![Page 4: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/4.jpg)
![Page 5: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/5.jpg)
![Page 6: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/6.jpg)
is an architectural pattern proposed by Greg Young that segregates reads and writes of a system into two separate subsystems.
CQRS
![Page 7: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/7.jpg)
writes are usually asynchronous and stored in a transactional storage while reads are eventually consistent and retrieved from de-normalised views
CQRS (details)
![Page 8: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/8.jpg)
BERTRAND MAYERDesigner of Eiffel
programming language
Coined “open/closed principle” and “design
by contract”
Introduced command query separation
(CQS)
![Page 9: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/9.jpg)
Use of commands and queries separates write and read concerns
![Page 10: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/10.jpg)
COMMANDTell to do something
![Page 11: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/11.jpg)
COMMAND• Command is the message to change state
• Message handled by a CommandHandler
• Returns void (so nothing)
• Describes business intent
• Immutable
![Page 12: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/12.jpg)
QUERYFetch state from data store
![Page 13: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/13.jpg)
QUERY
• Read state from data store
• Does not change state
• Has a return value
![Page 14: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/14.jpg)
WHY SHOULD I USE CQRS?
• Scalability
• Reduced complexity
• Flexibility
• Focus on the business
![Page 15: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/15.jpg)
• Fear of change
• Mental leap
• All-Or-Nothing approach
BE AWARE OF
![Page 16: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/16.jpg)
CQRS MYTHS
• is easy
• CQRS = Event Sourcing and vice versa
• requires an eventual consistent read store
• requires a bus/queues/asynchronous messaging
![Page 17: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/17.jpg)
– Udi Dahan
“Most people using CQRS (and event sourcing too) shouldn't have done so”
– Greg Young
“It's important to note though, that these are things you can do, not necessarily things you should do.
Separating the read and write models can be quite costly”
WHEN SHOULD I AVOID IT?
![Page 18: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/18.jpg)
WHATS NEXT?
• Event sourcing (ES)
• Eventual consistency
• Task based UI
• …
![Page 19: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/19.jpg)
![Page 20: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/20.jpg)
Thank you.
@realfuzzyMichele Franzin
![Page 21: hai detto CQRS a chi ?!?!?!](https://reader034.vdocuments.pub/reader034/viewer/2022052308/58ece2381a28ab12398b461d/html5/thumbnails/21.jpg)
CREDITSslide10 - www.defenceimagery.mod.uk - 45155579slide 12 - https://www.flickr.com/photos/broeckxsven/slides 4,9 - http://martinfowler.com/bliki/
http://martinfowler.com/bliki/CQRS.htmlhttp://udidahan.com/2009/12/09/clarified-cqrs/https://en.wikipedia.org/wiki/Command–query_separationhttps://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf
RESOURCES