SlideShare a Scribd company logo
Command / QueryResponsibility Segregation Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist
What will you see here? Some History Distributed Systems Architecture UI Design Domain Model What won’t you see here? Code
History
Paper ruled the world
And then came the computer
And with it data entry
And efficient UIs were designed for it
Source of truth
And then… the paper was gone Well, not GONE gone It just wasn’t the source of truth any more Now, it’s the machine
But the UI lingers to this day
No change to architecture either
Distributed Systems Architecture
Common Distributed Architecture DB
Let’s deal with the obvious…
Collaboration is good –  isn’t  it ? Get data Get data User is looking at stale data Change data
So why go through all the layers? Cache DB
Why transform between tiers? Cache UI WS DB Map from DTOs & WS to view model Map from DTOs and WS to domain object Use EF to map from tables to domain objects
What was the point of all this again?
Queries – showing data to the user
Why not be upfront about it? List of customers Data correct as of 10 minutes ago
Only data, no behavior There is no object So why use an Object/Relational Mapper?
Keep it simple - 2-Tier 2 Layers == 2 Tiers UI Query only Persistent View Model For each view in the UI,  have a view/table in the DB SELECT * FROM MyTable (WHERE ID = @ID)
Search First think about what the user wants to find Design some custom screens for that Eg. Amazon recommendations Separate UI talking to different data store SQL Server Full Text Search Lucene.net
No relations between views / tables No coupling between screens in the UI No foreign keys between tables in the persistent view model
Data duplication in views & tables The same information can be shown on different screens in the UI The same information can be stored in different tables in the persistent view model Tables contain a column for every piece of information shown in the UI Avoid calculations when doing queries Have the data calculated ahead of time
Deployment and Security Deploy the persistent view model DB to the web tier (only SELECT is permitted) Don’t have to go through the firewall – faster Role-based security Different screens for different roles go to different tables – SELECT permissions per role Just as secure as in-memory caches If not more so
Use for preliminary validation Before going to submit data, check if it already exists in the persistent view model Uniqueness Can expose to user (Yahoo user signup) Related Entity Existence Address validation – existence of street name Results in less commands being rejected
Commands – accepting user input
Can we fully trust users decisions?
Validation and Business Rules Validation: 	Is the input potentially good? 				Structured correctly? 				Ranges, lengths, etc Rules:		Should we do this? 				Based on the current system state 				What the user saw is irrelevant
Command Processing Layers DB
Transaction Command Processing Tiers Get current state Command WS Input DB Persist Validation Validation Rules
Should we do what the user asks?
User Interface Design
Traditional User Interfaces Orders Save Cancel
Capturing user intent Why is it important? Differentiating between: 	Correcting a mistyped shipping address 	The user moved – reroute shipments underway Sometimes users accidentally modify fields when tabbing between columns
Reservation systems
Reservation systems
Not capturing user intent In a traditional UI – what we have is the checkbox Why do users select multiple seats? 	Because they’re reserving for a family / friends But then, concurrency happens 	Somebody else got in first on one of the seats Try to find a block of seats somewhere else
Capturing user intent Group reservation: Small group – sitting together Large group – several small groups Enter number of people Enter preferred seat type – indicates cost System emails back when reservation can be filled 	Include waiting list functionality
Usability benefits 	More users get what they want with less clicks
Scalability benefits Thousands of seats, hundreds of thousands of requests 	            No need to show actual status
Revisiting the command
What’s a good command? The kind you can reply with: 	“Thank you. 	  Your confirmation email will arrive shortly” Inherently asynchronous Not really related to an entity
Eg. Posting a comment to a blog After the browser submits the comment, immediately shows it on the page using AJAX Why wait for a response from the server? It’s not like the user’s going to call their friends and say “hey, look at the comment I just posted” And even if they did, by then it probably would have already been processed by the server
Eg. Withdrawing cash from an ATM Before the ATM sends the command: Using the account information retrieved Account type, Max single withdrawal, Max daily withdrawal Decides to send the command (or not) If so, dispenses cash without waiting for a response Yes – really. Exposed to race conditions Cheaper for the bank to let them through And you pay ruinous interest in those cases
Queries not only for views Used to decide if commands should be sent Yes – this is business logic. Get over it Client-side controllers are supposed to do logic May require additional data
Domain Models
What aren’t they for? Validation 	Commands are validated before the domain model is called Queries 	Entity relationships for reading are unnecessary
What are they for? In addition to doing what the command said, doing other things as well Eg. When a new order is submitted, if the customer has ordered more than X in the past, give them a discount
Only persist what they need The domain model isn’t responsible for persisting all data only what it needs for its purposes The rest of the world is using the data in the query store anyway
Putting it all together
For better scalability, add pub/sub Data from input immediately overlaid on queries Queries View Model UI Queries Commands Publish WS Input Validation Validation Rules Cache Updater DB
Summary
Summary Keep queries simple – 2-Tier if possible No data transfer objects Have commands reflect user intent Adjust UI design to capture intent  Get the benefits of asynchronous programming Simple validation, focused business rules
Thank you Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist www.UdiDahan.com email@UdiDahan.com

