SlideShare a Scribd company logo
1 of 43
Download to read offline
CQRS : 
Introduction 
Shah Ali Newaj Topu, CTO, Selise
How do we architect enterprise application 
Application Layer (Client) 
Service Layer 
Business Logic Layer 
Data Access Layer 
Sec 
uri 
t 
y 
Loggi 
ng 
Relational Database
A typical request LifeCycle 
newContactID=ContactService.AddContact(Contact) 
return ContactManager.AddContact(Contact); 
If(Validate(Contact)) 
return ContactRepository.Add(Contact) 
Insert into… return newContactID 
Relational Database
What happens on UI
What happens on UI
and we wait
and taken back to the grid
Why we wait? 
Because it takes some time to add the 
information to the Database and return us the 
newly created ID.
Why database takes time? 
● More write operation might be in progress. 
● Lot of read operation might be in progress. 
● Some request itself might take longer than 
others because it has to update multiple 
tables. 
● And so on.
What happens when we read data 
contactList=ContactService.GetContacts() 
return ContactManager.GetContact(); 
return ContactRepository.Get() 
Select from ...join…join return contactList 
Relational Database
and we wait
and ta da..
We have 2 wait screens 
Can we get rid of them?
Why we wait? 
● Lots of Joins in Select query 
● There was some write request from other 
users which locked the table we were trying 
to read.
Why we have Joins 
Because we have Normalized Database
And we need Normalized database because
Normalization slows down read operation 
The best READ performance can be achieved 
from a Denormalized Database where data is 
duplicated and found in columns rather than 
rows.
Can we have best of both 
Imaging you have one service that does all the 
WRITE operation and updates your Normalized 
Database and ensures data integrity. 
Then you have one service that reads the data 
from a Denormalized Database. 
And somehow these two Databases are 
synchronized.
Separation of Read and Write 
contactList=ContactREADService. 
GetContacts() 
return ContactManager.GetContact(); 
return ContactRepository.Get() 
Select * from Contact return 
contactList 
Denormalized Database 
newContactID=ContactWRITEService. 
AddContact(Contact) 
return ContactManager.AddContact 
(Contact); 
If(Validate(Contact)) 
return ContactRepository.Add(Contact) 
Insert into… return newContactID 
Sync Normalized Database
We can deploy them separately 
More Read Service Less Write Service
But this just a small improvement 
We still need the loading screen because Sync 
will take time and if we make a call to the read 
service before the sync is done we will not get 
the data we are looking for.
But lets look back
We have all the data on the Client 
We refresh our grid to show the newly added row by doing 
a query to the read service. 
Why? 
We have all the data in the client because user just now 
entered it, remember? In the add contact screen. Why we 
need to query to the read service for data which we already 
have?
So.. 
Can we add the row to the grid without making 
a call to the Read Service?
But we still have to wait for Write 
Remember our Write Operation returns an ID. 
We need this ID to uniquely identify the Data 
we are writing. 
What if the Write takes long? We will need a 
wait for that anyway!
Redefining ID 
What if we stop asking the Database to create 
this id and send it back? 
What if we generate the ID at the client? 
What if the ID is a GUID?
Redefining ID 
ContactWRITEService.AddContact 
(Contact) 
ContactManager.AddContact(Contact); 
If(Validate(Contact)) 
ContactRepository.Add(Contact) 
Insert into… 
Normalized Database
Client becomes independent 
For each data change client can now make a 
call to the write service and without waiting for 
return value it go back to do the next operation. 
Write service can take its time to perform the 
operation and update the read database 
accordingly.
Read and Write are independent 
Read services only reads data 
Write services only changes the data.
Command Query Responsibility Segregation. 
● A Pattern 
○ Not an Architecture 
○ Not an Architectural style 
○ Not a principal 
Udi Dahan Greg Young 
● Based on Command Query Separation Principle
CQS Principal 
Command–query separation (CQS) is a principle of imperative computer 
programming. It was devised by Bertrand Meyer as part of his pioneering work 
on the Eiffel programming language. 
It states that a method should either change the state of an object or return a 
result but not both.
The Reactive Manifesto 
Systems built as Reactive Systems are more 
flexible, loosely-coupled and scalable. This 
makes them easier to develop and amenable to 
change. They are significantly more tolerant of 
failure and when failure does occur they meet it 
with elegance rather than disaster. Reactive 
Systems are highly responsive, giving users 
effective interactive feedback.
Reactive Systems are 
● Responsive 
● Resilient 
● Elastic 
● Message Driven
Necessary patterns 
CQRS 
Event Sourcing 
Domain Driven Design 
Event Driven Architecture
How does it look
Who is doing it? 
Microsoft 
In July 2012 Ms started a project called CQRS Journey. The project is focused 
on building highly scalable, highly available and maintainable applications with 
the Command & Query Responsibility Segregation and the Event Sourcing 
patterns. Now they published a book and a fully documented source for 
implementing CQRS.
Who is doing it? 
Java: 
● AxonFramework 
● Jdon Framework 
Scala: 
● eventsourced
Who is doing it? 
Selise: 
We are building Publiweb, a massive multi 
module, multi tenant , SaaS based highly 
scalable application using CQRS, Event 
Sourcing and Domain driven design for Swiss 
E-Gov.
What no one told me 
When you are asked to develop a scalable web 
application you are indeed asked to build a 
distributed system.
What is a Distributed System 
Write Read
What that has to do with Web App
Fallacies of Distributed Computing 
● The network is reliable. 
● Latency is zero. 
● Bandwidth is infinite. 
● The network is secure. 
● Topology doesn't change. 
● There is one administrator. 
● Transport cost is zero. 
● The network is homogeneous.
CQRS : Introduction

