SlideShare a Scribd company logo
Hexagonal
architecture: how,
why and when
Hexagonal Architecture: how, why and when - 11/2019 3
About meAbout me
Carlos Gándara
software developer at
@xoubaman
Hexagonal Architecture: how, why and when - 11/2019 4
Why?
Hexagonal Architecture: how, why and when - 11/2019 5
A journey through
architectural patterns
Hexagonal Architecture: how, why and when - 11/2019 6
Hexagonal Architecture: how, why and when - 11/2019 7
Spaghetti
Hexagonal Architecture: how, why and when - 11/2019 8
Spaghetti architecture
✅ Fun to revisit after some years...
✅ Valid for small proof of concept scripts
with a 10 minutes life expectancy
...although that means you have it on production
Hexagonal Architecture: how, why and when - 11/2019 9
Hexagonal Architecture: how, why and when - 11/2019 10
MVC
Hexagonal Architecture: how, why and when - 11/2019 11
HTTP
language
Database
language
Business
rules
Data
centric
MVC architecture
Hexagonal Architecture: how, why and when - 11/2019 12
Ctrl+C
Ctrl+V
We want to add
products from the
console
MVC architecture
Hexagonal Architecture: how, why and when - 11/2019 13
I just realized
products have also
a max price
WET code
(makes you sweat)
MVC architecture
Hexagonal Architecture: how, why and when - 11/2019 14
Controllers go fat
MVC architecture
Hexagonal Architecture: how, why and when - 11/2019 15
MVC architecture
❌ No isolation of business logic
✅ Valid for prototyping and purely CRUD applications
❌ Data centric
❌ Hard to test, infrastructure everywhere
Hexagonal Architecture: how, why and when - 11/2019 16
Hexagonal Architecture: how, why and when - 11/2019 17
Layered architecture
Hexagonal Architecture: how, why and when - 11/2019 18
Layered architecture
HTTP & CLI
Same application
service
Diagram from book DDD in PHP
Hexagonal Architecture: how, why and when - 11/2019 19
Layered architecture (the wrong way)
Now need to read
products from this
random API
And we should
notify warehouse
guys
Database
language
Outside
world
Outside
world
Our thing
Hexagonal Architecture: how, why and when - 11/2019 20
Layered architecture (the wrong way)
Hey, plz generate a
RSS feed with
products we read
from this weird
machine
And did I
mentioned we
are migrating to
Mongo?
Combinatorial explosion
Infrastructure coupling
Hexagonal Architecture: how, why and when - 11/2019 21
Layered architecture (the wrong way)
Hey, plz generate a
RSS feed with
products we read
from this weird
machine
And did I
mentioned we
are migrating to
Mongo?
Combinatorial explosion
Infrastructure coupling
Aren’t tests
taking too much
time?
Testability
Hexagonal Architecture: how, why and when - 11/2019 22
Layered architecture
❌ Data persistence is in the core*
✅ Separation of concerns
✅ Application layer encapsulating use cases
❌ Potential infrastructure leaks in other layers*
✅ You can build good stuff
❌ Lasagna antipattern
* if you do it wrong
Hexagonal Architecture: how, why and when - 11/2019 23
Hexagonal Architecture: how, why and when - 11/2019 24
Hexagonal architecture
Hexagonal Architecture: how, why and when - 11/2019 25
Aka Ports and Adapters
Coined by Alistair Cockburn in 2005
Hexagonal architecture
Check out Alistair in the "Hexagone" in Youtube
Hexagonal Architecture: how, why and when - 11/2019 26
Allow an application to equally be driven by users,
programs, automated test or batch scripts, and to be
developed and tested in isolation from its eventual run-time
devices and databases.
Hexagonal architecture
Hexagonal Architecture: how, why and when - 11/2019 27
Outside the application
A boundary
Application
Hexagonal architecture
Hexagonal Architecture: how, why and when - 11/2019 28
Port:
● Outside element
communicating with the
application
● Defined by an interface*
Application
Adapter:
● Implementation of a port
interface into what
application understands
*Not a code interface, although
sometimes represented by one
Ports and adapters
Hexagonal Architecture: how, why and when - 11/2019 29
Primary ports
Drivers
Secondary ports
Repositories and
recipients
Ports and adapters
Hexagonal Architecture: how, why and when - 11/2019 30
Test driver
User interface
Router + HTTP Controller
Ports and adapters
CLI
Console component
REST API
External application
Other adapter
Other adapter
Hexagonal Architecture: how, why and when - 11/2019 31
Ports and adapters
REST API adapter with Symfony:
● Routing component
● HTTP Kernel and Controller
● HTTP component Request
Hexagonal Architecture: how, why and when - 11/2019 32
Ports and adapters
Persistence
Queue
Feed
Interface implementation
Interface implementation
Interfaces
defined by the
application
Hexagonal Architecture: how, why and when - 11/2019 33
Ports and adapters
Persistence adapter with Doctrine ORM
Application defines the contract in its
own language
We don’t care about using database
or library language in the adapter
Hexagonal Architecture: how, why and when - 11/2019 34
Ports and adapters
Persistence adapter with Doctrine ORM
No infrastructure leaks
Testability improved!
Hexagonal Architecture: how, why and when - 11/2019 35
How?
Hexagonal Architecture: how, why and when - 11/2019 36
Allow an application to equally be driven by users,
programs, automated test or batch scripts, and to be
developed and tested in isolation from its eventual run-time
devices and databases.
Hexagonal architecture
No mention to
layers...
Hexagonal Architecture: how, why and when - 11/2019 37
Hexagonal architecture
You can put whatever you want inside the hexagon
Hexagonal Architecture: how, why and when - 11/2019 38
Hexagonal + Layered
Hexagonal Architecture: how, why and when - 11/2019 39
Hexagonal + Layered
Hexagonal Architecture: how, why and when - 11/2019 40
User Interface and Infrastructure layer:
● UI for primary ports adapters
● Infrastructure for secondary ports implementations
Application layer:
● Defines the system use cases
● Orchestrates the domain logic
● Command + Command Handler pattern
Domain layer:
● Holds all the business logic and invariants
● Defines the contracts implemented in infrastructure
Hexagonal + Layered: a proposal
Hexagonal Architecture: how, why and when - 11/2019 41
Hexagonal + Layered
Domain
Application
UI
Infrastructure
Hexagonal Architecture: how, why and when - 11/2019 42
Hexagonal + Layered: Domain layer
Domain
Application
UI
Infrastructure
Don’t leak
infrastructure in
your domain
Hexagonal Architecture: how, why and when - 11/2019 43
Hexagonal + Layered: Application layer
Domain
Application
UI
Infrastructure
More logic
than this is
suspicious
Hexagonal Architecture: how, why and when - 11/2019 44
Hexagonal + Layered: Driver port
Domain
Application
UI
Infrastructure
Hexagonal Architecture: how, why and when - 11/2019 45
Hexagonal + Layered: Repository port
Domain
Application
UI
Infrastructure
Dependency inversion
Hexagonal Architecture: how, why and when - 11/2019 46
When?
Hexagonal Architecture: how, why and when - 11/2019 47
When to apply hexagonal architecture?
ALWAYS*
Hexagonal Architecture: how, why and when - 11/2019 48
When to apply hexagonal architecture?
Pros
● Testability
● Promotes separation of
concerns
● Pushes accidental complexity
out of the domain
● Open/Closed
● Handy base for DDD
● Handy base for CQRS and ES
Cons
● Indirection
● Amount of boilerplate code
Hexagonal Architecture: how, why and when - 11/2019 49
When to apply hexagonal architecture?
Makes no sense for
● Scripting
● Prototyping
● Tooling
● Frameworks
Makes sense for
● Applications relying on external technologies
● CRUD applications
● Anything more complex than that
Hexagonal Architecture: how, why and when - 11/2019 50
When to apply hexagonal architecture?
Take decisions based on the context and needs
Keep in mind the reasons and the consequences
ALWAYS
Hexagonal Architecture: how, why and when - 11/2019 51
Questions?
Hexagonal Architecture: how, why and when - 11/2019
● Slides of this presentation anytime soon in @xoubaman
● Article: Hexagonal Architecture by Alistair Cockburn
● Article: Hexagonal Architecture by Fideloper
● Article: DDD, Hexagonal, Onion, Clean, CQRS, … How I put it all together by Hebert Graca
● Video: Introducción Arquitectura Hexagonal (Spanish) by CodelyTV
● Video: Hexagonal Architecture - Message-Oriented Software Design by Matthias Noback
● Video: Alistair in the “Hexagone” by DDD FR
● Book: DDD in PHP by Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary
● Book: Implementing Domain Driven Design by Vaughn Vernon
● Code samples glittered with Carbon
52
Some resources to follow up
Thank you!

