SlideShare a Scribd company logo
1 of 37
CQRSFROM A CONCEPT TO REAL LIFE ARCHITECTURE
Tiep Le DC3B
TMA Solutions
1
What is CQRS? 2
What’s going on around the world
 Connected via Internet
 Social networks
 Mobile Devices
 News
 Forums & Blogs
 e-commerce
 Search Engines
3
Social Networks 4
Facebook
 How many friends do you have?
 Thousand?
 Hundred?
 A few?
 Do you like to
 Post new status?
 Like?
 Comment?
 Share?
 There types of people:
 Social people
 Quite normal
 Look around
5
Activity
Facebook 6
Real number
Common Problem
We read more than we write
7
Problem?
 In traditional systems, both commands (updates to data) and queries
(request for data) are executed against a same set of entities of a
single data repository.
 Mismatch between read and write entity
 Create a lot of read-only model that presents the result from joining multi-
tables
 The system will be slow down if handle a large of requests since the
read/write action be handled in the same services.
 The number of reads and writes maybe very different in the enterprise
system
 Hard to manage security and permission because each entity is subject
to both read and write operations
8
Quote
 A single model cannot be appropriate for
reporting, searching and transactional behavior.
9
Greg Young, 2008
What?
CQRS
 CQRS: Command & Query Responsibility Segregation is simply the creation
of two objects where there was previously only one. The separation occurs
based upon whether the methods are a command or a query. Greg
Young
 CQRS enables us to optimize the read and write side independently
 CQRS is an architectural style that is often enabling of DDD
 Implementation of the model exists on the write side; it encapsulates the
complex business logic
 DDD divides large, complex systems into more manageable units known as
bounded context
10
Why? 11
 Scalability: by separating the read side and the write side into separate
models, we have ability to scale each side independently
 Reduced complexity: designing and implementing objects that are
responsible for both reading and writing data can exacerbate the
complexity. It becomes harder to deal with difficult issues such as multiple
users, shared data, performance, transactions, consistency, and stale
data with the same model.
 Flexibility: easier to make changes on both sides that doesn’t impact the
other
 Focus on the business: separating the different concerns into the read
side and the write side is a solution that is more adaptable in the face of
changing business requirements
 Facilitates building task-based UIs: design the UI to send the command to
the domain instead of CRUD operations
When? 12
 Collaborative domains: multiple operations are performed in parallel on
the same data
 Performance: when the read/write ratio is very high, and when horizontal
scaling is required
 Business rule change regularly: updating the model of a side doesn’t
affect to the other
 Work independently: one team of developers can focus on the complex
domain model that is part of the write model, and another less
experienced team can focus on the read model and the user interfaces
 Use with task-based UI: with complex domain models, and for teams
already familiar with DDD techniques.
When NOT? 13
 Business rules are simple
 Simple, static bounded context: less likely to warrant the up-front
investment in detailed analysis, modeling, and complex implementation
 Simple CRUD-style user interface and the related data access operations
are sufficient
Related Patterns 14
 Event Sourcing Pattern: simplify tasks in complex domains; improve
performance, scalability, and responsiveness; provide consistency for
transactional data; and maintain full audit trails and history that may
enable compensating actions
 Materialized View Pattern: The read model of a CQRS implementation
may contain materialized views of the write model data, or the read
model may be used to generate materialized views
CQRS & Event Sourcing 15
 Event Sourcing: Event sourcing is a way of persisting your application's
state by storing the history that determines the current state of your
application
 Audit trails
 Integration with other sub-systems
 Product troubleshot
 Fixing errors
 Testing
 ES is a great pattern to use to implement the link between the thing that
writes and the thing that reads
CQRS & Event Sourcing
continue
16
Stale data 17
We’re always working with stale data
Enterprise Service Bus 18
 ESB: Enterprise Service Bus is an infrastructure piece of software than a
pattern itself
 Implementing different message patterns:
 Publish / Subscribe
 Request / Reply
 Dead after channel
 Peer to peer
 Broad cast to all
Sherpa Project
 An enterprise social network
 Recruitment
 Resource planning
 Survey system
 Training
 Library
 Events
19
Case Study
Resource planning
 Member Availability
 Member Time-off
 Public Holiday
 Cost Center
 Shift Position
 Roster & Shift
 Timesheet
 Payroll Engine
