Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun...

183
Clean Architecture Patterns, Practices, and Principles @MatthewRenze #CodeMash

Transcript of Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun...

Page 1: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Clean ArchitecturePatterns, Practices, and Principles

@MatthewRenze

#CodeMash

Page 2: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern
Page 3: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern
Page 4: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern
Page 5: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern
Page 6: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern
Page 7: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern
Page 8: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Overview

1. Clean Architecture

Page 9: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Overview

1. Clean Architecture

2. Domain-Centric Architecture

Page 10: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Overview

1. Clean Architecture

2. Domain-Centric Architecture

3. Application Layer

Page 11: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Overview

1. Clean Architecture

2. Domain-Centric Architecture

3. Application Layer

4. Commands and Queries

Page 12: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Overview

1. Clean Architecture

2. Domain-Centric Architecture

3. Application Layer

4. Commands and Queries

5. Functional Organization

Page 13: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Overview

1. Clean Architecture

2. Domain-Centric Architecture

3. Application Layer

4. Commands and Queries

5. Functional Organization

6. Microservices

Page 14: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Focus

Enterprise Architecture

Page 15: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Focus

Enterprise Architecture

Modern equivalent of 3-Layer

Page 16: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Focus

Enterprise Architecture

Modern equivalent of 3-Layer

Generally applicable

Page 17: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Focus

Enterprise Architecture

Modern equivalent of 3-Layer

Generally applicable

6 Key Points

Page 18: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Focus

Enterprise Architecture

Modern equivalent of 3-Layer

Generally applicable

6 Key Points

Q & A

Page 19: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What is Software Architecture?

Source: http://msdn.microsoft.com/en-us/library/ff650706.aspx

Page 20: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What is Software Architecture?

High-level

Source: http://msdn.microsoft.com/en-us/library/ff650706.aspx

Page 21: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What is Software Architecture?

High-level

Structure

Source: http://msdn.microsoft.com/en-us/library/ff650706.aspx

Page 22: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What is Software Architecture?

High-level

Structure

Layers

Source: http://msdn.microsoft.com/en-us/library/ff650706.aspx

Page 23: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What is Software Architecture?

High-level

Structure

Layers

Components

Source: http://msdn.microsoft.com/en-us/library/ff650706.aspx

Page 24: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What is Software Architecture?

High-level

Structure

Layers

Components

Relationships

Source: http://msdn.microsoft.com/en-us/library/ff650706.aspx

Page 25: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Levels of Architectural Abstraction

System

Sub-systems

Layers

Components

Classes

Data and Methods

Page 26: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Levels of Architectural Abstraction

System

Sub-systems

Layers

Components

Classes

Data and Methods

Page 27: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Messy vs Clean Architecture

Page 28: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Messy vs Clean Architecture

Page 29: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Messy vs Clean Architecture

Page 30: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What Is Bad Architecture?

Complex

Inconsistent

Incoherent

Rigid

Brittle

Untestable

Unmaintainable

Page 31: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What Is Clean Architecture?

Simple

Understandable

Flexible

Emergent

Testable

Maintainable

Page 32: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What Is Clean Architecture?

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

Page 33: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What Is Clean Architecture?

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

Page 34: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What Is Clean Architecture?

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

Page 35: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What Is Clean Architecture?

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

Page 36: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What Is Clean Architecture?

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

Page 37: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Is Clean Architecture Important?

Cost/benefit

Page 38: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Is Clean Architecture Important?

Cost/benefit

Minimize cost to maintain

Page 39: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Is Clean Architecture Important?

Cost/benefit

Minimize cost to maintain

Maximize business value

Page 40: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Is Clean Architecture Important?

Cost/benefit

Minimize cost to maintain

Maximize business value

Maximize total ROI

Page 41: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Decisions, Decisions, Decisions…

Context is king

Page 42: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Decisions, Decisions, Decisions…

Context is king

All decisions are a tradeoff

Page 43: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Decisions, Decisions, Decisions…

Context is king

All decisions are a tradeoff

Use your best judgement

Page 44: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Domain-Centric Architecture

Page 45: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Earth

Moon

Mercury

Venus

SunMars

SaturnJupiter

Page 46: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Earth

Mercury

Venus Sun

SaturnJupiter

Mars

Page 47: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Geocentric Model Heliocentric Model

Earth

Moon

Mercury

Venus

SunMars

SaturnJupiter

Earth

Mercury

Venus Sun

SaturnJupiter

Mars

Page 48: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Classic 3-layer Database-centric Architecture

DatabaseDatabase

Data Access

Business Logic

UI

Page 49: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Database- vs. Domain-centric Architecture

