40
Aesthetics & the Beauty of an Architecture Tom Scott @tomwscott Adventures in CQRS & Event Sourcing

Aesthetics and the Beauty of an Architecture

Embed Size (px)

DESCRIPTION

CQRS & Event Sourcing are patterns gaining traction and popularity. In this presentation given at Øredev 2013 it talks about real-world experiences using these patterns, the good, the bad and the ugly.

Citation preview

Page 1: Aesthetics and the Beauty of an Architecture

Aesthetics & the Beauty of an Architecture

Tom Scott @tomwscott

Adventures in CQRS & Event Sourcing

Page 2: Aesthetics and the Beauty of an Architecture

What’s in it for you?

• Understanding of CQRS & Event Sourcing in the wild

• The mistakes we made…

• … the lessons we learnt …

• … and why we’re still happy!

rob.knight

Page 3: Aesthetics and the Beauty of an Architecture

art 1 |ɑːt| noun 1 [ mass noun ] the expression or application of human creative skill and imagination, typically in a visual form such as painting or sculpture, producing works to be appreciated primarily for their beauty or emotional power

Page 4: Aesthetics and the Beauty of an Architecture

art 1 |ɑːt| noun 1 [ mass noun ] the expression or application of human creative skill and imagination, typically in a visual form such as painting or sculpture, producing works to be appreciated primarily for their beauty or emotional power

Page 5: Aesthetics and the Beauty of an Architecture

Aesthetics

Page 6: Aesthetics and the Beauty of an Architecture

Scott’s Purely Arbitrary Criteria, Etceteras

For Evaluating Beautiful Architectures

Etceteras

Aesthetics

#SPACE_FEBA

Page 7: Aesthetics and the Beauty of an Architecture

Fully Operational

Page 8: Aesthetics and the Beauty of an Architecture

Simplicityecherries

Page 9: Aesthetics and the Beauty of an Architecture

Commitmentjustageek

Page 10: Aesthetics and the Beauty of an Architecture

Deferring Commitmentjustageek

Page 11: Aesthetics and the Beauty of an Architecture

MetaphorPetar Pavlov - http://bit.ly/9ySEUt

Page 12: Aesthetics and the Beauty of an Architecture

Discipline & Consistency

Page 13: Aesthetics and the Beauty of an Architecture

Serendipity

kathryn_rotondo

Page 14: Aesthetics and the Beauty of an Architecture

• Fully Operational

• Simplicity

• Deferred Commitment

• Metaphor

• Discipline

• Serendipity

#SPACE_FEBA

Page 15: Aesthetics and the Beauty of an Architecture

Price Comparison

!"

####

$

$

% $

$

&

££

Page 16: Aesthetics and the Beauty of an Architecture

The evolution of a system

'

%

|

Presentation

Application

Database

)*+

Page 17: Aesthetics and the Beauty of an Architecture

The Solution

archer10

Page 18: Aesthetics and the Beauty of an Architecture

Architectural Goals

• Structured

• Horizontal Scalability

• Availability & Reliability

• Visibility / Monitorability

• Flexibility & Replaceability

archer10

Page 19: Aesthetics and the Beauty of an Architecture

The Mandate!

• Service Oriented Architecture

• Domain Driven Design

• Micro-Services

• Continuous Delivery

• Oh and one more thing!

archer10

Page 20: Aesthetics and the Beauty of an Architecture

Domain Driven Design

• Entity

• Value Object

• Aggregate

• Service

• Repository

• Factory

• Bounded Context

archer10

Page 21: Aesthetics and the Beauty of an Architecture

Domain Driven Design

archer10

• Entity

• Value Object

• Aggregate

• Service

• Repository

• Factory

• Bounded Context

Page 22: Aesthetics and the Beauty of an Architecture

%

'

Service Oriented Architecture

% % ''

Page 23: Aesthetics and the Beauty of an Architecture

% '

Understand your Domain

!

####Home

JourneyPanel Quote

Engine

% % ''

"

Risk Enquiry Provider Quote

Page 24: Aesthetics and the Beauty of an Architecture

The End??

Page 25: Aesthetics and the Beauty of an Architecture

Just one more thing…http://m.cdn.blog.hu/ke/kedvessigmund/image/columbo.jpg

Page 26: Aesthetics and the Beauty of an Architecture

CQRS & Event Sourcing

• CQRS or “Why do we use the same schema for reads and writes?”

• Event Sourcing or “Why do we allow ORMs to dictate our object model?”

archer10

Page 27: Aesthetics and the Beauty of an Architecture

CQRS

Page 28: Aesthetics and the Beauty of an Architecture

Command Query Responsibility Segregation

,

, ,

, ,write

}read

}

Page 29: Aesthetics and the Beauty of an Architecture

