SlideShare une entreprise Scribd logo
1  sur  29
CQRS
Command Query Responsibility Segregation
What problems are we
trying to solve?
Once upon a time…
Paper was all around before the advent of computers
Then came our savior: the data entry screen
It’s a brave new world
No just about paper input anymore
But application architecture still reflects that idea
IT made it all about the data
Data centric apps are CRUD based
Insidious CRUD
This might be a good idea for catalog data type
But only for that type of application
How to change state with CRUD?
Read documentation?
Follow existing business process?
This feels so unnatural
If the domain model is the rules
Then don’t make the user be the domain model
Complexity of code and solution
Too many layers
Big data models
Anemic domain model
Focus on frameworks instead of on the domain
Scalability not considered at the core of the design
(scalability get hacked in too late)
Many perspectives on data
Typical one size fits all architecture
Which leads to maintainability issues
Monolithic and tighly coupled application
One does not simply draw a class diagram.
And poorly used tools
One SQL query to rule them all.
Good architects & layer best practices
Applications exist to support use cases
User intent to manipulate information
AKA a « mutator » (or setter)
User intent to find and read information
AKA an « accessor » (or getter)
CQRS
Functions that write (mutators) are called « Command » methods
They must not return a value
Functions that read (accessors) are called « Query » methods
They must have no side effects
Commands
Primary goal is to capture user intent
Supports a single use case and targets a single aggregate
Are imperative
CreateOrder
SendNotification
UnregisterConference
…
Queries
Query results contain only data, no logic
But there’s more about them…
I’ll tell you later on…
I promise!
Real life scenario
Alice reads
data
Bob reads
data
Oh, it’s coffee
time for Bob!
Alice update
data
Bob updates
stale data
KABOOM !
Optimistic Locking Exception
We’re always working with stale data
Think about your favorite browser
When the HTML page is rendered, several milliseconds have passed since the request was sent
The document could have changed on the server side
But you are OK with it
Think about the stars in the sky
When we observe one, several years have passed
The star has maybe exploded
But you are OK with it
This is what we call « eventual consistency »
Let’s use stale data to our advantage
Offload the database by using read models
Tailor each read models to match as close as possible the view to avoid mappings
Serve read models very quickly
So what is CQRS?
« CQRS is simply the creation of two objects
where there was previously only one. »
-- Greg Young
Queries
Query results contain only data, no logic
Query results are stale
Query operates on a completely denormalized data model
Query are fast and avoid as much as possible mappings and transformations
All we need is good synchronization
Events
Signal that something happened
Closely aligned to the domain model
Are handled by a messasing system
Are in the past tense
OrderCreated
NotificationSent
ConferenceUnregistered
…
Commands
Primary goal is to capture user intent
Supports a single use case and targets a single aggregate
Are imperative
CreateOrder
SendNotification
UnregisterConference
…
Mutate aggregate state which results in one or more events being published
Events as a source
It’s the ES (Event Sourcing) in CQRS/ES
Aggregate state is not stored as is
But rather the events that took place
Aggregate’s events represent its history
Built-in audit log
Any state can be rolled back
Snapshots can be taken when the event stream is big enough
A good example is your bank account
A typical sequence
References
Greg Young (@gregyoung)
Udi Dahan (@UdiDahan)
Martin Fowler (@martinfowler)

Contenu connexe

Tendances

Scaling Systems: Architectures that Grow
Scaling Systems: Architectures that GrowScaling Systems: Architectures that Grow
Scaling Systems: Architectures that GrowGibraltar Software
 
The Future of Services: Building Asynchronous, Resilient and Elastic Systems
The Future of Services: Building Asynchronous, Resilient and Elastic SystemsThe Future of Services: Building Asynchronous, Resilient and Elastic Systems
The Future of Services: Building Asynchronous, Resilient and Elastic SystemsLightbend
 
Serverless: The future of application delivery
Serverless: The future of application deliveryServerless: The future of application delivery
Serverless: The future of application deliveryDoug Vanderweide
 
Command Query Responsibility Segregation (CQRS)
Command Query Responsibility Segregation (CQRS)Command Query Responsibility Segregation (CQRS)
Command Query Responsibility Segregation (CQRS)Derek Comartin
 
