SlideShare une entreprise Scribd logo
1  sur  53
CQRS - Innovative solution for problems
of modern enterprise architectures.

 Andrey Lomakin (lomakin.andrey@gmail.com)
 Artem Orobets (enisher@gmail.com)
January 1, 2013    www.ExigenServices.com
Table of content

1. Why CQRS ?
   a) Milestones of enterprise architecture history
   b) Pitfalls of CRUD
   c) CQRS as solution
2. CQRS internals
3. Axon framework as CQRS implementation




                                                      2   www.ExigenServices.com
Why CQRS ?




I. Why CQRS ?

             3   www.ExigenServices.com
Back to the beginning


Lets talk about evolution of enterprise
             architecture
                ?




                               4   www.ExigenServices.com
Evolution of presentation of documents




Epoch of paper documents
                            5   www.ExigenServices.com
Evolution of presentation of documents




Epoch of electronic storages
                            6   www.ExigenServices.com
Epoch of electronic storages




                           7   www.ExigenServices.com
Epoch of electronic storages




                           8   www.ExigenServices.com
Evolution of data processing

Epoch of business processes




                               9   www.ExigenServices.com
However…




CRUD approach is oriented on data
 manipulation, but not on business
         logic modeling .



                           10   www.ExigenServices.com
Pitfalls of CRUD




   II. Pitfalls of CRUD



                          11   www.ExigenServices.com
Problem #1. Usage of JavaBeans ….

JavaBean – “Reusable software components
that can be manipulated visually in a builder
tool”.




                                     12   www.ExigenServices.com
… results in …

1. Broken encapsulation of business
   objects.
2. Worse code readability.
3. Harder maintainability.
4. All business logic
   is placed in service
   methods.

                                 13   www.ExigenServices.com
Problem #2. Performance
optimization and consequences.



Usage of ORM tools with
 denormalization dilutes




                           14    www.ExigenServices.com
Problem #3. Scalability


During business data processing we always chose
                C in CAP theorem




                                    15   www.ExigenServices.com
Problem #4:In real life concurrent data
         modification conflicts do not exist.




 Real life business processes do not have
  concurrent data modification conflicts.
 Detection of such conflict is sign of flaw in
  implementation of business logic.
 CRUD does not take this into account.

                                          16   www.ExigenServices.com
CQRS as solution




III. CQRS as solution
                     17   www.ExigenServices.com
CQRS




CQRS - Command Query
Responsibility Segregation

                    18   www.ExigenServices.com
Problem # 1: Usage of JavaBeans



JavaBeans are still used on query side only
     but JavaBean != Domain Entity.




                                    19    www.ExigenServices.com
Problem #2. Performance optimization and
  consequences.




Data denormailzation is used
     on query side only



                                20   www.ExigenServices.com
Data on query side

Each table – reflection of presentation of data on user
                         screen.

     Database are not restricted to be SQL only.

  Possible alternatives - Apache Cassandra, HBase,
                     OrientDB ….


                                          21   www.ExigenServices.com
Problem #3. Scalability




 Data consistency is needed on business
  logic side only.
 On query side eventual consistency is
  totally acceptable.



                                  22   www.ExigenServices.com
Problem #4:In real life concurrent data
           modification conflicts do not exist.


Two approaches to present object state

1. In the form of values of variables inside object




                                            23   www.ExigenServices.com
Two approaches to present object state


                2. In form of event queue




+11.2 M $   + 5.3 M $                                  - 8.2 M $

                              Sum: 8.3 M $




                                             24   www.ExigenServices.com
Two approaches to present object state




 Each aggregate (DDD) – event container.
 There is no need to use relational
  databases.
 It is preferable to have DB with ACID
  properties.

                                    25   www.ExigenServices.com
Two approaches to present object state

Advantages:
   System monitoring support.
   Ability rollback system state till any moment in
    the past.
   Framework for data replication and conflict
    resolution.



                                         26   www.ExigenServices.com
Conflict resolution


 Correct
customer
 address

                          Conflict     Customer
                          resolver    reallocated

 Customer
reallocated




                                     27      www.ExigenServices.com
Architecture of CQRS applications




IV. Architecture of CQRS applications



                                   28   www.ExigenServices.com
