Jonathan Oliver<br />Command QueryResponsibility Segregation<br />
Who Cares?<br />“This time, it’s going to be different.  Trust me.”<br />“Doctor, it hurts when I do that.”<br />Why?<br />
A Question of Perspective<br />Why are we doing this?<br />It’s a “Best Practice”.<br />The way it’s always been done.<br />
A Few Problems<br />UI<br />Services / Caching<br />Bottlenecks<br />Caching<br />Scalability<br />Translation code<br />I...
Stale Data?<br />Get data<br />Get data<br />Stale data<br />Update data<br />
Queries<br />If it’s stale anyway…<br />List of Customers<br />…………………….<br />…………………….<br />…………………….<br />…………………….<br /...
A Persistent View Model<br />Read only.<br />Stored in structure used by view.<br />Query<br />Persistent  View Model<br /...
That’s Blasphemy!<br />It’s the simplest thing that could possibly work.<br />Testability?<br />Maintainability?<br />Secu...
Commands and User Input<br />What is the user telling us?<br />Do we even know?<br />How?<br />Task-based UIs vs. CRUD-bas...
Validation and Business Rules<br />Pre-validation from view model.<br />Validation: Is this command complete?<br />String ...
Good Commands<br />Validated on client.<br />Revalidated on server.<br />Reply can be asynchronous:<br />Amazon<br />
CQRS<br />Image courtesy Udi Dahan<br />
Service Layer<br />Transaction Script.<br />Active Record / Table Module.<br />Domain Model.<br />No Getters/Setters<br />...
Questions?<br />
Upcoming SlideShare
Loading in …5
×

CQRS: An Introduction for Beginners

2,907 views

Published on

0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
2,907
On SlideShare
0
From Embeds
0
Number of Embeds
332
Actions
Shares
0
Downloads
72
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

CQRS: An Introduction for Beginners

  1. 1. Jonathan Oliver<br />Command QueryResponsibility Segregation<br />
  2. 2. Who Cares?<br />“This time, it’s going to be different. Trust me.”<br />“Doctor, it hurts when I do that.”<br />Why?<br />
  3. 3. A Question of Perspective<br />Why are we doing this?<br />It’s a “Best Practice”.<br />The way it’s always been done.<br />
  4. 4. A Few Problems<br />UI<br />Services / Caching<br />Bottlenecks<br />Caching<br />Scalability<br />Translation code<br />Impedance mismatch<br />Race conditions<br />Stale data<br />Business Logic<br />DAL<br />Database<br />
  5. 5. Stale Data?<br />Get data<br />Get data<br />Stale data<br />Update data<br />
  6. 6. Queries<br />If it’s stale anyway…<br />List of Customers<br />…………………….<br />…………………….<br />…………………….<br />…………………….<br />…………………….<br />(from 10 minutes ago)<br />
  7. 7. A Persistent View Model<br />Read only.<br />Stored in structure used by view.<br />Query<br />Persistent View Model<br />SELECT * FROM Table WHERE ID = …<br />
  8. 8. That’s Blasphemy!<br />It’s the simplest thing that could possibly work.<br />Testability?<br />Maintainability?<br />Security?<br />Data already shown over the web.<br />It’s already in your cache on the web tier.<br />Role-based SELECTs.<br />
  9. 9. Commands and User Input<br />What is the user telling us?<br />Do we even know?<br />How?<br />Task-based UIs vs. CRUD-based UIs.<br />Capture user intent explicitly.<br />
  10. 10. Validation and Business Rules<br />Pre-validation from view model.<br />Validation: Is this command complete?<br />String lengths<br />Required fields<br />Regex, etc.<br />Business Rules: Can I do what the user wants?<br />Where is the source of truth?<br />
  11. 11. Good Commands<br />Validated on client.<br />Revalidated on server.<br />Reply can be asynchronous:<br />Amazon<br />
  12. 12. CQRS<br />Image courtesy Udi Dahan<br />
  13. 13. Service Layer<br />Transaction Script.<br />Active Record / Table Module.<br />Domain Model.<br />No Getters/Setters<br />Transactional.<br />Separate database from queries.<br />The “source of truth”.<br />
  14. 14. Questions?<br />

×