Webinar: Eventual Consistency != Hopeful Consistency
Webinar: Eventual Consistency != Hopeful ConsistencyWebinar: Eventual Consistency != Hopeful Consistency
Webinar: Eventual Consistency != Hopeful ConsistencyDataStax
 
Dashboard project.
Dashboard project.Dashboard project.
Dashboard project.ratankadam
 
Digital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and MicroservicesDigital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and MicroservicesLightbend
 
Modern Software Architecture - Cloud Scale Computing
Modern Software Architecture - Cloud Scale ComputingModern Software Architecture - Cloud Scale Computing
Modern Software Architecture - Cloud Scale ComputingGiragadurai Vallirajan
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.jsratankadam
 
Cloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful ServerlessCloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful ServerlessLightbend
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDDennis Doomen
 
Event driven architecure
Event driven architecureEvent driven architecure
Event driven architecureTouraj Ebrahimi
 
Stream Collections - Scala Days
Stream Collections - Scala DaysStream Collections - Scala Days
Stream Collections - Scala DaysGreg Silin
 
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERAGeek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERAIDERA Software
 
How to Use OWASP Security Logging
How to Use OWASP Security LoggingHow to Use OWASP Security Logging
How to Use OWASP Security LoggingMilton Smith
 
SQL Azure - the good, the bad and the ugly.
SQL Azure - the good, the bad and the ugly.SQL Azure - the good, the bad and the ugly.
SQL Azure - the good, the bad and the ugly.Pini Krisher
 

Tendances (20)

Scaling Systems: Architectures that Grow
Scaling Systems: Architectures that GrowScaling Systems: Architectures that Grow
Scaling Systems: Architectures that Grow
 
The Future of Services: Building Asynchronous, Resilient and Elastic Systems
The Future of Services: Building Asynchronous, Resilient and Elastic SystemsThe Future of Services: Building Asynchronous, Resilient and Elastic Systems
The Future of Services: Building Asynchronous, Resilient and Elastic Systems
 
Serverless: The future of application delivery
Serverless: The future of application deliveryServerless: The future of application delivery
Serverless: The future of application delivery
 
Command Query Responsibility Segregation (CQRS)
Command Query Responsibility Segregation (CQRS)Command Query Responsibility Segregation (CQRS)
Command Query Responsibility Segregation (CQRS)
 
Webinar: Eventual Consistency != Hopeful Consistency
Webinar: Eventual Consistency != Hopeful ConsistencyWebinar: Eventual Consistency != Hopeful Consistency
Webinar: Eventual Consistency != Hopeful Consistency
 
Dashboard project.
Dashboard project.Dashboard project.
Dashboard project.
 
Digital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and MicroservicesDigital Transformation with Kubernetes, Containers, and Microservices
Digital Transformation with Kubernetes, Containers, and Microservices
 
Modern Software Architecture - Cloud Scale Computing
Modern Software Architecture - Cloud Scale ComputingModern Software Architecture - Cloud Scale Computing
Modern Software Architecture - Cloud Scale Computing
 
Designing microservices
Designing microservicesDesigning microservices
Designing microservices
 
Scalability using Node.js
Scalability using Node.jsScalability using Node.js
Scalability using Node.js
 
Cloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful ServerlessCloudstate - Towards Stateful Serverless
Cloudstate - Towards Stateful Serverless
 
CQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDDCQRS and Event Sourcing, An Alternative Architecture for DDD
CQRS and Event Sourcing, An Alternative Architecture for DDD
 
Event driven architecure
Event driven architecureEvent driven architecure
Event driven architecure
 
Os Solomon
Os SolomonOs Solomon
Os Solomon
 
Stream Collections - Scala Days
Stream Collections - Scala DaysStream Collections - Scala Days
Stream Collections - Scala Days
 
CQRS
CQRSCQRS
CQRS
 
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERAGeek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
Geek Sync | Data Integrity Demystified - Deborah Melkin | IDERA
 
Data in Azure
Data in AzureData in Azure
Data in Azure
 