20
Case Study
Member Time-off
 A member can belong to multi projects
 Member can view their list of time-off by time range
 Any manager can view list of all member’s time off by time range in
a specific project/group
 Manager can view only time-off with pending status
 Manager can approve/reject their time-off
21
Requirements
Member Time-off
 A member can belong to multi
projects/Group
 Manager can view list in any
projects/group
22
Use case diagram
uc Member TimeOff
Member Time-off
View my list
View detail
Create
Update
View list in group
Approve/Reject
Send Notification
Member
Manager
«invokes»
Member Time-off 23
Entity Diagram – Write part
Member Time-off 24
Query needed
 Query results contain only data – no logic
 Give me all my leaves this year
 Give me all my leaves this month
 Give me all team member’s leaves for project A
 Give me all team member’s leaves for project B for only this week
 Give me all leaves of project C that are in pending
 Give me all pending leaves of project D in next two weeks
 Give me all member M’s leaves of project E last month
NoSQL Storage 25
Azure storage
 Have no relationship
 Index by Partition Key & Row Key
 Searching priority from left to right as string
 1
 11
 111
 2
 No support paging (limitation)
Member Time-off
My Time-Off By pending By Groups
PartitionKey NetworkId_ AzureQueryType NetworkId_ AzureQueryType NetworkId_ AzureQueryType
RowKey MemberId_Date_MemberTimeOffId GroupId_Pending_Date_MemberTimeOffId GroupId_Date_MemberId_MemberTimeOffId
MemberTimeOffId int int int
MemberId int int int
StartDate DateTime DateTime DateTime
EndDate DateTime DateTime DateTime
TimeZoneId string string string
TimeOffType string string string
Status string string string
Username string string string
DisplayName string string string
Comment string string string
26
Entity Diagram – Read part
Member Time-off 27
Query Example
 My Time-Off: MemberId_Date_MemberTimeOffId
 19433_20151021_1
 19433_20151022_2
 19433_20151023_3
 19433_20151024_4
 19433_20151025_5
 19433_20151026_6
 19433_20151027_7
 19433_20151028_8
 19434_20151020_9
 19433_20151021_1
 19433_20151022_2
 19433_20151023_3
 19433_20151024_4
 19433_20151025_5
 19433_20151026_6
 19433_20151027_7
 19433_20151028_8
 19433_20151022_2
 19433_20151023_3
 19433_20151024_4
 19433_20151025_5
By member id: 19433 From date range: 22 Oct – 25 Oct
Row key: 19433_ Row key: >= 19433_20151022 && <= 19433_20151025
Member Time-off 28
Sequence diagram: Create
sd TimeOff.Create new
Member
SherpaWeb Sherpa APIV2 MemberTimeOffService MemberTimeOffRepository Database Sherpa.Application.Agents
memberTimeOff Id()
CreateMemberTimeOff()
«success»
Publish CreateMemberTimeOffMessage()
InsertMemberTimeOff()
Create Time-Off()
«success»
Insert(memberTimeOff)
POST: api/memberTimeOffs()
memberTimeOff Id()
new memberTimeOff()
Member Create Time-off
Member Time-off 29
Command vs Events
Command Event
CreateMemberTimeOff MemberTimeOffCreated
UpdateMemberTimeOff MemberTimeOffUpdated
DeleteMemberTimeOff MemberTimeOffDeleted
CancelMemberTimeOff MemberTimeOffCanceled
ApproveMemberTimeOff MemberTimeOffApproved
RejectMemberTimeOff MemberTimeOffRejected
Member Time-off 30
Message Entity Digram
Handle CreateMemberTimeOffMessage
Member Time-off 31
Sequence diagram: Handle Create
Handle CreateMemberTimeOffMessage
Member Time-off 32
Sequence diagram: Update member time-off
Update existed Member-Timeoff
Member Time-off 33
Sequence diagram: Handle Update
Handle UpdateMemberTimeOffMessage
Member Time-off 34
Sequence diagram: Member cancel
Handle CacelMemberTimeOffMessage
Lesion learn 35
 Developer works independently
 Requirements changed or added not affected much to design and code
 Design easily: What we want to get is a read model
Question & Answer 36
References 37
 Greg Young’s blog: http://goodenoughsoftware.net/
 CQRS Journey MSDN: https://msdn.microsoft.com/en-us/library/jj554200.aspx
 We’re social: http://wearesocial.net

