Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
CQRS: A More Effective Way
of Writing the Same
Applications
Dino Esposito
JetBrains
IITYWIMWYBMAD?
CQRS
If I Tell You What It Means Will You Buy Me A Drink?
2G2BT AGKWE KUTGW WTHIN?
One
Comprehensive
Software Model
for the Business
Domain
Query
 Returns data
 Doesn’t alter
state
Command
 Alter state
 Doesn’t
return data
Separation
Responsibility
Bertrand ...
ONE BIG ISSUE LEADING TO CQRS
How to design a single model to address of all
aspects and concerns of a business domain?
Ho...
Relevant data tables
Relevant tasks
WHERE DOES COMPLEXITY COME FROM?
Relevant data tables
Relevant tasks
WHERE DOES MORE COMPLEXITY COME FROM?
even more
Presentation layer
Application layer
Infrastructure layer
Canonical layered architecture
Domain layer
Presentation layer
A...
O(C x Q) vs. O(C + Q)
ONE BIG ISSUE LEADING TO CQRS
We faced a lot of complexity in modeling and
we thought it was inheren...
Benefits Simplification
of the design
Potential for
enhanced
scalability
Side effects
Easier to
maintain and
evolve stacks...
BUSINESS
DOMAIN
Command
Context #1
Query
Context #1
Command
Context #2
Query
Context #2
Command
Context #3
Query
Context #...
FLAVORS OF CQRS
• TX Script
• Your choice of DAL
• Shared DB
Regular
• Aggregates
• Your choice of DAL
• Data DB + snapsho...
REGULAR CQRS
PRESENTATION
TX SCRIPT TX SCRIPT
APPLICATION APPLICATION
DAL
Simply use s-procs to
read or ADO.NET or EF
or w...
PREMIUM CQRS
PRESENTATION
DOMAIN LAYER
APPLICATION APPLICATION
DAL
Business logic
implemented through
aggregates and
domai...
DELUXE CQRS
PRESENTATION
EVENT-DRIVEN BIZ
APPLICATION APPLICATION
DAL
Business logic
implemented through
aggregates and
do...
DELUXE CQRS
APPLICATION
Application logic
expressed through
commands pushed to
a bus generating
events handled by
sagas (s...
AT THE VERY END OF THE DAY
CQRS brings just one core idea: keep write and read
stacks completely separated and based on di...
FOLLOW
Вопросы?
facebook.com/naa4e
software2cents.wordpress.com
dino.esposito@jetbrains.com
@despos
http://naa4e.codeplex....
Upcoming SlideShare
Loading in …5
×

CQRS: A More Effective Way of Writing the Same Applications

1,071 views

Published on

Dino Esposito, Evangelist, Backend-секция CodeFest 2015

Published in: Software
  • Be the first to comment

  • Be the first to like this

CQRS: A More Effective Way of Writing the Same Applications

  1. 1. CQRS: A More Effective Way of Writing the Same Applications Dino Esposito JetBrains
  2. 2. IITYWIMWYBMAD? CQRS If I Tell You What It Means Will You Buy Me A Drink? 2G2BT AGKWE KUTGW WTHIN?
  3. 3. One Comprehensive Software Model for the Business Domain
  4. 4. Query  Returns data  Doesn’t alter state Command  Alter state  Doesn’t return data Separation Responsibility Bertrand Meyer called it Command/Query Separation back in the 1980s
  5. 5. ONE BIG ISSUE LEADING TO CQRS How to design a single model to address of all aspects and concerns of a business domain? How to do that effectively? Theory Begin End Practice
  6. 6. Relevant data tables Relevant tasks WHERE DOES COMPLEXITY COME FROM?
  7. 7. Relevant data tables Relevant tasks WHERE DOES MORE COMPLEXITY COME FROM? even more
  8. 8. Presentation layer Application layer Infrastructure layer Canonical layered architecture Domain layer Presentation layer Application layer Infrastructure layer CQRS Commands Queries Domain layer Data access + DTO
  9. 9. O(C x Q) vs. O(C + Q) ONE BIG ISSUE LEADING TO CQRS We faced a lot of complexity in modeling and we thought it was inherent domain complexity
  10. 10. Benefits Simplification of the design Potential for enhanced scalability Side effects Easier to maintain and evolve stacks Optimize each stack separately ASPECTS OF CQRS
  11. 11. BUSINESS DOMAIN Command Context #1 Query Context #1 Command Context #2 Query Context #2 Command Context #3 Query Context #3 CQRS Design DDD Analysis CONTEXT #1 CONTEXT #2 CONTEXT #3
  12. 12. FLAVORS OF CQRS • TX Script • Your choice of DAL • Shared DB Regular • Aggregates • Your choice of DAL • Data DB + snapshots Premium • Event-driven architecture • LET or any choice of DAL • Data DB + snapshots + event store Deluxe
  13. 13. REGULAR CQRS PRESENTATION TX SCRIPT TX SCRIPT APPLICATION APPLICATION DAL Simply use s-procs to read or ADO.NET or EF or whatever else suits you. Just use DTO to bring data back.
  14. 14. PREMIUM CQRS PRESENTATION DOMAIN LAYER APPLICATION APPLICATION DAL Business logic implemented through aggregates and domain model. State of aggregates also persisted in a format suitable for the UI. Sync
  15. 15. DELUXE CQRS PRESENTATION EVENT-DRIVEN BIZ APPLICATION APPLICATION DAL Business logic implemented through aggregates and domain model. State of aggregates also persisted in a format suitable for the UI. Sync
  16. 16. DELUXE CQRS APPLICATION Application logic expressed through commands pushed to a bus generating events handled by sagas (stateful) and handlers (stateless). Optionally events recorded to a log. Sync DOMAIN LAYER Event store QUERY STACK … Saga(s) Handler(s) BUS
  17. 17. AT THE VERY END OF THE DAY CQRS brings just one core idea: keep write and read stacks completely separated and based on different models and even different implementation patterns and technologies. Best-selling point of CQRS is that it looks like common sense and a smarter way of doing just the same things. CQRS is not a philosophy or a methodology: it's just about writing code.
  18. 18. FOLLOW Вопросы? facebook.com/naa4e software2cents.wordpress.com dino.esposito@jetbrains.com @despos http://naa4e.codeplex.com/ Project MERP

×