SlideShare a Scribd company logo
1 of 33
CQRS
IN 4 STEPS
WHAT IS THE
COMMAND QUERY RESPONSIBILITY
SEGREGATION
What is not required in CQRS
• More than 1 data source
• Domain events
• Event Sourcing
• Message buses
• And others
0
RECENT STATE
Ecommerce app
ProductsServiceProductsController
OrdersServiceOrdersController
Ecommerce app - NopCommerce
Disadvantages of this approach
• Enormous controllers / services / helpers
• Classes are not following SRP
• Refactoring is really difficult
• Complexity in writing unit tests
1
CQRS IS TWO OBJECTS
WHERE THERE WAS ONCE ONE
Jimmy Bogard - https://lostechies.com/jimmybogard/2012/08/22/busting-some-cqrs-myths/
Martin Fowler - https://martinfowler.com/bliki/CQRS.html
Step 1 – Splitting to objects
GetProducts
QueryHandler
ProductsController
AddProduct
CommandHandler
Mediator
Jimmy Bogard - https://lostechies.com/jimmybogard/2015/05/05/cqrs-with-mediatr-and-automapper/
Profit after this step
• Single responsibility
• Clearly defined target and dependencies
• Split to change and receive data
• Simplicity of writing unit tests
2
BOOSTING
YOUR QUERIES
Many objects
GetProductsQueryHandle
r
ProductsController
AddProductCommandHandler
CategoriesController
GetProductsFieldsQueryHandler
GetCategoriesQueryHandle
r
AddCategoryCommandHandler
GetCategoriesProductsQueryHandle
r
Objects without change
AddProductCommandHandler
GetProductsFieldsQueryHandler
AddCategoryCommandHandler
Step 2 – Request optimization
GetProductsQueryHandler
GetCategoriesQueryHandler
GetCategoriesProductsQueryHandle
r
X
Plenty of options
SQL Views
Materialized
AutoMapper
ProjectTo
Dapper
MicroORM
EF No tracking
OrmLite
MicroORM
SQL Queries
Profit after this step
• Improved speed of receiving data
• No impact on other parts of the system
3
CREATING SYNCHRONOUS
READMODEL
Publishing domain events
ChangeProductField
CommandHandler
Mediator
AddProduct
CommandHandler
Mediator
ProductAdded
ProductFieldChanged
Udi Dahan - http://udidahan.com/2009/06/14/domain-events-salvation/
Step 3 – Synchronous read model
ProductAdded
ProductFieldChanged
Product
View
Handler
ProductView
(table)
Profit after this step
• Iterative gain in read model
• Immediate queries
• No data loss
• Ability to recreate a view
4
CREATING ASYNCHRONOUS
READMODEL
Message bus
ProductAdded
ProductFieldChanged
Async
Job
Step 4 – Asynchronous read model
Product
Search
Handler
Async
Job
Product
Cache
Handler
Notify the user - SignalR
Product
Search
Handler
Async
Job
Products
Controller
SignalR
Correlation Identifier - http://www.enterpriseintegrationpatterns.com/patterns/messaging/CorrelationIdentifier.html
Profit after this step
• Read model per functionality
• Non-blockable commands
• Small, testable components
Summary
• 1 – split to objects: Command & Query
• 2 – query optimization
• 3 – synchronous read model
• 4 – asynchronous read model & notifications
THANK YOU

More Related Content

What's hot

Microservices
MicroservicesMicroservices
MicroservicesSmartBear
 
Microservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, KanbanMicroservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, KanbanAraf Karsh Hamid
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture PatternsAssaf Gannon
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices Bozhidar Bozhanov
 
4. 대용량 아키텍쳐 설계 패턴
4. 대용량 아키텍쳐 설계 패턴4. 대용량 아키텍쳐 설계 패턴
4. 대용량 아키텍쳐 설계 패턴Terry Cho
 
Microservices in the Apache Kafka Ecosystem
Microservices in the Apache Kafka EcosystemMicroservices in the Apache Kafka Ecosystem
Microservices in the Apache Kafka Ecosystemconfluent
 
Kafka replication apachecon_2013
Kafka replication apachecon_2013Kafka replication apachecon_2013
Kafka replication apachecon_2013Jun Rao
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeHolasz Kati
 