More Related Content

What's hot

Build Message-Based Web Services for SOA
Build Message-Based Web Services for SOABuild Message-Based Web Services for SOA
Build Message-Based Web Services for SOAJeffrey Hasan
 
Monolithic to Microservices - Handson
Monolithic to Microservices - HandsonMonolithic to Microservices - Handson
Monolithic to Microservices - HandsonKarthikeyan VK
 
Introduction to MicroServices (Oakjug)
Introduction to MicroServices (Oakjug)Introduction to MicroServices (Oakjug)
Introduction to MicroServices (Oakjug)Chris Richardson
 
Where i put my business logic - Greach 2014, Madrid, Spain
Where i put my business logic  - Greach 2014, Madrid, SpainWhere i put my business logic  - Greach 2014, Madrid, Spain
Where i put my business logic - Greach 2014, Madrid, SpainAntonio de la Torre Fernández
 
Azure Events and Messages
Azure Events and MessagesAzure Events and Messages
Azure Events and MessagesNeeraj Kumar
 
RedisConf17 - A pattern language for microservices - Chris Richardson
RedisConf17 - A pattern language for microservices - Chris RichardsonRedisConf17 - A pattern language for microservices - Chris Richardson
RedisConf17 - A pattern language for microservices - Chris RichardsonRedis Labs
 
Accessing data within VB Applications
Accessing data within VB ApplicationsAccessing data within VB Applications
Accessing data within VB Applicationsrobertbenard
 
#Techorama belgium 2018 vincent biret deep dive with the #MicrosoftGraph
#Techorama belgium 2018 vincent biret deep dive with the #MicrosoftGraph#Techorama belgium 2018 vincent biret deep dive with the #MicrosoftGraph
#Techorama belgium 2018 vincent biret deep dive with the #MicrosoftGraphVincent Biret
 
Pillars of great Azure Architecture
Pillars of great Azure ArchitecturePillars of great Azure Architecture
Pillars of great Azure ArchitectureKarthikeyan VK
 

What's hot (12)

Build Message-Based Web Services for SOA
Build Message-Based Web Services for SOABuild Message-Based Web Services for SOA
Build Message-Based Web Services for SOA
 
Monolithic to Microservices - Handson
Monolithic to Microservices - HandsonMonolithic to Microservices - Handson
Monolithic to Microservices - Handson
 
Introduction to MicroServices (Oakjug)
Introduction to MicroServices (Oakjug)Introduction to MicroServices (Oakjug)
Introduction to MicroServices (Oakjug)
 
