SlideShare a Scribd company logo
CQRS
Layered architecture
User Interface
Service layer
Data access layer
Domainmodel
Simple beginnings (agile)
Product
Customer
More and more entities: Complexity!
Product
Customer
Order
And a couple of iterations later...
OrderItem
Customer
Order
Product
Invoice
….
….
….
….
...
….
And after some more iterations...
OrderItem
Customer
Order
Product
Invoice
….
….
….
….
...
….
….
….
….
….
….
….
….
….
….
….
….
….
Complex data layer: Queries!
SELECT *
FROM ….
WHERE id IN (
SELECT id FROM product
INNER JOIN invoice …
INNER JOIN orderitem ...
INNER JOIN order
INNER JOIN …
INNER JOIN …
WHERE order.customerId = ?
AND …
AND …
) AND … IN (
SELECT id FROM product
INNER JOIN invoice …
INNER JOIN orderitem ...
WHERE …
) AND … IN (
SELECT id FROM product
INNER JOIN invoice …
INNER JOIN orderitem ...
WHERE …
)
…...
Complex service layer: Service dependencies!
class OrderService {
@Autowired
private ProductService productService;
@Autowired
private PaymentService paymentService;
@Autowired
private OrderItemService orderItemService;
@Autowired
private InvoiceService invoiceSerivce;
@Autowired
private SomeService someService;
@Autowired
private SomeService2 someService2;
…..
Anemic domain model
public class OrderLine {
private int quantity;
private BigDecimal price;
public int getQuantity() {
return quantity;
}
public void setQuantity(int quantity) {
this.quantity = quantity;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
}
Result
Data inconsistency!
● Domain constraints not enforced by all services
● Multiple concurrent transactions over huge relational data model lead to inconsistencies
Domain Driven Design - Eric Evans
Concrete example: Purchase order
Domain Driven Design:
It is difficult to guarantee the consistency of changes to objects in a model with
complex associations. Invariants need to be maintained that apply to closely
related groups of objects, not just discrete objects.
[Domain Driven Design - Eric Evans]
Solution: Aggregates
Aggregate
• The root ENTITY is ultimately responsible for checking invariants.
• Nothing outside the AGGREGATE boundary can hold a reference to anything inside, except to the
root ENTITY. The root ENTITY can hand references to the internal ENTITIES to other objects, but
those objects can use them only transiently, and they may not hold on to the reference.
• As a corollary to the previous rule, only AGGREGATE roots can be obtained directly with database
queries. All other objects must be found by traversal of associations.
• A delete operation must remove everything within the AGGREGATE boundary at once.
• When a change to any object within the AGGREGATE boundary is committed, all invariants of the
whole AGGREGATE must be satisfied.
[Domain driven design - Eric Evans]
Aggregate pitfalls
Don’t make your aggregates too big
● Remember editing an aggregate requires checking all business invariants which requires to
load all state of the aggregate.
● This results in huge transactions and memory usage
● Large aggregates means more chance that users interfere by editing parts of the same
aggregate
○ which should result in either an optimistic lock exception or in case of pessimistic locks
not being able to edit an aggregate.
Aggregate advantages
An aggregate is a small collection of entities that are kept consistent by invariant checking
● The aggregate can only check it invariants on its own internal state
● With (unit) tests you can easily prove that your aggregates stay consistent, because you don’t
need the state of any other part of the system
● Using small aggregates reduces the complexity of your application
○ Testing is simpler
○ Fewer moving state when processing an update
Long running business transactions across multiple
aggregates: Webshop
● A customer can only order a product if there is still stock in the inventory
● An order can only succeed if the customer has paid the order amount
Webshop
Product
product
amountInStock
productPrice
Order
(AggregateRoot)
orderLines
orderAmount
payment
OrderLine
product
amount
productPrice
Payment
amount
isPaid
Solution: Separate aggregates using eventual
consistency
Product
(AggregateRoot)
productId
amountInStock
productPrice
Payment
(AggregateRoot)
amount
isPaid
OrderManager
(AggregateRoot)
1. Order request
1.1 Reserve
Stock
1.1 Initiate
payment 2. Payment
Successful
3. Payment
failed
2.1 Order
fulfilled
3.1 Unreserve
stock
Invariants across multiple aggregates
Any rule that spans AGGREGATES will not be expected to be up-to-date at all times.
Through event processing, batch processing, or other update mechanisms, other
dependencies can be resolved within some specific time. [Domain Driven Design]
Introduction: CQRS
Example: CQRS shopping basket
Command Model
Shopping Basket
Command:
Add product to basket
Event:
Product added
CustomerViewShoppingBasket MarketingProductsAddedView
Query:
ShowCustomerShoppingBasket
Query:
ShowProductsAddedOverAllCustomers
Advantages CQRS
● We model business actions (commands) and important business events (event)
○ The intent of a business transactions is better captured in commands than in just crud
operations on a database
● Separate read model allows for scaling reads independently
● We can observe a business interaction from the outside (by observing the events) without
knowing the inner details of the aggregate (state and business invariants)
Eventually consistent webshop
Product
(AggregateRoot)
productId
amountInStock
productPrice
Payment
(AggregateRoot)
amount
isPaid
OrderManager
(AggregateRoot)
1. Order
requested
1.1 Reserve
Stock
1.1 Create
payment 2.Payment
successful
3. Cancel
payment
2.1 Order
Fulfilled3.1 Undo stock
reservation
Payment
(AggregateRoot)
amount
isPaid
OrderManager
(AggregateRoot)
reserveredStock
paymentReceived
1 Create
payment 2. Payment
successful
3. Payment
failed
Deposit
Deposit
Further reading
● Domain Driven Design - Eric Evans
● Domain Driven Design Distilled - Vaughn Vernon
● Implementing Domain Driven Design - Vaughn Vernon
Hands on!
Notes
● Command, events prevent distributed monolith
● Aggregates have nice boundaries for spreading across microservices

More Related Content

What's hot

Static Partitioning with Xen, LinuxRT, and Zephyr: A Concrete End-to-end Exam...
Static Partitioning with Xen, LinuxRT, and Zephyr: A Concrete End-to-end Exam...Static Partitioning with Xen, LinuxRT, and Zephyr: A Concrete End-to-end Exam...
Static Partitioning with Xen, LinuxRT, and Zephyr: A Concrete End-to-end Exam...
Stefano Stabellini
 
Agile Unified Process (AUP).pptx
Agile Unified Process (AUP).pptxAgile Unified Process (AUP).pptx
Agile Unified Process (AUP).pptx
Karim Monir
 
Union FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a ContainerUnion FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a Container
Knoldus Inc.
 
Planning in Software Projects
Planning in Software ProjectsPlanning in Software Projects
Planning in Software ProjectsJayakumar PP
 
Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell script
Bhavesh Padharia
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbg
Sam Bowne
 
Component based software engineering
Component based software engineeringComponent based software engineering
Component based software engineering
Charotar University Of Science And Technology,Gujrat
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
sudhir singh yadav
 
Class based modeling
Class based modelingClass based modeling
Class based modeling
Md. Shafiuzzaman Hira
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
Meghaj Mallick
 
System hardening - OS and Application
System hardening - OS and ApplicationSystem hardening - OS and Application
System hardening - OS and Application
edavid2685
 
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
NGINX, Inc.
 
Android - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTaskAndroid - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTaskHoang Ngo
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
KunalKewat1
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
Stephane Manciot
 
Identifying classes and objects ooad
Identifying classes and objects ooadIdentifying classes and objects ooad
Identifying classes and objects ooad
Melba Rosalind
 
Implementation issues software engineering
Implementation issues software engineeringImplementation issues software engineering
Implementation issues software engineering
rishi ram khanal
 
Presentation on uml
Presentation on umlPresentation on uml
Presentation on uml
Shruti Dalela
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software DevelopmentJignesh Patel
 
Object oriented software engineering concepts
Object oriented software engineering conceptsObject oriented software engineering concepts
Object oriented software engineering conceptsKomal Singh
 

What's hot (20)

Static Partitioning with Xen, LinuxRT, and Zephyr: A Concrete End-to-end Exam...
Static Partitioning with Xen, LinuxRT, and Zephyr: A Concrete End-to-end Exam...Static Partitioning with Xen, LinuxRT, and Zephyr: A Concrete End-to-end Exam...
Static Partitioning with Xen, LinuxRT, and Zephyr: A Concrete End-to-end Exam...
 
Agile Unified Process (AUP).pptx
Agile Unified Process (AUP).pptxAgile Unified Process (AUP).pptx
Agile Unified Process (AUP).pptx
 
Union FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a ContainerUnion FileSystem - A Building Blocks Of a Container
Union FileSystem - A Building Blocks Of a Container
 
Planning in Software Projects
Planning in Software ProjectsPlanning in Software Projects
Planning in Software Projects
 
Introduction to Shell script
Introduction to Shell scriptIntroduction to Shell script
Introduction to Shell script
 
Practical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbgPractical Malware Analysis: Ch 9: OllyDbg
Practical Malware Analysis: Ch 9: OllyDbg
 
Component based software engineering
Component based software engineeringComponent based software engineering
Component based software engineering
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Class based modeling
Class based modelingClass based modeling
Class based modeling
 
Design Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software EngineeringDesign Model & User Interface Design in Software Engineering
Design Model & User Interface Design in Software Engineering
 
System hardening - OS and Application
System hardening - OS and ApplicationSystem hardening - OS and Application
System hardening - OS and Application
 
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
Install and Configure NGINX Unit, the Universal Application, Web, and Proxy S...
 
Android - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTaskAndroid - Thread, Handler and AsyncTask
Android - Thread, Handler and AsyncTask
 
Linux Operating System
Linux Operating SystemLinux Operating System
Linux Operating System
 
Ansible - Introduction
Ansible - IntroductionAnsible - Introduction
Ansible - Introduction
 
Identifying classes and objects ooad
Identifying classes and objects ooadIdentifying classes and objects ooad
Identifying classes and objects ooad
 
Implementation issues software engineering
Implementation issues software engineeringImplementation issues software engineering
Implementation issues software engineering
 
Presentation on uml
Presentation on umlPresentation on uml
Presentation on uml
 
Aspect Oriented Software Development
Aspect Oriented Software DevelopmentAspect Oriented Software Development
Aspect Oriented Software Development
 
Object oriented software engineering concepts
Object oriented software engineering conceptsObject oriented software engineering concepts
Object oriented software engineering concepts
 

Similar to Workshop CQRS and DDD

Microservices patterns
Microservices patternsMicroservices patterns
Microservices patterns
Vikram Babu Kuruguntla
 
our srs (1).pdf
our srs (1).pdfour srs (1).pdf
our srs (1).pdf
ShaliniKumariGupta1
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB
 
Super market billing system using webcam
Super market billing system using webcam Super market billing system using webcam
Super market billing system using webcam
SahithBeats
 
26 story slicing techniques for any scrum team
26 story slicing techniques for any scrum team26 story slicing techniques for any scrum team
26 story slicing techniques for any scrum team
agilebin
 
Project Management Practical 01 - 04 (Mumbai University)
Project Management Practical 01 - 04 (Mumbai University)Project Management Practical 01 - 04 (Mumbai University)
Project Management Practical 01 - 04 (Mumbai University)
Satyendra Singh
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
Piotr Pelczar
 
Javaland 2015 - Bernd Zuther - Die Jagd nach mehr Konversion - Fluch oder Seg...
Javaland 2015 - Bernd Zuther - Die Jagd nach mehr Konversion - Fluch oder Seg...Javaland 2015 - Bernd Zuther - Die Jagd nach mehr Konversion - Fluch oder Seg...
Javaland 2015 - Bernd Zuther - Die Jagd nach mehr Konversion - Fluch oder Seg...
Bernd Zuther
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
Giovanni Scerra ☃
 
Object oriented design patterns for distributed systems
Object oriented design patterns for distributed systemsObject oriented design patterns for distributed systems
Object oriented design patterns for distributed systems
Jordan McBain
 
Blazor, lo sapevi che...
Blazor, lo sapevi che...Blazor, lo sapevi che...
Blazor, lo sapevi che...
Andrea Dottor
 
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Nagios
 
[WSO2Con USA 2018] Patterns for Building Streaming Apps
[WSO2Con USA 2018] Patterns for Building Streaming Apps[WSO2Con USA 2018] Patterns for Building Streaming Apps
[WSO2Con USA 2018] Patterns for Building Streaming Apps
WSO2
 
Kks sre book_ch10
Kks sre book_ch10Kks sre book_ch10
Kks sre book_ch10
Chris Huang
 
Software archiecture lecture08
Software archiecture   lecture08Software archiecture   lecture08
Software archiecture lecture08Luktalja
 
Keeping business logic out of your UIs
Keeping business logic out of your UIsKeeping business logic out of your UIs
Keeping business logic out of your UIs
Petter Holmström
 
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {2013-20...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {2013-20...Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {2013-20...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {2013-20...
Mumbai B.Sc.IT Study
 
B.tech admission in india
B.tech admission in indiaB.tech admission in india
B.tech admission in india
Edhole.com
 
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
Dave Stokes
 

Similar to Workshop CQRS and DDD (20)

Microservices patterns
Microservices patternsMicroservices patterns
Microservices patterns
 
our srs (1).pdf
our srs (1).pdfour srs (1).pdf
our srs (1).pdf
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
 
Super market billing system using webcam
Super market billing system using webcam Super market billing system using webcam
Super market billing system using webcam
 
Onlineshopping
OnlineshoppingOnlineshopping
Onlineshopping
 
26 story slicing techniques for any scrum team
26 story slicing techniques for any scrum team26 story slicing techniques for any scrum team
26 story slicing techniques for any scrum team
 
Project Management Practical 01 - 04 (Mumbai University)
Project Management Practical 01 - 04 (Mumbai University)Project Management Practical 01 - 04 (Mumbai University)
Project Management Practical 01 - 04 (Mumbai University)
 
Pragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecturePragmatic Monolith-First, easy to decompose, clean architecture
Pragmatic Monolith-First, easy to decompose, clean architecture
 
Javaland 2015 - Bernd Zuther - Die Jagd nach mehr Konversion - Fluch oder Seg...
Javaland 2015 - Bernd Zuther - Die Jagd nach mehr Konversion - Fluch oder Seg...Javaland 2015 - Bernd Zuther - Die Jagd nach mehr Konversion - Fluch oder Seg...
Javaland 2015 - Bernd Zuther - Die Jagd nach mehr Konversion - Fluch oder Seg...
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Object oriented design patterns for distributed systems
Object oriented design patterns for distributed systemsObject oriented design patterns for distributed systems
Object oriented design patterns for distributed systems
 
Blazor, lo sapevi che...
Blazor, lo sapevi che...Blazor, lo sapevi che...
Blazor, lo sapevi che...
 
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
Bryan Heden - Agile Networks - Using Nagios XI as the platform for Monitoring...
 
[WSO2Con USA 2018] Patterns for Building Streaming Apps
[WSO2Con USA 2018] Patterns for Building Streaming Apps[WSO2Con USA 2018] Patterns for Building Streaming Apps
[WSO2Con USA 2018] Patterns for Building Streaming Apps
 
Kks sre book_ch10
Kks sre book_ch10Kks sre book_ch10
Kks sre book_ch10
 
Software archiecture lecture08
Software archiecture   lecture08Software archiecture   lecture08
Software archiecture lecture08
 
Keeping business logic out of your UIs
Keeping business logic out of your UIsKeeping business logic out of your UIs
Keeping business logic out of your UIs
 
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {2013-20...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {2013-20...Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {2013-20...
Project Management (Practical Qustion Paper) [CBSGS - 75:25 Pattern] {2013-20...
 
B.tech admission in india
B.tech admission in indiaB.tech admission in india
B.tech admission in india
 
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
MySQL 8 - UKOUG Techfest Brighton December 2nd, 2019
 

Recently uploaded

Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Mind IT Systems
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
informapgpstrackings
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 

Recently uploaded (20)

Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
Custom Healthcare Software for Managing Chronic Conditions and Remote Patient...
 
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
Field Employee Tracking System| MiTrack App| Best Employee Tracking Solution|...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 

Workshop CQRS and DDD

  • 2. Layered architecture User Interface Service layer Data access layer Domainmodel
  • 4. More and more entities: Complexity! Product Customer Order
  • 5. And a couple of iterations later... OrderItem Customer Order Product Invoice …. …. …. …. ... ….
  • 6. And after some more iterations... OrderItem Customer Order Product Invoice …. …. …. …. ... …. …. …. …. …. …. …. …. …. …. …. …. ….
  • 7. Complex data layer: Queries! SELECT * FROM …. WHERE id IN ( SELECT id FROM product INNER JOIN invoice … INNER JOIN orderitem ... INNER JOIN order INNER JOIN … INNER JOIN … WHERE order.customerId = ? AND … AND … ) AND … IN ( SELECT id FROM product INNER JOIN invoice … INNER JOIN orderitem ... WHERE … ) AND … IN ( SELECT id FROM product INNER JOIN invoice … INNER JOIN orderitem ... WHERE … ) …...
  • 8.
  • 9. Complex service layer: Service dependencies! class OrderService { @Autowired private ProductService productService; @Autowired private PaymentService paymentService; @Autowired private OrderItemService orderItemService; @Autowired private InvoiceService invoiceSerivce; @Autowired private SomeService someService; @Autowired private SomeService2 someService2; …..
  • 10.
  • 11.
  • 12. Anemic domain model public class OrderLine { private int quantity; private BigDecimal price; public int getQuantity() { return quantity; } public void setQuantity(int quantity) { this.quantity = quantity; } public BigDecimal getPrice() { return price; } public void setPrice(BigDecimal price) { this.price = price; } }
  • 13. Result Data inconsistency! ● Domain constraints not enforced by all services ● Multiple concurrent transactions over huge relational data model lead to inconsistencies
  • 14.
  • 15. Domain Driven Design - Eric Evans
  • 17. Domain Driven Design: It is difficult to guarantee the consistency of changes to objects in a model with complex associations. Invariants need to be maintained that apply to closely related groups of objects, not just discrete objects. [Domain Driven Design - Eric Evans]
  • 19.
  • 20. Aggregate • The root ENTITY is ultimately responsible for checking invariants. • Nothing outside the AGGREGATE boundary can hold a reference to anything inside, except to the root ENTITY. The root ENTITY can hand references to the internal ENTITIES to other objects, but those objects can use them only transiently, and they may not hold on to the reference. • As a corollary to the previous rule, only AGGREGATE roots can be obtained directly with database queries. All other objects must be found by traversal of associations. • A delete operation must remove everything within the AGGREGATE boundary at once. • When a change to any object within the AGGREGATE boundary is committed, all invariants of the whole AGGREGATE must be satisfied. [Domain driven design - Eric Evans]
  • 21. Aggregate pitfalls Don’t make your aggregates too big ● Remember editing an aggregate requires checking all business invariants which requires to load all state of the aggregate. ● This results in huge transactions and memory usage ● Large aggregates means more chance that users interfere by editing parts of the same aggregate ○ which should result in either an optimistic lock exception or in case of pessimistic locks not being able to edit an aggregate.
  • 22. Aggregate advantages An aggregate is a small collection of entities that are kept consistent by invariant checking ● The aggregate can only check it invariants on its own internal state ● With (unit) tests you can easily prove that your aggregates stay consistent, because you don’t need the state of any other part of the system ● Using small aggregates reduces the complexity of your application ○ Testing is simpler ○ Fewer moving state when processing an update
  • 23. Long running business transactions across multiple aggregates: Webshop ● A customer can only order a product if there is still stock in the inventory ● An order can only succeed if the customer has paid the order amount
  • 25. Solution: Separate aggregates using eventual consistency Product (AggregateRoot) productId amountInStock productPrice Payment (AggregateRoot) amount isPaid OrderManager (AggregateRoot) 1. Order request 1.1 Reserve Stock 1.1 Initiate payment 2. Payment Successful 3. Payment failed 2.1 Order fulfilled 3.1 Unreserve stock
  • 26. Invariants across multiple aggregates Any rule that spans AGGREGATES will not be expected to be up-to-date at all times. Through event processing, batch processing, or other update mechanisms, other dependencies can be resolved within some specific time. [Domain Driven Design]
  • 28. Example: CQRS shopping basket Command Model Shopping Basket Command: Add product to basket Event: Product added CustomerViewShoppingBasket MarketingProductsAddedView Query: ShowCustomerShoppingBasket Query: ShowProductsAddedOverAllCustomers
  • 29. Advantages CQRS ● We model business actions (commands) and important business events (event) ○ The intent of a business transactions is better captured in commands than in just crud operations on a database ● Separate read model allows for scaling reads independently ● We can observe a business interaction from the outside (by observing the events) without knowing the inner details of the aggregate (state and business invariants)
  • 30. Eventually consistent webshop Product (AggregateRoot) productId amountInStock productPrice Payment (AggregateRoot) amount isPaid OrderManager (AggregateRoot) 1. Order requested 1.1 Reserve Stock 1.1 Create payment 2.Payment successful 3. Cancel payment 2.1 Order Fulfilled3.1 Undo stock reservation
  • 32. Further reading ● Domain Driven Design - Eric Evans ● Domain Driven Design Distilled - Vaughn Vernon ● Implementing Domain Driven Design - Vaughn Vernon
  • 34. Notes ● Command, events prevent distributed monolith ● Aggregates have nice boundaries for spreading across microservices