103
Clean Architecture Patterns, Practices, and Principles @matthewrenze #sddconf

Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Clean ArchitecturePatterns, Practices, and Principles

@matthewrenze

#sddconf

Page 2: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized
Page 3: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized
Page 4: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized
Page 5: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized
Page 6: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized
Page 7: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized
Page 8: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

About Me

Independent consultant

EducationB.S. in Computer Science (ISU)

B.A. in Philosophy (ISU)

CommunityPublic Speaker

Pluralsight Author

Microsoft MVP

ASPInsider

Open-Source Software

Page 9: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Overview

1. Clean Architecture

2. Domain-Centric Architecture

3. Application Layer

4. Commands and Queries

5. Functional Organization

6. Microservices

Page 10: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Focus

Enterprise Architecture

Line-of-Business Applications

Modern equivalent of 3-Layer

Page 11: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Focus

Generally applicable

6 Key Points

Q & A

Page 12: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What is Software Architecture?

High-level

Structure

Layers

Components

Relationships

Source: http://msdn.microsoft.com/

en-us/library/ff650706.aspx

Page 13: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Levels of Architectural Abstraction

System

Sub-systems

Layers

Components

Classes

Data and Methods

Page 14: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Levels of Architectural Abstraction

System

Sub-systems

Layers

Components

Classes

Data and Methods

Page 15: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Messy vs Clean Architecture

Page 16: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Messy vs Clean Architecture

Page 17: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Messy vs Clean Architecture

Page 18: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What Is Bad Architecture?

Complex

Inconsistent

Incoherent

Rigid

Brittle

Untestable

Unmaintainable

Page 19: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What Is Clean Architecture?

Simple

Understandable

Flexible

Emergent

Testable

Maintainable

Page 20: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What Is Clean Architecture?

Architecture that is designed for the inhabitants of the architecture… not for the architect… or the machine

Page 21: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What Is Clean Architecture?

Architecture that is designed for the inhabitants of the architecture… not for the architect… or the machine

Page 22: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What Is Clean Architecture?

Architecture that is designed for the inhabitants of the architecture… not for the architect… or the machine

Page 23: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What Is Clean Architecture?

Architecture that is designed for the inhabitants of the architecture… not for the architect… or the machine

Page 24: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What Is Clean Architecture?

Architecture that is designed for the inhabitants of the architecture… not for the architect… or the machine

Page 25: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Is Clean Architecture Important?

Cost/benefit

Minimize cost to maintain

Maximize business value

Page 26: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Decisions, Decisions, Decisions…

Context is king

All decisions are a tradeoff

Use your best judgement

Page 27: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Domain-Centric Architecture

Page 28: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Earth

Moon

Mercury

Venus

SunMars

SaturnJupiter

Page 29: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Earth

Mercury

Venus Sun

SaturnJupiter

Mars

Page 30: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Geocentric Model Heliocentric Model

Earth

Moon

Mercury

Venus

SunMars

SaturnJupiter

Earth

Mercury

Venus Sun

SaturnJupiter

Mars

Page 31: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Classic 3-layer Database-centric Architecture

DatabaseDatabase

Data Access

Business Logic

UI

Page 32: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Database- vs. Domain-centric Architecture

DatabaseDatabase

Data Access

Business Logic

UI

DatabaseDomain

Application

Presentation

Database

Page 33: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

“The first concern of the architect is to make sure that the house is

usable, it is not to ensure that the house is made of brick.”

– Uncle Bob

Page 34: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Essential vs. Detail

Space is essential

Usability is essential

Page 35: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Essential vs. Detail

Space is essential

Usability is essential

Building material is a detail

Ornamentation is a detail

Page 36: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Essential vs. Detail

Domain is essential

Use cases are essential

Page 37: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Essential vs. Detail

Domain is essential

Use cases are essential

Presentation is a detail

Persistence is a detail

Page 38: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Database- vs. Domain-centric Architecture

DatabaseDatabase

Data Access

Business Logic

UI

DatabaseDomain

Application

Presentation

Database

Page 39: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Hexagonal Architecture

Original source: http://alistair.cockburn.us/Hexagonal+architecture

Application

http