Where i put my business logic - Greach 2014, Madrid, Spain
Where i put my business logic  - Greach 2014, Madrid, SpainWhere i put my business logic  - Greach 2014, Madrid, Spain
Where i put my business logic - Greach 2014, Madrid, Spain
 
Azure Events and Messages
Azure Events and MessagesAzure Events and Messages
Azure Events and Messages
 
RedisConf17 - A pattern language for microservices - Chris Richardson
RedisConf17 - A pattern language for microservices - Chris RichardsonRedisConf17 - A pattern language for microservices - Chris Richardson
RedisConf17 - A pattern language for microservices - Chris Richardson
 
Cloud Design Patterns
Cloud Design PatternsCloud Design Patterns
Cloud Design Patterns
 
Accessing data within VB Applications
Accessing data within VB ApplicationsAccessing data within VB Applications
Accessing data within VB Applications
 
#Techorama belgium 2018 vincent biret deep dive with the #MicrosoftGraph
#Techorama belgium 2018 vincent biret deep dive with the #MicrosoftGraph#Techorama belgium 2018 vincent biret deep dive with the #MicrosoftGraph
#Techorama belgium 2018 vincent biret deep dive with the #MicrosoftGraph
 
Event sourcing
Event sourcingEvent sourcing
Event sourcing
 
Whitepaper : Event Driven Micro Services
Whitepaper : Event Driven Micro ServicesWhitepaper : Event Driven Micro Services
Whitepaper : Event Driven Micro Services
 
Pillars of great Azure Architecture
Pillars of great Azure ArchitecturePillars of great Azure Architecture
Pillars of great Azure Architecture
 

Similar to CQRS : Introduction

ESPC19: What is the cdm and how to use it?
ESPC19: What is the cdm and how to use it?ESPC19: What is the cdm and how to use it?
ESPC19: What is the cdm and how to use it?Nicolas Georgeault
 
devworkshop-10_28_1015-amazon-conference-presentation
devworkshop-10_28_1015-amazon-conference-presentationdevworkshop-10_28_1015-amazon-conference-presentation
devworkshop-10_28_1015-amazon-conference-presentationAlex Wu
 
Cloud Modernization and Data as a Service Option
Cloud Modernization and Data as a Service OptionCloud Modernization and Data as a Service Option
Cloud Modernization and Data as a Service OptionDenodo
 
Chapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingChapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingPraveen M Jigajinni
 
Why Should Nonprofits Care About Cloud Computing
Why Should Nonprofits Care About Cloud ComputingWhy Should Nonprofits Care About Cloud Computing
Why Should Nonprofits Care About Cloud ComputingTechSoup Global
 
Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patternsMd. Sadhan Sarker
 
Evolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di PalmaEvolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di PalmaMongoDB
 
Performance and Cost Analysis of Modern Public Cloud Services
Performance and Cost Analysis of Modern Public Cloud ServicesPerformance and Cost Analysis of Modern Public Cloud Services
Performance and Cost Analysis of Modern Public Cloud ServicesMd.Saiedur Rahaman
 
Service Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSService Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSAndolasoft Inc
 
Data As A Service Composition Of Daas And Negotiation...
Data As A Service Composition Of Daas And Negotiation...Data As A Service Composition Of Daas And Negotiation...
Data As A Service Composition Of Daas And Negotiation...Christina Berger
 
CLOUD PROPOSAL2CLOUD PROPOSAL16Cloud Proposal.docx
CLOUD PROPOSAL2CLOUD PROPOSAL16Cloud Proposal.docxCLOUD PROPOSAL2CLOUD PROPOSAL16Cloud Proposal.docx
CLOUD PROPOSAL2CLOUD PROPOSAL16Cloud Proposal.docxclarebernice
 
Why NBC Universal Migrated to MongoDB Atlas
Why NBC Universal Migrated to MongoDB AtlasWhy NBC Universal Migrated to MongoDB Atlas
Why NBC Universal Migrated to MongoDB AtlasDatavail
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchMongoDB
 
The Evolution of a Scrappy Startup to a Successful Web Service
The Evolution of a Scrappy Startup to a Successful Web ServiceThe Evolution of a Scrappy Startup to a Successful Web Service
The Evolution of a Scrappy Startup to a Successful Web ServicePoornima Vijayashanker
 
