Upload
luis-ruiz-pavon
View
737
Download
1
Embed Size (px)
DESCRIPTION
En esta charla veremos las bases de una arquitectura CQRS así como su implementación utilizando Windows Azure Service Bus y SignalR. Mediante la creación de una pequeña aplicación veremos los pasos para implementar esta arquitectura, así como sus beneficios a la hora de desarrollar aplicaciones donde es necesaria una gran escalabilidad.
Citation preview
CQRSUSING WINDOWS AZURE SERVICE BUS
¿Quiénes somos?
Luis Ruiz Pavón@luisruizpavon
Roberto González@robertogg
3
CQRS
CQRS = “Command Query Responsibility Segregation”
A design – pattern -architecture – Framework – Principle – Something
4
CQS Defined
Bertrand Meyer (via Wikipedia) “Command Query Separation”
◦ “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.”
Benefits of CQRS
Isolated changes to the application User Interface can change with zero impact to storage Storage can be changed with zero impact to UI
Availability is very high, as all reads are unblocked
Queries 90%+ of access to our applications are READS from the datastore Very Fast Eventual Consistency Cache It
Commands Commands are directives to the domain to perform some action Commands may be declined/rejected by the domain for various reasons Processing a Command will result in 0:n Events raised Commands are always in the imperative:
PlaceOrder, not OrderPlaced
Handler per command Command can be queued
Split into separate queues
Demystifying Commandspublic class PlaceOrderCommand
{
//properties
public readonly Guid OrderId;
public readonly string Comment;
//ctor
public PlaceOrderCommand(Guid id, string comment)
{
OrderId = id;
Comment = comment;
}
}
Events Events are the result of some action having already happened in the Domain Events may never be declined/rejected; they are evidence that something already happened Events are always in the past-tense:
OrderPlaced, not PlaceOrder
Eventual Consistency Property of a system such that not all records of state guaranteed to agree at any given point in time.
Applicable to whole systems or parts of systems (such as a database)
As opposed to Strongly Consistent (or Instantly Consistent) Eventual Consistency is natural characteristic of a useful, scalable distributed systems
Why Eventual Consistency? CAP TheoremConsistency: all nodes see the same data at the same timeAvailability: a guarantee that every request receives a response about whether it was successful or failed)Partition tolerance: the system continues to operate despite arbitrary message loss
From: http://en.wikipedia.org/wiki/CAP_theorem
CQRS in Windows AzureWE NEED:
Compute resource to run our codeWeb Roles (IIS) and Worker Roles (w/o IIS)
Reliable Queue to communicateWindows Azure Service Bus Queues
Durable/Persistent StorageSQL Azure
Fast ViewAzure Cache + NoSQL
Should I do CQRS?
… “Probably Not”
Links Udi Dahan: http://www.udidahan.com
Greg Young: http://goodenoughsoftware.net/
CQRS Documents: http://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf