SlideShare a Scribd company logo
1 of 28
Yuriy Taras
 Conventional architecture and its problems
 CQRS introduction
 Bonus – Event Sourcing
 Collaborations – when users are working on same set of data
 Staleness – when data may expire between read and write
Data is stale anyway. Why don’t admit it?
We can create read-optimized database to show data.
                                                 Remember OLAP and OLTP?
SELECT
title, short_text, publish_date, publisher_name, comme
nt_count FROM posts_list
Good scalability, good performance
You can use direct mapping from tables to UI
1.   Manager loads client info
2.   He’s editing data
     a)   Address is changed
     b)   Status is changed to ‘preferred’
3.   In background status is changed to ‘delinquent’
4.   Manager submits data
What would you do?
                                                       Example by Udi Dahan
Conventional way – here’s updated copy of your data, save it to database
CQRS (in fact, DDD) way – do this with your entity
 Commands are verbs – RenameUser, PublishPost
 Most of them will be idempotent – no more double submit problem
 Include version of your data – will help to resolve conflicts
 Commands are asynchronous – remember about DDD’s CQS concept?
 Do command validation before sending it – if you can’t do it without making command
 synchronous, it’s no longer a validation and we’ll talk later about it
public final class ChangeStatus implements Serializable {
// private final fields skipped
 public ChangeStatus(Status status, EntityKey userId, long
version, String description) {
    assertNotNull(status);
    if (status == Status.REQUIRES_ACTION) {
    assertNotNull(description);
    }
    // and so on
}
}
Usually it’s Domain Model – commands matches perfectly with DDD’s entities and
services.
Still you can use Transaction Script or Table Module patterns – CQRS doesn’t care.
Stale data – most of the time you’ll be able to merge changes in different branches without
conflicts.
                                                  do you see DCVS terminology here?
Example:
CustomerStatus(delinquent) + ChangeCustomerAddress = merge automatically
CustomerStatus(delinquent) + CustomerStatus(preferred) = depends on a
business logic, but probably make it delinquent and notify manager
What if billing command would be late?
CustomerStatus(preferred) + CustomerStatus(delinquent) = make it delinquent
and notify manager
 Database deadlock
 Some component down
 Kernel panic somewhere
 Bug in our software
 Other infrastructure issues
Retry!
Command processor should emit (publish) events.
Commands are DoThis. Events are ThisDone.
Read database is the most obvious subscriber:
UPDATE post_lists SET comments_count = comments_count
+ 1 WHERE post_id = #{post_id}
INSERT INTO comments_list SET …
                            Do you still remember our OLTP/OLAP analogy?
 Send email notification
 Write to file
 Notify other system via Web service or ESB
 Push notification to Web-client with Web sockets
 Ring the alarm
Pros
   Better scalability
   Taking staleness into account
   Works better in collaboration scenarios
Cons
   Harder to understand and implement
   Not widely known/adopted
   Requires more setup that conventional architecture
   In simple cases is overcomplicated
 Complex business domain
 Users that collaborate on common data
 Scalability and performance
 Large or distributed team
Conventional way to store domain objects – database tables.
Post(id: 5, title: ‘CQRS+ES’, content: ‘Today I want
to…’)
Other way be storing it as a series of events:
1. PostCreated(id: 1)
2. PostTitled(‘CQRS+ES’)
3. PostContentSet(‘Will add content later’)
4. PostContentSet(‘I want to…’)
5. PostPublished(Fri, 13)
Pros
   Audit for free
   Event centric
   Better conflict merging
   Simpler testing
Cons
   Even more infrastructure to set up (snapshots, cleanups, etc)
   Not very known/popular
   Higher entrance threshold
 CQRS Jorney http://msdn.microsoft.com/en-us/library/jj554200.aspx
 CQRS Blog http://cqrs.wordpress.com/
 Clarified CQRS http://www.udidahan.com/2009/12/09/clarified-cqrs/
 Fowler’s articles
   http://martinfowler.com/bliki/CQRS.html
   http://martinfowler.com/eaaDev/EventSourcing.html

 Other links http://www.mindmeister.com/181195534/cqrs-ddd-links

More Related Content

What's hot

Lect 08 materialized view
Lect 08 materialized viewLect 08 materialized view
Lect 08 materialized viewBilal khan
 
Parallel processing in data warehousing and big data
Parallel processing in data warehousing and big dataParallel processing in data warehousing and big data
Parallel processing in data warehousing and big dataAbhishek Sharma
 
Mca3020 advanced database management system
Mca3020  advanced database management systemMca3020  advanced database management system
Mca3020 advanced database management systemsmumbahelp
 
DATABASE INTRODUCTION
DATABASE INTRODUCTIONDATABASE INTRODUCTION
DATABASE INTRODUCTIONghazi103
 
Orleans Cloud Computing
Orleans Cloud Computing  Orleans Cloud Computing
Orleans Cloud Computing Huzaifa zafar
 
Mca3020 advanced database management system
Mca3020  advanced database management systemMca3020  advanced database management system
Mca3020 advanced database management systemsmumbahelp
 
Kaashiv SQL Server Interview Questions Presentation
Kaashiv SQL Server Interview Questions PresentationKaashiv SQL Server Interview Questions Presentation
Kaashiv SQL Server Interview Questions Presentationkaashiv1
 
New Features Sql 2008
New Features Sql 2008New Features Sql 2008
New Features Sql 2008tomerl
 
Mca3020 advanced database management system
Mca3020  advanced database management systemMca3020  advanced database management system
Mca3020 advanced database management systemsmumbahelp
 
Mi0034 – database management system
Mi0034 – database management systemMi0034 – database management system
Mi0034 – database management systemsmumbahelp
 
PATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETPATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETMichael Heron
 
Distributed database
Distributed databaseDistributed database
Distributed databasesanjay joshi
 

What's hot (16)

Lect 08 materialized view
Lect 08 materialized viewLect 08 materialized view
Lect 08 materialized view
 
Parallel processing in data warehousing and big data
Parallel processing in data warehousing and big dataParallel processing in data warehousing and big data
Parallel processing in data warehousing and big data
 
Discover Database
Discover DatabaseDiscover Database
Discover Database
 
Mca3020 advanced database management system
Mca3020  advanced database management systemMca3020  advanced database management system
Mca3020 advanced database management system
 
DATABASE INTRODUCTION
DATABASE INTRODUCTIONDATABASE INTRODUCTION
DATABASE INTRODUCTION
 
Orleans Cloud Computing
Orleans Cloud Computing  Orleans Cloud Computing
Orleans Cloud Computing
 
Mca3020 advanced database management system
Mca3020  advanced database management systemMca3020  advanced database management system
Mca3020 advanced database management system
 
Ch12
Ch12Ch12
Ch12
 
Chapter 4 u
Chapter 4 uChapter 4 u
Chapter 4 u
 
Kaashiv SQL Server Interview Questions Presentation
Kaashiv SQL Server Interview Questions PresentationKaashiv SQL Server Interview Questions Presentation
Kaashiv SQL Server Interview Questions Presentation
 
Distributed D B
Distributed  D BDistributed  D B
Distributed D B
 
New Features Sql 2008
New Features Sql 2008New Features Sql 2008
New Features Sql 2008
 
Mca3020 advanced database management system
Mca3020  advanced database management systemMca3020  advanced database management system
Mca3020 advanced database management system
 
Mi0034 – database management system
Mi0034 – database management systemMi0034 – database management system
Mi0034 – database management system
 
PATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETPATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NET
 
Distributed database
Distributed databaseDistributed database
Distributed database
 

Viewers also liked

Domain driven design
Domain driven designDomain driven design
Domain driven designYura Taras
 
Technologische trends voor journalistiek
Technologische trends voor journalistiekTechnologische trends voor journalistiek
Technologische trends voor journalistiekBart Van Belle
 
Amigos de verdad
Amigos de verdadAmigos de verdad
Amigos de verdaderickadomi
 
Phenomenal Oct, 29, 2009
Phenomenal Oct, 29, 2009Phenomenal Oct, 29, 2009
Phenomenal Oct, 29, 2009etalcomendras
 
Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Ohio LETC
 
Apture Publisher Overview
Apture Publisher OverviewApture Publisher Overview
Apture Publisher OverviewApture
 
Biopython at BOSC 2010
Biopython at BOSC 2010Biopython at BOSC 2010
Biopython at BOSC 2010Brad Chapman
 
Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009etalcomendras
 
Laserendoveineux b anastasie 1 er partie
Laserendoveineux  b anastasie   1 er partieLaserendoveineux  b anastasie   1 er partie
Laserendoveineux b anastasie 1 er partiesfa_angeiologie
 
Practical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time DebuggingPractical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time Debugginglienhard
 
Itf ipp ch10_2012_final
Itf ipp ch10_2012_finalItf ipp ch10_2012_final
Itf ipp ch10_2012_finaldphil002
 

Viewers also liked (20)

Domain driven design
Domain driven designDomain driven design
Domain driven design
 
201506 CSE340 Lecture 14
201506 CSE340 Lecture 14201506 CSE340 Lecture 14
201506 CSE340 Lecture 14
 
Technologische trends voor journalistiek
Technologische trends voor journalistiekTechnologische trends voor journalistiek
Technologische trends voor journalistiek
 
Amigos de verdad
Amigos de verdadAmigos de verdad
Amigos de verdad
 
Huizenprijzen in amsterdam
Huizenprijzen in amsterdamHuizenprijzen in amsterdam
Huizenprijzen in amsterdam
 
Mpv2010
Mpv2010Mpv2010
Mpv2010
 
Chapter 3
Chapter 3Chapter 3
Chapter 3
 
Thehub euromed
Thehub   euromedThehub   euromed
Thehub euromed
 
Phenomenal Oct, 29, 2009
Phenomenal Oct, 29, 2009Phenomenal Oct, 29, 2009
Phenomenal Oct, 29, 2009
 
201506 CSE340 Lecture 16
201506 CSE340 Lecture 16201506 CSE340 Lecture 16
201506 CSE340 Lecture 16
 
Week9
Week9Week9
Week9
 
Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009Login Seminars Blackboard Directions 2009
Login Seminars Blackboard Directions 2009
 
Apture Publisher Overview
Apture Publisher OverviewApture Publisher Overview
Apture Publisher Overview
 
Biopython at BOSC 2010
Biopython at BOSC 2010Biopython at BOSC 2010
Biopython at BOSC 2010
 
Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009Phenomenal Oct 8, 2009
Phenomenal Oct 8, 2009
 
Laserendoveineux b anastasie 1 er partie
Laserendoveineux  b anastasie   1 er partieLaserendoveineux  b anastasie   1 er partie
Laserendoveineux b anastasie 1 er partie
 
Practical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time DebuggingPractical Object-Oriented Back-in-Time Debugging
Practical Object-Oriented Back-in-Time Debugging
 
Itf ipp ch10_2012_final
Itf ipp ch10_2012_finalItf ipp ch10_2012_final
Itf ipp ch10_2012_final
 
201506 CSE340 Lecture 13
201506 CSE340 Lecture 13201506 CSE340 Lecture 13
201506 CSE340 Lecture 13
 
Windowsxp
WindowsxpWindowsxp
Windowsxp
 

Similar to CQRS introduction

Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas JellemaModern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas JellemaLucas Jellema
 
Apache Cassandra 2.0
Apache Cassandra 2.0Apache Cassandra 2.0
Apache Cassandra 2.0Joe Stein
 
Greenfield Development with CQRS
Greenfield Development with CQRSGreenfield Development with CQRS
Greenfield Development with CQRSDavid Hoerster
 
Software architecture case study - why and why not sql server replication
Software architecture   case study - why and why not sql server replicationSoftware architecture   case study - why and why not sql server replication
Software architecture case study - why and why not sql server replicationShahzad
 
Air Line Management System | DBMS project
Air Line Management System | DBMS projectAir Line Management System | DBMS project
Air Line Management System | DBMS projectAniketHandore
 
Architectural Anti Patterns - Notes on Data Distribution and Handling Failures
Architectural Anti Patterns - Notes on Data Distribution and Handling FailuresArchitectural Anti Patterns - Notes on Data Distribution and Handling Failures
Architectural Anti Patterns - Notes on Data Distribution and Handling FailuresGleicon Moraes
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core ModuleKatie Gulley
 
Using Cassandra with your Web Application
Using Cassandra with your Web ApplicationUsing Cassandra with your Web Application
Using Cassandra with your Web Applicationsupertom
 
