SlideShare a Scribd company logo
1 of 21
Query or Command
(Short) Introduction to CQRS
Zbyszko Papierski
Solutions Architect @ allegro.pl
Twitter: @ZPapierski
Linkedin: https://www.linkedin.com/in/zbyszko
http://allegrotech.io/authors/zbyszko.papierski/
C.R.U.D.
Command
Query
Responsibility
Segregation
Greg Young
Bertrand Meyer
Martin Fowler
Command (vs) Query
Responsibility Segregation
NOT
one style to rule them all
scalable
but
eventually consistent
more elastic
but
more (globally) complex
What’s next?
Event Sourcing
Task Based UI
Google says you don’t need that save button...
Technology Stack?
Axon Framework
Jdon
Anything you like
Stack Example - communication
● Kafka - distributed pub/sub
● AngularJS - js framework with good
ansychronous mechanisms
● Vert.X - asynchronous web
communication
● RxJava - Reactive view changes
Stack Example - db solutions
● any db you need
● Cassandra - extremely fast writes and
pretty fast reads
● MongoDB - fast document store
● Akka Persistence - great
implementation of Event Sourcing
Key Takeaways
● As always - “right tool for the job”
● Build your views asynchronously
● Consider what is the best model for
each query and each command
● Consider your consistency and
performance requirements
Mandatory Links Slide
● https://cqrs.wordpress.com/ - not updated,
but interesting read
● http://martinfowler.com/bliki/CQRS.html -
Martin Fowler on CQRS
● http://www.axonframework.org/
● http://en.jdon.com/
???

More Related Content

What's hot

Debugging Grails Database Performance
Debugging Grails Database PerformanceDebugging Grails Database Performance
Debugging Grails Database Performance
Energized Work
 
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
OdessaJS Conf
 

What's hot (12)

Debugging Grails Database Performance
Debugging Grails Database PerformanceDebugging Grails Database Performance
Debugging Grails Database Performance
 
Programming pillars
Programming pillarsProgramming pillars
Programming pillars
 
Testing JavaScript with Jasmine
Testing JavaScript with JasmineTesting JavaScript with Jasmine
Testing JavaScript with Jasmine
 
Frontend performance metrics
Frontend performance metricsFrontend performance metrics
Frontend performance metrics
 
Measuring Front-End Performance - What, When and How?
Measuring Front-End Performance - What, When and How?Measuring Front-End Performance - What, When and How?
Measuring Front-End Performance - What, When and How?
 
Node.js basics
Node.js basicsNode.js basics
Node.js basics
 
Advent of magento2
Advent of magento2Advent of magento2
Advent of magento2
 
Moving From Angular to React
Moving From Angular to ReactMoving From Angular to React
Moving From Angular to React
 
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
Максим Климишин "Що такого особливого у пропозиції вартості шаблону Micro Fro...
 
Stripe con 2021 UI stack
Stripe con 2021 UI stackStripe con 2021 UI stack
Stripe con 2021 UI stack
 
Arsitektur Aplikasi Modern - Faisal Henry Susanto
Arsitektur Aplikasi Modern - Faisal Henry SusantoArsitektur Aplikasi Modern - Faisal Henry Susanto
Arsitektur Aplikasi Modern - Faisal Henry Susanto
 
Reusability is the goal
Reusability is the goalReusability is the goal
Reusability is the goal
 

Similar to Query or Command - (short) introduction to CQRS

Similar to Query or Command - (short) introduction to CQRS (20)

JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
Batch Processing with Amazon EC2 Container Service
Batch Processing with Amazon EC2 Container ServiceBatch Processing with Amazon EC2 Container Service
Batch Processing with Amazon EC2 Container Service
 
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
Критика "библиотечного" подхода в разработке под Android. UA Mobile 2016.
 
