ddd and beyond … on rails! !
DESCRIPTION
DDD and Beyond … on Rails! !. Why Rails?. Ruby is awesome! Vibrant community & ecosystem CoC - less boilerplate code Supports rapid development Asset pipeline Built-in ORM – ActiveRecord And more …. Why DDD?. Powerful practices & patterns for tackling complex problems - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/1.jpg)
DDD and Beyond … on Rails!!
![Page 2: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/2.jpg)
Why Rails?
• Ruby is awesome!• Vibrant community & ecosystem• CoC - less boilerplate code• Supports rapid development• Asset pipeline• Built-in ORM – ActiveRecord• And more …
![Page 3: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/3.jpg)
Why DDD?• Powerful practices & patterns for tackling complex problems
– Both tactical and strategic• Align business & technology
– Zero translations (Ubiquitous Language)– Domain experts contribute to software design– Code becomes a living description of the business
• Increased clarity and understanding– Collaboration that results in well understood models
• Strategic development– Prioritize resources & investment toward more complex or differentiating
areas of the business• Organized architecture
– Align physical systems with distinct areas of the business
![Page 4: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/4.jpg)
DDD on Rails
Rails• Ruby is awesome!• Vibrant community• Less boilerplate• Rapid development• Asset pipeline• ActiveRecord
DDD• Tackle complex domains• Align business & technology• Clarity & understanding• Strategic development• Organized Architecture
* ActiveRecord is a DDD antipattern ….
![Page 5: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/5.jpg)
![Page 6: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/6.jpg)
![Page 7: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/7.jpg)
DDD: Strategic Patterns
SubdomainsUbiquitous Language
Bounded Context
• Separate areas of the business• Ideally one Domain Model per Subdomain
• Language used & understood by all stakeholders in a project • Used to express a Domain Model
• Sets the context for terms in a Ubiquitous Language• Ideally one Bounded Context per Subdomain
![Page 8: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/8.jpg)
Conference Management
![Page 9: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/9.jpg)
Subdomains
![Page 10: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/10.jpg)
Ubiquitous Language
• Program Mgmt. Context– Organizers create Conferences– Organizers call for Proposals– Candidates submit Proposals– Once received, Reviewers rate Proposals– Organizers choose Proposals for Session topics
• Access Control Context– Public Users register to create an Account– Accounts are assigned to one or more Roles– Users sign in to begin an authenticated Session
![Page 11: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/11.jpg)
User Story:As a candidateI would like to submit a proposal to a conferenceSo that it may be available for review
Ubiquitous Language
![Page 12: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/12.jpg)
Isolating Contexts
Gem, Engine, App
Gem, Engine, App
![Page 13: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/13.jpg)
Anticorruption Layer
![Page 14: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/14.jpg)
DDD: Tactical Patterns
• Entity• Aggregate• Repository• Value Object• Domain Event• Domain Service
* Building blocks of a Domain Model
![Page 15: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/15.jpg)
ActiveRecord – Schema First
![Page 16: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/16.jpg)
DDD – Model First
![Page 17: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/17.jpg)
ActiveRecord
DDD Entity
Organizer creates a conference.
![Page 18: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/18.jpg)
ActiveRecord
DDD Entity
Organizer calls for proposals.
![Page 19: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/19.jpg)
ActiveRecord
DDD Entity
Candidate creates and submits a proposal.
![Page 20: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/20.jpg)
ActiveRecord
Proposals can only be received once the organizer has called for proposals.
![Page 21: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/21.jpg)
DDD Entity
Proposals can only be received once the organizer has called for proposals.
![Page 22: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/22.jpg)
ActiveRecord vs DDD Entity
ActiveRecord• Shaped by DB schema• CRUD semantics baked in• No Encapsulation• Multiple responsibilities
– Data access– Business logic– REST resource/view data
DDD Entity• Shaped by UL• Blank canvas to express UL• Enforces invariants• Single responsibility
– Encapsulate business logic
![Page 23: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/23.jpg)
Repositories
• Collection semantics for an Aggregate Root– add(conference), find_by(id) etc.
• Modify one Aggregate per transaction *– Consistency boundary– Watch out for false invariants
• Easily implemented with NoSQL solutions– Object/Document/Key-values etc.
![Page 24: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/24.jpg)
Event Sourcing
• Raise explicit event for every state change• Persist serialized events to an event store
• To retrieve persisted entity– Deserialize events and replay– Conference.allocate.replay(events)
Event Name Source Id Event Args
conference_created 7 { id: 12, name: “Test Conf” }
conference_scheduled 7 { id: 12, date: “2013-31-01”}
proposal_received 7 { id: 12, title: “Test Prop …
![Page 25: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/25.jpg)
Event Sourcing & CQRS
Client
Application
Domain Model
Commands Queries
Query Store
Application
Read-only
AsyncHandlers
DB
Events
![Page 26: DDD and Beyond … on Rails! !](https://reader034.vdocuments.net/reader034/viewer/2022052317/568168cd550346895ddfbcee/html5/thumbnails/26.jpg)
More Information
• A great DDD Introhttp://www.infoq.com/minibooks/domain-driven-design-quickly
• More on CQRShttp://cqrs.wordpress.com/2010/09/08/welcome-to-cqrs-info/
• My Open Source Projecthttps://github.com/domaindrivendev/puree