Designing a Scalable Twitter - Patterns for Designing Scalable Real-Time Web ...
Designing a Scalable Twitter - Patterns for Designing Scalable Real-Time Web ...Designing a Scalable Twitter - Patterns for Designing Scalable Real-Time Web ...
Designing a Scalable Twitter - Patterns for Designing Scalable Real-Time Web ...Nati Shalom
 
Movile Internet Movel SA: A Change of Seasons: A big move to Apache Cassandra
Movile Internet Movel SA: A Change of Seasons: A big move to Apache CassandraMovile Internet Movel SA: A Change of Seasons: A big move to Apache Cassandra
Movile Internet Movel SA: A Change of Seasons: A big move to Apache CassandraDataStax Academy
 
Cassandra Summit 2015 - A Change of Seasons
Cassandra Summit 2015 - A Change of SeasonsCassandra Summit 2015 - A Change of Seasons
Cassandra Summit 2015 - A Change of SeasonsEiti Kimura
 
Managing SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAManaging SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAConcentrated Technology
 
Data base testing
Data base testingData base testing
Data base testingBugRaptors
 
Db2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallsDb2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallssam2sung2
 
SQL Server - High availability
SQL Server - High availabilitySQL Server - High availability
SQL Server - High availabilityPeter Gfader
 

Similar to CQRS introduction (20)

Modern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas JellemaModern Database Development Oow2008 Lucas Jellema
Modern Database Development Oow2008 Lucas Jellema
 
Cassandra data modelling best practices
Cassandra data modelling best practicesCassandra data modelling best practices
Cassandra data modelling best practices
 
Apache Cassandra 2.0
Apache Cassandra 2.0Apache Cassandra 2.0
Apache Cassandra 2.0
 
Greenfield Development with CQRS
Greenfield Development with CQRSGreenfield Development with CQRS
Greenfield Development with CQRS
 
Software architecture case study - why and why not sql server replication
Software architecture   case study - why and why not sql server replicationSoftware architecture   case study - why and why not sql server replication
Software architecture case study - why and why not sql server replication
 
Air Line Management System | DBMS project
Air Line Management System | DBMS projectAir Line Management System | DBMS project
Air Line Management System | DBMS project
 
Managing SQLserver
Managing SQLserverManaging SQLserver
Managing SQLserver
 
Architectural Anti Patterns - Notes on Data Distribution and Handling Failures
Architectural Anti Patterns - Notes on Data Distribution and Handling FailuresArchitectural Anti Patterns - Notes on Data Distribution and Handling Failures
Architectural Anti Patterns - Notes on Data Distribution and Handling Failures
 
Questions On The Code And Core Module
Questions On The Code And Core ModuleQuestions On The Code And Core Module
Questions On The Code And Core Module
 
AWS RDS Migration Tool
AWS RDS Migration Tool AWS RDS Migration Tool
AWS RDS Migration Tool
 
Using Cassandra with your Web Application
Using Cassandra with your Web ApplicationUsing Cassandra with your Web Application
Using Cassandra with your Web Application
 
Designing a Scalable Twitter - Patterns for Designing Scalable Real-Time Web ...
Designing a Scalable Twitter - Patterns for Designing Scalable Real-Time Web ...Designing a Scalable Twitter - Patterns for Designing Scalable Real-Time Web ...
Designing a Scalable Twitter - Patterns for Designing Scalable Real-Time Web ...
 
Movile Internet Movel SA: A Change of Seasons: A big move to Apache Cassandra
Movile Internet Movel SA: A Change of Seasons: A big move to Apache CassandraMovile Internet Movel SA: A Change of Seasons: A big move to Apache Cassandra
Movile Internet Movel SA: A Change of Seasons: A big move to Apache Cassandra
 
Cassandra Summit 2015 - A Change of Seasons
Cassandra Summit 2015 - A Change of SeasonsCassandra Summit 2015 - A Change of Seasons
Cassandra Summit 2015 - A Change of Seasons
 
Managing SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBAManaging SQLserver for the reluctant DBA
Managing SQLserver for the reluctant DBA
 
Supporting SQLserver
Supporting SQLserverSupporting SQLserver
Supporting SQLserver
 
No sql
No sqlNo sql
No sql
 
Data base testing
Data base testingData base testing
Data base testing
 
Db2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfallsDb2 migration -_tips,_tricks,_and_pitfalls
Db2 migration -_tips,_tricks,_and_pitfalls
 