More Related Content

Viewers also liked

S O X In Telecom Industry
S O X In  Telecom  IndustryS O X In  Telecom  Industry
S O X In Telecom Industryravindra sharma
 
GDPR: Requirements for Cloud Providers
GDPR: Requirements for Cloud ProvidersGDPR: Requirements for Cloud Providers
GDPR: Requirements for Cloud Providers
IT Governance Ltd
 
Revising policies and procedures under the new EU GDPR
Revising policies and procedures under the new EU GDPRRevising policies and procedures under the new EU GDPR
Revising policies and procedures under the new EU GDPR
IT Governance Ltd
 
EU GDPR and you: requirements for marketing
EU GDPR and you: requirements for marketingEU GDPR and you: requirements for marketing
EU GDPR and you: requirements for marketing
IT Governance Ltd
 
Rethinking Segregation of Duties: Where Is Your Business Most Exposed?
Rethinking Segregation of Duties: Where Is Your Business Most Exposed?Rethinking Segregation of Duties: Where Is Your Business Most Exposed?
Rethinking Segregation of Duties: Where Is Your Business Most Exposed?
SAPinsider Events
 
CyNation: 7 Things You Should Know about EU GDPR
CyNation: 7 Things You Should Know about EU GDPRCyNation: 7 Things You Should Know about EU GDPR
CyNation: 7 Things You Should Know about EU GDPR
Iryna Chekanava
 
GDPR in practice
GDPR in practiceGDPR in practice
GDPR in practice
ZoneFox
 
DevOps vs GDPR: How to Comply and Stay Agile
DevOps vs GDPR: How to Comply and Stay AgileDevOps vs GDPR: How to Comply and Stay Agile
DevOps vs GDPR: How to Comply and Stay Agile
Ben Saunders
 
What is GDPR and why does it matter to me?
What is GDPR and why does it matter to me? What is GDPR and why does it matter to me?
What is GDPR and why does it matter to me?
Desynit
 
EU GDPR: The role of the data protection officer
EU GDPR: The role of the data protection officer EU GDPR: The role of the data protection officer
EU GDPR: The role of the data protection officer
IT Governance Ltd
 
Data Flow Mapping and the EU GDPR
Data Flow Mapping and the EU GDPRData Flow Mapping and the EU GDPR
Data Flow Mapping and the EU GDPR
IT Governance Ltd
 
Profiling for SAP - Compliance Management, Access Control and Segregation of ...
Profiling for SAP - Compliance Management, Access Control and Segregation of ...Profiling for SAP - Compliance Management, Access Control and Segregation of ...
Profiling for SAP - Compliance Management, Access Control and Segregation of ...
TransWare AG
 
Preparing for EU GDPR
Preparing for EU GDPRPreparing for EU GDPR
Preparing for EU GDPR
IT Governance Ltd
 
Effective Segregation of Duties for PeopleSoft 2011-02-23
Effective Segregation of Duties for PeopleSoft 2011-02-23Effective Segregation of Duties for PeopleSoft 2011-02-23
Effective Segregation of Duties for PeopleSoft 2011-02-23
Smart ERP Solutions, Inc.
 