CQRS – is approach only




       CQRS is approach only,
how it will be implemented, depends
                on you.


                                29   www.ExigenServices.com
Queries


  Multilayer architecture              CQRS

         DB query                     DB query


Conversion to domain model   Conversion to domain model


     Conversion to DTO           Conversion to DTO

   Transmutation of data        Transmutation of data
         to client                    to client

                                           31    www.ExigenServices.com
Commands

Command – presentation of business action, action
  which is meaningful for end user.

Advantages of usage of commands:
1. Orientation on business problems.
2. Convenient facilities for monitoring and scalability.




                                               33   www.ExigenServices.com
….advantages…..

1. Good preconditions for DDD usage.
2. Usage of complex event processing
   possibilities.
3. Simplicity of distribution of responsibilities
   between highly specialized commands.




                                      36   www.ExigenServices.com
CQRS frameworks




V. CQRS frameworks

                    37   www.ExigenServices.com
Axon framework




Axon framework - most popular and
           feature rich.

                          38   www.ExigenServices.com
Example of CQRS application




Address Book – address
 list management




                                      39   www.ExigenServices.com
Command creation and submission




                          41   www.ExigenServices.com
Command processing




                     43   www.ExigenServices.com
Business action




                  44   www.ExigenServices.com
Event processing on query side




                            45   www.ExigenServices.com
Query side




             47   www.ExigenServices.com
Simplicity of configuration




                              48   www.ExigenServices.com
Axon – repository и event store.



Repository

                                 JPA



Event Store

               File System       JPA            Mongo DB
                                           49      www.ExigenServices.com
Event Stores – pros and cons

    JPA Event Store

                            Mongo DB, File system




Transactional but slow

                             There is no ACID support
                                 better performance

                                          50   www.ExigenServices.com
Questions



            51   www.ExigenServices.com
Authors




 Artem Orobets. twitter: @Dr_EniSh ,
   enisher@gmail.com, skype: dr_enish
 Andrey Lomakin. twitter: @Andrey_Lomakin ,
  lomakin.andrey@gmail.com , skype: lomakin_andrey




                                                 52   www.ExigenServices.com
Sources

1. First CQRS introduction http://www.infoq.com/presentations/greg-
   young-unshackle-qcon08
2. CQRS architecture overview -
   http://elegantcode.com/2009/11/11/cqrs-la-greg-young/
3. Greg Young blog - http://codebetter.com/gregyoung/
4. Race conditions does not exist
   http://www.udidahan.com/2010/08/31/race-conditions-dont-exist/
5. Domain Driven Design Aggregator -
   http://domaindrivendesign.org/
6. Axon framework home page -
   http://code.google.com/p/axonframework/
7. Mark Nijhof blog http://cre8ivethought.com/blog


                                                     53    www.ExigenServices.com

Contenu connexe

Similaire à CQRS innovations (English version)

Enterprise Trends for MongoDB as a Service
Enterprise Trends for MongoDB as a ServiceEnterprise Trends for MongoDB as a Service
Enterprise Trends for MongoDB as a ServiceMongoDB
 
MicroServices-Part-1.pdf
MicroServices-Part-1.pdfMicroServices-Part-1.pdf
MicroServices-Part-1.pdfchanhluc2112
 
JavaBeer_Clean architecture_update.v2.pptx
JavaBeer_Clean architecture_update.v2.pptxJavaBeer_Clean architecture_update.v2.pptx
JavaBeer_Clean architecture_update.v2.pptxssuser78ac77
 
Solving enterprise applications performance puzzles queuing models to the r...
Solving enterprise applications performance puzzles   queuing models to the r...Solving enterprise applications performance puzzles   queuing models to the r...
Solving enterprise applications performance puzzles queuing models to the r...Leonid Grinshpan, Ph.D.
 
Dark Energy, Dark Matter and the Microservices Patterns?!
Dark Energy, Dark Matter and the Microservices Patterns?!Dark Energy, Dark Matter and the Microservices Patterns?!
Dark Energy, Dark Matter and the Microservices Patterns?!Chris Richardson
 
Database Performance Tuning Introduction
Database  Performance Tuning IntroductionDatabase  Performance Tuning Introduction
Database Performance Tuning IntroductionMyOnlineITCourses
 