DatabaseDatabase

Data Access

Business Logic

UI

DatabaseDomain

Application

Presentation

Database

Page 50: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

“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 51: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Page 52: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Space is essential

Page 53: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Space is essential

Usability is essential

Page 54: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Building material is a detail

Page 55: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Building material is a detail

Ornamentation is a detail

Page 56: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Page 57: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Domain is essential

Page 58: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Domain is essential

Use cases are essential

Page 59: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Presentation is a detail

Page 60: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Essential vs. Detail

Presentation is a detail

Persistence is a detail

Page 61: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Database- vs. Domain-centric Architecture

DatabaseDatabase

Data Access

Business Logic

UI

DatabaseDomain

Application

Presentation

Database

Page 62: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Database- vs. Domain-centric Architecture

DatabaseDatabase

Data Access

Business Logic

UI

Page 63: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Database- vs. Domain-centric Architecture

DatabaseDomain

Application

Presentation

Database

Page 64: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Hexagonal Architecture

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

Application

httpfeed

GUI

httpadapter

app-to-appadapter

testadapter

mockdatabase

databaseadapter

mocktelephone

emailadapter

answeringmachineadapter

app

DB

Page 65: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Onion Architecture

Database

Application Services

User Interface

Domain Model

Domain Services

Application Core

DB

webservice

file

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

Page 66: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 caseinteractor

Use caseinput port

Controller

Flowof

Control

I

I

Clean Architecture

Page 67: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 68: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Domain-Centric Architecture?

ProsFocus on essential

Page 69: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Domain-Centric Architecture?

ProsFocus on essential

Less coupling to details

Page 70: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Domain-Centric Architecture?

ProsFocus on essential

Less coupling to details

Necessary for DDD

Page 71: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Domain-Centric Architecture?

ProsFocus on essential

Less coupling to details

Necessary for DDD

ConsChange is difficult

Page 72: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Domain-Centric Architecture?

ProsFocus on essential

Less coupling to details

Necessary for DDD

ConsChange is difficult

Requires extra thought

Page 73: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 74: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Application Layer

Page 75: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

What Are Layers?

Levels of abstraction

Single-Responsibility Principle

Developer roles / skills

Multiple implementations

Varying rates of change

Page 76: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Classic 3-Layer Architecture

UI

Business Logic

Data Access

Database

Users

Dependency

Page 77: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Modern 4-Layer Architecture

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Dependency

Page 78: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Application Layer

Implements use cases Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Dependency

Page 79: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Application Layer

Implements use cases

High-level application logic

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Dependency

Page 80: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Application Layer

Implements use cases

High-level application logic

Knows about domain

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Dependency

Page 81: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Application Layer

Implements use cases

High-level application logic

Knows about domain

No knowledge of other layers

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Dependency

Page 82: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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

oncern

s

Dependency

Page 83: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Layer Dependencies

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Flow of Control Dependency

Page 84: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Layer Dependencies

Dependency inversionPresentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Flow of Control Dependency

Page 85: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Layer Dependencies

Dependency inversion

Inversion of control

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Flow of Control Dependency

Page 86: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Layer Dependencies

Dependency inversion

Inversion of control

Independent deployability

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Flow of Control Dependency

Page 87: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Layer Dependencies

Dependency inversion

Inversion of control

Independent deployability

Flexibility and maintainability

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Flow of Control Dependency

Page 88: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Users

OSDatabase

Composition

ImplementsDatabaseContext

IDatabaseContext

Sale

ICreateSaleCommand

CreateSaleCommand

SalesController

IInventoryClient

InventoryClient

Cro

ss-Cuttin

gC

oncern

s

IDateService

DateService

Presentation

Application

Persistence

Domain

Infrastructure

Page 89: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use an Application Layer?

ProsFocus is on use cases

Page 90: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use an Application Layer?

ProsFocus is on use cases

Easy to understand

Page 91: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use an Application Layer?

ProsFocus is on use cases

Easy to understand

Follows DIP

Page 92: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use an Application Layer?

ProsFocus is on use cases

Easy to understand

Follows DIP

ConsAdditional cost

Page 93: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use an Application Layer?

ProsFocus is on use cases

Easy to understand

Follows DIP

ConsAdditional cost

Requires extra thought

Page 94: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 95: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Commands and Queries

Page 96: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Command-Query Separation

CommandDoes something

Should modify state

Should not return a value

Page 97: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 98: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 99: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Architectures

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 100: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Architectures

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 101: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Architectures

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 102: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Architectures

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 103: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 1 – Single Database

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 104: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 1 – Single Database

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 105: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 1 – Single Database

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Data Flow

Page 106: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 2 – Read/Write Databases