IT Control Objectives for SOX
IT Control Objectives for SOXIT Control Objectives for SOX
IT Control Objectives for SOX
Mahesh Patwardhan
 
GDPR in a nutshell
GDPR in a nutshellGDPR in a nutshell
GDPR in a nutshell
Initio
 
SureSkills GDPR - Discover the Smart Solution
SureSkills GDPR - Discover the Smart Solution SureSkills GDPR - Discover the Smart Solution
SureSkills GDPR - Discover the Smart Solution
Google
 
Automating PeopleSoft Segregation of Duties: HCM and Financials
Automating PeopleSoft Segregation of Duties: HCM and FinancialsAutomating PeopleSoft Segregation of Duties: HCM and Financials
Automating PeopleSoft Segregation of Duties: HCM and Financials
Smart ERP Solutions, Inc.
 
Segregation of Duties Solutions
Segregation of Duties SolutionsSegregation of Duties Solutions
Segregation of Duties SolutionsAhmed Abdul Hamed
 

Viewers also liked (19)

S O X In Telecom Industry
S O X In  Telecom  IndustryS O X In  Telecom  Industry
S O X In Telecom Industry
 
GDPR: Requirements for Cloud Providers
GDPR: Requirements for Cloud ProvidersGDPR: Requirements for Cloud Providers
GDPR: Requirements for Cloud Providers
 
Revising policies and procedures under the new EU GDPR
Revising policies and procedures under the new EU GDPRRevising policies and procedures under the new EU GDPR
Revising policies and procedures under the new EU GDPR
 
EU GDPR and you: requirements for marketing
EU GDPR and you: requirements for marketingEU GDPR and you: requirements for marketing
EU GDPR and you: requirements for marketing
 
Rethinking Segregation of Duties: Where Is Your Business Most Exposed?
Rethinking Segregation of Duties: Where Is Your Business Most Exposed?Rethinking Segregation of Duties: Where Is Your Business Most Exposed?
Rethinking Segregation of Duties: Where Is Your Business Most Exposed?
 
CyNation: 7 Things You Should Know about EU GDPR
CyNation: 7 Things You Should Know about EU GDPRCyNation: 7 Things You Should Know about EU GDPR
CyNation: 7 Things You Should Know about EU GDPR
 
GDPR in practice
GDPR in practiceGDPR in practice
GDPR in practice
 
DevOps vs GDPR: How to Comply and Stay Agile
DevOps vs GDPR: How to Comply and Stay AgileDevOps vs GDPR: How to Comply and Stay Agile
DevOps vs GDPR: How to Comply and Stay Agile
 
What is GDPR and why does it matter to me?
What is GDPR and why does it matter to me? What is GDPR and why does it matter to me?
What is GDPR and why does it matter to me?
 
EU GDPR: The role of the data protection officer
EU GDPR: The role of the data protection officer EU GDPR: The role of the data protection officer
EU GDPR: The role of the data protection officer
 
Data Flow Mapping and the EU GDPR
Data Flow Mapping and the EU GDPRData Flow Mapping and the EU GDPR
Data Flow Mapping and the EU GDPR
 
Profiling for SAP - Compliance Management, Access Control and Segregation of ...
Profiling for SAP - Compliance Management, Access Control and Segregation of ...Profiling for SAP - Compliance Management, Access Control and Segregation of ...
Profiling for SAP - Compliance Management, Access Control and Segregation of ...
 
Preparing for EU GDPR
Preparing for EU GDPRPreparing for EU GDPR
Preparing for EU GDPR
 
Effective Segregation of Duties for PeopleSoft 2011-02-23
Effective Segregation of Duties for PeopleSoft 2011-02-23Effective Segregation of Duties for PeopleSoft 2011-02-23
Effective Segregation of Duties for PeopleSoft 2011-02-23
 
IT Control Objectives for SOX
IT Control Objectives for SOXIT Control Objectives for SOX
IT Control Objectives for SOX
 
GDPR in a nutshell
GDPR in a nutshellGDPR in a nutshell
GDPR in a nutshell
 
