SlideShare a Scribd company logo
Andrea Saltarello
@andysal74
CEO @ Managed Designs
http://www.manageddesigns.it
Making workflow implementation
easy with CQRS
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
A workflow consists of an orchestrated and
repeatable pattern of business activity enabled by the
systematic organization of resources into processes that
transform materials, provide services, or process
information.[1]
It can be depicted as a sequence of operations,
declared as work of a person or group,[2] an organization
of staff, or one or more simple or complex mechanisms.
[Wikipedia]
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
A simple workflow: Invoicing
Issue
Payment
Ship
NotifyExpires IsPaid Collect
No
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
A simple workflow: Invoicing
Either a user or a scheduler fires code such as:
public void NotifyCustomersAboutPertainingExpiredInvoices()
{
var expiredInvoices = from i in db.OutgoingInvoices
where SomeClausesPointingToStillUnpaidExpiredInvoices
select i;
foreach(var invoice in expiredInvoices)
{
NotifyExpiredInvoiceToCustomer(invoice);
}
}
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Enter CQRS
Presentation layer
Application layer
Infrastructure layer
Domain Model
Domain layer
Presentation layer
Infrastructure layer
CQRS
Queries
Data
access
Commands
Application
+
Domain
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Why CQRS?
We faced a lot of complexity in modeling
We thought it was inherent domain complexity
Long story short: a single model caring about all aspects of the domain is
hard. Enter CQS
Command/Query Separation
(cit. Bertrand Meyer – 1980s)
Query
> Returns data
> Doesn’t alter state
Command
> Alter state
> Doesn’t return data
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
CQRS in action
As a business unit manager, I want to notify
customers about expired invoices
Database
.OutgoingInvoices.
.PerBusinessUnit(businessUnitId)
.ExpiredOnly()
.Select(i => new {InvoiceNumber = i.Number, CustomerId =
i.Customer.Id})
.AsParallel()
.ForAll(i => NotifyCustomer(i.InvoiceNumber, i.CustomerId));
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
The result
Pros:
• Easy to read
• Close to Ubiquitous Language
Cons:
• Synchronous (lower scalability)
• Either a scheduling engine or human interaction is
required
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Commands: a different strategy
1. Application sends a command to the system
2. Commands are dispatched to workflow managers
(a.k.a. Sagas) which will execute them and then state
success/failure accordingly
3. Responses are notified to interested subscribers (a.k.a.
handlers) such as Denormalizers, which will
(eventually) update the read model’s database
Note: command/responses dispatch will be managed by a
Mediator
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
CQRS in action, part 2
As a business unit manager, I want to notify
customers about expired invoices
Database
.OutgoingInvoices.
.PerBusinessUnit(businessUnitId)
.ExpiredOnly()
.Select(i => new {InvoiceNumber = i.Number, CustomerId = i.Customer.Id})
.AsParallel()
.ForAll(i => mediator.Send(new NotifyPaymentDueCommand(i.InvoiceNumber,
i.CustomerId)));
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
The result, part 2
Pros:
• Easy to read
• Close to Ubiquitous Language
• Asynchronous
Cons:
• Either a scheduling engine or human interaction is
required
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Queues or buses? That is the question (semi cit. )
Although both categories are viable options and support
common features (e.g.: message durability), a bus is generally
preferable due to advanced capabilities (e.g.: message
scheduling)
Mediator, who art thou?
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Sagas 1-2-3
In a messaging system, a saga orchestrate a set of
messages. The main benefit of using a saga is that it
allows us to manage the interaction in a stateful manner
(easy to think and reason about) while actually working in a
distributed and asynchronous environment.
[Ayende]
Though Saga are not proper workflow/process manager,
they are effective at pretending to be 
Sagas in action
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
More resources:
• “Microsoft .NET: Architecting Applications for the Enterprise”
by Andrea Saltarello and Dino Esposito, Microsoft Press (2014)
• Merp (http://naa4e.codeplex.com)
Links
Thank you

More Related Content

Similar to Making workflow implementation easy with CQRS

Pre-Con Education: What Is CA Unified Infrastructure Management and what's ne...
Pre-Con Education: What Is CA Unified Infrastructure Management and what's ne...Pre-Con Education: What Is CA Unified Infrastructure Management and what's ne...
Pre-Con Education: What Is CA Unified Infrastructure Management and what's ne...
CA Technologies
 
lecture13.ppt
lecture13.pptlecture13.ppt
lecture13.ppt
IrfanAkbar35
 
Cloud computing set 3
Cloud computing set 3Cloud computing set 3
Cloud computing set 3
Nicole Valerio
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
Vikash Sharma
 
8 Key Elements to Modern IT Operations Management with a Digital Operations C...
8 Key Elements to Modern IT Operations Management with a Digital Operations C...8 Key Elements to Modern IT Operations Management with a Digital Operations C...
8 Key Elements to Modern IT Operations Management with a Digital Operations C...
OpsRamp
 
Getting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Getting Started with Nastel AutoPilot Business Views and Policies - a TutorialGetting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Getting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Sam Garforth
 
Cbse computer science (c++) class 12 board project bank managment system
Cbse computer science (c++)  class 12 board project  bank managment systemCbse computer science (c++)  class 12 board project  bank managment system
Cbse computer science (c++) class 12 board project bank managment system
pranoy_seenu
 
Tutorial 22 mastering olap reporting drilling through using mdx
Tutorial 22 mastering olap reporting drilling through using mdxTutorial 22 mastering olap reporting drilling through using mdx
Tutorial 22 mastering olap reporting drilling through using mdx
Subandi Wahyudi
 
Proposed pricing model for cloud computing
Proposed pricing model for cloud computingProposed pricing model for cloud computing
Proposed pricing model for cloud computing
Adeel Javaid
 
1.My Presentation.pptx
1.My Presentation.pptx1.My Presentation.pptx
1.My Presentation.pptx
ArslanAliArslanAli
 
Thesis1 3-23
Thesis1 3-23Thesis1 3-23
Thesis1 3-23
Hemant Dhoot
 
Synchronicity of a distributed financial system
Synchronicity of a distributed financial systemSynchronicity of a distributed financial system
Synchronicity of a distributed financial system
DataWorks Summit
 
Smart Services & Smart Clients - How Microservices Change the Way You Build a...
Smart Services & Smart Clients - How Microservices Change the Way You Build a...Smart Services & Smart Clients - How Microservices Change the Way You Build a...
Smart Services & Smart Clients - How Microservices Change the Way You Build a...
Neil Mansilla
 
WF_in_retail_banking_enterprise_systems
WF_in_retail_banking_enterprise_systemsWF_in_retail_banking_enterprise_systems
WF_in_retail_banking_enterprise_systemsOleh Zheleznyak
 
Survey on reliable sla based monitoring for billing scheme in cloud computing
Survey on reliable sla based monitoring for billing scheme in cloud computingSurvey on reliable sla based monitoring for billing scheme in cloud computing
Survey on reliable sla based monitoring for billing scheme in cloud computing
eSAT Journals
 
Scheduling
SchedulingScheduling
Orwell Hortonworks Data Summit
Orwell Hortonworks Data SummitOrwell Hortonworks Data Summit
Orwell Hortonworks Data Summit
Luis Caldeira
 
Sap tr um_dm_meter reading order reversal_v1.0
Sap tr um_dm_meter reading order reversal_v1.0Sap tr um_dm_meter reading order reversal_v1.0
Sap tr um_dm_meter reading order reversal_v1.0
UF Technology
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
Thibaud Desodt
 

Similar to Making workflow implementation easy with CQRS (20)

Pre-Con Education: What Is CA Unified Infrastructure Management and what's ne...
Pre-Con Education: What Is CA Unified Infrastructure Management and what's ne...Pre-Con Education: What Is CA Unified Infrastructure Management and what's ne...
Pre-Con Education: What Is CA Unified Infrastructure Management and what's ne...
 
lecture13.ppt
lecture13.pptlecture13.ppt
lecture13.ppt
 
Cloud computing set 3
Cloud computing set 3Cloud computing set 3
Cloud computing set 3
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
8 Key Elements to Modern IT Operations Management with a Digital Operations C...
8 Key Elements to Modern IT Operations Management with a Digital Operations C...8 Key Elements to Modern IT Operations Management with a Digital Operations C...
8 Key Elements to Modern IT Operations Management with a Digital Operations C...
 
Getting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Getting Started with Nastel AutoPilot Business Views and Policies - a TutorialGetting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
Getting Started with Nastel AutoPilot Business Views and Policies - a Tutorial
 
Cbse computer science (c++) class 12 board project bank managment system
Cbse computer science (c++)  class 12 board project  bank managment systemCbse computer science (c++)  class 12 board project  bank managment system
Cbse computer science (c++) class 12 board project bank managment system
 
Tutorial 22 mastering olap reporting drilling through using mdx
Tutorial 22 mastering olap reporting drilling through using mdxTutorial 22 mastering olap reporting drilling through using mdx
Tutorial 22 mastering olap reporting drilling through using mdx
 
Proposed pricing model for cloud computing
Proposed pricing model for cloud computingProposed pricing model for cloud computing
Proposed pricing model for cloud computing
 
1.My Presentation.pptx
1.My Presentation.pptx1.My Presentation.pptx
1.My Presentation.pptx
 
Thesis1 3-23
Thesis1 3-23Thesis1 3-23
Thesis1 3-23
 
Synchronicity of a distributed financial system
Synchronicity of a distributed financial systemSynchronicity of a distributed financial system
Synchronicity of a distributed financial system
 
Smart Services & Smart Clients - How Microservices Change the Way You Build a...
Smart Services & Smart Clients - How Microservices Change the Way You Build a...Smart Services & Smart Clients - How Microservices Change the Way You Build a...
Smart Services & Smart Clients - How Microservices Change the Way You Build a...
 
WF_in_retail_banking_enterprise_systems
WF_in_retail_banking_enterprise_systemsWF_in_retail_banking_enterprise_systems
WF_in_retail_banking_enterprise_systems
 
Survey on reliable sla based monitoring for billing scheme in cloud computing
Survey on reliable sla based monitoring for billing scheme in cloud computingSurvey on reliable sla based monitoring for billing scheme in cloud computing
Survey on reliable sla based monitoring for billing scheme in cloud computing
 
Scheduling
SchedulingScheduling
Scheduling
 
Orwell Hortonworks Data Summit
Orwell Hortonworks Data SummitOrwell Hortonworks Data Summit
Orwell Hortonworks Data Summit
 
Sap tr um_dm_meter reading order reversal_v1.0
Sap tr um_dm_meter reading order reversal_v1.0Sap tr um_dm_meter reading order reversal_v1.0
Sap tr um_dm_meter reading order reversal_v1.0
 
Dependency injection - the right way
Dependency injection - the right wayDependency injection - the right way
Dependency injection - the right way
 
Proteus CMMS Overview
Proteus CMMS OverviewProteus CMMS Overview
Proteus CMMS Overview
 

More from Particular Software

Scaling for Success: Lessons from handling peak loads on Azure with NServiceBus
Scaling for Success: Lessons from handling peak loads on Azure with NServiceBusScaling for Success: Lessons from handling peak loads on Azure with NServiceBus
Scaling for Success: Lessons from handling peak loads on Azure with NServiceBus
Particular Software
 
Beyond simple benchmarks—a practical guide to optimizing code
Beyond simple benchmarks—a practical guide to optimizing code Beyond simple benchmarks—a practical guide to optimizing code
Beyond simple benchmarks—a practical guide to optimizing code
Particular Software
 
An exception occurred - Please try again
An exception occurred - Please try againAn exception occurred - Please try again
An exception occurred - Please try again
Particular Software
 
Tales from the trenches creating complex distributed systems
Tales from the trenches  creating complex distributed systemsTales from the trenches  creating complex distributed systems
Tales from the trenches creating complex distributed systems
Particular Software
 
Got the time?
Got the time?Got the time?
Got the time?
Particular Software
 
Implementing outbox model-checking first
Implementing outbox   model-checking firstImplementing outbox   model-checking first
Implementing outbox model-checking first
Particular Software
 
Reports from the field azure functions in practice
Reports from the field   azure functions in practiceReports from the field   azure functions in practice
Reports from the field azure functions in practice
Particular Software
 
Finding your service boundaries - a practical guide
Finding your service boundaries - a practical guideFinding your service boundaries - a practical guide
Finding your service boundaries - a practical guide
Particular Software
 
Decomposing .NET Monoliths with NServiceBus and Docker
Decomposing .NET Monoliths with NServiceBus and DockerDecomposing .NET Monoliths with NServiceBus and Docker
Decomposing .NET Monoliths with NServiceBus and Docker
Particular Software
 
DIY Async Message Pump: Lessons from the trenches
DIY Async Message Pump: Lessons from the trenchesDIY Async Message Pump: Lessons from the trenches
DIY Async Message Pump: Lessons from the trenches
Particular Software
 
Share the insight of ServiceInsight
Share the insight of ServiceInsightShare the insight of ServiceInsight
Share the insight of ServiceInsight
Particular Software
 
What to consider when monitoring microservices
What to consider when monitoring microservicesWhat to consider when monitoring microservices
What to consider when monitoring microservices
Particular Software
 
Making communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBusMaking communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBus
Particular Software
 
Making communication across boundaries simple with Azure Service Bus
Making communication across boundaries simple with Azure Service BusMaking communication across boundaries simple with Azure Service Bus
Making communication across boundaries simple with Azure Service Bus
Particular Software
 
How to avoid microservice pitfalls
How to avoid microservice pitfallsHow to avoid microservice pitfalls
How to avoid microservice pitfalls
Particular Software
 
Connect front end to back end using SignalR and Messaging
Connect front end to back end using SignalR and MessagingConnect front end to back end using SignalR and Messaging
Connect front end to back end using SignalR and Messaging
Particular Software
 
Async/Await: NServiceBus v6 API Update
Async/Await: NServiceBus v6 API UpdateAsync/Await: NServiceBus v6 API Update
Async/Await: NServiceBus v6 API Update
Particular Software
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps
Particular Software
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
Particular Software
 
Cqrs but different
Cqrs but differentCqrs but different
Cqrs but different
Particular Software
 

More from Particular Software (20)

Scaling for Success: Lessons from handling peak loads on Azure with NServiceBus
Scaling for Success: Lessons from handling peak loads on Azure with NServiceBusScaling for Success: Lessons from handling peak loads on Azure with NServiceBus
Scaling for Success: Lessons from handling peak loads on Azure with NServiceBus
 
Beyond simple benchmarks—a practical guide to optimizing code
Beyond simple benchmarks—a practical guide to optimizing code Beyond simple benchmarks—a practical guide to optimizing code
Beyond simple benchmarks—a practical guide to optimizing code
 
An exception occurred - Please try again
An exception occurred - Please try againAn exception occurred - Please try again
An exception occurred - Please try again
 
Tales from the trenches creating complex distributed systems
Tales from the trenches  creating complex distributed systemsTales from the trenches  creating complex distributed systems
Tales from the trenches creating complex distributed systems
 
Got the time?
Got the time?Got the time?
Got the time?
 
Implementing outbox model-checking first
Implementing outbox   model-checking firstImplementing outbox   model-checking first
Implementing outbox model-checking first
 
Reports from the field azure functions in practice
Reports from the field   azure functions in practiceReports from the field   azure functions in practice
Reports from the field azure functions in practice
 
Finding your service boundaries - a practical guide
Finding your service boundaries - a practical guideFinding your service boundaries - a practical guide
Finding your service boundaries - a practical guide
 
Decomposing .NET Monoliths with NServiceBus and Docker
Decomposing .NET Monoliths with NServiceBus and DockerDecomposing .NET Monoliths with NServiceBus and Docker
Decomposing .NET Monoliths with NServiceBus and Docker
 
DIY Async Message Pump: Lessons from the trenches
DIY Async Message Pump: Lessons from the trenchesDIY Async Message Pump: Lessons from the trenches
DIY Async Message Pump: Lessons from the trenches
 
Share the insight of ServiceInsight
Share the insight of ServiceInsightShare the insight of ServiceInsight
Share the insight of ServiceInsight
 
What to consider when monitoring microservices
What to consider when monitoring microservicesWhat to consider when monitoring microservices
What to consider when monitoring microservices
 
Making communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBusMaking communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBus
 
Making communication across boundaries simple with Azure Service Bus
Making communication across boundaries simple with Azure Service BusMaking communication across boundaries simple with Azure Service Bus
Making communication across boundaries simple with Azure Service Bus
 
How to avoid microservice pitfalls
How to avoid microservice pitfallsHow to avoid microservice pitfalls
How to avoid microservice pitfalls
 
Connect front end to back end using SignalR and Messaging
Connect front end to back end using SignalR and MessagingConnect front end to back end using SignalR and Messaging
Connect front end to back end using SignalR and Messaging
 
Async/Await: NServiceBus v6 API Update
Async/Await: NServiceBus v6 API UpdateAsync/Await: NServiceBus v6 API Update
Async/Await: NServiceBus v6 API Update
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
 
Cqrs but different
Cqrs but differentCqrs but different
Cqrs but different
 

Recently uploaded

Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Jay Das
 
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
 
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
 
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
 
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
 
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
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
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
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
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
 
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
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
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
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 

Recently uploaded (20)

Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdfEnhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
Enhancing Project Management Efficiency_ Leveraging AI Tools like ChatGPT.pdf
 
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...
 
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...
 
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
 
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
 
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
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
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
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
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 ...
 
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
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
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
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 

Making workflow implementation easy with CQRS

  • 1. Andrea Saltarello @andysal74 CEO @ Managed Designs http://www.manageddesigns.it Making workflow implementation easy with CQRS
  • 2. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS A workflow consists of an orchestrated and repeatable pattern of business activity enabled by the systematic organization of resources into processes that transform materials, provide services, or process information.[1] It can be depicted as a sequence of operations, declared as work of a person or group,[2] an organization of staff, or one or more simple or complex mechanisms. [Wikipedia]
  • 3. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS A simple workflow: Invoicing Issue Payment Ship NotifyExpires IsPaid Collect No
  • 4. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS A simple workflow: Invoicing Either a user or a scheduler fires code such as: public void NotifyCustomersAboutPertainingExpiredInvoices() { var expiredInvoices = from i in db.OutgoingInvoices where SomeClausesPointingToStillUnpaidExpiredInvoices select i; foreach(var invoice in expiredInvoices) { NotifyExpiredInvoiceToCustomer(invoice); } }
  • 5. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS Enter CQRS Presentation layer Application layer Infrastructure layer Domain Model Domain layer Presentation layer Infrastructure layer CQRS Queries Data access Commands Application + Domain
  • 6. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS Why CQRS? We faced a lot of complexity in modeling We thought it was inherent domain complexity Long story short: a single model caring about all aspects of the domain is hard. Enter CQS Command/Query Separation (cit. Bertrand Meyer – 1980s) Query > Returns data > Doesn’t alter state Command > Alter state > Doesn’t return data
  • 7. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS CQRS in action As a business unit manager, I want to notify customers about expired invoices Database .OutgoingInvoices. .PerBusinessUnit(businessUnitId) .ExpiredOnly() .Select(i => new {InvoiceNumber = i.Number, CustomerId = i.Customer.Id}) .AsParallel() .ForAll(i => NotifyCustomer(i.InvoiceNumber, i.CustomerId));
  • 8. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS The result Pros: • Easy to read • Close to Ubiquitous Language Cons: • Synchronous (lower scalability) • Either a scheduling engine or human interaction is required
  • 9. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS Commands: a different strategy 1. Application sends a command to the system 2. Commands are dispatched to workflow managers (a.k.a. Sagas) which will execute them and then state success/failure accordingly 3. Responses are notified to interested subscribers (a.k.a. handlers) such as Denormalizers, which will (eventually) update the read model’s database Note: command/responses dispatch will be managed by a Mediator
  • 10. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS CQRS in action, part 2 As a business unit manager, I want to notify customers about expired invoices Database .OutgoingInvoices. .PerBusinessUnit(businessUnitId) .ExpiredOnly() .Select(i => new {InvoiceNumber = i.Number, CustomerId = i.Customer.Id}) .AsParallel() .ForAll(i => mediator.Send(new NotifyPaymentDueCommand(i.InvoiceNumber, i.CustomerId)));
  • 11. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS The result, part 2 Pros: • Easy to read • Close to Ubiquitous Language • Asynchronous Cons: • Either a scheduling engine or human interaction is required
  • 12. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS Queues or buses? That is the question (semi cit. ) Although both categories are viable options and support common features (e.g.: message durability), a bus is generally preferable due to advanced capabilities (e.g.: message scheduling) Mediator, who art thou?
  • 13. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS Sagas 1-2-3 In a messaging system, a saga orchestrate a set of messages. The main benefit of using a saga is that it allows us to manage the interaction in a stateful manner (easy to think and reason about) while actually working in a distributed and asynchronous environment. [Ayende] Though Saga are not proper workflow/process manager, they are effective at pretending to be 
  • 15. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS More resources: • “Microsoft .NET: Architecting Applications for the Enterprise” by Andrea Saltarello and Dino Esposito, Microsoft Press (2014) • Merp (http://naa4e.codeplex.com) Links