More Related Content

What's hot

Angular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHTAngular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHTtayebbousfiha1
 
Midi technique - présentation docker
Midi technique - présentation dockerMidi technique - présentation docker
Midi technique - présentation dockerOlivier Eeckhoutte
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event HandlingWebStackAcademy
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring bootAntoine Rey
 
敏捷开发技术最佳实践(统一敏捷开发过程)
敏捷开发技术最佳实践(统一敏捷开发过程)敏捷开发技术最佳实践(统一敏捷开发过程)
敏捷开发技术最佳实践(统一敏捷开发过程)Weijun Zhong
 
Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...
Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...
Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...Saâd Zerhouni
 
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...Nawres Farhat
 
Services web soap-el-habib-nfaoui
Services web soap-el-habib-nfaouiServices web soap-el-habib-nfaoui
Services web soap-el-habib-nfaouiEl Habib NFAOUI
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to DockerAditya Konarde
 
AngularJS - Présentation (french)
AngularJS - Présentation (french)AngularJS - Présentation (french)
AngularJS - Présentation (french)Yacine Rezgui
 
Présentation PFE: Système de gestion des réclamations et interventions clients
Présentation PFE: Système de gestion des réclamations et interventions clientsPrésentation PFE: Système de gestion des réclamations et interventions clients
Présentation PFE: Système de gestion des réclamations et interventions clientsMohamed Ayoub OUERTATANI
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An IntroductionPOSSCON
 
Introduction To Docker, Docker Compose, Docker Swarm
Introduction To Docker, Docker Compose, Docker SwarmIntroduction To Docker, Docker Compose, Docker Swarm
Introduction To Docker, Docker Compose, Docker SwarmAn Nguyen
 
Présentation docker et kubernetes
Présentation docker et kubernetesPrésentation docker et kubernetes
Présentation docker et kubernetesKiwi Backup
 

What's hot (20)

Angular Avancé
Angular AvancéAngular Avancé
Angular Avancé
 
Angular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHTAngular Framework présentation PPT LIGHT
Angular Framework présentation PPT LIGHT
 
Midi technique - présentation docker
Midi technique - présentation dockerMidi technique - présentation docker
Midi technique - présentation docker
 
Introduction à Angular
Introduction à AngularIntroduction à Angular
Introduction à Angular
 
Angular - Chapter 4 - Data and Event Handling
 Angular - Chapter 4 - Data and Event Handling Angular - Chapter 4 - Data and Event Handling
Angular - Chapter 4 - Data and Event Handling
 
Introduction à spring boot
Introduction à spring bootIntroduction à spring boot
Introduction à spring boot
 
敏捷开发技术最佳实践(统一敏捷开发过程)
敏捷开发技术最佳实践(统一敏捷开发过程)敏捷开发技术最佳实践(统一敏捷开发过程)
敏捷开发技术最佳实践(统一敏捷开发过程)
 
Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...
Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...
Application de gestion des projets en J2EE (Spring-Hibernate) avec architectu...
 
Docker Introduction
Docker IntroductionDocker Introduction
Docker Introduction
 
Angular
AngularAngular
Angular
 
Getting Started with J2EE, A Roadmap
Getting Started with J2EE, A RoadmapGetting Started with J2EE, A Roadmap
Getting Started with J2EE, A Roadmap
 
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
Rapport pfe- Refonte et déploiement d’une solution de messagerie en utilisant...
 
Services web soap-el-habib-nfaoui
Services web soap-el-habib-nfaouiServices web soap-el-habib-nfaoui
Services web soap-el-habib-nfaoui
 
What is Docker
What is DockerWhat is Docker
What is Docker
 
Introduction to Docker
Introduction to DockerIntroduction to Docker
Introduction to Docker
 
AngularJS - Présentation (french)
AngularJS - Présentation (french)AngularJS - Présentation (french)
AngularJS - Présentation (french)
 
Présentation PFE: Système de gestion des réclamations et interventions clients
Présentation PFE: Système de gestion des réclamations et interventions clientsPrésentation PFE: Système de gestion des réclamations et interventions clients
Présentation PFE: Système de gestion des réclamations et interventions clients
 
Docker 101: An Introduction
Docker 101: An IntroductionDocker 101: An Introduction
Docker 101: An Introduction
 