How to Get Cloud Architecture and Design Right the First Time
How to Get Cloud Architecture and Design Right the First TimeHow to Get Cloud Architecture and Design Right the First Time
How to Get Cloud Architecture and Design Right the First TimeDavid Linthicum
 
(BDT312) Using the Cloud to Scale from a Database to a Data Platform | AWS re...
(BDT312) Using the Cloud to Scale from a Database to a Data Platform | AWS re...(BDT312) Using the Cloud to Scale from a Database to a Data Platform | AWS re...
(BDT312) Using the Cloud to Scale from a Database to a Data Platform | AWS re...Amazon Web Services
 
January 2017 - Deep dive on AWS Lambda and DevOps
January 2017 - Deep dive on AWS Lambda and DevOpsJanuary 2017 - Deep dive on AWS Lambda and DevOps
January 2017 - Deep dive on AWS Lambda and DevOpsDavid McDaniel
 
SFSCON23 - Daniele Fontani Daniele Ciulli - CrudIt an opensource framework t...
SFSCON23 - Daniele Fontani Daniele Ciulli - CrudIt  an opensource framework t...SFSCON23 - Daniele Fontani Daniele Ciulli - CrudIt  an opensource framework t...
SFSCON23 - Daniele Fontani Daniele Ciulli - CrudIt an opensource framework t...South Tyrol Free Software Conference
 

Similar to CQRS : Introduction (20)

Designingapplswithnet
DesigningapplswithnetDesigningapplswithnet
Designingapplswithnet
 
ESPC19: What is the cdm and how to use it?
ESPC19: What is the cdm and how to use it?ESPC19: What is the cdm and how to use it?
ESPC19: What is the cdm and how to use it?
 
devworkshop-10_28_1015-amazon-conference-presentation
devworkshop-10_28_1015-amazon-conference-presentationdevworkshop-10_28_1015-amazon-conference-presentation
devworkshop-10_28_1015-amazon-conference-presentation
 
Cloud Modernization and Data as a Service Option
Cloud Modernization and Data as a Service OptionCloud Modernization and Data as a Service Option
Cloud Modernization and Data as a Service Option
 
Chapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computingChapter 3 cloud computing and intro parrallel computing
Chapter 3 cloud computing and intro parrallel computing
 
Why Should Nonprofits Care About Cloud Computing
Why Should Nonprofits Care About Cloud ComputingWhy Should Nonprofits Care About Cloud Computing
Why Should Nonprofits Care About Cloud Computing
 
Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patterns
 
Evolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di PalmaEvolving your Data Access with MongoDB Stitch - Drew Di Palma
Evolving your Data Access with MongoDB Stitch - Drew Di Palma
 
Performance and Cost Analysis of Modern Public Cloud Services
Performance and Cost Analysis of Modern Public Cloud ServicesPerformance and Cost Analysis of Modern Public Cloud Services
Performance and Cost Analysis of Modern Public Cloud Services
 
Service Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJSService Oriented Architecture in NodeJS
Service Oriented Architecture in NodeJS
 
Data As A Service Composition Of Daas And Negotiation...
Data As A Service Composition Of Daas And Negotiation...Data As A Service Composition Of Daas And Negotiation...
Data As A Service Composition Of Daas And Negotiation...
 
CLOUD PROPOSAL2CLOUD PROPOSAL16Cloud Proposal.docx
CLOUD PROPOSAL2CLOUD PROPOSAL16Cloud Proposal.docxCLOUD PROPOSAL2CLOUD PROPOSAL16Cloud Proposal.docx
CLOUD PROPOSAL2CLOUD PROPOSAL16Cloud Proposal.docx
 
Why NBC Universal Migrated to MongoDB Atlas
Why NBC Universal Migrated to MongoDB AtlasWhy NBC Universal Migrated to MongoDB Atlas
Why NBC Universal Migrated to MongoDB Atlas
 
Tutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB StitchTutorial: Building Your First App with MongoDB Stitch
Tutorial: Building Your First App with MongoDB Stitch
 