Flexible, hybrid API-led software architectures with Kong
Flexible, hybrid API-led software architectures with KongFlexible, hybrid API-led software architectures with Kong
Flexible, hybrid API-led software architectures with KongSven Bernhardt
 
Micro services vs Monolith Architecture
Micro services vs Monolith ArchitectureMicro services vs Monolith Architecture
Micro services vs Monolith ArchitectureMohamedElGohary71
 
OpenAPI 3.0, And What It Means for the Future of Swagger
OpenAPI 3.0, And What It Means for the Future of SwaggerOpenAPI 3.0, And What It Means for the Future of Swagger
OpenAPI 3.0, And What It Means for the Future of SwaggerSmartBear
 
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐Terry Cho
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudEberhard Wolff
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Patternjeetendra mandal
 
Azure Spring Cloud Workshop - June 17, 2020
Azure Spring Cloud Workshop - June 17, 2020Azure Spring Cloud Workshop - June 17, 2020
Azure Spring Cloud Workshop - June 17, 2020VMware Tanzu
 
Open API and API Management - Introduction and Comparison of Products: TIBCO ...
Open API and API Management - Introduction and Comparison of Products: TIBCO ...Open API and API Management - Introduction and Comparison of Products: TIBCO ...
Open API and API Management - Introduction and Comparison of Products: TIBCO ...Kai Wähner
 

What's hot (20)

Microservices
MicroservicesMicroservices
Microservices
 
Microservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, KanbanMicroservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, Kanban
 
Software Architecture Patterns
Software Architecture PatternsSoftware Architecture Patterns
Software Architecture Patterns
 
Monoliths and Microservices
Monoliths and Microservices Monoliths and Microservices
Monoliths and Microservices
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
4. 대용량 아키텍쳐 설계 패턴
4. 대용량 아키텍쳐 설계 패턴4. 대용량 아키텍쳐 설계 패턴
4. 대용량 아키텍쳐 설계 패턴
 
Microservices in the Apache Kafka Ecosystem
Microservices in the Apache Kafka EcosystemMicroservices in the Apache Kafka Ecosystem
Microservices in the Apache Kafka Ecosystem
 
Kafka replication apachecon_2013
Kafka replication apachecon_2013Kafka replication apachecon_2013
Kafka replication apachecon_2013
 
Maven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafeMaven Presentation - SureFire vs FailSafe
Maven Presentation - SureFire vs FailSafe
 
Flexible, hybrid API-led software architectures with Kong
Flexible, hybrid API-led software architectures with KongFlexible, hybrid API-led software architectures with Kong
Flexible, hybrid API-led software architectures with Kong
 
Micro services vs Monolith Architecture
Micro services vs Monolith ArchitectureMicro services vs Monolith Architecture
Micro services vs Monolith Architecture
 
OpenAPI 3.0, And What It Means for the Future of Swagger
OpenAPI 3.0, And What It Means for the Future of SwaggerOpenAPI 3.0, And What It Means for the Future of Swagger
OpenAPI 3.0, And What It Means for the Future of Swagger
 
Windows Azure Service Bus
Windows Azure Service BusWindows Azure Service Bus
Windows Azure Service Bus
 
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
대용량 분산 아키텍쳐 설계 #4. soa 아키텍쳐
 
Azure Resource Manager (ARM) Templates
Azure Resource Manager (ARM) TemplatesAzure Resource Manager (ARM) Templates
Azure Resource Manager (ARM) Templates
 
Microservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring CloudMicroservices with Java, Spring Boot and Spring Cloud
Microservices with Java, Spring Boot and Spring Cloud
 
Welcome to Azure Devops
Welcome to Azure DevopsWelcome to Azure Devops
Welcome to Azure Devops
 
Event Driven Software Architecture Pattern
Event Driven Software Architecture PatternEvent Driven Software Architecture Pattern
Event Driven Software Architecture Pattern
 
Azure Spring Cloud Workshop - June 17, 2020
Azure Spring Cloud Workshop - June 17, 2020Azure Spring Cloud Workshop - June 17, 2020
Azure Spring Cloud Workshop - June 17, 2020
 
Open API and API Management - Introduction and Comparison of Products: TIBCO ...
Open API and API Management - Introduction and Comparison of Products: TIBCO ...Open API and API Management - Introduction and Comparison of Products: TIBCO ...
Open API and API Management - Introduction and Comparison of Products: TIBCO ...
 

Similar to CQRS in 4 steps - Lightning Talk

Continuous Performance Testing
Continuous Performance TestingContinuous Performance Testing
Continuous Performance TestingGrid Dynamics
 
quality center.ppt
quality center.pptquality center.ppt
quality center.pptAnilKumarARS
 
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 PotsdamFrom Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 PotsdamAndreas Grabner
 
Collaboration for Executives
Collaboration for ExecutivesCollaboration for Executives
Collaboration for Executivescolleenfry
 
Overcoming Barriers to the Cloud
Overcoming Barriers to the Cloud Overcoming Barriers to the Cloud
Overcoming Barriers to the Cloud Andy Milsark
 
[TDC 2018 - Trilha XP] Feature flags e releases controlados
[TDC 2018 - Trilha XP] Feature flags e releases controlados[TDC 2018 - Trilha XP] Feature flags e releases controlados
[TDC 2018 - Trilha XP] Feature flags e releases controladosEduardo Colabardini
 
TDC2018SP | Trilha UX - Feature flags e Releases controlados
TDC2018SP | Trilha UX - Feature flags e Releases controladosTDC2018SP | Trilha UX - Feature flags e Releases controlados
TDC2018SP | Trilha UX - Feature flags e Releases controladostdc-globalcode
 
Building real-time data analytics on Google Cloud
Building real-time data analytics on Google CloudBuilding real-time data analytics on Google Cloud
Building real-time data analytics on Google CloudJonny Daenen
 
Jagger: Сервер непрерывного тестирования производительности
Jagger: Сервер непрерывного тестирования производительностиJagger: Сервер непрерывного тестирования производительности
Jagger: Сервер непрерывного тестирования производительностиSQALab
 
Using Q-Pulse to Manage Maintenance & Errors
Using Q-Pulse to Manage Maintenance & ErrorsUsing Q-Pulse to Manage Maintenance & Errors
Using Q-Pulse to Manage Maintenance & ErrorsFionaMacGael
 
Mobile apps that win
Mobile apps that winMobile apps that win
Mobile apps that winDellFoglight
 
Observability with Spring-based distributed systems
Observability with Spring-based distributed systemsObservability with Spring-based distributed systems
Observability with Spring-based distributed systemsRakuten Group, Inc.
 
Design Reviews for Operations - Velocity Europe 2014
Design Reviews for Operations - Velocity Europe 2014Design Reviews for Operations - Velocity Europe 2014
Design Reviews for Operations - Velocity Europe 2014Mandi Walls
 
Yasgui: not just another sparql gui
Yasgui: not just another sparql guiYasgui: not just another sparql gui
Yasgui: not just another sparql guilaurensrietveld
 
The Top 5 Practices of a Highly Successful ChangeMan ZMF Administrator
The Top 5 Practices of a Highly Successful ChangeMan ZMF AdministratorThe Top 5 Practices of a Highly Successful ChangeMan ZMF Administrator
The Top 5 Practices of a Highly Successful ChangeMan ZMF AdministratorSerena Software
 
Tools and techniques for APIs
Tools and techniques for APIsTools and techniques for APIs
Tools and techniques for APIsJason Harmon
 
New Tech for Project Managers
New Tech for Project ManagersNew Tech for Project Managers
New Tech for Project ManagersPratip Mallik
 

Similar to CQRS in 4 steps - Lightning Talk (20)

Continuous Performance Testing
Continuous Performance TestingContinuous Performance Testing
Continuous Performance Testing
 
quality center.ppt
quality center.pptquality center.ppt
quality center.ppt
 
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 PotsdamFrom Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
From Zero to Performance Hero in Minutes - Agile Testing Days 2014 Potsdam
 
Collaboration for Executives
Collaboration for ExecutivesCollaboration for Executives
Collaboration for Executives
 
Agile & Wakanda
Agile & WakandaAgile & Wakanda
Agile & Wakanda
 
Overcoming Barriers to the Cloud
Overcoming Barriers to the Cloud Overcoming Barriers to the Cloud
Overcoming Barriers to the Cloud
 