WORKSHOP: Microservices as Containers on AWS
WORKSHOP: Microservices as Containers on AWSWORKSHOP: Microservices as Containers on AWS
WORKSHOP: Microservices as Containers on AWSCasey Lee
 
设计开发实效 Web2.0 应用程序
设计开发实效 Web2.0 应用程序设计开发实效 Web2.0 应用程序
设计开发实效 Web2.0 应用程序Shawn Zhu
 
Containers as Infrastructure for New Gen Apps
Containers as Infrastructure for New Gen AppsContainers as Infrastructure for New Gen Apps
Containers as Infrastructure for New Gen AppsKhalid Ahmed
 
Efficient Performance Analysis and Tuning with MySQL Enterprise Monitor
Efficient Performance Analysis and Tuning with MySQL Enterprise MonitorEfficient Performance Analysis and Tuning with MySQL Enterprise Monitor
Efficient Performance Analysis and Tuning with MySQL Enterprise MonitorMark Matthews
 
Sunserver Open Solaris
Sunserver Open SolarisSunserver Open Solaris
Sunserver Open Solarispankaj009
 
Refactoring to Microservices
Refactoring to MicroservicesRefactoring to Microservices
Refactoring to MicroservicesJacinto Limjap
 
Cytoscape CI Chapter 2
Cytoscape CI Chapter 2Cytoscape CI Chapter 2
Cytoscape CI Chapter 2bdemchak
 
Stateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the CloudStateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the CloudMarkus Eisele
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaAraf Karsh Hamid
 
When Architecture Meets Data
When Architecture Meets DataWhen Architecture Meets Data
When Architecture Meets DataEoin Woods
 
2016 - 10 questions you should answer before building a new microservice
2016 - 10 questions you should answer before building a new microservice2016 - 10 questions you should answer before building a new microservice
2016 - 10 questions you should answer before building a new microservicedevopsdaysaustin
 
Introduction to enterprise applications capacity planning
Introduction to enterprise applications capacity planning Introduction to enterprise applications capacity planning
Introduction to enterprise applications capacity planning Leonid Grinshpan, Ph.D.
 
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...Amazon Web Services
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolithStay productive while slicing up the monolith
Stay productive while slicing up the monolithMarkus Eisele
 

Similaire à CQRS innovations (English version) (20)

Enterprise Trends for MongoDB as a Service
Enterprise Trends for MongoDB as a ServiceEnterprise Trends for MongoDB as a Service
Enterprise Trends for MongoDB as a Service
 
MicroServices-Part-1.pdf
MicroServices-Part-1.pdfMicroServices-Part-1.pdf
MicroServices-Part-1.pdf
 
JavaBeer_Clean architecture_update.v2.pptx
JavaBeer_Clean architecture_update.v2.pptxJavaBeer_Clean architecture_update.v2.pptx
JavaBeer_Clean architecture_update.v2.pptx
 
Solving enterprise applications performance puzzles queuing models to the r...
Solving enterprise applications performance puzzles   queuing models to the r...Solving enterprise applications performance puzzles   queuing models to the r...
Solving enterprise applications performance puzzles queuing models to the r...
 
Dark Energy, Dark Matter and the Microservices Patterns?!
Dark Energy, Dark Matter and the Microservices Patterns?!Dark Energy, Dark Matter and the Microservices Patterns?!
Dark Energy, Dark Matter and the Microservices Patterns?!
 
Database Performance Tuning Introduction
Database  Performance Tuning IntroductionDatabase  Performance Tuning Introduction
Database Performance Tuning Introduction
 
WORKSHOP: Microservices as Containers on AWS
WORKSHOP: Microservices as Containers on AWSWORKSHOP: Microservices as Containers on AWS
WORKSHOP: Microservices as Containers on AWS
 
设计开发实效 Web2.0 应用程序
设计开发实效 Web2.0 应用程序设计开发实效 Web2.0 应用程序
设计开发实效 Web2.0 应用程序
 
Containers as Infrastructure for New Gen Apps
Containers as Infrastructure for New Gen AppsContainers as Infrastructure for New Gen Apps
Containers as Infrastructure for New Gen Apps
 