feed

GUI

http

adapter

app-to-app

adapter

test

adapter

mock

database

database

adapter

mock

telephone

email

adapter

answering

machine

adapter

app

DB

Page 40: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Onion Architecture

Database

Application Services

User Interface

Domain

Model

Domain Services

Application Core

DB

web

service

file

Original source: http://jeffreypalermo.com/blog/the-onion-architecture-part-2/

Page 41: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Database

Controllers

Entities

Use Cases

Original source: http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html

External

Interfaces

PresenterUse case

output port

Use case

interactor

Use case

input portController

Flow

of

Control

I

I

Clean Architecture

Page 42: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

It’s All the Same Thing

Hexagonal Onion Clean

Original Source: http://blog.ploeh.dk/2013/12/03/layers-onions-ports-adapters-its-all-the-same/

Page 43: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use Domain-Centric Architecture?

ProsFocus on essential

Less coupling to details

Necessary for DDD

Page 44: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use Domain-Centric Architecture?

ProsFocus on essential

Less coupling to details

Necessary for DDD

ConsChange is difficult

Requires extra thought

Initial higher cost

Page 45: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Application Layer

Page 46: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

What Are Layers?

Levels of abstraction

Single-Responsibility Principle

Developer roles / skills

Multiple implementations

Varying rates of change

Page 47: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Classic 3-Layer Architecture

UI

Business Logic

Data Access

Database

Users

Dependency

Page 48: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Modern 4-Layer Architecture

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

once

rns

Dependency

Page 49: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Application Layer

Implements use cases

High-level application logic

Knows about domain

No knowledge of other layers

Contains interfaces for details

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

once

rns

Dependency

Page 50: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Layer Dependencies

Dependency inversion

Inversion of control

Independent deployability

Flexibility and maintainability

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

once

rns

Flow of Control Dependency

Page 51: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Users

OSDatabase

Composition

ImplementsDatabaseContext

IDatabaseContext

Sale

ICreateSaleCommand

CreateSaleCommand

SalesController

IInventoryClient

InventoryClient

Cro

ss-Cuttin

gC

once

rns

IDate

Service

Date

Service

Presentation

Application

Persistence

Domain

Infrastructure

Page 52: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use an Application Layer?

ProsFocus is on use cases

Easy to understand

Follows DIP

Page 53: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use an Application Layer?

ProsFocus is on use cases

Easy to understand

Follows DIP

ConsAdditional cost

Requires extra thought

IoC is counter-intuitive

Page 54: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Commands and Queries

Page 55: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Command-Query Separation

CommandDoes something

Should modify state

Should not return a value

Page 56: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Command-Query Separation

CommandDoes something

Should modify state

Should not return a value

QueryAnswers a question

Should not modify state

Always returns a value

Page 57: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Command-Query Separation

CommandDoes something

Should modify state

Should not return a value (ideally)

QueryAnswers a question

Should not modify state

Always returns a value

Avoid mixing the two!

Page 58: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

CQRS Architectures

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 59: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

CQRS Type 1 – Single Database

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 60: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

CQRS Type 2 – Read/Write Databases

Presentation

Domain

Persistence

Users

Queries

Write

Database

Commands

Data Access

Read

Database

Data Flow

Page 61: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

CQRS Type 3 – Event Sourcing

Presentation

Domain

Persistence

Users

Queries

Event

Store

Commands

Data Access

Read

Database

Data Flow

Page 62: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

CQRS Type 3 – Event Sourcing

Complete audit trail

Point-in-time reconstruction

Replay events

Rebuild production database

Presentation

Domain

Persistence

Users

Queries

Event

Store

Commands

Data Access

Read

Database

Page 63: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use CQRS?

ProsMore efficient design

Simpler within each stack

Optimized performance

Page 64: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use CQRS?

ProsMore efficient design

Simpler within each stack

Optimized performance

ConsInconsistent across stacks

Type 2 is more complex

Type 3 might be overkill

Page 65: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Functional Organization

Page 66: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

“The architecture should screamthe intent of the system!”

– Uncle Bob

Page 67: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Bed

roo

mBed

roo

m

Din

ing

Ro

om

Livi

ng

Ro

