760 likes | 1.27k Views
CQRS:. Crack for Architecture Addicts… -or- …An Idea Who’s Time Has Come?. Thanks for celebrating 10 years of the .NET Community with INETA. Happy Birthday!.
E N D
CQRS: Crack for Architecture Addicts… -or- …An Idea Who’s Time Has Come?
Thanks for celebrating 10 years of the .NET Community with INETA Happy Birthday!
Follow us at @ineta. Tweet using the hashtag#INETA10 for a chance to win a prize in our daily random drawing throughout February. Tweet for Prizes
Post your User Group photo and send us a link (at birthday@ineta.org) to be entered in the User Group weekly random drawing during February. We’ll post the link on the birthday page. Send Your Photo to Win
GrapeCity is putting together a video featuring user group leaders. See the February newsletter for details and send your video clip to be included. Birthday Video http://ineta.org/newsletters/2012_02.htm
INETA's birthday gift to you! A complimentary one year subscription to Code Magazine is available to all new subscribing U. S. Members. Go to www.codemag.com/subscribe/ineta10 to receive your free subscription! Special offer from CODE Magazine
Thank you Platinum Sponsors http://www.componentone.com
Thank you Platinum Sponsors http://www.esri.com
Thank you Platinum Sponsors http://www.infragistics.com
Thank you Platinum Sponsors http://www.telerik.com
Thank you Gold and Silver Sponsors http://www.red-gate.com http://www.grapecity.com
Thank you Donation Sponsors oreilly.com grapecity.com typemock.com
Thank you Donation Sponsors winconnections.com code-magazine.com ssware.com
About INETA INETA provides structured, peer-based organizational, educational, and promotional support to the growing worldwide community of Microsoft® .NET user groups. http://ineta.org
INETA Programs - Community Speakers program- Virtual Groups and Speakers- Community Champions - INETA Live!- Outreach and recognition for user groups- Offers from sponsors for groups and members http://ineta.org
INETA Newsletter Keep up with news on programs, training, special events and other happenings in the world of the .NET community.Visit the link on the archive page and enter your email address to be added to the mailing list. http://ineta.org/newsletters
Community Speakers Program Anyone can register to become part of the program. Group leaders can find speakers as often as you like. http://ineta.org/Speakers/
INETA Live Learn something new with the community presentation recordings available now on INETA Live! http://live.ineta.org/
Community Champions Tell us what you do to support the .NET Community and get recognized. http://inetachamps.com
Get Your Code On and Win Win a scholarship and paid travel to either DevConnections in Las Vegas or TechEd in Orlando with the Component Code Challenge. http://ineta.org/CodeChallenge
Special Offers for INETAMembers and Groups http://ineta.org/offers
CQRS: Crack for Architecture Addicts… -or- …An Idea Who’s Time Has Come?
Do I Suck? http://speakerrate.com/talks/9298
Who am I? • …and why should you care? • Steve Bohlen • I Read Books + Write Software • vs. “Read Software + Write Books” • Blog, Screencast, Speak, Share, Learn
Nearly 20 years developing software LISP, Delphi, C/C++, VB, VB.NET, C#, Ruby Senior Engineer Springsource/VMware Co-Founder, NYC Alt.Net User Group http://nyalt.net • Co-Organizer, NYC DDD User Group • http://dddnyc.org Contributor: various OSS projects Nhibernatehttp://www.nhforge.org • NDbUnithttp://www.googlecode.com/ndbunit • Spring.NET http://www.springframework.net blog: http://blog.unhandled-exceptions.com e-mail: sbohlen@gmail.com twitter: @sbohlen
Agenda • What’s wrong with Traditional Application Architecture? • What is CQRS? • Commands and Events • Persistence • Understanding Event Sourcing • Exploring a simple CQRS sample app • Exploring a comprehensive CQRS sample app (?) • Resources to Learn more • Q+A
Traditional Architecture Client Return DTO ACK Returned LAN/WAN Request DTO Command Remote Services Application Services Domain Object Domain Object Domain Object Domain Object RDBMS
Application Design Pain Points • Scalability of System is by larger and larger RDBMS • Surprise, surprise! • Persistence means ‘save the Current State’ of the domain model • Query concerns are at odds with Transactional concerns • 1NF vs. 3NF • more…
Domain Modeling Pain Points • Business Rules only exist in user’s heads • Converting Domain Objects to DTOs (and back again!) • Domain Object Persistence • Lazy vs. Eager Fetching • Optimizing Domain for efficient Queries • Setter/Getter Anti-Pattern • Tests are (often) brittle • more…
Business Pain Points • Must know what business questions we want to ask up front • Optimizing for Queries and Optimzing for Transactions are tied together (and expensive) • Evolving Requirements is hard/expensive • more…
Self-Delusion • One model can be made to efficiently serve two (or more!) different masters • Competing optimization needs of Queries and the Transactions can be efficiently balanced • Getters/Setters are a necessary evil • Persisting State is the only way to think about the problem
Command-Query Separation Command-Query Separation (CQS) states that every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, asking a question should not change the answer. More formally, methods should return a value only if they are referentially transparent and hence possess no side effects. -Bertrand Meyer, designing the Eiffel language
Command-QueryResponsibility Segregation • The CQS principles applied to your domain modeling and system architecture • Enable each element of your architecture to be optimized for a single responsibility • Decomposition for your architecture rather than just for your objects
Slicing and Dicing our Architecture Client Return DTO ACK Returned LAN/WAN Request DTO Command Client Remote Services Server Application Services Domain Object Domain Object Domain Object Domain Object RDBMS Read Write
Refactoring our Architecture Client Return DTO ACK Returned LAN/WAN Request DTO Command Remote Services Remote Services Remote Services Application Services Application Services Domain Object Domain Object Domain Object Domain Object Light-Weight Query Services Persistence RDBMS Persistence Eventually Read Write
Scaling our Systems Write Read C A P CAP Theorem: onsistency, vailability, artition-Tolerance; pick any two! A P C
About “Eventual Consistency” • Domain Experts deal in ‘stale’ data all the time • Edit screens, Reports, Analysis, OLAP • ‘Staleness’ is often already implicitly in our systems • Caching, Optimistic Concurrency, and more • Eventual Consistency is making that ‘staleness’ an explicit (and acknowledged) fact in the system • Language matters: say staleand oldernot out-of-dateor inconsistent • Opportunity to actually discuss ‘how stale is OK?’ • Often we make data stale without this discussion at all
Refresher: the Aggregate Root Pattern Aggregate Boundary Aggregate Boundary Entity1 Entity1 Entity2 Entity2 ValueObject1 Entity3 Aggregate Boundary ValueObject1 Entity1 ValueObject2 ValueObject1 ValueObject2