More Related Content

What's hot

Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
CodelyTV
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
Yevgeniy Brikman
 
Istio service mesh introduction
Istio service mesh introductionIstio service mesh introduction
Istio service mesh introduction
Kyohei Mizumoto
 
Hexagonal Architecture.pdf
Hexagonal Architecture.pdfHexagonal Architecture.pdf
Hexagonal Architecture.pdf
VladimirRadzivil
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
Mohamed Galal
 
Microservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, KanbanMicroservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, Kanban
Araf Karsh Hamid
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
Roger van de Kimmenade
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with Backstage
Opsta
 
Microservices architecture overview v2
Microservices architecture overview v2Microservices architecture overview v2
Microservices architecture overview v2
Dmitry Skaredov
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
Oğuzhan Soykan
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
NSCoder Mexico
 
Microservices and SOA
Microservices and SOAMicroservices and SOA
Microservices and SOA
Capgemini
 
ISTIO Deep Dive
ISTIO Deep DiveISTIO Deep Dive
ISTIO Deep Dive
Yong Feng
 
Arquitectura hexagonal
Arquitectura hexagonalArquitectura hexagonal
Arquitectura hexagonal
540deg
 
Best Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with TerraformBest Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with Terraform
DevOps.com
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
Ryan Riley
 
Clean Infrastructure as Code
Clean Infrastructure as Code Clean Infrastructure as Code
Clean Infrastructure as Code
QAware GmbH
 
