16
CQRS USING WINDOWS AZURE SERVICE BUS

CQRS con Windows Azure Service Bus y SignalR

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

Page 1: CQRS con Windows Azure Service Bus y SignalR

CQRSUSING WINDOWS AZURE SERVICE BUS

Page 2: CQRS con Windows Azure Service Bus y SignalR

¿Quiénes somos?

Luis Ruiz Pavón@luisruizpavon

Roberto González@robertogg

Page 3: CQRS con Windows Azure Service Bus y SignalR

3

CQRS

CQRS = “Command Query Responsibility Segregation”

A design – pattern -architecture – Framework – Principle – Something

Page 4: CQRS con Windows Azure Service Bus y SignalR

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.”

Page 5: CQRS con Windows Azure Service Bus y SignalR

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

Page 6: CQRS con Windows Azure Service Bus y SignalR
Page 7: CQRS con Windows Azure Service Bus y SignalR
Page 8: CQRS con Windows Azure Service Bus y SignalR

Queries 90%+ of access to our applications are READS from the datastore Very Fast Eventual Consistency Cache It

Page 9: CQRS con Windows Azure Service Bus y SignalR

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

Page 10: CQRS con Windows Azure Service Bus y SignalR

Demystifying Commandspublic class PlaceOrderCommand

{         

//properties

public readonly Guid OrderId;

public readonly string Comment;

//ctor

public PlaceOrderCommand(Guid id, string comment)

{

OrderId = id;

Comment = comment;

}

}

Page 11: CQRS con Windows Azure Service Bus y SignalR

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

Page 12: CQRS con Windows Azure Service Bus y SignalR

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

Page 13: CQRS con Windows Azure Service Bus y SignalR

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

Page 14: CQRS con Windows Azure Service Bus y SignalR

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

Page 15: CQRS con Windows Azure Service Bus y SignalR

Should I do CQRS?

… “Probably Not”

Page 16: CQRS con Windows Azure Service Bus y SignalR

Links Udi Dahan: http://www.udidahan.com

Greg Young: http://goodenoughsoftware.net/

CQRS Documents: http://cqrs.files.wordpress.com/2010/11/cqrs_documents.pdf