B_110500002
B_110500002B_110500002
B_110500002
 
The Evolution of a Scrappy Startup to a Successful Web Service
The Evolution of a Scrappy Startup to a Successful Web ServiceThe Evolution of a Scrappy Startup to a Successful Web Service
The Evolution of a Scrappy Startup to a Successful Web Service
 
How to Get Cloud Architecture and Design Right the First Time
How to Get Cloud Architecture and Design Right the First TimeHow to Get Cloud Architecture and Design Right the First Time
How to Get Cloud Architecture and Design Right the First Time
 
(BDT312) Using the Cloud to Scale from a Database to a Data Platform | AWS re...
(BDT312) Using the Cloud to Scale from a Database to a Data Platform | AWS re...(BDT312) Using the Cloud to Scale from a Database to a Data Platform | AWS re...
(BDT312) Using the Cloud to Scale from a Database to a Data Platform | AWS re...
 
January 2017 - Deep dive on AWS Lambda and DevOps
January 2017 - Deep dive on AWS Lambda and DevOpsJanuary 2017 - Deep dive on AWS Lambda and DevOps
January 2017 - Deep dive on AWS Lambda and DevOps
 
SFSCON23 - Daniele Fontani Daniele Ciulli - CrudIt an opensource framework t...
SFSCON23 - Daniele Fontani Daniele Ciulli - CrudIt  an opensource framework t...SFSCON23 - Daniele Fontani Daniele Ciulli - CrudIt  an opensource framework t...
SFSCON23 - Daniele Fontani Daniele Ciulli - CrudIt an opensource framework t...
 

Recently uploaded

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...Karmanjay Verma
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFMichael Gough
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Jeffrey Haguewood
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Alkin Tezuysal
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch TuesdayIvanti
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observabilityitnewsafrica
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Karmanjay Verma
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructureitnewsafrica
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 

Recently uploaded (20)

Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...React JS; all concepts. Contains React Features, JSX, functional & Class comp...
React JS; all concepts. Contains React Features, JSX, functional & Class comp...
 
