SlideShare una empresa de Scribd logo
1 de 37
Descargar para leer sin conexión
The Domain Event!
The Hidden Gem of DDD
Henrik Møller Rasmussen
Founder and CTO
The digital daycare
The digital daycare
6 institutions!
~1.000 children
Vaughn Vernon: Implementing Domain-Driven DesignEric Evans: Domain-Driven Design: Tackling …
2003

Theoretical
2013!
Practical
Domain-Driven Design
Do you DDD?
• Domain Model
• Repository
• Ubiquitous language
• Domain Service
• Application Service
• Bounded context
• Context map
• Domain Event
• Anti Corruption Layer
• And many more…
class Product {
!
protected $title;
!
protected $price;
!
public function setPrice($price) {
// ..
}
!
public function getPrice() {
// ..
}
!
public function setTitle($title) {
// ..
}
!
public function getTitle() {
// ..
}
!
}
Is this your domain model?
class ProductController {
!
public function addToBasketAction($product) {
if ($product->getInStock() <= 0) {
$this->redirect();
}
!
// Add to basket
}
}
Where's your business logic?
Let’s build a shop..
Models, Views and Controllers
• Domain models grow into huge classes
• Hard to reason about (mental model)
• Domain models and relations are designed for viewing purposes
• Everything is extremely coupled
• “Big ball of mud”
Package: My.Shop
Proper DDD
Product
Category
Invoice
Order
Email
Customer
Reporting
Searching
Inventory
Shipping
Product
Category
Invoice
Order
Email
Customer
Reporting
Searching
Inventory
Shipping
Catalog
Inventory
Billing
Search
Reporting
…
…
…
Bounded Contexts / Modules
Catalog
Domain models
Product Category
Repositories
CatalogService (Application Service)
Inventory
Domain models
Product
Repositories
InventoryService (Application Service)
There will be more than one class
representing a product
• Small models / modules / bounded contexts
• Easy to reason about
• Easy to test
• Loosely coupled
Benefits
Catalog
Inventory
Billing
Search
Reporting
…
…
…
Communication
Introducing

The Domain Event
So what is a domain event?
• It’s a message …
• .. implemented as a class
• .. published to “the world”
• It’s past tense (e.g. OrderCompletedEvent)
• It’s transactionally coupled to your domain model
• It’s asynchronous
class OrderCompletedEvent {
!
public $orderId;
!
public $amount;
!
public $completedAt;
!
public $customerId;
!
}
Example
class Order {
!
public function complete() {
$this->completedAt = new DateTime();
!
$this->eventService->publish(
new OrderCompletedEvent(…)
);
}
!
}
Publishing event
Catalog
Inventory
Search
Billing
MessageBus
EXAMPLE: Order Completed
Why not use

signal/slots for that?
1. Customer places order

2. Signal / Slot trigger a foreign context to

send the order confirmation via email

3. Something breaks during persistence of the order.



What now?
Signal / Slot example
START TRANSACTION!
UPDATE order …
INSERT INTO event_store …
COMMIT!
!
!
If this succeeds the event is published to the message bus
Transactionally safe domain events
Catalog
Inventory
Search
Billing
MessageBus
EXAMPLE: InStock is updated in the inventory
Catalog
Inventory
Search
Billing
MessageBus
EXAMPLE: Product description updated in the catalog
Benefits of using domain events
• Allows you to integrate bounded contexts with minimal

coupling and dependencies.
• Add features to the system with no changes to existing code.
• Get a more responsive system since a lot of functionality

is handled asynchronous.
• Get a more robust system. Easier to build fault tolerant system.

(Fx. problems with third party services like payment gateways etc.)
UI
Catalog
Inventory
Billing
Search
Reporting
…
…
…
Is it simple to maintain?!
Does it perform?!
Yes!
No!
(Come see my talk tomorrow about CQRS)
Is it simple to build?! Yes!
Let’s talk Flow
What is a bounded context?
Package?!
Subdirectory?!
Its own Flow installation?!
Another system?
Could be any of above as long as they are independent
and only integrate through domain events (or service calls).
!
No sharing of domain models etc.
How do I get started?
https://github.com/agitso/event
• Uses Doctrine’s PostFlush event listener to hook into

Doctrine after persistence and handle domain events.

• The same technique is used in Famly, where we have

currently handled +500.000 domain events
Recap
• Split your system into smaller modules / bounded contexts
• Put your business logic into the domain models
• Integrate modules with Domain Events (use application service calls

for synchronous interactions).
• Use controllers to orchestrate the views - that is fetch data

from Application Services and assign to views and similar.

NO BUSINESS LOGIC HERE.
Henrik Møller Rasmussen!
hmr@famly.dk


Twitter: @heinodk
IRC: Come join us at #ddd
The digital daycare

Más contenido relacionado

La actualidad más candente

List of Top 50 Companies Using Blockchain Technology
List of Top 50 Companies Using Blockchain TechnologyList of Top 50 Companies Using Blockchain Technology
List of Top 50 Companies Using Blockchain Technology
101 Blockchains
 
PHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an AnalysisPHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an Analysis
Positive Hack Days
 

La actualidad más candente (20)

Introduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart ContractsIntroduction to Blockchain and Smart Contracts
Introduction to Blockchain and Smart Contracts
 
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
Smart Contracts Programming Tutorial | Solidity Programming Language | Solidi...
 
Kerberos
KerberosKerberos
Kerberos
 
Tokenization vs encryption vs masking
Tokenization vs encryption vs maskingTokenization vs encryption vs masking
Tokenization vs encryption vs masking
 
Scaling Ethereum using Zero-Knowledge Proofs
Scaling Ethereum using Zero-Knowledge ProofsScaling Ethereum using Zero-Knowledge Proofs
Scaling Ethereum using Zero-Knowledge Proofs
 