Presentation

Domain

Persistence

Users

Queries

WriteDatabase

Commands

Data Access

ReadDatabase

Data Flow

Page 107: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 2 – Read/Write Databases

Presentation

Domain

Persistence

Users

Queries

WriteDatabase

Commands

Data Access

ReadDatabase

Data Flow

Page 108: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 2 – Read/Write Databases

Presentation

Domain

Persistence

Users

Queries

WriteDatabase

Commands

Data Access

ReadDatabase

Data Flow

Page 109: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 2 – Read/Write Databases

Presentation

Domain

Persistence

Users

Queries

WriteDatabase

Commands

Data Access

ReadDatabase

Data Flow

Page 110: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 2 – Read/Write Databases

Presentation

Domain

Persistence

Users

Queries

WriteDatabase

Commands

Data Access

ReadDatabase

Data Flow

Page 111: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 3 – Event Sourcing

Presentation

Domain

Persistence

Users

Queries

Event Store

Commands

Data Access

ReadDatabase

Data Flow

Page 112: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 3 – Event Sourcing

Presentation

Domain

Persistence

Users

Queries

Event Store

Commands

Data Access

ReadDatabase

Data Flow

Sale Created

Item 1 Added

Item 2 Added

Payment Made

Sale Completed

Events

Page 113: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 3 – Event Sourcing

Presentation

Domain

Persistence

Users

Queries

Event Store

Commands

Data Access

ReadDatabase

Data Flow

Sale Created

Item 1 Added

Item 2 Added

Payment Made

Sale Completed

Events

Page 114: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 3 – Event Sourcing

Presentation

Domain

Persistence

Users

Queries

Event Store

Commands

Data Access

ReadDatabase

Data Flow

Page 115: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 3 – Event Sourcing

Presentation

Domain

Persistence

Users

Queries

Event Store

Commands

Data Access

ReadDatabase

Page 116: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 3 – Event Sourcing

Complete audit trail

Presentation

Domain

Persistence

Users

Queries

Event Store

Commands

Data Access

ReadDatabase

Page 117: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 3 – Event Sourcing

Complete audit trail

Point-in-time reconstruction

Presentation

Domain

Persistence

Users

Queries

Event Store

Commands

Data Access

ReadDatabase

Page 118: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

CQRS Type 3 – Event Sourcing

Complete audit trail

Point-in-time reconstruction

Replay events

Presentation

Domain

Persistence

Users

Queries

Event Store

Commands

Data Access

ReadDatabase

Page 119: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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

ReadDatabase

Page 120: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use CQRS?

ProsMore efficient design

Page 121: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use CQRS?

ProsMore efficient design

Simpler within each stack

Page 122: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use CQRS?

ProsMore efficient design

Simpler within each stack

Optimized performance

Page 123: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use CQRS?

ProsMore efficient design

Simpler within each stack

Optimized performance

ConsInconsistent across stacks

Page 124: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use CQRS?

ProsMore efficient design

Simpler within each stack

Optimized performance

ConsInconsistent across stacks

Type 2 is more complex

Page 125: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 126: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Functional Organization

Page 127: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

“The architecture should screamthe intent of the system!”

– Uncle Bob

Page 128: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Bed

roo

mBed

roo

m

Din

ing

Ro

om

Livi

ng

Ro

om

Kitc

hen

Entr

y

Util

ityBat

h

Page 129: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Bed

roo

mBed

roo

m

Din

ing

Ro

om

Livi

ng

Ro

om

Kitc

hen

Entr

y

Util

ityBat

h

Page 130: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 131: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

ControllersViews

Models

Page 132: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

ControllersViews

Models

vs

VendorsProducts

Customers

Page 133: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Content

Controllers

Models

Scripts

Views

Page 134: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

vs

Content

Controllers

Models

Scripts

Views

Customers

Employees

Products

Sales

Vendors

Page 135: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

So what?

Page 136: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern
Page 137: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

vs

Page 138: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Functional Organization

ProsSpatial locality

Page 139: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Functional Organization

ProsSpatial locality

Easy to navigate

Page 140: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Functional Organization

ProsSpatial locality

Easy to navigate

Avoid vendor lock-in

Page 141: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Functional Organization

ProsSpatial locality

Easy to navigate

Avoid vendor lock-in

ConsLose framework conventions

Page 142: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Functional Organization

ProsSpatial locality

Easy to navigate

Avoid vendor lock-in

ConsLose framework conventions

Lose automatic scaffolding

Page 143: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

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 144: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Microservices

Page 145: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Components

UI

Business

Data Access

Database

Users

Sales Support Inventory

Sales Support Inventory