om

Kitch

en

Entr

y

Utilit

yBath

Page 68: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Material Quantity Cost

Appliances 5 $5,000

Cabinets 10 $2,500

Doors 15 $750

Fixtures 12 $2,400

Floors 9 $4,000

Walls 20 $10,000

Windows 8 $2,500

Page 69: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

ControllersViews

Models

Page 70: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

ControllersViews

Models

vs

VendorsProducts

Customers

Page 71: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Content

Controllers

Models

Scripts

Views

Page 72: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

vs

Content

Controllers

Models

Scripts

Views

Customers

Employees

Products

Sales

Vendors

Page 73: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

So what?

Page 74: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized
Page 75: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

vs

Page 76: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use Functional Organization

ProsSpatial locality

Easy to navigate

Avoid vendor lock-in

Page 77: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use Functional Organization

ProsSpatial locality

Easy to navigate

Avoid vendor lock-in

ConsLose framework conventions

Lose automatic scaffolding

Categorical is easier at first

Page 78: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Microservices

Page 79: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Components

UI

Business

Data Access

Database

Users

Sales Support Inventory

Sales Support Inventory

Sales Support Inventory

Page 80: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Problem Domain

SalesSales Opportunity

Contact

Sales Person

Product

Sales Territory

SupportSupport Ticket

Customer

Support Person

Product

Resolution

Page 81: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Single Domain Model

Sales

Opportunity

Support

TicketProduct

Employee

Customer

Sales

TerritoryResolution

Page 82: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

SupportSales

Overlapping Contexts

Sales

Opportunity

Support

TicketProduct

Employee

Customer

Sales

TerritoryResolution

Page 83: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

SupportSales

Bounded Contexts

Sales

Opportunity

Support

TicketProduct

Contact

Sales

TerritoryResolution

Customer

Product

Support

PersonSales Person

Page 84: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Microservice Architectures

Subdivide system

Bounded contexts

Small teams

Sales

Support

Inventory

Marketing HR

Page 85: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Microservice Architectures

Independent

Similar to SOA

Sales

Support

Inventory

Marketing HR

Page 86: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use Microservices?

ProsLess cost for large domains

Smaller teams

Independence

Page 87: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Why Use Microservices?

ProsLess cost for large domains

Smaller teams

Independence

ConsOnly for large domains

Higher up-front cost

Distributed system costs

Page 88: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Code Demo

Page 89: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Where to Go Next?

Martin Fowler

Page 90: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Where to Go Next?

http://cleancoders.com/ Robert C. Martin

Page 91: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Where to Go Next?

Eric Evans

Page 92: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Where to Go Next?

Greg Young Udi Dahan

Page 93: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Where to Go Next?

Articles

Courses

Presentations

Source Code

Videos

www.matthewrenze.com

Page 94: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

www.pluralsight.com/authors/matthew-renze

Page 95: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Conclusion

Page 96: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Summary

Focus on the inhabitants

Page 97: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Summary

Focus on the inhabitants

Domain-centric Architecture

DatabaseDomain

Application

Presentation

Page 98: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Summary

Focus on the inhabitants

Domain-centric Architecture

Application Layer

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

once

rns

Page 99: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Summary

Focus on the inhabitants

Domain-centric Architecture

Application Layer

Commands and Queries

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Page 100: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Summary

Focus on the inhabitants

Domain-centric Architecture

Application Layer

Commands and Queries

Functional CohesionVendorsProducts

Customers

Page 101: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Summary

Focus on the inhabitants

Domain-centric Architecture

Application Layer

Commands and Queries

Functional Cohesion

Bounded Contexts

Sales

Support

Inventory

Marketing HR

Page 102: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Feedback

Feedback is very important to me!

One thing you liked?

One thing I could improve?

Page 103: Clean Architecture - SDD Conferencesddconf.com/brands/sdd/library/20170518_-_Clean... · 2017. 5. 5. · Why Use CQRS? Pros More efficient design Simpler within each stack Optimized

Contact Info

Matthew Renze

Data Science Consultant

Renze Consulting

Twitter: @matthewrenze

Email: [email protected]

Website: www.matthewrenze.com

Thank You! : )