List of Top 50 Companies Using Blockchain Technology
List of Top 50 Companies Using Blockchain TechnologyList of Top 50 Companies Using Blockchain Technology
List of Top 50 Companies Using Blockchain Technology
 
Solana decentralized blockchain
Solana decentralized blockchainSolana decentralized blockchain
Solana decentralized blockchain
 
Gaming in blockchain
Gaming in blockchainGaming in blockchain
Gaming in blockchain
 
Domain driven design and model driven development
Domain driven design and model driven developmentDomain driven design and model driven development
Domain driven design and model driven development
 
從開發人員角度十分鐘理解區塊鏈技術
從開發人員角度十分鐘理解區塊鏈技術從開發人員角度十分鐘理解區塊鏈技術
從開發人員角度十分鐘理解區塊鏈技術
 
Contract Practice with Remix
Contract Practice with RemixContract Practice with Remix
Contract Practice with Remix
 
What makes blockchain secure: Key Characteristics & Security Architecture
What makes blockchain secure: Key Characteristics & Security ArchitectureWhat makes blockchain secure: Key Characteristics & Security Architecture
What makes blockchain secure: Key Characteristics & Security Architecture
 
PHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an AnalysisPHP Object Injection Vulnerability in WordPress: an Analysis
PHP Object Injection Vulnerability in WordPress: an Analysis
 
Bitcoin Script
Bitcoin ScriptBitcoin Script
Bitcoin Script
 
Ethereum 2.0
Ethereum 2.0Ethereum 2.0
Ethereum 2.0
 
Blockchain Tokenization
Blockchain TokenizationBlockchain Tokenization
Blockchain Tokenization
 
mastering the curl command line.pdf
mastering the curl command line.pdfmastering the curl command line.pdf
mastering the curl command line.pdf
 
IOTA - Ledger of Things
IOTA - Ledger of ThingsIOTA - Ledger of Things
IOTA - Ledger of Things
 
The Algorand Blockchain
The Algorand BlockchainThe Algorand Blockchain
The Algorand Blockchain
 
The taxonomy of blockchain and cryptocurrency
The taxonomy of blockchain and cryptocurrencyThe taxonomy of blockchain and cryptocurrency
The taxonomy of blockchain and cryptocurrency
 

Similar a Domain Event - The Hidden Gem of DDD

Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan
 
Relentless Refactoring
Relentless RefactoringRelentless Refactoring
Relentless Refactoring
Mark Rickerby
 

Similar a Domain Event - The Hidden Gem of DDD (20)

IDI 2020 - Containers Meet Serverless
IDI 2020 - Containers Meet ServerlessIDI 2020 - Containers Meet Serverless
IDI 2020 - Containers Meet Serverless
 
Microservices with .Net - NDC Sydney, 2016
Microservices with .Net - NDC Sydney, 2016Microservices with .Net - NDC Sydney, 2016
Microservices with .Net - NDC Sydney, 2016
 
Cloud computing and the Windows Azure Services Platform (KU Leuven)
Cloud computing and the Windows Azure Services Platform (KU Leuven)Cloud computing and the Windows Azure Services Platform (KU Leuven)
Cloud computing and the Windows Azure Services Platform (KU Leuven)
 
Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2Daniel Egan Msdn Tech Days Oc Day2
Daniel Egan Msdn Tech Days Oc Day2
 
ArcReady - Architecting For The Cloud
ArcReady - Architecting For The CloudArcReady - Architecting For The Cloud
ArcReady - Architecting For The Cloud
 
Microservices Architecture
Microservices ArchitectureMicroservices Architecture
Microservices Architecture
 
The Next Five Years of Rails
The Next Five Years of RailsThe Next Five Years of Rails
The Next Five Years of Rails
 
RavenDB overview
RavenDB overviewRavenDB overview
RavenDB overview
 
Getting Started with Docker - Nick Stinemates
Getting Started with Docker - Nick StinematesGetting Started with Docker - Nick Stinemates
Getting Started with Docker - Nick Stinemates
 
Azure Umbraco workshop
Azure Umbraco workshopAzure Umbraco workshop
Azure Umbraco workshop
 
DDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVCDDD, CQRS and testing with ASP.Net MVC
DDD, CQRS and testing with ASP.Net MVC
 
Microservices Chaos Testing at Jet
Microservices Chaos Testing at JetMicroservices Chaos Testing at Jet
Microservices Chaos Testing at Jet
 
Tampere Docker meetup - Happy 5th Birthday Docker
Tampere Docker meetup - Happy 5th Birthday DockerTampere Docker meetup - Happy 5th Birthday Docker
Tampere Docker meetup - Happy 5th Birthday Docker
 
Relentless Refactoring
Relentless RefactoringRelentless Refactoring
Relentless Refactoring
 
Arc Ready Cloud Computing
Arc Ready Cloud ComputingArc Ready Cloud Computing
Arc Ready Cloud Computing
 
How to Think Multi-Cloud
How to Think Multi-CloudHow to Think Multi-Cloud
How to Think Multi-Cloud
 
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
Journey to containers by Chet Lintz - AWS Chicago Jan 17,2018 user group on C...
 
Azure and Umbraco CMS
Azure and Umbraco CMSAzure and Umbraco CMS
Azure and Umbraco CMS
 
The challenge of application distribution - Introduction to Docker (2014 dec ...
The challenge of application distribution - Introduction to Docker (2014 dec ...The challenge of application distribution - Introduction to Docker (2014 dec ...
The challenge of application distribution - Introduction to Docker (2014 dec ...
 
Modern Web Development (2018)
Modern Web Development (2018)Modern Web Development (2018)
Modern Web Development (2018)
 

Último

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Último (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

Domain Event - The Hidden Gem of DDD