[TDC 2018 - Trilha XP] Feature flags e releases controlados
[TDC 2018 - Trilha XP] Feature flags e releases controlados[TDC 2018 - Trilha XP] Feature flags e releases controlados
[TDC 2018 - Trilha XP] Feature flags e releases controlados
 
TDC2018SP | Trilha UX - Feature flags e Releases controlados
TDC2018SP | Trilha UX - Feature flags e Releases controladosTDC2018SP | Trilha UX - Feature flags e Releases controlados
TDC2018SP | Trilha UX - Feature flags e Releases controlados
 
Building real-time data analytics on Google Cloud
Building real-time data analytics on Google CloudBuilding real-time data analytics on Google Cloud
Building real-time data analytics on Google Cloud
 
Jagger: Сервер непрерывного тестирования производительности
Jagger: Сервер непрерывного тестирования производительностиJagger: Сервер непрерывного тестирования производительности
Jagger: Сервер непрерывного тестирования производительности
 
The Continuous PHP Pipeline
The Continuous PHP PipelineThe Continuous PHP Pipeline
The Continuous PHP Pipeline
 
Using Q-Pulse to Manage Maintenance & Errors
Using Q-Pulse to Manage Maintenance & ErrorsUsing Q-Pulse to Manage Maintenance & Errors
Using Q-Pulse to Manage Maintenance & Errors
 
Mobile apps that win
Mobile apps that winMobile apps that win
Mobile apps that win
 
ADF Performance Monitor
ADF Performance MonitorADF Performance Monitor
ADF Performance Monitor
 
Observability with Spring-based distributed systems
Observability with Spring-based distributed systemsObservability with Spring-based distributed systems
Observability with Spring-based distributed systems
 
Design Reviews for Operations - Velocity Europe 2014
Design Reviews for Operations - Velocity Europe 2014Design Reviews for Operations - Velocity Europe 2014
Design Reviews for Operations - Velocity Europe 2014
 
Yasgui: not just another sparql gui
Yasgui: not just another sparql guiYasgui: not just another sparql gui
Yasgui: not just another sparql gui
 
The Top 5 Practices of a Highly Successful ChangeMan ZMF Administrator
The Top 5 Practices of a Highly Successful ChangeMan ZMF AdministratorThe Top 5 Practices of a Highly Successful ChangeMan ZMF Administrator
The Top 5 Practices of a Highly Successful ChangeMan ZMF Administrator
 
Tools and techniques for APIs
Tools and techniques for APIsTools and techniques for APIs
Tools and techniques for APIs
 
New Tech for Project Managers
New Tech for Project ManagersNew Tech for Project Managers
New Tech for Project Managers
 

Recently uploaded

Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...SUHANI PANDEY
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirtrahman018755
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceEscorts Call Girls
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"growthgrids
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...nilamkumrai
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)Delhi Call girls
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...SUHANI PANDEY
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...tanu pandey
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdfMatthew Sinclair
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.soniya singh
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLimonikaupta
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...SUHANI PANDEY
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...SUHANI PANDEY
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...SUHANI PANDEY
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...Neha Pandey
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftAanSulistiyo
 

Recently uploaded (20)

Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
Pirangut | Call Girls Pune Phone No 8005736733 Elite Escort Service Available...
 