The Paved Road at Netflix
The Paved Road at NetflixThe Paved Road at Netflix
The Paved Road at Netflix
Dianne Marsh
 
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
Daniel Oh
 
Big Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb ShardingBig Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb Sharding
Araf Karsh Hamid
 

What's hot (20)

Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
Acercándonos a la Programación Funcional a través de la Arquitectura Hexag...
 
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...How to test infrastructure code: automated testing for Terraform, Kubernetes,...
How to test infrastructure code: automated testing for Terraform, Kubernetes,...
 
Istio service mesh introduction
Istio service mesh introductionIstio service mesh introduction
Istio service mesh introduction
 
Hexagonal Architecture.pdf
Hexagonal Architecture.pdfHexagonal Architecture.pdf
Hexagonal Architecture.pdf
 
SOLID Principles and The Clean Architecture
SOLID Principles and The Clean ArchitectureSOLID Principles and The Clean Architecture
SOLID Principles and The Clean Architecture
 
Microservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, KanbanMicroservices, Containers, Kubernetes, Kafka, Kanban
Microservices, Containers, Kubernetes, Kafka, Kanban
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Let's build Developer Portal with Backstage
Let's build Developer Portal with BackstageLet's build Developer Portal with Backstage
Let's build Developer Portal with Backstage
 
Microservices architecture overview v2
Microservices architecture overview v2Microservices architecture overview v2
Microservices architecture overview v2
 
Domain Driven Design(DDD) Presentation
Domain Driven Design(DDD) PresentationDomain Driven Design(DDD) Presentation
Domain Driven Design(DDD) Presentation
 
Clean Architecture
Clean ArchitectureClean Architecture
Clean Architecture
 
Microservices and SOA
Microservices and SOAMicroservices and SOA
Microservices and SOA
 
ISTIO Deep Dive
ISTIO Deep DiveISTIO Deep Dive
ISTIO Deep Dive
 
Arquitectura hexagonal
Arquitectura hexagonalArquitectura hexagonal
Arquitectura hexagonal
 