Spark Workflow Management
Spark Workflow ManagementSpark Workflow Management
Spark Workflow Management
 
Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference
Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. UnconferenceFlavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference
Flavius Ștef: Big Rewrites Without Big Risks at I T.A.K.E. Unconference
 
Big rewrites without big risks
Big rewrites without big risksBig rewrites without big risks
Big rewrites without big risks
 
CQRS recepies
CQRS recepiesCQRS recepies
CQRS recepies
 
LAMP is so yesterday, MEAN is so tomorrow! :)
LAMP is so yesterday, MEAN is so tomorrow! :) LAMP is so yesterday, MEAN is so tomorrow! :)
LAMP is so yesterday, MEAN is so tomorrow! :)
 
Angular From The Trenches - 10 Lessons
Angular From The Trenches - 10 LessonsAngular From The Trenches - 10 Lessons
Angular From The Trenches - 10 Lessons
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
CQRS In An Hour Or So
CQRS In An Hour Or SoCQRS In An Hour Or So
CQRS In An Hour Or So
 
Joomla!Day Poland 2013 - Joomla Architecture (Ofer Cohen)
Joomla!Day Poland 2013 - Joomla Architecture  (Ofer Cohen)Joomla!Day Poland 2013 - Joomla Architecture  (Ofer Cohen)
Joomla!Day Poland 2013 - Joomla Architecture (Ofer Cohen)
 
Deep dive into Android async operations
Deep dive into Android async operationsDeep dive into Android async operations
Deep dive into Android async operations
 
Daniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého SchizmaDaniel Steigerwald - Este.js - konec velkého Schizma
Daniel Steigerwald - Este.js - konec velkého Schizma
 
Agile
AgileAgile
Agile
 
Few Tips for asp.net developers 2014 and beyond
Few Tips for asp.net developers 2014 and beyondFew Tips for asp.net developers 2014 and beyond
Few Tips for asp.net developers 2014 and beyond
 
Rapid app building with loopback framework
Rapid app building with loopback frameworkRapid app building with loopback framework
Rapid app building with loopback framework
 
Gnizr Architecture (for developers)
Gnizr Architecture (for developers)Gnizr Architecture (for developers)
Gnizr Architecture (for developers)
 
Flux architecture and Redux - theory, context and practice
Flux architecture and Redux - theory, context and practiceFlux architecture and Redux - theory, context and practice
Flux architecture and Redux - theory, context and practice
 

Recently uploaded

Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
raffaeleoman
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
amilabibi1
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
Kayode Fayemi
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
Sheetaleventcompany
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
Kayode Fayemi
 

Recently uploaded (20)

lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.lONG QUESTION ANSWER PAKISTAN STUDIES10.
lONG QUESTION ANSWER PAKISTAN STUDIES10.
 
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
Busty Desi⚡Call Girls in Sector 51 Noida Escorts >༒8448380779 Escort Service-...
 
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 97 Noida Escorts >༒8448380779 Escort Service
 
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptxChiulli_Aurora_Oman_Raffaele_Beowulf.pptx
Chiulli_Aurora_Oman_Raffaele_Beowulf.pptx
 
Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510Thirunelveli call girls Tamil escorts 7877702510
Thirunelveli call girls Tamil escorts 7877702510
 
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdfThe workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
The workplace ecosystem of the future 24.4.2024 Fabritius_share ii.pdf
 
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
Bring back lost lover in USA, Canada ,Uk ,Australia ,London Lost Love Spell C...
 
ICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdfICT role in 21st century education and it's challenges.pdf
ICT role in 21st century education and it's challenges.pdf
 
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdfAWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
AWS Data Engineer Associate (DEA-C01) Exam Dumps 2024.pdf
 
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort ServiceBDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
BDSM⚡Call Girls in Sector 93 Noida Escorts >༒8448380779 Escort Service
 
Air breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animalsAir breathing and respiratory adaptations in diver animals
Air breathing and respiratory adaptations in diver animals
 
Uncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac FolorunsoUncommon Grace The Autobiography of Isaac Folorunso
Uncommon Grace The Autobiography of Isaac Folorunso
 
Causes of poverty in France presentation.pptx
Causes of poverty in France presentation.pptxCauses of poverty in France presentation.pptx
Causes of poverty in France presentation.pptx
 
Dreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio IIIDreaming Music Video Treatment _ Project & Portfolio III
Dreaming Music Video Treatment _ Project & Portfolio III
 
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
Aesthetic Colaba Mumbai Cst Call girls 📞 7738631006 Grant road Call Girls ❤️-...
 
Report Writing Webinar Training
Report Writing Webinar TrainingReport Writing Webinar Training
Report Writing Webinar Training
 
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
No Advance 8868886958 Chandigarh Call Girls , Indian Call Girls For Full Nigh...
 
If this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New NigeriaIf this Giant Must Walk: A Manifesto for a New Nigeria
If this Giant Must Walk: A Manifesto for a New Nigeria
 
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, YardstickSaaStr Workshop Wednesday w/ Lucas Price, Yardstick
SaaStr Workshop Wednesday w/ Lucas Price, Yardstick
 
Presentation on Engagement in Book Clubs
Presentation on Engagement in Book ClubsPresentation on Engagement in Book Clubs
Presentation on Engagement in Book Clubs
 

Query or Command - (short) introduction to CQRS