Trump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts SweatshirtTrump Diapers Over Dems t shirts Sweatshirt
Trump Diapers Over Dems t shirts Sweatshirt
 
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts ServiceReal Escorts in Al Nahda +971524965298 Dubai Escorts Service
Real Escorts in Al Nahda +971524965298 Dubai Escorts Service
 
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
6.High Profile Call Girls In Punjab +919053900678 Punjab Call GirlHigh Profil...
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
( Pune ) VIP Baner Call Girls 🎗️ 9352988975 Sizzling | Escorts | Girls Are Re...
 
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
WhatsApp 📞 8448380779 ✅Call Girls In Mamura Sector 66 ( Noida)
 
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Himatnagar 7001035870 Whatsapp Number, 24/07 Booking
 
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
Wagholi & High Class Call Girls Pune Neha 8005736733 | 100% Gennuine High Cla...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
Call Now ☎ 8264348440 !! Call Girls in Green Park Escort Service Delhi N.C.R.
 
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRLLucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
Lucknow ❤CALL GIRL 88759*99948 ❤CALL GIRLS IN Lucknow ESCORT SERVICE❤CALL GIRL
 
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...Russian Call Girls Pune  (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
Russian Call Girls Pune (Adult Only) 8005736733 Escort Service 24x7 Cash Pay...
 
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
Sarola * Female Escorts Service in Pune | 8005736733 Independent Escorts & Da...
 
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
Yerawada ] Independent Escorts in Pune - Book 8005736733 Call Girls Available...
 
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
(INDIRA) Call Girl Pune Call Now 8250077686 Pune Escorts 24x7
 
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
Low Sexy Call Girls In Mohali 9053900678 🥵Have Save And Good Place 🥵
 
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
𓀤Call On 7877925207 𓀤 Ahmedguda Call Girls Hot Model With Sexy Bhabi Ready Fo...
 
Microsoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck MicrosoftMicrosoft Azure Arc Customer Deck Microsoft
Microsoft Azure Arc Customer Deck Microsoft
 

CQRS in 4 steps - Lightning Talk