SureSkills GDPR - Discover the Smart Solution
SureSkills GDPR - Discover the Smart Solution SureSkills GDPR - Discover the Smart Solution
SureSkills GDPR - Discover the Smart Solution
 
Automating PeopleSoft Segregation of Duties: HCM and Financials
Automating PeopleSoft Segregation of Duties: HCM and FinancialsAutomating PeopleSoft Segregation of Duties: HCM and Financials
Automating PeopleSoft Segregation of Duties: HCM and Financials
 
Segregation of Duties Solutions
Segregation of Duties SolutionsSegregation of Duties Solutions
Segregation of Duties Solutions
 

Similar to Command Query Responsibility Segregation

Interface usability-adding-schweppervescence-ver3-8
Interface usability-adding-schweppervescence-ver3-8Interface usability-adding-schweppervescence-ver3-8
Interface usability-adding-schweppervescence-ver3-8
SSW
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
Cory Foy
 
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
Simon Munro
 
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
Marco Parenzan
 
Short reference architecture
Short reference architectureShort reference architecture
Short reference architectureSteve Feldman
 
Preparing Your Data for ECM
Preparing Your Data for ECMPreparing Your Data for ECM
Preparing Your Data for ECM
Axis Technical Group
 
How to deliver a Single View in Financial Services
 How to deliver a Single View in Financial Services How to deliver a Single View in Financial Services
How to deliver a Single View in Financial Services
MongoDB
 
Look Beyond Data Trends - A Technique to Find Hidden Design Implications from...
Look Beyond Data Trends - A Technique to Find Hidden Design Implications from...Look Beyond Data Trends - A Technique to Find Hidden Design Implications from...
Look Beyond Data Trends - A Technique to Find Hidden Design Implications from...
UXPA International
 
Final wireframes from screen concept to user interaction v0.4
Final wireframes  from screen concept to user interaction v0.4Final wireframes  from screen concept to user interaction v0.4
Final wireframes from screen concept to user interaction v0.4Mia Horrigan
 
Patterns&Antipatternsof SOA
Patterns&Antipatternsof SOAPatterns&Antipatternsof SOA
Patterns&Antipatternsof SOA
Mohamed Samy
 
Automating With Excel An Object Oriented Approach
Automating  With  Excel    An  Object  Oriented  ApproachAutomating  With  Excel    An  Object  Oriented  Approach
Automating With Excel An Object Oriented Approach
Razorleaf Corporation
 
system-design-interview-an-insiders-guide-2nbsped-9798664653403.pdf
system-design-interview-an-insiders-guide-2nbsped-9798664653403.pdfsystem-design-interview-an-insiders-guide-2nbsped-9798664653403.pdf
system-design-interview-an-insiders-guide-2nbsped-9798664653403.pdf
ParthNavale
 
System Design
System DesignSystem Design
System Design
SyeedAbrarZaoad1
 
Interface Usability - Adding Schweppervescence
Interface Usability - Adding SchweppervescenceInterface Usability - Adding Schweppervescence
Interface Usability - Adding Schweppervescence
SSW
 
Systemation Corizon Enterprise Mashup
Systemation Corizon Enterprise MashupSystemation Corizon Enterprise Mashup
Systemation Corizon Enterprise MashupEdwin Systemation
 
Living in a MultiOrg World
Living in a MultiOrg WorldLiving in a MultiOrg World
Living in a MultiOrg World
Traction on Demand
 
How To Buy Data Warehouse
How To Buy Data WarehouseHow To Buy Data Warehouse
How To Buy Data WarehouseEric Sun
 

Similar to Command Query Responsibility Segregation (20)

Interface usability-adding-schweppervescence-ver3-8
Interface usability-adding-schweppervescence-ver3-8Interface usability-adding-schweppervescence-ver3-8
Interface usability-adding-schweppervescence-ver3-8
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Chapter 7)
Chapter 7)Chapter 7)
Chapter 7)
 
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
 
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
 
Dat336
Dat336Dat336
Dat336
 
Short reference architecture
Short reference architectureShort reference architecture
Short reference architecture
 