Editor's Notes

  1. Witajcie. Jestem Zbyszko. Pracuję w Allegro jako architekt rozwiązań. Chciałbym dziś z Wami porozmawiać o pewnym popularnym wzorcu o nazwie CQRS. Chcę Wam pokazać przykładowy diagram opisującą dość klasyczny przypadek, opowiedzieć trochę o zyskach i problemach związanych z CQRS, a także opisać pokrótce kilka narzędzi ułatwiających pracę z CQRS, także odnosząc się do mojego doświadczenia w temacie. Wzorzec ten może wydać się Wam w wielu miejscach znajomy, mam nadzieje jednak, że moja prezentacja pozwoli Wam uzyskać większą świadomość wykorzystaniu go w pracy codziennej.
  2. CRUDa każdy zna - Create Read Update Delete CRUD jest łatwy ale mało elastyczny nasze dane rzadko od razu wyglądają tak jak chcemy zwykle bazy dające nam swobodę modelowania nie są szybkie, szybkie nie dają swobody modelowania
  3. Oparta o koncepcję Command–query separation - Bertranda Meyera Koncepcję rozwinął Greg Young do formy Command Query Responsibility Segregation Duży wkład w rozpropagowanie idei ma do dziś Martin Fowler
  4. Każda metoda jest albo poleceniem (Command) albo zapytaniem (Query)
  5. Polecenia i zapytania są od siebie fizycznie oddzielone Zarówno procesy jak i model są oddzielne
  6. Basic assumption - View does not to be 100% accurate 100% of the time (in any case, it rarely is) Query - Getting data for some purpose (e.g. page rendering) Command - instruction for data update Autonomous Component - component seperate from other components in the system There must be some way to synchronize autonomous components
  7. Query call are most of the times synchronous Commands don’t have to - but it would be great to handle events about execution Simple way to synchronize querable components - events
  8. Autonomous components do not share model or backends Query Model should be optimized for queries - denormalization and lack of typical relations (as in RDBMS) is normal! Domain model represents the abstraction of our knowledge about the domain and can have completely different performance requirements QueryDB is not mandatory - can be replaced by a caching solution
  9. CQRS używamy przede wszystkim wtedy, kiedy model zapytań się różni od modelu domenowego mamy różne wymagania wydajnościowe wobec zapytań i zapisów możemy pozwolić sobie na system ostatecznie spójny
  10. Nie jesteśmy ograniczeni ilością w tym modelu - usług widokowych może być więcej, mogą też reprezentować więcej niż jeden model tej samej informacji Nic nie stoi na przekodzie żeby polecenie miały oddzielne modele poleceń Nie jest to styl transakcyjny!
  11. Polecenia i zapytania są od siebie fizycznie oddzielone Zarówno procesy jak i model są oddzielne Model zapytań może bardzo dokładnie odwzorowywać nasze zapotrzebowanie system lokalnie może być prostszy, ale globalnie jest bardziej złożony synchronizacja stanowi narzut jeśli chodzi o globalną złożoność model odwzorowujący lokalny potrzebę zmniejsza lokalną złożoność
  12. Co daje nam CQRS już mniej więcej opowiedzieliśmy, ale to nie wszystko
  13. Nie tyle zysk co sposób uzyskania CQRS - Na podstawie eventów odwzorowujemy kształt w naszym systemie event powinien posiadać nową wartość po update zwykle są mechanizmy na odzyskanie ich w razie awarii node’a
  14. Rodzaj UI który rozdziela funkcjonalności na pojedynczej stronie na odseparowane od siebie procesy Przykład - Dokumenty Google’a, Gmail (drafty tworzone są na bieżąco) Wszystkie polecenia idą asynchronicznie, ale istnieją mechanizmy sprawdzające (i wyświetlające!) czy polecenie się udało (“All changes saved in Drive”) Oczywiście inne widoki (strony) nie zawsze będą 100% na bieżąco, ale zwykle trwa to na tyle mało czasu, że nie robi to różnicy
  15. Czy istnieją rozwiązania wspomagające?
  16. Istnieją frameworki wspomagające implementację CQRS - Axon czy Jdon Nie ma potrzeby budowania frameworków CQRS - jest to styl architektoniczny, można go zaimplementować używając tego co akurat potrzebujesz
  17. Kafka - świetna metoda powiadamiania innych komponentów o zmianach AngularJS ułatwia asynchroniczną komunikację z frontendem (pozwala na to nawet JS, angularJS pozwala to obudować w wygodne struktrury) Vert.x - jego częścią jest niezły mechanizm komunikacyjny, pozwalający nawet na komunikację z przeglądarków użytkownika za pomocą WebSocketów RxJava - programowanie reaktywne dobrze wpasowuje się w ideę asynchronicznej komunikacji
  18. Jaką bazę potrzebujesz, taką użyj Cassandra - świetna baza jeśli musisz naprawdę dużo pisać Mongo DB - jsonowatość bazy pozwala na dobre odwzorowanie danych widokowych, a także szybką modyfikację jej części Akka Persisistence - świetny mechanizm do implementacji Event Sourceingu - pozwala nie tylko na zapisywanie zdarzeń do wybranej bazy, ale także tworzenie snapshotów (nawet w kompletnie innej, lepiej nadającej się do celu, bazie)
  19. Używaj właściwego narzędzia - czy jest nim framework, system kolejkowy czy baza danych Staraj się budować swoje widoki tak, żeby najrzadziej musiały się dobijać do innych komponentów systemu, dostarczając im dane w sposób asynchroniczny Tak samo jak w pierwszym punkcie - myśl lokalnie o reprezentacji swoich danych - nie ma powodu dla którego model widoku czy poleceń nie może być dokładnie taki jaki potrzebujesz CQRS nie jest dla każdej sytuacji - weź pod uwagę jakie masz wymagania dotyczące spójności i wydajności dostępu do danych
  20. Rodzaj UI który rozdziela funkcjonalności na pojedynczej stronie na odseparowane od siebie procesy Przykład - Dokumenty Google’a, Gmail (drafty tworzone są na bieżąco) Wszystkie polecenia idą asynchronicznie, ale istnieją mechanizmy sprawdzające (i wyświetlające!) czy polecenie się udało (“All changes saved in Drive”) Oczywiście inne widoki (strony) nie zawsze będą 100% na bieżąco, ale zwykle trwa to na tyle mało czasu, że nie robi to różnicy