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.
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.”
4
5. 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
6.
7.
8. Queries
90%+ of access to our applications are READS from the datastore
Very Fast
Eventual Consistency
Cache It
9. 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
10. Demystifying Commands
public class PlaceOrderCommand
{
//properties
public readonly Guid OrderId;
public readonly string Comment;
//ctor
public PlaceOrderCommand(Guid id, string comment)
{
OrderId = id;
Comment = comment;
}
}
11. 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
12. 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
13. Why Eventual Consistency?
CAP Theorem
Consistency: all nodes see the same data at
the same time
Availability: 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
14. CQRS in Windows Azure
WE NEED:
Compute resource to run our code
Web Roles (IIS) and Worker Roles (w/o IIS)
Reliable Queue to communicate
Windows Azure Service Bus Queues
Durable/Persistent Storage
SQL Azure
Fast View
Azure Cache + NoSQL