Efficient Performance Analysis and Tuning with MySQL Enterprise Monitor
Efficient Performance Analysis and Tuning with MySQL Enterprise MonitorEfficient Performance Analysis and Tuning with MySQL Enterprise Monitor
Efficient Performance Analysis and Tuning with MySQL Enterprise Monitor
 
Sunserver Open Solaris
Sunserver Open SolarisSunserver Open Solaris
Sunserver Open Solaris
 
Refactoring to Microservices
Refactoring to MicroservicesRefactoring to Microservices
Refactoring to Microservices
 
Cytoscape CI Chapter 2
Cytoscape CI Chapter 2Cytoscape CI Chapter 2
Cytoscape CI Chapter 2
 
Stateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the CloudStateful on Stateless - The Future of Applications in the Cloud
Stateful on Stateless - The Future of Applications in the Cloud
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and Kafka
 
When Architecture Meets Data
When Architecture Meets DataWhen Architecture Meets Data
When Architecture Meets Data
 
2016 - 10 questions you should answer before building a new microservice
2016 - 10 questions you should answer before building a new microservice2016 - 10 questions you should answer before building a new microservice
2016 - 10 questions you should answer before building a new microservice
 
Introduction to enterprise applications capacity planning
Introduction to enterprise applications capacity planning Introduction to enterprise applications capacity planning
Introduction to enterprise applications capacity planning
 
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...
AWS Partner Webcast - Disaster Recovery: Implementing DR Across On-premises a...
 
Stay productive while slicing up the monolith
Stay productive while slicing up the monolithStay productive while slicing up the monolith
Stay productive while slicing up the monolith
 

Dernier

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Dernier (20)

Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