Preparing Your Data for ECM
Preparing Your Data for ECMPreparing Your Data for ECM
Preparing Your Data for ECM
 
How to deliver a Single View in Financial Services
 How to deliver a Single View in Financial Services How to deliver a Single View in Financial Services
How to deliver a Single View in Financial Services
 
Look Beyond Data Trends - A Technique to Find Hidden Design Implications from...
Look Beyond Data Trends - A Technique to Find Hidden Design Implications from...Look Beyond Data Trends - A Technique to Find Hidden Design Implications from...
Look Beyond Data Trends - A Technique to Find Hidden Design Implications from...
 
Final wireframes from screen concept to user interaction v0.4
Final wireframes  from screen concept to user interaction v0.4Final wireframes  from screen concept to user interaction v0.4
Final wireframes from screen concept to user interaction v0.4
 
Managing SQLserver
Managing SQLserverManaging SQLserver
Managing SQLserver
 
Patterns&Antipatternsof SOA
Patterns&Antipatternsof SOAPatterns&Antipatternsof SOA
Patterns&Antipatternsof SOA
 
Automating With Excel An Object Oriented Approach
Automating  With  Excel    An  Object  Oriented  ApproachAutomating  With  Excel    An  Object  Oriented  Approach
Automating With Excel An Object Oriented Approach
 
system-design-interview-an-insiders-guide-2nbsped-9798664653403.pdf
system-design-interview-an-insiders-guide-2nbsped-9798664653403.pdfsystem-design-interview-an-insiders-guide-2nbsped-9798664653403.pdf
system-design-interview-an-insiders-guide-2nbsped-9798664653403.pdf
 
System Design
System DesignSystem Design
System Design
 
Interface Usability - Adding Schweppervescence
Interface Usability - Adding SchweppervescenceInterface Usability - Adding Schweppervescence
Interface Usability - Adding Schweppervescence
 
Systemation Corizon Enterprise Mashup
Systemation Corizon Enterprise MashupSystemation Corizon Enterprise Mashup
Systemation Corizon Enterprise Mashup
 
Living in a MultiOrg World
Living in a MultiOrg WorldLiving in a MultiOrg World
Living in a MultiOrg World
 
How To Buy Data Warehouse
How To Buy Data WarehouseHow To Buy Data Warehouse
How To Buy Data Warehouse
 

More from Skills Matter

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence
Skills Matter
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
Skills Matter
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Skills Matter
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimSkills Matter
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Skills Matter
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Skills Matter
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.js
Skills Matter
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Skills Matter
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Skills Matter
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Skills Matter
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Skills Matter
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#
Skills Matter
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testing
Skills Matter
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveSkills Matter
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
Skills Matter
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tSkills Matter
 

More from Skills Matter (20)

5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence5 things cucumber is bad at by Richard Lawrence
5 things cucumber is bad at by Richard Lawrence
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvmScala e xchange 2013 haoyi li on metascala a tiny diy jvm
Scala e xchange 2013 haoyi li on metascala a tiny diy jvm
 
Oscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheimOscar reiken jr on our success at manheim
Oscar reiken jr on our success at manheim
 
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
Progressive f# tutorials nyc dmitry mozorov & jack pappas on code quotations ...
 
Cukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberlCukeup nyc ian dees on elixir, erlang, and cucumberl
Cukeup nyc ian dees on elixir, erlang, and cucumberl
 
Cukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.jsCukeup nyc peter bell on getting started with cucumber.js
Cukeup nyc peter bell on getting started with cucumber.js
 
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
Agile testing & bdd e xchange nyc 2013 jeffrey davidson & lav pathak & sam ho...
 
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
Progressive f# tutorials nyc rachel reese & phil trelford on try f# from zero...
 
Progressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source worldProgressive f# tutorials nyc don syme on keynote f# in the open source world
Progressive f# tutorials nyc don syme on keynote f# in the open source world
 
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
Agile testing & bdd e xchange nyc 2013 gojko adzic on bond villain guide to s...
 
Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#Dmitry mozorov on code quotations code as-data for f#
Dmitry mozorov on code quotations code as-data for f#
 
A poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testingA poet's guide_to_acceptance_testing
A poet's guide_to_acceptance_testing
 
Russ miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-diveRuss miles-cloudfoundry-deep-dive
Russ miles-cloudfoundry-deep-dive
 
Serendipity-neo4j
Serendipity-neo4jSerendipity-neo4j
Serendipity-neo4j
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Plug 20110217
Plug   20110217Plug   20110217
Plug 20110217
 
Lug presentation
Lug presentationLug presentation
Lug presentation
 
I went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_tI went to_a_communications_workshop_and_they_t
I went to_a_communications_workshop_and_they_t
 
Plug saiku
Plug   saikuPlug   saiku
Plug saiku
 

Recently uploaded

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 

Command Query Responsibility Segregation

  • 1. Command / QueryResponsibility Segregation Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist
  • 2.
  • 3. What will you see here? Some History Distributed Systems Architecture UI Design Domain Model What won’t you see here? Code
  • 6. And then came the computer
  • 7. And with it data entry
  • 8. And efficient UIs were designed for it
  • 10. And then… the paper was gone Well, not GONE gone It just wasn’t the source of truth any more Now, it’s the machine
  • 11. But the UI lingers to this day
  • 12. No change to architecture either
  • 15. Let’s deal with the obvious…
  • 16. Collaboration is good – isn’t it ? Get data Get data User is looking at stale data Change data
  • 17. So why go through all the layers? Cache DB
  • 18. Why transform between tiers? Cache UI WS DB Map from DTOs & WS to view model Map from DTOs and WS to domain object Use EF to map from tables to domain objects
  • 19. What was the point of all this again?
  • 20. Queries – showing data to the user
  • 21. Why not be upfront about it? List of customers Data correct as of 10 minutes ago
  • 22. Only data, no behavior There is no object So why use an Object/Relational Mapper?
  • 23. Keep it simple - 2-Tier 2 Layers == 2 Tiers UI Query only Persistent View Model For each view in the UI, have a view/table in the DB SELECT * FROM MyTable (WHERE ID = @ID)
  • 24. Search First think about what the user wants to find Design some custom screens for that Eg. Amazon recommendations Separate UI talking to different data store SQL Server Full Text Search Lucene.net
  • 25. No relations between views / tables No coupling between screens in the UI No foreign keys between tables in the persistent view model
  • 26. Data duplication in views & tables The same information can be shown on different screens in the UI The same information can be stored in different tables in the persistent view model Tables contain a column for every piece of information shown in the UI Avoid calculations when doing queries Have the data calculated ahead of time
  • 27. Deployment and Security Deploy the persistent view model DB to the web tier (only SELECT is permitted) Don’t have to go through the firewall – faster Role-based security Different screens for different roles go to different tables – SELECT permissions per role Just as secure as in-memory caches If not more so
  • 28. Use for preliminary validation Before going to submit data, check if it already exists in the persistent view model Uniqueness Can expose to user (Yahoo user signup) Related Entity Existence Address validation – existence of street name Results in less commands being rejected
  • 30. Can we fully trust users decisions?
  • 31. Validation and Business Rules Validation: Is the input potentially good? Structured correctly? Ranges, lengths, etc Rules: Should we do this? Based on the current system state What the user saw is irrelevant
  • 33. Transaction Command Processing Tiers Get current state Command WS Input DB Persist Validation Validation Rules
  • 34. Should we do what the user asks?
  • 36. Traditional User Interfaces Orders Save Cancel
  • 37.
  • 38. Capturing user intent Why is it important? Differentiating between: Correcting a mistyped shipping address The user moved – reroute shipments underway Sometimes users accidentally modify fields when tabbing between columns
  • 41. Not capturing user intent In a traditional UI – what we have is the checkbox Why do users select multiple seats? Because they’re reserving for a family / friends But then, concurrency happens Somebody else got in first on one of the seats Try to find a block of seats somewhere else
  • 42. Capturing user intent Group reservation: Small group – sitting together Large group – several small groups Enter number of people Enter preferred seat type – indicates cost System emails back when reservation can be filled Include waiting list functionality
  • 43. Usability benefits More users get what they want with less clicks
  • 44. Scalability benefits Thousands of seats, hundreds of thousands of requests No need to show actual status
  • 46. What’s a good command? The kind you can reply with: “Thank you. Your confirmation email will arrive shortly” Inherently asynchronous Not really related to an entity
  • 47. Eg. Posting a comment to a blog After the browser submits the comment, immediately shows it on the page using AJAX Why wait for a response from the server? It’s not like the user’s going to call their friends and say “hey, look at the comment I just posted” And even if they did, by then it probably would have already been processed by the server
  • 48. Eg. Withdrawing cash from an ATM Before the ATM sends the command: Using the account information retrieved Account type, Max single withdrawal, Max daily withdrawal Decides to send the command (or not) If so, dispenses cash without waiting for a response Yes – really. Exposed to race conditions Cheaper for the bank to let them through And you pay ruinous interest in those cases
  • 49. Queries not only for views Used to decide if commands should be sent Yes – this is business logic. Get over it Client-side controllers are supposed to do logic May require additional data
  • 51. What aren’t they for? Validation Commands are validated before the domain model is called Queries Entity relationships for reading are unnecessary
  • 52. What are they for? In addition to doing what the command said, doing other things as well Eg. When a new order is submitted, if the customer has ordered more than X in the past, give them a discount
  • 53. Only persist what they need The domain model isn’t responsible for persisting all data only what it needs for its purposes The rest of the world is using the data in the query store anyway
  • 54. Putting it all together
  • 55. For better scalability, add pub/sub Data from input immediately overlaid on queries Queries View Model UI Queries Commands Publish WS Input Validation Validation Rules Cache Updater DB
  • 57. Summary Keep queries simple – 2-Tier if possible No data transfer objects Have commands reflect user intent Adjust UI design to capture intent Get the benefits of asynchronous programming Simple validation, focused business rules
  • 58. Thank you Udi Dahan – The Software Simplist Enterprise Development Expert & SOA Specialist www.UdiDahan.com email@UdiDahan.com

