Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
Andrea Saltarello
@andysal74
CEO @ Managed Designs
http://www.manageddesigns.it
Making workflow implementation
easy with C...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
A workflow consists of an orch...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
A simple workflow: Invoicing
I...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
A simple workflow: Invoicing
E...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Enter CQRS
Presentation layer
...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Why CQRS?
We faced a lot of co...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
CQRS in action
As a business u...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
The result
Pros:
• Easy to rea...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Commands: a different strategy...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
CQRS in action, part 2
As a bu...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
The result, part 2
Pros:
• Eas...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Queues or buses? That is the q...
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
Sagas 1-2-3
In a messaging sys...
Sagas in action
Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS
More resources:
• “Microsoft ....
Thank you
Upcoming SlideShare
Loading in …5
×

Making workflow implementation easy with CQRS

1,338 views

Published on

Andrea Saltarello shows how to evolve systems architecture leveraging CQRS principles and NServiceBus Sagas.

Published in: Software
  • I can advise you this service - ⇒ www.HelpWriting.net ⇐ Bought essay here. No problem.
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Making workflow implementation easy with CQRS

  1. 1. Andrea Saltarello @andysal74 CEO @ Managed Designs http://www.manageddesigns.it Making workflow implementation easy with CQRS
  2. 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. 3. Introduction to ServiceInsight for NServiceBusMaking workflow implementation easy with CQRS A simple workflow: Invoicing Issue Payment Ship NotifyExpires IsPaid Collect No
  4. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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 
  14. 14. Sagas in action
  15. 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
  16. 16. Thank you

×