Best Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with TerraformBest Practices of Infrastructure as Code with Terraform
Best Practices of Infrastructure as Code with Terraform
 
Domain Driven Design
Domain Driven DesignDomain Driven Design
Domain Driven Design
 
Clean Infrastructure as Code
Clean Infrastructure as Code Clean Infrastructure as Code
Clean Infrastructure as Code
 
The Paved Road at Netflix
The Paved Road at NetflixThe Paved Road at Netflix
The Paved Road at Netflix
 
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
Microservice 4.0 Journey - From Spring NetFlix OSS to Istio Service Mesh and ...
 
Big Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb ShardingBig Data Redis Mongodb Dynamodb Sharding
Big Data Redis Mongodb Dynamodb Sharding
 

Similar to Hexagonal architecture: how, why and when

UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
Karen Cannell
 
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, AirbusAPIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
apidays
 
Why Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik RamasamyWhy Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik Ramasamy
StreamNative
 
Pulsar summit-keynote-final
Pulsar summit-keynote-finalPulsar summit-keynote-final
Pulsar summit-keynote-final
Karthik Ramasamy
 
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in..."Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
DECIDEH2020
 
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
Yenlo
 
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Trivadis
 
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
APEX Interactive Grid API Essentials:  The Stuff You Will Really UseAPEX Interactive Grid API Essentials:  The Stuff You Will Really Use
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
Karen Cannell
 
2019 09-13 kubernetes is hard - k8s community days
2019 09-13 kubernetes is hard - k8s community days2019 09-13 kubernetes is hard - k8s community days
2019 09-13 kubernetes is hard - k8s community days
Eldad Assis
 
Web Development
Web DevelopmentWeb Development
Web Development
Shubham Khan
 
Agile Mëtteg series session 7
Agile Mëtteg series session 7Agile Mëtteg series session 7
Agile Mëtteg series session 7
Agile Partner S.A.
 
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approachDevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps_Fest
 
Apache Pulsar @Splunk
Apache Pulsar @SplunkApache Pulsar @Splunk
Apache Pulsar @Splunk
Karthik Ramasamy
 
Bring cloud on premises with a kubernetes-native infrastructure
Bring cloud on premises with a kubernetes-native infrastructureBring cloud on premises with a kubernetes-native infrastructure
Bring cloud on premises with a kubernetes-native infrastructure
Abhinav Joshi
 
Serverless Kafka Patterns
Serverless Kafka PatternsServerless Kafka Patterns
Serverless Kafka Patterns
Taras Slipets
 
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry DaysStock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Vidyasagar Machupalli
 
Openbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar 2 - Leuven - Faros - Invisible InfrastructureOpenbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar
 
Cloud native past, present and future
Cloud native past, present and futureCloud native past, present and future
Cloud native past, present and future
Cheryl Hung
 
Empowering your Process Automation with Machine Learning
Empowering your Process Automation with Machine LearningEmpowering your Process Automation with Machine Learning
Empowering your Process Automation with Machine Learning
Lykle Thijssen
 
Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
 Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e... Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
VMware Tanzu
 

Similar to Hexagonal architecture: how, why and when (20)

UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
UTOUG Training Days 2019 APEX Interactive Grids: API Essentials, the Stuff Yo...
 
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, AirbusAPIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
APIdays Paris 2019 - Challenges at Global Scale by Nizar Chaouch, Airbus
 
Why Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik RamasamyWhy Splunk Chose Pulsar_Karthik Ramasamy
Why Splunk Chose Pulsar_Karthik Ramasamy
 