Editor's Notes

  1. There is a lot of noise about CQRS. When you search through the Internet to look for information and implementation of this pattern you will find enormous number of arcticles. And it's really hard to start with CQRS when you read that without X Y Z you shouldn't start with CQRS. Or without A B C it's not CQRS but only some silly tries. And I deeply refuse these ideas. It's really great to talk about these additions but at the beginning of the project it's really hard to plan that we will need these technologies. Due to this problem a lot of people refuses to interest about CQRS, so finally we are following the same mistakes over and over. For me CQRS is “Segregate operations that read data from operations that update data by using separate interfaces. This can maximize performance, scalability, and security.” – from Microsoft tutorial page.
  2. To begin with CQRS you don't need any of these stuff: - you can start with single data source and add  - your code can be a simple procedure without domain side-effects - event sourcing is a great pattern but not needed in CQRS - async message buses are not needed as well
  3. But to show you the power of CQRS lets start with an example of application that everybody would know.
  4. Let's assume that you create an ecommerce app with your loved ORM – e.g. Entity Framework. You add layer of services which handle requests from controllers. In there you put validations, requests to database, handling business logic etc. Week after week, month after month, your application starts growing. And it starts looking as:
  5. Maybe you are familiar with the best open-source .NET ecommerce solutution. It's really great peace of product, that you can use to build your own store, with plenty of functionalities. But unfortunately it is built in a typical layered way, that is really hard to mantain in such long-term and complicated projects.
  6. Here are the examples:  OrderProcessingService – 187 times changed, 41 injected dependencies Product Service – 173 times changed,, 27 injected dependencies Everything that is somehow connected with orders or products is moved to these services. With such architecture you finish with god objects responsible for handling almost each request from particular domain.
  7. So this approach is not fitting great in more complex applications: - god objects with dependencies difficult to understand  - classes are responsible for multiple action - it's really hard to split such objects or change their dependencies - with need to mock multiple object and handle their behaviour writing unit tests is almost impossible or such unit tests do not add value to your application So what we can do now?
  8. This quote is from Bogard's post, by which was a big inspiration for me. So you don't really needs to do something difficult to implement CQRS in your projects – only thing is a split from object which changes and receives data to two different one's.
  9. Moreover, Martin Fowler was writing about CQRS showing that to introduce this pattern to your app you need to split for model to command and queries:
  10. So step by step, method by method, you divide your ProductService, which handles requests from ProductController, to two or more objects which handle particular actions. Action which changes data is called command and action which receives data is called query. Controller is using some implementation of dispatcher pattern (check Mediator library created by Jimmy Bogard) to publish these commands and queries. They are handled in appriopriate connected handlers. And this is it, you have made a first step and implemented elements of CQRS in your projects. This is it – you can even stop at this point and call this CQRS – your actions are clearly defined and by definition you would know which object is changing data and which is just receiving it.
  11. It may seem as simple and straigthforward step, but it delivers great value to your application: - your object are now separated and you know what is their responsibility - you know why this object was created and what are its connections to other part of your application - you can easily find elements which changes data and focus on them when something is modifying your database - writing unit tests, with clearly defined output and narrowed number of dependecies, is much easier and gives more value To sum it up, it is much easier to develop and maintain your application if it is divided into small, separate part.
  12. Of course this step is not enhancing performance of your application. So in some point you get to the point when your data querying is too time consuming and is not accepted by the end user. And of course, your best ORM is responsible for it. So what you can do in that point?
  13. You focus on improving performance of your queries, with advantages taken from first step to CQRS – splitting to commands and queries.
  14. So in that point you got some controllers handling requests by divided handlers. And you see that some of your handlers are struggling from using Entity Framework. 
  15. But not all handlers needs our attention. A lot of handlers work really well with our ORM – data queried there is relatively small and query is generated in a moment. In that case you do not need to change anything.
  16. But for some handlers, with difficult queries are too slow for Entity Framework and you have to do something with it. And because you have strictly separated queries and command it's really easy to focus only on these requiring some attention. So you change a way as application connects to database and queries data to better fitted one – with better performance, quicker SQL query generation, less memory needed.
  17. There are plenty of options to achieve such improvement: – you can use No tracking option in EF not to track data changes - SQL Queries and SQL Views are more detailed option to query data, fastest but hardest to maintain as well - you can use one of many micro orms that are not so heavyweight as used one - in .NET there is an option to use Automapper library and extension called ProjectTo to query data on basis of created maps. It's really fast and easy to introduct to your project
  18. By that point you gained big performance improvement but without impact on other parts of the system.
  19. Your system grows and you reach to the point where even how hard you try to improve performance of querying your data, you cannot achieve it. In some situations data is structured in a way that unables you to query it effectively – you need to make multiple unions, joins that makes querying slow on big amount of data. So what you can do in this situation?
  20. In that case you can create additional model which store your data in a way that will be able to be queried fast and without overheads.
  21. First you need to publish domain events – you can use previously created / used dispatcher. At the end of your handler you add a logic that raises event about action done.
  22. Your events are synchronously handled by event handler which knows how to flatten your data to be quickly queried by your application. And puts this data to your database, the same as you currently using. But what is really important is that command handler and event handler is being runned in one transaction, so if adding data to ProductView fails application will also rollback previous operation. You are still using your current database, but part of your data is duplicated to be able to handle different query scenario.
  23. This step solves few problems: - data, which is hard to query, then command by command, is being transfered to simple read model - your model is optimized to be queried really fast - due to synchronous hadling and database transaction you don't lose your data - at any level of your application you can recreate your view and add handle new commands
  24. Unfortunately synchronous model of handling events has one major disadvantage – is synchronous. With many time-consuming event handlers your application freezes until all actions are done. 
  25. So you need to introduce asynchronous read model.
  26. At the beginning you need to change way of handling your events – instead of handling events immidietaly you put your events to message bus. Then some async job, which is connected to the bus, will be notified about new event to be handled.
  27. This async job runs event handlers which moves data to recent or new database. In your store you push product information to Elastic Search to search it efficiently and to Redis to cache data and use it in your queries.
  28. In many cases your end-user will require to get the info when the handler pushing data to async data store finished its work. In that case you can use broadly described pattern called Correlation identifier and great library called SignalR. Every request from end user contains unique CorrelationId. It is being transported through every layer as value in Command and Events to have an ability to find which particular user caused our change. In that case you will notify this user by push notification, so he can query the data from our new model, just after pushing data into it.
  29. Advantages of this step are pretty clear: - you can create any read model, that you will require in current situation - because events are handled asynchronously your command handling is very fast - you end with many different but tiny object which are easy to test and maintain Of course such step does not come without disadvantages, the bigest one are: - you implemented eventual consistency pattern with all its consequences - you need to handle all scenarios where command is done but event fails  - monitoring and debugging of your application is now much more complex than before
  30. Ok, so to sum it all:
  31. Path to CQRS, in my case, contains 4 steps: - splitting objects to command and queries - optimization places which requires such change - creating synchronous read model - creating asynchronous read model What is really important, in different bounded context you can implement these steps in whole or only a part of them, depending of the needs and the use cases. Even more, nothing prevents you to have two different models in theoretically similar queries or commands – it all depends on how complex your application is and what are the needs of your end-user.