Building a Distributed Application Using CQRS Principles

  • 726 views
Uploaded on

Whether you're building a new application from scratch or enhancing an existing one with new functionality, being able to scale is very important to the life of your application. While some may say …

Whether you're building a new application from scratch or enhancing an existing one with new functionality, being able to scale is very important to the life of your application. While some may say that you should just throw more hardware at the problem, designing your system up front properly will save you a number of headaches down the road. Command Query Responsibility Segregation (CQRS) is a pattern that helps you design your system to scale over time by taking messaging and applying it to commands your application issues and events that it raises. We'll see a very simple message distribution system and see how applying CQRS along with some event-driven concepts can help your application grow and scale over time.

(Presented at the Rockville, MD .NET User Group on 12/11/2013.)

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
726
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
20
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. http://geekswithblogs.net/DavidHoerster david@agileways.com
  • 2. Business Logic Client Searching Black Box System User Services Data Store
  • 3. Business Logic Client Searching Application System User Services Data Store
  • 4. Client Searching Application System User Services Repository Business Logic Data Store
  • 5. Client User Services Repository Repository Business Searching Logic Application System Data Store
  • 6. Repository Searching Client Business Logic Application System User Services Repository Repository Data Store
  • 7. SearchRepo Searching Client Business Logic Application System User Services UserRepo AppRepo Data Store
  • 8. Bounded Context Search Store SearchRepo Searching Client Business Logic Application System User Services UserRepo AppRepo Data Store
  • 9. Bounded Context Search Store SearchRepo Search Svc Reads Writes Search Queue Handler Client Business Logic Application System User Services UserRepo AppRepo Data Store
  • 10. “every method should either be a command that performs an action, or a query that returns data to the caller, but not both. In other words, asking a question should not change the answer” (Meyer)
  • 11. Bounded Context Search Store SearchRepo Search Req’s Writes Reads Search Queue Cmd Handler Search Domain and Events Cmd Client Business Logic Application System User Services UserRepo AppRepo Data Store
  • 12. Read Model Command Client Repository / Read Model Command Handler Write Store Domain Read Store Event(s) Event Handler(s)
  • 13. public class CreatePlayer : CommandBase { public Int32 LahmanId { get; set; } public String PlayerId { get; set; } public String FirstName { get; set; } public String LastName { get; set; } public String NickName { get; set; } public String College { get; set; } public String Bats { get; set; } public String Throws { get; set; } public Int32 Height { get; set; } public Int32 Weight { get; set; } public DateTime? Debut { get; set; } public DateTime? FinalGame { get; set; } }
  • 14. public class PlayerCreated : EventBase { public String FullName { get; set; } public String PlayerId { get; set; } }
  • 15. public class PlayerHandler : IHandle<PlayerCreated>, IHandle<PlayerYearAdded> { public void Handle(PlayerCreated theEvent) { //do something } public void Handle(PlayerYearAdded theEvent) { //do something else } }
  • 16. SalesOrderHeader (SalesLT) SalesOrderID SalesOrderDetail (SalesLT) SalesOrderID SalesOrderDetailID RevisionNumber OrderQty OrderDate ProductID DueDate Product (SalesLT) UnitPrice ShipDate ProductID UnitPriceDiscount Status Name LineTotal OnlineOrderFlag SalesOrderNumber PurchaseOrderNumber ProductNumber rowguid Color ModifiedDate StandardCost AccountNumber ListPrice CustomerID Size ShipToAddressID Weight BillToAddressID ProductCategoryID ShipMethod ProductModelID CreditCardApprovalCode SellStartDate SubTotal SellEndDate TaxAmt Freight Customer (SalesLT) ProductModel (SalesLT) ProductCategory (SalesLT) CustomerID ProductModelID NameStyle Name ParentProductCategoryID Title CatalogDescription Name FirstName rowguid rowguid MiddleName ModifiedDate ModifiedDate LastName Suffix CompanyName SalesPerson EmailAddress ProductCategoryID
  • 17. SELECT c.FirstName, c.MiddleName, c.LastName, soh.SalesOrderID, soh.OrderDate, sod.UnitPrice, sod.OrderQty, sod.LineTotal, p.Name as 'ProductName', p.Color, p.ProductNumber, pm.Name as 'ProductModel', pc.Name as 'ProductCategory', pcParent.Name as 'ProductParentCategory' FROM SalesLT.Customer c INNER JOIN SalesLT.SalesOrderHeader soh ON c.CustomerID = soh.CustomerID INNER JOIN SalesLT.SalesOrderDetail sod ON soh.SalesOrderID = sod.SalesOrderID INNER JOIN SalesLT.Product p ON sod.ProductID = p.ProductID INNER JOIN SalesLT.ProductModel pm ON p.ProductModelID = pm.ProductModelID INNER JOIN SalesLT.ProductCategory pc ON p.ProductCategoryID = pc.ProductCategoryID INNER JOIN SalesLT.ProductCategory pcParent ON pc.ParentProductCategoryID = pcParent.ProductCategoryID WHERE c.FirstName = 'David' AND soh.OrderDate > (GETDATE()-30)
  • 18. SELECT FirstName, MiddleName, LastName, SalesOrderID, OrderDate, UnitPrice, OrderQty, LineTotal, ProductName, Color, ProductNumber, ProductModel, ProductCategory, ProductParentCategory FROM CustomerSales WHERE FirstName = 'David' AND OrderDate > (GETDATE()-30)
  • 19. Repository (SolrNet) Client Web Server (Nancy) Solr Service Cmd MongoDB Event Handler Event Cmd MSMQ Command Handler Domain
  • 20. https://github.com/DavidHoerster/Conference https://github.com/mspnp/cqrs-journey-doc http://cqrs.wordpress.com/ http://groups.google.com/group/dddcqrs http://www.udidahan.com/2009/12/09/clarified-cqrs/ http://abdullin.com/cqrs http://distributedpodcast.com/
  • 21. Query Side Command Side Client Data Requested/Returned Repository Command Issued – ack/nack Command Service Domain (ARs) Event Handler Read Model Store Denormalizer Event Store