Editor's Notes

  1. The goal being to get the data from the paper to the machine as quickly as possible.And the important thing about data entry is that the printed page is …
  2. If there was any conflict between the computer and the printed page – the printed page won.
  3. You’d think that something as significant as a change to the source of truth would influence software architecture in some way
  4. This is a fact of life – like gravity – you can’t fight it.
  5. If the result is that users are going to be seeing stale data anyway – why go all the way to the database?And if we’re going to be putting a cache in there anyway – we’re practically ensuring staleness, we just don’t tell anybody, right?
  6. That’s a lot of transformation!
  7. Maintainability? With all of this possibly redundant mapping code?It couldn’t be performance, because all of these transformations are taking up extra cycles.
  8. We see this on Twitter and Facebook – telling us how long ago something happened
  9. They’re tightly coupled anyway – sticking a bunch of layers in between won’t change that.This can be as simple as statically defined views on top of your tables.
  10. Reminding ourselves that users are looking at stale data…
  11. Sometimes developers mix up these two, but they’re different – first we validate the command, AFTER that, we perform rules, AFTER that we store/update data.
  12. But what kind of rules will we need? The kind that answer the following question…
  13. But, if we’ve already validated their input, is there any reason why we shouldn’t do what they want?
  14. These kinds of screens are often described as CRUD – for create, read, update, and delete in the developer lingoAlso known in the user lingo as CRAP. Though, you’ve got to admit, it’s got a certain …
  15. Matrix feel to it. The thing is, other than straight data manipulation, those screens don’t let us capture WHY the user is changing the data or what they’re trying to achieve.
  16. The user who can correct a mistyped shipping address may not be permitted to change the user’s address.By automatically shoving all data into the same grid without thinking through these rules, we make it harder on ourselves to later implement these rules.For example…
  17. I’m using this image because it’s small enough to understand what’s going on – to see the detail of what’s available, reserved, confirmed, etc.Now imagine larger scales…
  18. Each one of the slots here is a block of seats – not just one.
  19. This way, reads and writes don’t interfere with each other in the DB