SlideShare a Scribd company logo
Road from Hex. Architecture
to Event Sourcing
Carlos Buenosvinos (@buenosvinos)
February, 05th , 2019
Porto
Carlos Buenosvinos
@buenosvinos
2
VP Technology @ XING
Consultant and Trainer as Hobby
+10 years as CTO, VPs, Director
Teams up to 100 people
E-Commerce, E-Learning,
Payments, Classifieds, Recruiting
Atrápalo (500M EUR),
PCComponentes (300M EUR)
Domain-Driven
Design in PHP
Carlos Buenosvinos, Christian Soronellas and Keyvan
Akbary
https://leanpub.com/ddd-in-php
Ansistrano
https://ansistrano.com
4
@buenosvinos
5
Road From Hex. Architecture to Event Sourcing
Barcelona ValenciaPorto
https://corporate.xing.com/en/career/jobs/
Road From Hex. Architecture to Event Sourcing
Buenosvinos
Maturity Model
Level 1: Spaghetti
Level 2: Framework Fanboy
Level 3: Hexagonal Architecture
Level 4: Hex. + Domain Events
Level 5: Stepping Stone
(CQRS) Level 6: Event
Sourcing + CQRS
9
Buenosvinos
Maturity Model
Level 1: Spaghetti
Level 2: Framework Fanboy
Level 3: Hexagonal Architecture
Level 4: Hex. + Domain Events
Level 5: Stepping Stone
(CQRS) Level 6: Event
Sourcing + CQRS
10
I want to tell
1
1
you a real story about…
a
Company
1
2
evolving its architecture.
I don’t rewrite
Apps from
Scratch 13
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Level 1:
Spaghetti Architecture
• Multiple Application Entry Points
- create_user.php, delete_user.php, …
• Infrastructure and Domain Together
- PHP and SQL within HTML
• Lack of Testing
• Difficult to Maintain
1
6
New App Old App
Matching by
URL
Moving Away:
Middleware Approach
https://carlosbuenosvinos.com/migrating-progressively-to-symfony-without-pain-with-stackphp/
Level 2:
Layered Architecture /
Framework Fanboy Architecture
• Single Application Entry Point
- app.php
• Some structure is present (MVC)
• Still Mixing Infrastructure and Domain
- Long Controllers with SQL and
Business Logic, Dummy Entities
(getters and setters)
• No testing or using Web Framework
• Difficult to upgrade Infrastructure
Components
1
8
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Moving to
Hexagonal Architecture
• Pick an action in the Web Controller
- Coloring Exercise: Identify Infrastructure
references (ORM, HTTP Rest Calls, Caching,
etc.)
- Extract Variable and to the top
• Extract Business Logic into Application Services
(Copy and Paste)
• Move Infrastructure references away
- Interfaces Infrastructure and the Rest
- Database Tx can be move to Repositories
• Start Unit Testing from Application Services 26
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Benefits of
Hexagonal Architecture
• Separation of Concerns
• Decoupled from the Framework
• Delays Infrastructure Decisions
- Persistence Storage or Delivery
Mechanism (Web, API, CLI, etc.)
• Easy to Test
- Testing Application Services (or CH)
- Testing Entities
- Mocking between the boundaries
30
https://carlosbuenosvinos.com/rigor-talks-php-13-refactor-use-case-i-spanish/
https://carlosbuenosvinos.com/rigor-talks-php-14-refactor-use-case-ii-spanish/
https://carlosbuenosvinos.com/rigor-talks-php-15-refactor-use-case-iii-spanish/
https://carlosbuenosvinos.com/rigor-talks-php-16-refactor-use-case-iv-spanish/
https://carlosbuenosvinos.com/rigor-talks-php-17-refactor-use-case-v-spanish/
https://carlosbuenosvinos.com/rigor-talks-php-18-tell-dont-ask-spanish/
https://carlosbuenosvinos.com/rigor-talks-php-19-refactor-use-case-vi-spanish/
New Tech Policies in the
Team:
1. Everything New: Hexagonal Architecture
2. Touching an Old Feature: Boy Scout Rule ("Always
leave the campground cleaner than you found it.”)
3. 100% Coverage in the Application Services
32
Coverag
e going
up!
33
Buenosvinos
Maturity Model
Level 1: Spaghetti
Level 2: Framework Fanboy
Level 3: Hexagonal Architecture
Level 4: Hex. + Domain Events
Level 5: Stepping Stone
(CQRS) Level 6: Event
Sourcing + CQRS
34
At this point,
35
you can be consultant too!
“… and I want to
notify the user by
email, logging and
sending a BI tracking”
Company’s Product Owner
36
2
2
Team starts to
face new issues
• # of Dependencies Grows
• Application Service complexity Grows
• More Chances to Introduce Bugs
- More developers touching the same
file (Main Task and Subtasks mixed)
• More Subtasks in the same feature,
Worse Performance!!
38
Domain
Events
39
to the rescue!
Domain Event
Example
40
Firing a Domain
Event
41
Domain Event
Publisher
Example
42
Domain Event
Listener
(Elastic Example)
43
Road From Hex. Architecture to Event Sourcing
Domain Event
Listener
(MySQL
Example)
45
Domain Event
Listener
(Rabbit Example)
46
Registering
Domain Event
Listeners
47
Sync all the
things!
48
TechPoliciesAdded (ok, it’s a bad joke!)
1. Subtasks of a Feature are developed in a different
Application Service and attached via Listener
2. Fire any new Event that Business may be interested
3. Let’s have a TV screen to monitor realtime Business
metrics to be proactive.
49
Composition by
Domain Events
50
Buenosvinos
Maturity Model
Level 1: Spaghetti
Level 2: Framework Fanboy
Level 3: Hexagonal Architecture
Level 4: Hex. + Domain
Events Level 5: Stepping
Stone (CQRS) Level 6: Event
Sourcing + CQRS
51
“Hey team! Have you
realised that the item
page is getting quite
slow?”
Company’s Product Owner
52
Perfomance!
53
Multiple Costly Requests
(#, external, joins, etc.)
Async all the
things!
54
55
Restaurant
Page 1 Query
Redis o
Elastic
WorkerDomain
Event
Command
(Application
Service)
RESPONSIBILITY SEGREGATION (CQRS)
Road From Hex. Architecture to Event Sourcing
NOT PROPER CQRS
Problem #1:
2 Infras / 1 Tx
59
What strategies to deal with these
inconsistencies can we follow?
• Let inconsistencies happen
- The Command Handler will manage
itself (firing ArticleWasAdded, sent to
RabbitMQ, but failed Database Tx)
- Feasible for most operational tasks
(sending email, non-critical tracking,
etc.)
• New Article Added Action and its Event
persisted in the same Tx. Then Worker
to move Events to Rabbit.
• Global TX (Noooooooooo!)
60
Problem #2:
Diff(ORM) !==
Diff(Events)
61
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Max
Performance!
64
Buenosvinos
Maturity Model
Level 1: Spaghetti
Level 2: Framework Fanboy
Level 3: Hexagonal Architecture
Level 4: Hex. + Domain Events
Level 5: Stepping Stone
(CQRS) Level 6: Event
Sourcing + CQRS
* Tested with just 20 companies aprox.
65
Road From Hex. Architecture to Event Sourcing
Buenosvinos
Maturity Model
Level 1: Spaghetti
Level 2: Framework Fanboy
Level 3: Hexagonal Architecture
Level 4: Hex. + Domain Events
Level 5: Stepping Stone
(CQRS) Level 6: Event
Sourcing + CQRS
67
Moving to Event Sourcing
• Every Entity is reconstituted from
Events
• Benefits:
• Historical Logs of our Entities
• Audit Environments
• Realtime processing
• Reproduce environments up to
specific state
68
Road From Hex. Architecture to Event Sourcing
Our Main Database is nothing
but a Cache (Can we get rid
of it? How much does it cost?)
70
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Road From Hex. Architecture to Event Sourcing
Buenosvinos
Maturity Model
Level 1: Spaghetti
Level 2: Framework Fanboy
Level 3: Hexagonal Architecture
Level 4: Hex. + Domain Events
Level 5: Stepping Stone
(CQRS) Level 6: Event
Sourcing + CQRS
74
Road From Hex. Architecture to Event Sourcing
@buenosvinos
7
6
Thank you
for your attention.

More Related Content

PDF
Ansible
PDF
Monitoring real-life Azure applications: When to use what and why
PPTX
Platform engineering 101
PPTX
ELK Elasticsearch Logstash and Kibana Stack for Log Management
PDF
[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입
PPTX
Backstage at CNCF Madison.pptx
PDF
Apache NiFi SDLC Improvements
Ansible
Monitoring real-life Azure applications: When to use what and why
Platform engineering 101
ELK Elasticsearch Logstash and Kibana Stack for Log Management
[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입
Backstage at CNCF Madison.pptx
Apache NiFi SDLC Improvements

What's hot (20)

PDF
Introducing ELK
PDF
Repository Management with JFrog Artifactory
PPTX
Microservices
PDF
Jenkins
PPTX
Introduction to Github for Team Project
PPTX
Room 2 - 4 - Juncheng Anthony Lin - Redhat - A Practical Approach to Traditio...
PPTX
Salesforce DevOps using GitHub Action
PDF
Introduction to Kong API Gateway
PPTX
Container based CI/CD on GitHub Actions
PDF
Jenkins 101: Getting Started
PDF
OpenShift Container Platform 4.12 Release Notes
PPTX
Introduction to KSQL: Streaming SQL for Apache Kafka®
PPTX
Best practices for ansible
PDF
A GitOps Kubernetes Native CICD Solution with Argo Events, Workflows, and CD
PDF
Automate the operation of your Oracle Cloud infrastructure v2.0
PPTX
SRE 101 (Site Reliability Engineering)
PDF
ArgoCD and Tekton: Match made in Kubernetes heaven | DevNation Tech Talk
PDF
From airflow to google cloud composer
PPTX
01. Kubernetes-PPT.pptx
PDF
Red Hat Container Strategy
Introducing ELK
Repository Management with JFrog Artifactory
Microservices
Jenkins
Introduction to Github for Team Project
Room 2 - 4 - Juncheng Anthony Lin - Redhat - A Practical Approach to Traditio...
Salesforce DevOps using GitHub Action
Introduction to Kong API Gateway
Container based CI/CD on GitHub Actions
Jenkins 101: Getting Started
OpenShift Container Platform 4.12 Release Notes
Introduction to KSQL: Streaming SQL for Apache Kafka®
Best practices for ansible
A GitOps Kubernetes Native CICD Solution with Argo Events, Workflows, and CD
Automate the operation of your Oracle Cloud infrastructure v2.0
SRE 101 (Site Reliability Engineering)
ArgoCD and Tekton: Match made in Kubernetes heaven | DevNation Tech Talk
From airflow to google cloud composer
01. Kubernetes-PPT.pptx
Red Hat Container Strategy
Ad

Similar to Road From Hex. Architecture to Event Sourcing (20)

PDF
De Arquitectura Hexagonal a Event Sourcing
PDF
A Journey from Hexagonal Architecture to Event Sourcing
PDF
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
PDF
Fighting legacy with hexagonal architecture and frameworkless php
PDF
From class to architecture
PDF
DDD - 4 - Domain Driven Design_ Architectural patterns.pdf
PDF
Modern times - architectures for a Next Generation of IT
PDF
Hpc lunch and learn
PDF
Cascading concurrent yahoo lunch_nlearn
PPTX
Pragmatic Approach to Microservices and Cell-based Architecture
PDF
Advanced web application architecture - PHP Barcelona
PPTX
Real-world software design practices when developing ASP.NET web systems by B...
PDF
Adam boczek 2015 agile architecture in 10 steps v1.0
PDF
Adam boczek 2015 agile architecture in 10 steps v1.0
ODP
Path Dependent Development (PyCon AU)
PDF
Reactive Microservices with Spring 5: WebFlux
PPTX
AppliFire Blue Print Design Guidelines
PDF
PPTX
Go Faster - Remove Inhibitors to Rapid Innovation
PPTX
Melbourne Microservices Meetup: Agenda for a new Architecture
De Arquitectura Hexagonal a Event Sourcing
A Journey from Hexagonal Architecture to Event Sourcing
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
Fighting legacy with hexagonal architecture and frameworkless php
From class to architecture
DDD - 4 - Domain Driven Design_ Architectural patterns.pdf
Modern times - architectures for a Next Generation of IT
Hpc lunch and learn
Cascading concurrent yahoo lunch_nlearn
Pragmatic Approach to Microservices and Cell-based Architecture
Advanced web application architecture - PHP Barcelona
Real-world software design practices when developing ASP.NET web systems by B...
Adam boczek 2015 agile architecture in 10 steps v1.0
Adam boczek 2015 agile architecture in 10 steps v1.0
Path Dependent Development (PyCon AU)
Reactive Microservices with Spring 5: WebFlux
AppliFire Blue Print Design Guidelines
Go Faster - Remove Inhibitors to Rapid Innovation
Melbourne Microservices Meetup: Agenda for a new Architecture
Ad

More from Carlos Buenosvinos (20)

PDF
Kit de Supervivencia para CTOs y Engineering Managers
PDF
Deliveritis Crónica - CAS Spain 2020 (Agile Is The New Normal)
PDF
Eventos, mensajería y otras fábulas - PulpoCon 2019
PDF
Primeros Pasos Liderando Equipos Técnicos - Techne 2018
PDF
Scrum, no eres tú, soy yo
PDF
Integrating Bounded Contexts Tips - Dutch PHP 2016
PDF
Economía del Desarrollo de Software - PHP Barcelona - Marzo 2015
PDF
Desarrollo Profesional con PHP 2014/15 - Nivel Bajo / Medio
PDF
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
PDF
PHP 2014/15 - Visión global del ecosistema PHP
PDF
Desarrollo móvil con Titanium, PhoneGap y otros
PDF
Introducción a Agile y Scrum (BetaBeers.com)
PDF
Team Engagement PHP Barcelona 2011
PDF
"Al rico" PHP
PDF
Scrum al Detalle: Revision práctica y perversiones humanas
PPT
Zend PHP 5.3 Demo Certification Test
PDF
Scrum en Grupo Intercom
KEY
Comparativa Zend vs Symphony
PDF
Aplicaciones Php Para Empresas
PDF
Kit de Supervivencia para CTOs y Engineering Managers
Deliveritis Crónica - CAS Spain 2020 (Agile Is The New Normal)
Eventos, mensajería y otras fábulas - PulpoCon 2019
Primeros Pasos Liderando Equipos Técnicos - Techne 2018
Scrum, no eres tú, soy yo
Integrating Bounded Contexts Tips - Dutch PHP 2016
Economía del Desarrollo de Software - PHP Barcelona - Marzo 2015
Desarrollo Profesional con PHP 2014/15 - Nivel Bajo / Medio
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
PHP 2014/15 - Visión global del ecosistema PHP
Desarrollo móvil con Titanium, PhoneGap y otros
Introducción a Agile y Scrum (BetaBeers.com)
Team Engagement PHP Barcelona 2011
"Al rico" PHP
Scrum al Detalle: Revision práctica y perversiones humanas
Zend PHP 5.3 Demo Certification Test
Scrum en Grupo Intercom
Comparativa Zend vs Symphony
Aplicaciones Php Para Empresas

Recently uploaded (20)

PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Spectroscopy.pptx food analysis technology
PPT
Teaching material agriculture food technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Encapsulation theory and applications.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Building Integrated photovoltaic BIPV_UPV.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
The AUB Centre for AI in Media Proposal.docx
Big Data Technologies - Introduction.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
MYSQL Presentation for SQL database connectivity
Diabetes mellitus diagnosis method based random forest with bat algorithm
Spectroscopy.pptx food analysis technology
Teaching material agriculture food technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
“AI and Expert System Decision Support & Business Intelligence Systems”
Understanding_Digital_Forensics_Presentation.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Encapsulation theory and applications.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx

Road From Hex. Architecture to Event Sourcing