All These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDFAll These Sophisticated Attacks, Can We Really Detect Them - PDF
All These Sophisticated Attacks, Can We Really Detect Them - PDF
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
Email Marketing Automation for Bonterra Impact Management (fka Social Solutio...
 
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
Transcript: New from BookNet Canada for 2024: BNC SalesData and LibraryData -...
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
Unleashing Real-time Insights with ClickHouse_ Navigating the Landscape in 20...
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
2024 April Patch Tuesday
2024 April Patch Tuesday2024 April Patch Tuesday
2024 April Patch Tuesday
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security ObservabilityGlenn Lazarus- Why Your Observability Strategy Needs Security Observability
Glenn Lazarus- Why Your Observability Strategy Needs Security Observability
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#Microservices, Docker deploy and Microservices source code in C#
Microservices, Docker deploy and Microservices source code in C#
 
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical InfrastructureVarsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
Varsha Sewlal- Cyber Attacks on Critical Critical Infrastructure
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 

CQRS : Introduction

  • 1. CQRS : Introduction Shah Ali Newaj Topu, CTO, Selise
  • 2. How do we architect enterprise application Application Layer (Client) Service Layer Business Logic Layer Data Access Layer Sec uri t y Loggi ng Relational Database
  • 3. A typical request LifeCycle newContactID=ContactService.AddContact(Contact) return ContactManager.AddContact(Contact); If(Validate(Contact)) return ContactRepository.Add(Contact) Insert into… return newContactID Relational Database
  • 7. and taken back to the grid
  • 8. Why we wait? Because it takes some time to add the information to the Database and return us the newly created ID.
  • 9. Why database takes time? ● More write operation might be in progress. ● Lot of read operation might be in progress. ● Some request itself might take longer than others because it has to update multiple tables. ● And so on.
  • 10. What happens when we read data contactList=ContactService.GetContacts() return ContactManager.GetContact(); return ContactRepository.Get() Select from ...join…join return contactList Relational Database
  • 13. We have 2 wait screens Can we get rid of them?
  • 14. Why we wait? ● Lots of Joins in Select query ● There was some write request from other users which locked the table we were trying to read.
  • 15. Why we have Joins Because we have Normalized Database
  • 16. And we need Normalized database because
  • 17. Normalization slows down read operation The best READ performance can be achieved from a Denormalized Database where data is duplicated and found in columns rather than rows.
  • 18. Can we have best of both Imaging you have one service that does all the WRITE operation and updates your Normalized Database and ensures data integrity. Then you have one service that reads the data from a Denormalized Database. And somehow these two Databases are synchronized.
  • 19. Separation of Read and Write contactList=ContactREADService. GetContacts() return ContactManager.GetContact(); return ContactRepository.Get() Select * from Contact return contactList Denormalized Database newContactID=ContactWRITEService. AddContact(Contact) return ContactManager.AddContact (Contact); If(Validate(Contact)) return ContactRepository.Add(Contact) Insert into… return newContactID Sync Normalized Database
  • 20. We can deploy them separately More Read Service Less Write Service
  • 21. But this just a small improvement We still need the loading screen because Sync will take time and if we make a call to the read service before the sync is done we will not get the data we are looking for.
  • 23. We have all the data on the Client We refresh our grid to show the newly added row by doing a query to the read service. Why? We have all the data in the client because user just now entered it, remember? In the add contact screen. Why we need to query to the read service for data which we already have?
  • 24. So.. Can we add the row to the grid without making a call to the Read Service?
  • 25. But we still have to wait for Write Remember our Write Operation returns an ID. We need this ID to uniquely identify the Data we are writing. What if the Write takes long? We will need a wait for that anyway!
  • 26. Redefining ID What if we stop asking the Database to create this id and send it back? What if we generate the ID at the client? What if the ID is a GUID?
  • 27. Redefining ID ContactWRITEService.AddContact (Contact) ContactManager.AddContact(Contact); If(Validate(Contact)) ContactRepository.Add(Contact) Insert into… Normalized Database
  • 28. Client becomes independent For each data change client can now make a call to the write service and without waiting for return value it go back to do the next operation. Write service can take its time to perform the operation and update the read database accordingly.
  • 29. Read and Write are independent Read services only reads data Write services only changes the data.
  • 30. Command Query Responsibility Segregation. ● A Pattern ○ Not an Architecture ○ Not an Architectural style ○ Not a principal Udi Dahan Greg Young ● Based on Command Query Separation Principle
  • 31. CQS Principal Command–query separation (CQS) is a principle of imperative computer programming. It was devised by Bertrand Meyer as part of his pioneering work on the Eiffel programming language. It states that a method should either change the state of an object or return a result but not both.
  • 32. The Reactive Manifesto Systems built as Reactive Systems are more flexible, loosely-coupled and scalable. This makes them easier to develop and amenable to change. They are significantly more tolerant of failure and when failure does occur they meet it with elegance rather than disaster. Reactive Systems are highly responsive, giving users effective interactive feedback.
  • 33. Reactive Systems are ● Responsive ● Resilient ● Elastic ● Message Driven
  • 34. Necessary patterns CQRS Event Sourcing Domain Driven Design Event Driven Architecture
  • 35. How does it look
  • 36. Who is doing it? Microsoft In July 2012 Ms started a project called CQRS Journey. The project is focused on building highly scalable, highly available and maintainable applications with the Command & Query Responsibility Segregation and the Event Sourcing patterns. Now they published a book and a fully documented source for implementing CQRS.
  • 37. Who is doing it? Java: ● AxonFramework ● Jdon Framework Scala: ● eventsourced
  • 38. Who is doing it? Selise: We are building Publiweb, a massive multi module, multi tenant , SaaS based highly scalable application using CQRS, Event Sourcing and Domain driven design for Swiss E-Gov.
  • 39. What no one told me When you are asked to develop a scalable web application you are indeed asked to build a distributed system.
  • 40. What is a Distributed System Write Read
  • 41. What that has to do with Web App
  • 42. Fallacies of Distributed Computing ● The network is reliable. ● Latency is zero. ● Bandwidth is infinite. ● The network is secure. ● Topology doesn't change. ● There is one administrator. ● Transport cost is zero. ● The network is homogeneous.