Cloud patterns

Data Consistency Primer:

https://msdn.microsoft.com/en-us/library/dn589800.aspx

CQRS (Command Query Responsibility Segregation) –

https://msdn.microsoft.com/en-us/magazine/mt736455.aspx

At its heart is the notion that you can use a different model to update information than the model you use to read information. For some situations, this separation can be valuable, but beware that for most systems CQRS adds risky complexity.

The mainstream approach people use for interacting with an information system is to treat it as a CRUD datastore. By this I mean that we have mental model of some record structure where we can create new records, read records, update existing records, and delete records when we’re done with them. In the simplest case, our interactions are all about storing and retrieving these records.

As our needs become more sophisticated we steadily move away from that model. We may want to look at the information in a different way to the record store, perhaps collapsing multiple records into one, or forming virtual records by combining information for different places. On the update side we may find validation rules that only allow certain combinations of data to be stored, or may even infer data to be stored that’s different from that we provide

The change that CQRS introduces is to split that conceptual model into separate models for update and display, which it refers to as Command and Query respectively following the vocabulary of CommandQuerySeparation. The rationale is that for many problems, particularly in more complicated domains, having the same conceptual model for commands and queries leads to a more complex model that does neither well.

 

 

From <http://martinfowler.com/bliki/CQRS.html>

Service Locator:

Context

You have classes with dependencies on services whose concrete types are specified at compile time. In the following example, ClassA has compile time dependencies on ServiceA and ServiceB. The following diagram illustrates this.

Classes with dependencies on services

Ff648968.ec21f438-394d-42e8-b51e-b7c5029e52eb(en-us,PandP.10).png

This situation has the following drawbacks:

  • To replace or update the dependencies, you must change your classes’ source code and recompile the solution.
  • The concrete implementation of the dependencies must be available at compile time.
  • Your classes are difficult to test in isolation because they have a direct reference to their dependencies. This means that these dependencies cannot be replaced with stubs or mock objects.
  • Your classes contain repetitive code for creating, locating, and managing their dependencies.

Solution

Create a service locator that contains references to the services and that encapsulates the logic that locates them. In your classes, use the service locator to obtain service instances. The following diagram illustrates how classes use a service locator.

How classes use a service locator

Ff648968.3622491a-3b9f-4368-aee4-493f7fb95027(en-us,PandP.10).png

The Service Locator pattern does not describe how to instantiate the services. It describes a way to register services and locate them. Typically, the Service Locator pattern is combined with the Factory pattern and/or the Dependency Injection pattern. This combination allows a service locator to create instances of services.

From <https://msdn.microsoft.com/en-us/library/ff648968.aspx>

This can be used interchangeably with DI containers.

Polyglot programming:

Idea is that applications should be written in a mix of languages to take advantage of the fact that different languages are suitable for tackling different problems. Complex applications combine different types of problems, so picking the right language for the job may be more productive than trying to fit all aspects into a single language

From <http://martinfowler.com/bliki/PolyglotPersistence.html>

Leave a comment