Introduction To Docker, Docker Compose, Docker Swarm
Introduction To Docker, Docker Compose, Docker SwarmIntroduction To Docker, Docker Compose, Docker Swarm
Introduction To Docker, Docker Compose, Docker Swarm
 
Présentation docker et kubernetes
Présentation docker et kubernetesPrésentation docker et kubernetes
Présentation docker et kubernetes
 

Similar to CQRS

Exploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with DaliExploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with DaliCarl Steinbach
 
P209 leithiser-relationaldb-formal-specifications
P209 leithiser-relationaldb-formal-specificationsP209 leithiser-relationaldb-formal-specifications
P209 leithiser-relationaldb-formal-specificationsBob Leithiser
 
Final Project presentation (on App devlopment)
Final Project presentation (on App devlopment)Final Project presentation (on App devlopment)
Final Project presentation (on App devlopment)S.M. Fazla Rabbi
 
Sigmod 2013 - On Brewing Fresh Espresso - LinkedIn's Distributed Data Serving...
Sigmod 2013 - On Brewing Fresh Espresso - LinkedIn's Distributed Data Serving...Sigmod 2013 - On Brewing Fresh Espresso - LinkedIn's Distributed Data Serving...
Sigmod 2013 - On Brewing Fresh Espresso - LinkedIn's Distributed Data Serving...Mihir Gandhi
 
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)Espresso: LinkedIn's Distributed Data Serving Platform (Paper)
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)Amy W. Tang
 
STI Tugas 1_Building and Managing System_Kelompok 1 (1).pptx
STI Tugas 1_Building and Managing System_Kelompok 1 (1).pptxSTI Tugas 1_Building and Managing System_Kelompok 1 (1).pptx
STI Tugas 1_Building and Managing System_Kelompok 1 (1).pptxDEANALEXANDER15
 
Office automation system report
Office automation system reportOffice automation system report
Office automation system reportAmit Kulkarni
 
Office automation system report
Office automation system reportOffice automation system report
Office automation system reportAmit Kulkarni
 
Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patternsMd. Sadhan Sarker
 
What is the difference between Data and Information give an exa
What is the difference between Data and Information give an exaWhat is the difference between Data and Information give an exa
What is the difference between Data and Information give an exavictorring
 
1-SDLC - Development Models – Waterfall, Rapid Application Development, Agile...
1-SDLC - Development Models – Waterfall, Rapid Application Development, Agile...1-SDLC - Development Models – Waterfall, Rapid Application Development, Agile...
1-SDLC - Development Models – Waterfall, Rapid Application Development, Agile...JOHNLEAK1
 
LinkedIn's Logical Data Access Layer for Hadoop -- Strata London 2016
LinkedIn's Logical Data Access Layer for Hadoop -- Strata London 2016LinkedIn's Logical Data Access Layer for Hadoop -- Strata London 2016
LinkedIn's Logical Data Access Layer for Hadoop -- Strata London 2016Carl Steinbach
 
SE2023 0207 Software Architectural Design.pptx
SE2023 0207 Software Architectural Design.pptxSE2023 0207 Software Architectural Design.pptx
SE2023 0207 Software Architectural Design.pptxBharat Chawda
 
College information management system.doc
College information management system.docCollege information management system.doc
College information management system.docKamal Acharya
 
Basic-Project-Estimation-1999
Basic-Project-Estimation-1999Basic-Project-Estimation-1999
Basic-Project-Estimation-1999Michael Wigley
 
Data Access Control Schemes in Cloud Computing: A Review
Data Access Control Schemes in Cloud Computing: A ReviewData Access Control Schemes in Cloud Computing: A Review
Data Access Control Schemes in Cloud Computing: A ReviewIRJET Journal
 

Similar to CQRS (20)

Project report
Project reportProject report
Project report
 
Exploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with DaliExploiting the Data / Code Duality with Dali
Exploiting the Data / Code Duality with Dali
 
P209 leithiser-relationaldb-formal-specifications
P209 leithiser-relationaldb-formal-specificationsP209 leithiser-relationaldb-formal-specifications
P209 leithiser-relationaldb-formal-specifications
 
Final Project presentation (on App devlopment)
Final Project presentation (on App devlopment)Final Project presentation (on App devlopment)
Final Project presentation (on App devlopment)
 