UPDATE  Address    SET    number  =  10,            street  =  ‘Downing  Street’,            city  =  ‘London’,            postcode  =  ‘SW1A  2AA’  WHERE  _id  =  ‘590b9902’

{          “_id”  :  “590b9902”,          “event”  :  “PolicySpecified”,          “data”  :  {             “type”  :  “ContentsInsurance”,       “excess”  :  750      }  }

{          “_id”  :  “590b9902”,          “event”  :  “AddressModified”,          “data”  :  {             “number”  :  10,       “street”  :  “Downing  Street”,              “city”  :  “London”,       “postcode”  :  “SW1A  2AA”      }  }

Use SQL?

-

,./

%

/

/ / / / /

Page 30: Aesthetics and the Beauty of an Architecture

     public  class  Customer  :  AggregateRoot        {                  private  readonly  Guid  id;  !                private  Address  currentAddress;                                  //  Business  Logic                  public  void  ChangeAddress(Address  newAddress)                  {                if  (newAddress.IsValid())             {                                 Raise(new  AddressModified(id,  newAddress));                                 }                  }                !                //  State  Transition                  public  void  Apply(AddressModified  @event)                    {                          currentAddress  =  @event.Address;                  }  !!       ......  !!                //  Business  Logic                  public  void  SpecifyCommunicationPreferences(CommunicationPrefs  preferences)                  {                          Raise(new  CommunicationPreferencesSpecified(id,  preferences));                                  

Event Sourcing (C#)

Page 31: Aesthetics and the Beauty of an Architecture

Eventual Consistency

% '

!

-

,.

/ / / / /

POST /risk/new GET /risk/590b9902:v1

/

HTTP/1.1 302 !Location: /risk/590b9902:v1

0

Page 32: Aesthetics and the Beauty of an Architecture

What we ended up with:% '-

% '-

% '-

% '-

% '-

# # # # # # # # # #

)* +

1

2 % '-

2% '-

2

Page 33: Aesthetics and the Beauty of an Architecture

The Conclusion

tim_norris

Page 34: Aesthetics and the Beauty of an Architecture

Fully Operational

Simple

Commitment

Metaphor

Discipline

Serendipity

3 +?

3?3

Page 35: Aesthetics and the Beauty of an Architecture

The Power!

     public  class  Customer  :  AggregateRoot        {                  private  readonly  Guid  id;  !                private  Address  currentAddress;  !                public  void  ChangeAddress(Address  newAddress)                  {                                              Raise(new  AddressModified(id,  newAddress));                                        }  !                public  void  Apply(AddressModified  @event)                  {                          currentAddress  =  @event.Address;                  }          }

Page 36: Aesthetics and the Beauty of an Architecture

The Power!      public  class  Customer  :  AggregateRoot        {                  private  readonly  Guid  id;  !                private  Address  currentAddress;  !                public  void  ChangeAddress(Address  newAddress)                  {                          if  (currentAddress.IsSignificantlyDifferentFrom(newAddress))                          {                                  Raise(new  CustomerMoved(id,  newAddress));                          }                          else                          {                                  Raise(new  AddressModified(id,  newAddress));                          }                  }  !                public  void  Apply(CustomerMoved  @event)                  {                          currentAddress  =  @event.Address;                  }  !                public  void  Apply(AddressModified  @event)                  {                          currentAddress  =  @event.Address;                  }          }

Page 37: Aesthetics and the Beauty of an Architecture

The Flexibility!

var  connection  =  rabbit.createConnection({  url:  ‘amqp://localhost:5672'  })  !connection.on('ready',  function  ()  {          console.info('Connected');          exchange  =  connection.exchange('SOURCE:Exchange',  {  'type':  'topic',  durable:  true  },  function  ()  {                  var  queue  =  connection.queue('PROJECTION:Map',  {  durable:  false,  exclusive:  true  },                  function  ()  {                          console.info("Joined  Queue");                          queue.subscribe(function  (message,  headers,  deliveryInfo)  {                                  var  policyDetails  =  JSON.parse(message.data.toString());                                  io.sockets.emit('postcode',  policyDetails.Address.Postcode);                          });                          queue.bind(exchange.name,  'AddressDetailsSpecified');                  });                  queue.on('queueBindOk',  function  ()  {  console.info('Bound  queue  to  exchange');  });          });  !});

Page 38: Aesthetics and the Beauty of an Architecture

Is it a silver bullet?

Page 39: Aesthetics and the Beauty of an Architecture

rob.knight

Lessons Learnt

• Prefer simpler communication protocols

• Messaging == Push == Transient,

• HTTP == Pull == Permanent

• Difficult to evolve Domain Events

• Events as the system contract

Page 40: Aesthetics and the Beauty of an Architecture

Thank You!!

Tom Scott @tomwscott