Pulsar summit-keynote-final
Pulsar summit-keynote-finalPulsar summit-keynote-final
Pulsar summit-keynote-final
 
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in..."Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
"Contribution to the uptake of Cloud Computing solutions" by Juncal Alonso in...
 
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
WSO2-Yenlo Integration Summit Stuttgart 15 may 2019
 
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
Azure Days 2019: Azure Chatbot Development for Airline Irregularities (Remco ...
 
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
APEX Interactive Grid API Essentials:  The Stuff You Will Really UseAPEX Interactive Grid API Essentials:  The Stuff You Will Really Use
APEX Interactive Grid API Essentials: The Stuff You Will Really Use
 
2019 09-13 kubernetes is hard - k8s community days
2019 09-13 kubernetes is hard - k8s community days2019 09-13 kubernetes is hard - k8s community days
2019 09-13 kubernetes is hard - k8s community days
 
Web Development
Web DevelopmentWeb Development
Web Development
 
Agile Mëtteg series session 7
Agile Mëtteg series session 7Agile Mëtteg series session 7
Agile Mëtteg series session 7
 
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approachDevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
DevOps Fest 2019. Володимир Кімак. Mobile CI/CD. Cross-platform app approach
 
Apache Pulsar @Splunk
Apache Pulsar @SplunkApache Pulsar @Splunk
Apache Pulsar @Splunk
 
Bring cloud on premises with a kubernetes-native infrastructure
Bring cloud on premises with a kubernetes-native infrastructureBring cloud on premises with a kubernetes-native infrastructure
Bring cloud on premises with a kubernetes-native infrastructure
 
Serverless Kafka Patterns
Serverless Kafka PatternsServerless Kafka Patterns
Serverless Kafka Patterns
 
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry DaysStock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
Stock portfolio analysis with Cloud Foundry and AI services - Cloud Foundry Days
 
Openbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar 2 - Leuven - Faros - Invisible InfrastructureOpenbar 2 - Leuven - Faros - Invisible Infrastructure
Openbar 2 - Leuven - Faros - Invisible Infrastructure
 
Cloud native past, present and future
Cloud native past, present and futureCloud native past, present and future
Cloud native past, present and future
 
Empowering your Process Automation with Machine Learning
Empowering your Process Automation with Machine LearningEmpowering your Process Automation with Machine Learning
Empowering your Process Automation with Machine Learning
 
Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
 Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e... Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
Cloud-Native .Net des applications containerisées .Net sur Linux, Windows e...
 

Recently uploaded

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
Max Andersen
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Globus
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
Boni García
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Globus
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
Google
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
ShamsuddeenMuhammadA
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
timtebeek1
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Yara Milbes
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
Neo4j
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
abdulrafaychaudhry
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Globus
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 

Recently uploaded (20)

Quarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden ExtensionsQuarkus Hidden and Forbidden Extensions
Quarkus Hidden and Forbidden Extensions
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)APIs for Browser Automation (MoT Meetup 2024)
APIs for Browser Automation (MoT Meetup 2024)
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI AppAI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
AI Fusion Buddy Review: Brand New, Groundbreaking Gemini-Powered AI App
 
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptxText-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
Text-Summarization-of-Breaking-News-Using-Fine-tuning-BART-Model.pptx
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdfAutomated software refactoring with OpenRewrite and Generative AI.pptx.pdf
Automated software refactoring with OpenRewrite and Generative AI.pptx.pdf
 
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi ArabiaTop 7 Unique WhatsApp API Benefits | Saudi Arabia
Top 7 Unique WhatsApp API Benefits | Saudi Arabia
 
GraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph TechnologyGraphSummit Paris - The art of the possible with Graph Technology
GraphSummit Paris - The art of the possible with Graph Technology
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Pro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp BookPro Unity Game Development with C-sharp Book
Pro Unity Game Development with C-sharp Book
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 