SQL Server - High availability
SQL Server - High availabilitySQL Server - High availability
SQL Server - High availability
 

Recently uploaded

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 

Recently uploaded (20)

Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 

CQRS introduction

  • 2.  Conventional architecture and its problems  CQRS introduction  Bonus – Event Sourcing
  • 3.
  • 4.
  • 5.  Collaborations – when users are working on same set of data  Staleness – when data may expire between read and write
  • 6.
  • 7.
  • 8.
  • 9. Data is stale anyway. Why don’t admit it? We can create read-optimized database to show data. Remember OLAP and OLTP? SELECT title, short_text, publish_date, publisher_name, comme nt_count FROM posts_list Good scalability, good performance You can use direct mapping from tables to UI
  • 10. 1. Manager loads client info 2. He’s editing data a) Address is changed b) Status is changed to ‘preferred’ 3. In background status is changed to ‘delinquent’ 4. Manager submits data What would you do? Example by Udi Dahan
  • 11. Conventional way – here’s updated copy of your data, save it to database CQRS (in fact, DDD) way – do this with your entity
  • 12.  Commands are verbs – RenameUser, PublishPost  Most of them will be idempotent – no more double submit problem  Include version of your data – will help to resolve conflicts  Commands are asynchronous – remember about DDD’s CQS concept?  Do command validation before sending it – if you can’t do it without making command synchronous, it’s no longer a validation and we’ll talk later about it
  • 13. public final class ChangeStatus implements Serializable { // private final fields skipped public ChangeStatus(Status status, EntityKey userId, long version, String description) { assertNotNull(status); if (status == Status.REQUIRES_ACTION) { assertNotNull(description); } // and so on } }
  • 14. Usually it’s Domain Model – commands matches perfectly with DDD’s entities and services. Still you can use Transaction Script or Table Module patterns – CQRS doesn’t care.
  • 15. Stale data – most of the time you’ll be able to merge changes in different branches without conflicts. do you see DCVS terminology here? Example: CustomerStatus(delinquent) + ChangeCustomerAddress = merge automatically CustomerStatus(delinquent) + CustomerStatus(preferred) = depends on a business logic, but probably make it delinquent and notify manager What if billing command would be late? CustomerStatus(preferred) + CustomerStatus(delinquent) = make it delinquent and notify manager
  • 16.  Database deadlock  Some component down  Kernel panic somewhere  Bug in our software  Other infrastructure issues Retry!
  • 17. Command processor should emit (publish) events. Commands are DoThis. Events are ThisDone.
  • 18. Read database is the most obvious subscriber: UPDATE post_lists SET comments_count = comments_count + 1 WHERE post_id = #{post_id} INSERT INTO comments_list SET … Do you still remember our OLTP/OLAP analogy?
  • 19.  Send email notification  Write to file  Notify other system via Web service or ESB  Push notification to Web-client with Web sockets  Ring the alarm
  • 20.
  • 21.
  • 22. Pros Better scalability Taking staleness into account Works better in collaboration scenarios Cons Harder to understand and implement Not widely known/adopted Requires more setup that conventional architecture In simple cases is overcomplicated
  • 23.  Complex business domain  Users that collaborate on common data  Scalability and performance  Large or distributed team
  • 24. Conventional way to store domain objects – database tables. Post(id: 5, title: ‘CQRS+ES’, content: ‘Today I want to…’)
  • 25. Other way be storing it as a series of events: 1. PostCreated(id: 1) 2. PostTitled(‘CQRS+ES’) 3. PostContentSet(‘Will add content later’) 4. PostContentSet(‘I want to…’) 5. PostPublished(Fri, 13)
  • 26. Pros Audit for free Event centric Better conflict merging Simpler testing Cons Even more infrastructure to set up (snapshots, cleanups, etc) Not very known/popular Higher entrance threshold
  • 27.
  • 28.  CQRS Jorney http://msdn.microsoft.com/en-us/library/jj554200.aspx  CQRS Blog http://cqrs.wordpress.com/  Clarified CQRS http://www.udidahan.com/2009/12/09/clarified-cqrs/  Fowler’s articles  http://martinfowler.com/bliki/CQRS.html  http://martinfowler.com/eaaDev/EventSourcing.html  Other links http://www.mindmeister.com/181195534/cqrs-ddd-links