How to Use OWASP Security Logging
How to Use OWASP Security LoggingHow to Use OWASP Security Logging
How to Use OWASP Security Logging
 
SQL Azure - the good, the bad and the ugly.
SQL Azure - the good, the bad and the ugly.SQL Azure - the good, the bad and the ugly.
SQL Azure - the good, the bad and the ugly.
 

En vedette

CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event SourcingMike Bild
 
Microservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingMicroservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingBen Wilcock
 
A Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
A Visual Introduction to Event Sourcing and CQRS by Lorenzo NicoraA Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
A Visual Introduction to Event Sourcing and CQRS by Lorenzo NicoraOpenCredo
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...Chris Richardson
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingJoe Drumgoole
 
ISTA 2016: Event Sourcing
ISTA 2016: Event SourcingISTA 2016: Event Sourcing
ISTA 2016: Event SourcingVladik Khononov
 
CQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафорCQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафорAlexander Byndyu
 
A year with event sourcing and CQRS
A year with event sourcing and CQRSA year with event sourcing and CQRS
A year with event sourcing and CQRSSteve Pember
 
CQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETCQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETDavid Hoerster
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureThomas Jaskula
 
CQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHPCQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHPDavide Bellettini
 
Andrii Gryshchenko: "An Overview of CQRS and Event Sourcing"
Andrii Gryshchenko: "An Overview of CQRS and Event Sourcing"Andrii Gryshchenko: "An Overview of CQRS and Event Sourcing"
Andrii Gryshchenko: "An Overview of CQRS and Event Sourcing"LogeekNightUkraine
 

En vedette (15)

CQRS + Event Sourcing
CQRS + Event SourcingCQRS + Event Sourcing
CQRS + Event Sourcing
 
Microservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event SourcingMicroservice Architecture with CQRS and Event Sourcing
Microservice Architecture with CQRS and Event Sourcing
 
Owin & katana
Owin & katanaOwin & katana
Owin & katana
 
A Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
A Visual Introduction to Event Sourcing and CQRS by Lorenzo NicoraA Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
A Visual Introduction to Event Sourcing and CQRS by Lorenzo Nicora
 
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...Developing event-driven microservices with event sourcing and CQRS  (svcc, sv...
Developing event-driven microservices with event sourcing and CQRS (svcc, sv...
 
CQRS
CQRSCQRS
CQRS
 
Introduction to CQRS and Event Sourcing
Introduction to CQRS and Event SourcingIntroduction to CQRS and Event Sourcing
Introduction to CQRS and Event Sourcing
 
ISTA 2016: Event Sourcing
ISTA 2016: Event SourcingISTA 2016: Event Sourcing
ISTA 2016: Event Sourcing
 
CQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафорCQRS на практике. В поиске точки масштабирования и новых метафор
CQRS на практике. В поиске точки масштабирования и новых метафор
 
A year with event sourcing and CQRS
A year with event sourcing and CQRSA year with event sourcing and CQRS
A year with event sourcing and CQRS
 
Revit 2018 API News
Revit 2018 API NewsRevit 2018 API News
Revit 2018 API News
 
CQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NETCQRS Evolved - CQRS + Akka.NET
CQRS Evolved - CQRS + Akka.NET
 
CQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architectureCQRS recipes or how to cook your architecture
CQRS recipes or how to cook your architecture
 
CQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHPCQRS and Event Sourcing with MongoDB and PHP
CQRS and Event Sourcing with MongoDB and PHP
 
Andrii Gryshchenko: "An Overview of CQRS and Event Sourcing"
Andrii Gryshchenko: "An Overview of CQRS and Event Sourcing"Andrii Gryshchenko: "An Overview of CQRS and Event Sourcing"
Andrii Gryshchenko: "An Overview of CQRS and Event Sourcing"
 

Similaire à CQRS

Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented developmentrajmundr
 
What Impact Will Entity Framework Have On Architecture
What Impact Will Entity Framework Have On ArchitectureWhat Impact Will Entity Framework Have On Architecture
What Impact Will Entity Framework Have On ArchitectureEric Nelson
 
Non-Relational Databases: This hurts. I like it.
Non-Relational Databases: This hurts. I like it.Non-Relational Databases: This hurts. I like it.
Non-Relational Databases: This hurts. I like it.Onyxfish
 
Azure Cosmos DB - NoSQL In the Microsoft Cloud
Azure Cosmos DB - NoSQL In the Microsoft CloudAzure Cosmos DB - NoSQL In the Microsoft Cloud
Azure Cosmos DB - NoSQL In the Microsoft CloudJosh Lane
 
Database revolution opening webcast 01 18-12
Database revolution opening webcast 01 18-12Database revolution opening webcast 01 18-12
Database revolution opening webcast 01 18-12mark madsen
 
Database Revolution - Exploratory Webcast
Database Revolution - Exploratory WebcastDatabase Revolution - Exploratory Webcast
Database Revolution - Exploratory WebcastInside Analysis
 
No more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureNo more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureMarco Parenzan
 
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim RemaniFinding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim RemaniJAXLondon2014
 
Big data, Cloud Computing and No SQL
Big data, Cloud Computing and No SQLBig data, Cloud Computing and No SQL
Big data, Cloud Computing and No SQLManu Cohen-Yashar
 
Runaway complexity in Big Data... and a plan to stop it
Runaway complexity in Big Data... and a plan to stop itRunaway complexity in Big Data... and a plan to stop it
Runaway complexity in Big Data... and a plan to stop itnathanmarz
 
Cloud Architecture Patterns for Mere Mortals - Bill Wilder - Vermont Code Cam...
Cloud Architecture Patterns for Mere Mortals - Bill Wilder - Vermont Code Cam...Cloud Architecture Patterns for Mere Mortals - Bill Wilder - Vermont Code Cam...
Cloud Architecture Patterns for Mere Mortals - Bill Wilder - Vermont Code Cam...Bill Wilder
 
SQLBits VI - Improving database performance by removing the database
SQLBits VI - Improving database performance by removing the databaseSQLBits VI - Improving database performance by removing the database
SQLBits VI - Improving database performance by removing the databaseSimon Munro
 
2007 Mark Logic User Conference Keynote
2007 Mark Logic User Conference Keynote2007 Mark Logic User Conference Keynote
2007 Mark Logic User Conference KeynoteDave Kellogg
 
2014.11.14 Data Opportunities with Azure
2014.11.14 Data Opportunities with Azure2014.11.14 Data Opportunities with Azure
2014.11.14 Data Opportunities with AzureMarco Parenzan
 
Extending on premise applications to the cloud
Extending on premise applications to the cloudExtending on premise applications to the cloud
Extending on premise applications to the cloudIntechnica
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015Christopher Curtin
 
Melbourne Microservices Meetup: Agenda for a new Architecture
Melbourne Microservices Meetup: Agenda for a new ArchitectureMelbourne Microservices Meetup: Agenda for a new Architecture
Melbourne Microservices Meetup: Agenda for a new ArchitectureSaul Caganoff
 

Similaire à CQRS (20)

Domain oriented development
Domain oriented developmentDomain oriented development
Domain oriented development
 
What Impact Will Entity Framework Have On Architecture
What Impact Will Entity Framework Have On ArchitectureWhat Impact Will Entity Framework Have On Architecture
What Impact Will Entity Framework Have On Architecture
 
Non-Relational Databases: This hurts. I like it.
Non-Relational Databases: This hurts. I like it.Non-Relational Databases: This hurts. I like it.
Non-Relational Databases: This hurts. I like it.
 
Azure Cosmos DB - NoSQL In the Microsoft Cloud
Azure Cosmos DB - NoSQL In the Microsoft CloudAzure Cosmos DB - NoSQL In the Microsoft Cloud
Azure Cosmos DB - NoSQL In the Microsoft Cloud
 
Database revolution opening webcast 01 18-12
Database revolution opening webcast 01 18-12Database revolution opening webcast 01 18-12
Database revolution opening webcast 01 18-12
 
Database Revolution - Exploratory Webcast
Database Revolution - Exploratory WebcastDatabase Revolution - Exploratory Webcast
Database Revolution - Exploratory Webcast
 
No more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and AzureNo more Three Tier - A path to a better code for Cloud and Azure
No more Three Tier - A path to a better code for Cloud and Azure
 
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim RemaniFinding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
Finding your Way in the Midst of the NoSQL Haze - Abdelmonaim Remani
 
Intro to Databases
Intro to DatabasesIntro to Databases
Intro to Databases
 
Technology Disruption
Technology DisruptionTechnology Disruption
Technology Disruption
 
Big data, Cloud Computing and No SQL
Big data, Cloud Computing and No SQLBig data, Cloud Computing and No SQL
Big data, Cloud Computing and No SQL
 
Azure and cloud design patterns
Azure and cloud design patternsAzure and cloud design patterns
Azure and cloud design patterns
 
Runaway complexity in Big Data... and a plan to stop it
Runaway complexity in Big Data... and a plan to stop itRunaway complexity in Big Data... and a plan to stop it
Runaway complexity in Big Data... and a plan to stop it
 
Cloud Architecture Patterns for Mere Mortals - Bill Wilder - Vermont Code Cam...
Cloud Architecture Patterns for Mere Mortals - Bill Wilder - Vermont Code Cam...Cloud Architecture Patterns for Mere Mortals - Bill Wilder - Vermont Code Cam...
Cloud Architecture Patterns for Mere Mortals - Bill Wilder - Vermont Code Cam...
 
SQLBits VI - Improving database performance by removing the database
SQLBits VI - Improving database performance by removing the databaseSQLBits VI - Improving database performance by removing the database
SQLBits VI - Improving database performance by removing the database
 
2007 Mark Logic User Conference Keynote
2007 Mark Logic User Conference Keynote2007 Mark Logic User Conference Keynote
2007 Mark Logic User Conference Keynote
 
2014.11.14 Data Opportunities with Azure
2014.11.14 Data Opportunities with Azure2014.11.14 Data Opportunities with Azure
2014.11.14 Data Opportunities with Azure
 
Extending on premise applications to the cloud
Extending on premise applications to the cloudExtending on premise applications to the cloud
Extending on premise applications to the cloud
 
UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015UnConference for Georgia Southern Computer Science March 31, 2015
UnConference for Georgia Southern Computer Science March 31, 2015
 
Melbourne Microservices Meetup: Agenda for a new Architecture
Melbourne Microservices Meetup: Agenda for a new ArchitectureMelbourne Microservices Meetup: Agenda for a new Architecture
Melbourne Microservices Meetup: Agenda for a new Architecture
 

Plus de Fabian Vilers

JavaScript: bonnes pratiques, astuces, et cauchemars
JavaScript: bonnes pratiques, astuces, et cauchemarsJavaScript: bonnes pratiques, astuces, et cauchemars
JavaScript: bonnes pratiques, astuces, et cauchemarsFabian Vilers
 
REST in peace avec GraphQL
REST in peace avec GraphQLREST in peace avec GraphQL
REST in peace avec GraphQLFabian Vilers
 
MEAN (Jeudis du Libre)
MEAN (Jeudis du Libre)MEAN (Jeudis du Libre)
MEAN (Jeudis du Libre)Fabian Vilers
 
Introduction au BDD (Behavior Driven Development)
Introduction au BDD (Behavior Driven Development)Introduction au BDD (Behavior Driven Development)
Introduction au BDD (Behavior Driven Development)Fabian Vilers
 
Introduction à meteor
Introduction à meteorIntroduction à meteor
Introduction à meteorFabian Vilers
 
Social Sitters Final Pitch
Social Sitters Final PitchSocial Sitters Final Pitch
Social Sitters Final PitchFabian Vilers
 

Plus de Fabian Vilers (9)

React live coding
React live codingReact live coding
React live coding
 
JavaScript: bonnes pratiques, astuces, et cauchemars
JavaScript: bonnes pratiques, astuces, et cauchemarsJavaScript: bonnes pratiques, astuces, et cauchemars
JavaScript: bonnes pratiques, astuces, et cauchemars
 
REST in peace avec GraphQL
REST in peace avec GraphQLREST in peace avec GraphQL
REST in peace avec GraphQL
 
MEAN (Jeudis du Libre)
MEAN (Jeudis du Libre)MEAN (Jeudis du Libre)
MEAN (Jeudis du Libre)
 
MEAN (DevFM)
MEAN (DevFM)MEAN (DevFM)
MEAN (DevFM)
 
Introduction au BDD (Behavior Driven Development)
Introduction au BDD (Behavior Driven Development)Introduction au BDD (Behavior Driven Development)
Introduction au BDD (Behavior Driven Development)
 
Introduction à meteor
Introduction à meteorIntroduction à meteor
Introduction à meteor
 
TypeScript
TypeScriptTypeScript
TypeScript
 
Social Sitters Final Pitch
Social Sitters Final PitchSocial Sitters Final Pitch
Social Sitters Final Pitch
 

Dernier

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Dernier (20)

Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

CQRS

  • 2. What problems are we trying to solve?
  • 3. Once upon a time…
  • 4. Paper was all around before the advent of computers
  • 5. Then came our savior: the data entry screen
  • 6. It’s a brave new world No just about paper input anymore But application architecture still reflects that idea IT made it all about the data Data centric apps are CRUD based
  • 7. Insidious CRUD This might be a good idea for catalog data type But only for that type of application How to change state with CRUD? Read documentation? Follow existing business process? This feels so unnatural If the domain model is the rules Then don’t make the user be the domain model
  • 8. Complexity of code and solution Too many layers Big data models Anemic domain model Focus on frameworks instead of on the domain Scalability not considered at the core of the design (scalability get hacked in too late)
  • 10. Typical one size fits all architecture
  • 11. Which leads to maintainability issues
  • 12. Monolithic and tighly coupled application One does not simply draw a class diagram.
  • 13. And poorly used tools One SQL query to rule them all.
  • 14. Good architects & layer best practices
  • 15. Applications exist to support use cases User intent to manipulate information AKA a « mutator » (or setter) User intent to find and read information AKA an « accessor » (or getter)
  • 16. CQRS Functions that write (mutators) are called « Command » methods They must not return a value Functions that read (accessors) are called « Query » methods They must have no side effects
  • 17. Commands Primary goal is to capture user intent Supports a single use case and targets a single aggregate Are imperative CreateOrder SendNotification UnregisterConference …
  • 18. Queries Query results contain only data, no logic But there’s more about them… I’ll tell you later on… I promise!
  • 19. Real life scenario Alice reads data Bob reads data Oh, it’s coffee time for Bob! Alice update data Bob updates stale data KABOOM ! Optimistic Locking Exception
  • 20. We’re always working with stale data Think about your favorite browser When the HTML page is rendered, several milliseconds have passed since the request was sent The document could have changed on the server side But you are OK with it Think about the stars in the sky When we observe one, several years have passed The star has maybe exploded But you are OK with it This is what we call « eventual consistency »
  • 21. Let’s use stale data to our advantage Offload the database by using read models Tailor each read models to match as close as possible the view to avoid mappings Serve read models very quickly
  • 22. So what is CQRS? « CQRS is simply the creation of two objects where there was previously only one. » -- Greg Young
  • 23. Queries Query results contain only data, no logic Query results are stale Query operates on a completely denormalized data model Query are fast and avoid as much as possible mappings and transformations
  • 24. All we need is good synchronization
  • 25. Events Signal that something happened Closely aligned to the domain model Are handled by a messasing system Are in the past tense OrderCreated NotificationSent ConferenceUnregistered …
  • 26. Commands Primary goal is to capture user intent Supports a single use case and targets a single aggregate Are imperative CreateOrder SendNotification UnregisterConference … Mutate aggregate state which results in one or more events being published
  • 27. Events as a source It’s the ES (Event Sourcing) in CQRS/ES Aggregate state is not stored as is But rather the events that took place Aggregate’s events represent its history Built-in audit log Any state can be rolled back Snapshots can be taken when the event stream is big enough A good example is your bank account
  • 29. References Greg Young (@gregyoung) Udi Dahan (@UdiDahan) Martin Fowler (@martinfowler)