Hexagonal architecture: how, why and when

  • 1.
  • 3. Hexagonal Architecture: how, why and when - 11/2019 3 About meAbout me Carlos Gándara software developer at @xoubaman
  • 4. Hexagonal Architecture: how, why and when - 11/2019 4 Why?
  • 5. Hexagonal Architecture: how, why and when - 11/2019 5 A journey through architectural patterns
  • 6. Hexagonal Architecture: how, why and when - 11/2019 6
  • 7. Hexagonal Architecture: how, why and when - 11/2019 7 Spaghetti
  • 8. Hexagonal Architecture: how, why and when - 11/2019 8 Spaghetti architecture ✅ Fun to revisit after some years... ✅ Valid for small proof of concept scripts with a 10 minutes life expectancy ...although that means you have it on production
  • 9. Hexagonal Architecture: how, why and when - 11/2019 9
  • 10. Hexagonal Architecture: how, why and when - 11/2019 10 MVC
  • 11. Hexagonal Architecture: how, why and when - 11/2019 11 HTTP language Database language Business rules Data centric MVC architecture
  • 12. Hexagonal Architecture: how, why and when - 11/2019 12 Ctrl+C Ctrl+V We want to add products from the console MVC architecture
  • 13. Hexagonal Architecture: how, why and when - 11/2019 13 I just realized products have also a max price WET code (makes you sweat) MVC architecture
  • 14. Hexagonal Architecture: how, why and when - 11/2019 14 Controllers go fat MVC architecture
  • 15. Hexagonal Architecture: how, why and when - 11/2019 15 MVC architecture ❌ No isolation of business logic ✅ Valid for prototyping and purely CRUD applications ❌ Data centric ❌ Hard to test, infrastructure everywhere
  • 16. Hexagonal Architecture: how, why and when - 11/2019 16
  • 17. Hexagonal Architecture: how, why and when - 11/2019 17 Layered architecture
  • 18. Hexagonal Architecture: how, why and when - 11/2019 18 Layered architecture HTTP & CLI Same application service Diagram from book DDD in PHP
  • 19. Hexagonal Architecture: how, why and when - 11/2019 19 Layered architecture (the wrong way) Now need to read products from this random API And we should notify warehouse guys Database language Outside world Outside world Our thing
  • 20. Hexagonal Architecture: how, why and when - 11/2019 20 Layered architecture (the wrong way) Hey, plz generate a RSS feed with products we read from this weird machine And did I mentioned we are migrating to Mongo? Combinatorial explosion Infrastructure coupling
  • 21. Hexagonal Architecture: how, why and when - 11/2019 21 Layered architecture (the wrong way) Hey, plz generate a RSS feed with products we read from this weird machine And did I mentioned we are migrating to Mongo? Combinatorial explosion Infrastructure coupling Aren’t tests taking too much time? Testability
  • 22. Hexagonal Architecture: how, why and when - 11/2019 22 Layered architecture ❌ Data persistence is in the core* ✅ Separation of concerns ✅ Application layer encapsulating use cases ❌ Potential infrastructure leaks in other layers* ✅ You can build good stuff ❌ Lasagna antipattern * if you do it wrong
  • 23. Hexagonal Architecture: how, why and when - 11/2019 23
  • 24. Hexagonal Architecture: how, why and when - 11/2019 24 Hexagonal architecture
  • 25. Hexagonal Architecture: how, why and when - 11/2019 25 Aka Ports and Adapters Coined by Alistair Cockburn in 2005 Hexagonal architecture Check out Alistair in the "Hexagone" in Youtube
  • 26. Hexagonal Architecture: how, why and when - 11/2019 26 Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases. Hexagonal architecture
  • 27. Hexagonal Architecture: how, why and when - 11/2019 27 Outside the application A boundary Application Hexagonal architecture
  • 28. Hexagonal Architecture: how, why and when - 11/2019 28 Port: ● Outside element communicating with the application ● Defined by an interface* Application Adapter: ● Implementation of a port interface into what application understands *Not a code interface, although sometimes represented by one Ports and adapters
  • 29. Hexagonal Architecture: how, why and when - 11/2019 29 Primary ports Drivers Secondary ports Repositories and recipients Ports and adapters
  • 30. Hexagonal Architecture: how, why and when - 11/2019 30 Test driver User interface Router + HTTP Controller Ports and adapters CLI Console component REST API External application Other adapter Other adapter
  • 31. Hexagonal Architecture: how, why and when - 11/2019 31 Ports and adapters REST API adapter with Symfony: ● Routing component ● HTTP Kernel and Controller ● HTTP component Request
  • 32. Hexagonal Architecture: how, why and when - 11/2019 32 Ports and adapters Persistence Queue Feed Interface implementation Interface implementation Interfaces defined by the application
  • 33. Hexagonal Architecture: how, why and when - 11/2019 33 Ports and adapters Persistence adapter with Doctrine ORM Application defines the contract in its own language We don’t care about using database or library language in the adapter
  • 34. Hexagonal Architecture: how, why and when - 11/2019 34 Ports and adapters Persistence adapter with Doctrine ORM No infrastructure leaks Testability improved!
  • 35. Hexagonal Architecture: how, why and when - 11/2019 35 How?
  • 36. Hexagonal Architecture: how, why and when - 11/2019 36 Allow an application to equally be driven by users, programs, automated test or batch scripts, and to be developed and tested in isolation from its eventual run-time devices and databases. Hexagonal architecture No mention to layers...
  • 37. Hexagonal Architecture: how, why and when - 11/2019 37 Hexagonal architecture You can put whatever you want inside the hexagon
  • 38. Hexagonal Architecture: how, why and when - 11/2019 38 Hexagonal + Layered
  • 39. Hexagonal Architecture: how, why and when - 11/2019 39 Hexagonal + Layered
  • 40. Hexagonal Architecture: how, why and when - 11/2019 40 User Interface and Infrastructure layer: ● UI for primary ports adapters ● Infrastructure for secondary ports implementations Application layer: ● Defines the system use cases ● Orchestrates the domain logic ● Command + Command Handler pattern Domain layer: ● Holds all the business logic and invariants ● Defines the contracts implemented in infrastructure Hexagonal + Layered: a proposal
  • 41. Hexagonal Architecture: how, why and when - 11/2019 41 Hexagonal + Layered Domain Application UI Infrastructure
  • 42. Hexagonal Architecture: how, why and when - 11/2019 42 Hexagonal + Layered: Domain layer Domain Application UI Infrastructure Don’t leak infrastructure in your domain
  • 43. Hexagonal Architecture: how, why and when - 11/2019 43 Hexagonal + Layered: Application layer Domain Application UI Infrastructure More logic than this is suspicious
  • 44. Hexagonal Architecture: how, why and when - 11/2019 44 Hexagonal + Layered: Driver port Domain Application UI Infrastructure
  • 45. Hexagonal Architecture: how, why and when - 11/2019 45 Hexagonal + Layered: Repository port Domain Application UI Infrastructure Dependency inversion
  • 46. Hexagonal Architecture: how, why and when - 11/2019 46 When?
  • 47. Hexagonal Architecture: how, why and when - 11/2019 47 When to apply hexagonal architecture? ALWAYS*
  • 48. Hexagonal Architecture: how, why and when - 11/2019 48 When to apply hexagonal architecture? Pros ● Testability ● Promotes separation of concerns ● Pushes accidental complexity out of the domain ● Open/Closed ● Handy base for DDD ● Handy base for CQRS and ES Cons ● Indirection ● Amount of boilerplate code
  • 49. Hexagonal Architecture: how, why and when - 11/2019 49 When to apply hexagonal architecture? Makes no sense for ● Scripting ● Prototyping ● Tooling ● Frameworks Makes sense for ● Applications relying on external technologies ● CRUD applications ● Anything more complex than that
  • 50. Hexagonal Architecture: how, why and when - 11/2019 50 When to apply hexagonal architecture? Take decisions based on the context and needs Keep in mind the reasons and the consequences ALWAYS
  • 51. Hexagonal Architecture: how, why and when - 11/2019 51 Questions?
  • 52. Hexagonal Architecture: how, why and when - 11/2019 ● Slides of this presentation anytime soon in @xoubaman ● Article: Hexagonal Architecture by Alistair Cockburn ● Article: Hexagonal Architecture by Fideloper ● Article: DDD, Hexagonal, Onion, Clean, CQRS, … How I put it all together by Hebert Graca ● Video: Introducción Arquitectura Hexagonal (Spanish) by CodelyTV ● Video: Hexagonal Architecture - Message-Oriented Software Design by Matthias Noback ● Video: Alistair in the “Hexagone” by DDD FR ● Book: DDD in PHP by Carlos Buenosvinos, Christian Soronellas, and Keyvan Akbary ● Book: Implementing Domain Driven Design by Vaughn Vernon ● Code samples glittered with Carbon 52 Some resources to follow up