Sales Support Inventory

Page 146: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Components

UI

Business

Data Access

Database

Users

Sales Support Inventory

Sales Support Inventory

Sales Support Inventory

Page 147: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Problem Domain

SalesSales Opportunity

Contact

Sales Person

Product

Sales Territory

SupportSupport Ticket

Customer

Support Person

Product

Resolution

Page 148: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Single Domain Model

Sales Opportunity

Support Ticket

Product

Employee

Customer

Sales Territory

Resolution

Page 149: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Single Domain Model

Sales Opportunity

Support Ticket

Product

Employee

Customer

Sales Territory

Resolution

Page 150: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Single Domain Model

Sales Opportunity

Support Ticket

Product

Employee

Customer

Sales Territory

Resolution

Page 151: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Single Domain Model

Sales Opportunity

Support Ticket

Product

Employee

Customer

Sales Territory

Resolution

Page 152: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

SupportSales

Overlapping Contexts

Sales Opportunity

Support Ticket

Product

Employee

Customer

Sales Territory

Resolution

Page 153: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

SupportSales

Bounded Contexts

Sales Opportunity

Support Ticket

Product

Contact

Sales Territory

Resolution

Customer

Product

Support Person

Sales Person

Page 154: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Microservice Architectures

Sales

Support

Inventory

Marketing HR

Page 155: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Microservice Architectures

Subdivide system Sales

Support

Inventory

Marketing HR

Page 156: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Microservice Architectures

Subdivide system

Light-weight APIsSales

Support

Inventory

Marketing HR

Page 157: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Microservice Architectures

Subdivide system

Light-weight APIs

Small teams

Sales

Support

Inventory

Marketing HR

Page 158: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Microservice Architectures

Independent Sales

Support

Inventory

Marketing HR

Page 159: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Microservice Architectures

Independent

Similar to SOASales

Support

Inventory

Marketing HR

Page 160: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Microservice Architectures

Independent

Similar to SOA

Size matters

Sales

Support

Inventory

Marketing HR

Page 161: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Microservices?

ProsLess cost for large domains

Page 162: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Microservices?

ProsLess cost for large domains

Smaller teams

Page 163: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Microservices?

ProsLess cost for large domains

Smaller teams

Independence

Page 164: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Microservices?

ProsLess cost for large domains

Smaller teams

Independence

ConsOnly for large domains

Page 165: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Microservices?

ProsLess cost for large domains

Smaller teams

Independence

ConsOnly for large domains

Higher up-front cost

Page 166: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Why Use Microservices?

ProsLess cost for large domains

Smaller teams

Independence

ConsOnly for large domains

Higher up-front cost

Distributed system costs

Page 167: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Code Demo

Page 168: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Where to Go Next?

Page 169: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Where to Go Next?

Martin Fowler

Page 170: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Where to Go Next?

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

Page 171: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Where to Go Next?

Eric Evans

Page 172: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Where to Go Next?

Greg Young Udi Dahan

Page 173: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Where to Go Next?

Articles

Courses

Presentations

Source Code

Videos

www.matthewrenze.com

Page 174: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

www.pluralsight.com/authors/matthew-renze

Page 175: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Conclusion

Page 176: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Summary

Focus on the inhabitants

Page 177: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Summary

Focus on the inhabitants

Domain-centric Architecture

DatabaseDomain

Application

Presentation

Page 178: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Summary

Focus on the inhabitants

Domain-centric Architecture

Application Layer

Presentation

Domain

Persistence

Users

Application

Infrastructure

OSDatabase

Cro

ss-Cuttin

g C

oncern

s

Page 179: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Summary

Focus on the inhabitants

Domain-centric Architecture

Application Layer

Commands and Queries

Presentation

Domain

Persistence

Users

Queries

Database

Commands

Data Access

Page 180: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Summary

Focus on the inhabitants

Domain-centric Architecture

Application Layer

Commands and Queries

Functional CohesionVendorsProducts

Customers

Page 181: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Summary

Focus on the inhabitants

Domain-centric Architecture

Application Layer

Commands and Queries

Functional Cohesion

Bounded Contexts

Sales

Support

Inventory

Marketing HR

Page 182: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Feedback

Very important to me!

One thing you liked?

One thing I could improve?

Page 183: Clean Architecture - MatthewrenzeGeocentric Model Heliocentric Model Earth Moon Mercury Venus Sun Mars Saturn Jupiter Earth Mercury Venus Sun Saturn Jupiter Mars “The first concern

Contact Info

Matthew Renze

Data Science Consultant

Renze Consulting

Twitter: @matthewrenze

Email: [email protected]

Website: www.matthewrenze.com

Thank You! : )