CQRS innovations (English version)

  • 1. CQRS - Innovative solution for problems of modern enterprise architectures. Andrey Lomakin (lomakin.andrey@gmail.com) Artem Orobets (enisher@gmail.com) January 1, 2013 www.ExigenServices.com
  • 2. Table of content 1. Why CQRS ? a) Milestones of enterprise architecture history b) Pitfalls of CRUD c) CQRS as solution 2. CQRS internals 3. Axon framework as CQRS implementation 2 www.ExigenServices.com
  • 3. Why CQRS ? I. Why CQRS ? 3 www.ExigenServices.com
  • 4. Back to the beginning Lets talk about evolution of enterprise architecture ? 4 www.ExigenServices.com
  • 5. Evolution of presentation of documents Epoch of paper documents 5 www.ExigenServices.com
  • 6. Evolution of presentation of documents Epoch of electronic storages 6 www.ExigenServices.com
  • 7. Epoch of electronic storages 7 www.ExigenServices.com
  • 8. Epoch of electronic storages 8 www.ExigenServices.com
  • 9. Evolution of data processing Epoch of business processes 9 www.ExigenServices.com
  • 10. However… CRUD approach is oriented on data manipulation, but not on business logic modeling . 10 www.ExigenServices.com
  • 11. Pitfalls of CRUD II. Pitfalls of CRUD 11 www.ExigenServices.com
  • 12. Problem #1. Usage of JavaBeans …. JavaBean – “Reusable software components that can be manipulated visually in a builder tool”. 12 www.ExigenServices.com
  • 13. … results in … 1. Broken encapsulation of business objects. 2. Worse code readability. 3. Harder maintainability. 4. All business logic is placed in service methods. 13 www.ExigenServices.com
  • 14. Problem #2. Performance optimization and consequences. Usage of ORM tools with denormalization dilutes 14 www.ExigenServices.com
  • 15. Problem #3. Scalability During business data processing we always chose C in CAP theorem 15 www.ExigenServices.com
  • 16. Problem #4:In real life concurrent data modification conflicts do not exist.  Real life business processes do not have concurrent data modification conflicts.  Detection of such conflict is sign of flaw in implementation of business logic.  CRUD does not take this into account. 16 www.ExigenServices.com
  • 17. CQRS as solution III. CQRS as solution 17 www.ExigenServices.com
  • 18. CQRS CQRS - Command Query Responsibility Segregation 18 www.ExigenServices.com
  • 19. Problem # 1: Usage of JavaBeans JavaBeans are still used on query side only but JavaBean != Domain Entity. 19 www.ExigenServices.com
  • 20. Problem #2. Performance optimization and consequences. Data denormailzation is used on query side only 20 www.ExigenServices.com
  • 21. Data on query side Each table – reflection of presentation of data on user screen. Database are not restricted to be SQL only. Possible alternatives - Apache Cassandra, HBase, OrientDB …. 21 www.ExigenServices.com
  • 22. Problem #3. Scalability  Data consistency is needed on business logic side only.  On query side eventual consistency is totally acceptable. 22 www.ExigenServices.com
  • 23. Problem #4:In real life concurrent data modification conflicts do not exist. Two approaches to present object state 1. In the form of values of variables inside object 23 www.ExigenServices.com
  • 24. Two approaches to present object state 2. In form of event queue +11.2 M $ + 5.3 M $ - 8.2 M $ Sum: 8.3 M $ 24 www.ExigenServices.com
  • 25. Two approaches to present object state  Each aggregate (DDD) – event container.  There is no need to use relational databases.  It is preferable to have DB with ACID properties. 25 www.ExigenServices.com
  • 26. Two approaches to present object state Advantages:  System monitoring support.  Ability rollback system state till any moment in the past.  Framework for data replication and conflict resolution. 26 www.ExigenServices.com
  • 27. Conflict resolution Correct customer address Conflict Customer resolver reallocated Customer reallocated 27 www.ExigenServices.com
  • 28. Architecture of CQRS applications IV. Architecture of CQRS applications 28 www.ExigenServices.com
  • 29. CQRS – is approach only CQRS is approach only, how it will be implemented, depends on you. 29 www.ExigenServices.com
  • 30.
  • 31. Queries Multilayer architecture CQRS DB query DB query Conversion to domain model Conversion to domain model Conversion to DTO Conversion to DTO Transmutation of data Transmutation of data to client to client 31 www.ExigenServices.com
  • 32.
  • 33. Commands Command – presentation of business action, action which is meaningful for end user. Advantages of usage of commands: 1. Orientation on business problems. 2. Convenient facilities for monitoring and scalability. 33 www.ExigenServices.com
  • 34.
  • 35.
  • 36. ….advantages….. 1. Good preconditions for DDD usage. 2. Usage of complex event processing possibilities. 3. Simplicity of distribution of responsibilities between highly specialized commands. 36 www.ExigenServices.com
  • 37. CQRS frameworks V. CQRS frameworks 37 www.ExigenServices.com
  • 38. Axon framework Axon framework - most popular and feature rich. 38 www.ExigenServices.com
  • 39. Example of CQRS application Address Book – address list management 39 www.ExigenServices.com
  • 40.
  • 41. Command creation and submission 41 www.ExigenServices.com
  • 42.
  • 43. Command processing 43 www.ExigenServices.com
  • 44. Business action 44 www.ExigenServices.com
  • 45. Event processing on query side 45 www.ExigenServices.com
  • 46.
  • 47. Query side 47 www.ExigenServices.com
  • 48. Simplicity of configuration 48 www.ExigenServices.com
  • 49. Axon – repository и event store. Repository JPA Event Store File System JPA Mongo DB 49 www.ExigenServices.com
  • 50. Event Stores – pros and cons JPA Event Store Mongo DB, File system Transactional but slow There is no ACID support better performance 50 www.ExigenServices.com
  • 51. Questions 51 www.ExigenServices.com
  • 52. Authors  Artem Orobets. twitter: @Dr_EniSh , enisher@gmail.com, skype: dr_enish  Andrey Lomakin. twitter: @Andrey_Lomakin , lomakin.andrey@gmail.com , skype: lomakin_andrey 52 www.ExigenServices.com
  • 53. Sources 1. First CQRS introduction http://www.infoq.com/presentations/greg- young-unshackle-qcon08 2. CQRS architecture overview - http://elegantcode.com/2009/11/11/cqrs-la-greg-young/ 3. Greg Young blog - http://codebetter.com/gregyoung/ 4. Race conditions does not exist http://www.udidahan.com/2010/08/31/race-conditions-dont-exist/ 5. Domain Driven Design Aggregator - http://domaindrivendesign.org/ 6. Axon framework home page - http://code.google.com/p/axonframework/ 7. Mark Nijhof blog http://cre8ivethought.com/blog 53 www.ExigenServices.com