Sigmod 2013 - On Brewing Fresh Espresso - LinkedIn's Distributed Data Serving...
Sigmod 2013 - On Brewing Fresh Espresso - LinkedIn's Distributed Data Serving...Sigmod 2013 - On Brewing Fresh Espresso - LinkedIn's Distributed Data Serving...
Sigmod 2013 - On Brewing Fresh Espresso - LinkedIn's Distributed Data Serving...
 
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)Espresso: LinkedIn's Distributed Data Serving Platform (Paper)
Espresso: LinkedIn's Distributed Data Serving Platform (Paper)
 
S18 das
S18 dasS18 das
S18 das
 
STI Tugas 1_Building and Managing System_Kelompok 1 (1).pptx
STI Tugas 1_Building and Managing System_Kelompok 1 (1).pptxSTI Tugas 1_Building and Managing System_Kelompok 1 (1).pptx
STI Tugas 1_Building and Managing System_Kelompok 1 (1).pptx
 
Office automation system report
Office automation system reportOffice automation system report
Office automation system report
 
Office automation system report
Office automation system reportOffice automation system report
Office automation system report
 
Software architecture patterns
Software architecture patternsSoftware architecture patterns
Software architecture patterns
 
What is the difference between Data and Information give an exa
What is the difference between Data and Information give an exaWhat is the difference between Data and Information give an exa
What is the difference between Data and Information give an exa
 
Know the user
Know the userKnow the user
Know the user
 
1-SDLC - Development Models – Waterfall, Rapid Application Development, Agile...
1-SDLC - Development Models – Waterfall, Rapid Application Development, Agile...1-SDLC - Development Models – Waterfall, Rapid Application Development, Agile...
1-SDLC - Development Models – Waterfall, Rapid Application Development, Agile...
 
LinkedIn's Logical Data Access Layer for Hadoop -- Strata London 2016
LinkedIn's Logical Data Access Layer for Hadoop -- Strata London 2016LinkedIn's Logical Data Access Layer for Hadoop -- Strata London 2016
LinkedIn's Logical Data Access Layer for Hadoop -- Strata London 2016
 
SE2023 0207 Software Architectural Design.pptx
SE2023 0207 Software Architectural Design.pptxSE2023 0207 Software Architectural Design.pptx
SE2023 0207 Software Architectural Design.pptx
 
College information management system.doc
College information management system.docCollege information management system.doc
College information management system.doc
 
What is jad_session
What is jad_sessionWhat is jad_session
What is jad_session
 
Basic-Project-Estimation-1999
Basic-Project-Estimation-1999Basic-Project-Estimation-1999
Basic-Project-Estimation-1999
 
Data Access Control Schemes in Cloud Computing: A Review
Data Access Control Schemes in Cloud Computing: A ReviewData Access Control Schemes in Cloud Computing: A Review
Data Access Control Schemes in Cloud Computing: A Review
 

CQRS

  • 1. CQRSFROM A CONCEPT TO REAL LIFE ARCHITECTURE Tiep Le DC3B TMA Solutions 1
  • 3. What’s going on around the world  Connected via Internet  Social networks  Mobile Devices  News  Forums & Blogs  e-commerce  Search Engines 3
  • 5. Facebook  How many friends do you have?  Thousand?  Hundred?  A few?  Do you like to  Post new status?  Like?  Comment?  Share?  There types of people:  Social people  Quite normal  Look around 5 Activity
  • 7. Common Problem We read more than we write 7
  • 8. Problem?  In traditional systems, both commands (updates to data) and queries (request for data) are executed against a same set of entities of a single data repository.  Mismatch between read and write entity  Create a lot of read-only model that presents the result from joining multi- tables  The system will be slow down if handle a large of requests since the read/write action be handled in the same services.  The number of reads and writes maybe very different in the enterprise system  Hard to manage security and permission because each entity is subject to both read and write operations 8
  • 9. Quote  A single model cannot be appropriate for reporting, searching and transactional behavior. 9 Greg Young, 2008
  • 10. What? CQRS  CQRS: Command & Query Responsibility Segregation is simply the creation of two objects where there was previously only one. The separation occurs based upon whether the methods are a command or a query. Greg Young  CQRS enables us to optimize the read and write side independently  CQRS is an architectural style that is often enabling of DDD  Implementation of the model exists on the write side; it encapsulates the complex business logic  DDD divides large, complex systems into more manageable units known as bounded context 10
  • 11. Why? 11  Scalability: by separating the read side and the write side into separate models, we have ability to scale each side independently  Reduced complexity: designing and implementing objects that are responsible for both reading and writing data can exacerbate the complexity. It becomes harder to deal with difficult issues such as multiple users, shared data, performance, transactions, consistency, and stale data with the same model.  Flexibility: easier to make changes on both sides that doesn’t impact the other  Focus on the business: separating the different concerns into the read side and the write side is a solution that is more adaptable in the face of changing business requirements  Facilitates building task-based UIs: design the UI to send the command to the domain instead of CRUD operations
  • 12. When? 12  Collaborative domains: multiple operations are performed in parallel on the same data  Performance: when the read/write ratio is very high, and when horizontal scaling is required  Business rule change regularly: updating the model of a side doesn’t affect to the other  Work independently: one team of developers can focus on the complex domain model that is part of the write model, and another less experienced team can focus on the read model and the user interfaces  Use with task-based UI: with complex domain models, and for teams already familiar with DDD techniques.
  • 13. When NOT? 13  Business rules are simple  Simple, static bounded context: less likely to warrant the up-front investment in detailed analysis, modeling, and complex implementation  Simple CRUD-style user interface and the related data access operations are sufficient
  • 14. Related Patterns 14  Event Sourcing Pattern: simplify tasks in complex domains; improve performance, scalability, and responsiveness; provide consistency for transactional data; and maintain full audit trails and history that may enable compensating actions  Materialized View Pattern: The read model of a CQRS implementation may contain materialized views of the write model data, or the read model may be used to generate materialized views
  • 15. CQRS & Event Sourcing 15  Event Sourcing: Event sourcing is a way of persisting your application's state by storing the history that determines the current state of your application  Audit trails  Integration with other sub-systems  Product troubleshot  Fixing errors  Testing  ES is a great pattern to use to implement the link between the thing that writes and the thing that reads
  • 16. CQRS & Event Sourcing continue 16
  • 17. Stale data 17 We’re always working with stale data
  • 18. Enterprise Service Bus 18  ESB: Enterprise Service Bus is an infrastructure piece of software than a pattern itself  Implementing different message patterns:  Publish / Subscribe  Request / Reply  Dead after channel  Peer to peer  Broad cast to all
  • 19. Sherpa Project  An enterprise social network  Recruitment  Resource planning  Survey system  Training  Library  Events 19 Case Study
  • 20. Resource planning  Member Availability  Member Time-off  Public Holiday  Cost Center  Shift Position  Roster & Shift  Timesheet  Payroll Engine 20 Case Study
  • 21. Member Time-off  A member can belong to multi projects  Member can view their list of time-off by time range  Any manager can view list of all member’s time off by time range in a specific project/group  Manager can view only time-off with pending status  Manager can approve/reject their time-off 21 Requirements
  • 22. Member Time-off  A member can belong to multi projects/Group  Manager can view list in any projects/group 22 Use case diagram uc Member TimeOff Member Time-off View my list View detail Create Update View list in group Approve/Reject Send Notification Member Manager «invokes»
  • 23. Member Time-off 23 Entity Diagram – Write part
  • 24. Member Time-off 24 Query needed  Query results contain only data – no logic  Give me all my leaves this year  Give me all my leaves this month  Give me all team member’s leaves for project A  Give me all team member’s leaves for project B for only this week  Give me all leaves of project C that are in pending  Give me all pending leaves of project D in next two weeks  Give me all member M’s leaves of project E last month
  • 25. NoSQL Storage 25 Azure storage  Have no relationship  Index by Partition Key & Row Key  Searching priority from left to right as string  1  11  111  2  No support paging (limitation)
  • 26. Member Time-off My Time-Off By pending By Groups PartitionKey NetworkId_ AzureQueryType NetworkId_ AzureQueryType NetworkId_ AzureQueryType RowKey MemberId_Date_MemberTimeOffId GroupId_Pending_Date_MemberTimeOffId GroupId_Date_MemberId_MemberTimeOffId MemberTimeOffId int int int MemberId int int int StartDate DateTime DateTime DateTime EndDate DateTime DateTime DateTime TimeZoneId string string string TimeOffType string string string Status string string string Username string string string DisplayName string string string Comment string string string 26 Entity Diagram – Read part
  • 27. Member Time-off 27 Query Example  My Time-Off: MemberId_Date_MemberTimeOffId  19433_20151021_1  19433_20151022_2  19433_20151023_3  19433_20151024_4  19433_20151025_5  19433_20151026_6  19433_20151027_7  19433_20151028_8  19434_20151020_9  19433_20151021_1  19433_20151022_2  19433_20151023_3  19433_20151024_4  19433_20151025_5  19433_20151026_6  19433_20151027_7  19433_20151028_8  19433_20151022_2  19433_20151023_3  19433_20151024_4  19433_20151025_5 By member id: 19433 From date range: 22 Oct – 25 Oct Row key: 19433_ Row key: >= 19433_20151022 && <= 19433_20151025
  • 28. Member Time-off 28 Sequence diagram: Create sd TimeOff.Create new Member SherpaWeb Sherpa APIV2 MemberTimeOffService MemberTimeOffRepository Database Sherpa.Application.Agents memberTimeOff Id() CreateMemberTimeOff() «success» Publish CreateMemberTimeOffMessage() InsertMemberTimeOff() Create Time-Off() «success» Insert(memberTimeOff) POST: api/memberTimeOffs() memberTimeOff Id() new memberTimeOff() Member Create Time-off
  • 29. Member Time-off 29 Command vs Events Command Event CreateMemberTimeOff MemberTimeOffCreated UpdateMemberTimeOff MemberTimeOffUpdated DeleteMemberTimeOff MemberTimeOffDeleted CancelMemberTimeOff MemberTimeOffCanceled ApproveMemberTimeOff MemberTimeOffApproved RejectMemberTimeOff MemberTimeOffRejected
  • 30. Member Time-off 30 Message Entity Digram Handle CreateMemberTimeOffMessage
  • 31. Member Time-off 31 Sequence diagram: Handle Create Handle CreateMemberTimeOffMessage
  • 32. Member Time-off 32 Sequence diagram: Update member time-off Update existed Member-Timeoff
  • 33. Member Time-off 33 Sequence diagram: Handle Update Handle UpdateMemberTimeOffMessage
  • 34. Member Time-off 34 Sequence diagram: Member cancel Handle CacelMemberTimeOffMessage
  • 35. Lesion learn 35  Developer works independently  Requirements changed or added not affected much to design and code  Design easily: What we want to get is a read model
  • 37. References 37  Greg Young’s blog: http://goodenoughsoftware.net/  CQRS Journey MSDN: https://msdn.microsoft.com/en-us/library/jj554200.aspx  We’re social: http://wearesocial.net

Editor's Notes

  1. Big company in the world used, are using it Just a few company in Vietnam applied it Proud to be the first one in TMA design it & implemented it This day last year I had a presentation about Modern Web Hope that this day next year, we will see more people understanding, more project applying this
  2. Usually talking about definition at the second slide But today
  3. We’re living in the world that everyone is connected to Internet When saying “connected” , thinking about social network And mobiles help us to connect easily (show some funny numbers) Besides, this is daily activity that I believe we’re using most
  4. There is plenty of social network platform out there but I’ll show you some of famous ones. Some information about social networks. Then pick facebook at one example I believe
  5. Number of friends, then number of feeds Talk about the habit of people when using facebook How they react with other friends or other news: How many views to like? To comment?
  6. Number of friends, then number of feeds Talk about the habit of people when using facebook How they react with other friends or other news: How many views to like? To comment? There is less than 5% people react on a feed
  7. We read more than we write
  8. Quick develop by scaffolding Hard to scale out database, to distribute system
  9. Quick develop by scaffolding Hard to scale out database, to distribute system
  10. A bounded context is map with the business components
  11. adding a new query to support a new report screen in the UI, when you can be confident that you won't have any impact on the behavior of the business logic. On the write side, having a model that concerns itself solely with the core business logic in the domain means that you have a simpler model to deal with than a model that includes read logic as well.
  12. The write model has a full command-processing stack with business logic, input validation, and business validation to ensure that everything is always consistent for each of the aggregates (each cluster of associated objects that are treated as a unit for the purpose of data changes) in the write model. The read model has no business logic or validation stack and just returns a DTO for use in a view model. The read model is eventually consistent with the write model. Decouple every component we have
  13. \
  14. \
  15. \
  16. Let make this to be our advantage by off-loading from database using read-model
  17. \
  18. No need to check permission of time-off and don’t need to get list of member of projetcs