SlideShare a Scribd company logo
A Journey from
Hexagonal Architecture
to Event Sourcing
Carlos Buenosvinos (@buenosvinos)
SymfonyCon Cluj 2017, November 16th, 2017
Who am I?
Carlos Buenosvinos
• VP of Technology @ XING
• Consultant as a Hobby
• +10 years on Tech Leadership
(CTO, VP of Engineering, Director)
• Teams up to 100 people
• E-Commerce, E-Learning,
Payments, Classifieds, Recruiting
• Atrápalo (500M EUR),
PCComponentes (300M EUR)
@buenosvinos
Domain-Driven
Design in PHP Book
Carlos Buenosvinos, Christian Soronellas and Keyvan Akbary
https://leanpub.com/ddd-in-php
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
I want to tell
you a real story about…
6
a Company
evolving its architecture.
7
Buenosvinos
Maturity Model
8
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
Spaghetti
Architecture
9
• 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
Framework Fanboy
Architecture
10
• 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
11
Application
Service
Any Random
Action in a Web
Controller
Benefits of
Hexagonal Architecture
12
• Separation of Concerns
• Promotes decoupling 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
13
Web Controller
14
Application
Service
Moving to
Hexagonal Architecture
15
1. Pick an action in the Web Controller
Identify Infrastructure references (ORM,
HTTP Rest Calls, Caching, etc.)
Extract Variable and move them to the top
2. Extract Business Logic into Application
Services (Extract Class/Copy & Paste)
3. Move Infrastructure references away
ORM flush() into add() in Repositories
4. Start Unit Testing from Application
Services
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
16
17
Coverage
going up!
Buenosvinos
Maturity Model
18
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
At this point,
you can be consultant too!
19
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
21
“… and I want to
notify the user by
email, logging and
sending a BI tracking”
Company’s Product Owner
22
Team starts to
face new issues
23
• # 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!!
Domain Events
to the rescue!
24
25
Domain Event
Example
26
Firing a Domain
Event
27
Domain Event
Publisher
Example
28
Domain Event
Listener
(Elastic Example)
29
30
Domain Event
Listener
(MySQL Example)
31
Domain Event
Listener
(Rabbit Example)
32
Registering
Domain Event
Listeners
Sync all the
things!
…and buy more servers
33
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.
34
35
Composition by
Domain Events
Buenosvinos
Maturity Model
36
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
37
“Hey team! Have you
realised that the item
page is getting quite
slow?”
Company’s Product Owner
Perfomance!
Multiple Costly Requests
(#, external, joins, etc.)
38
Async all the
things!
39
CQRS
to the rescue!
40
41
42
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
Problem #1:
2 Infras / 1 Tx
45
What strategies to deal with these
inconsistencies can we follow?
46
• 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!)
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
Problem #2:
Diff(ORM) !== Diff(Events)
48
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
Changes from Hexagonal Architecture
to Stepping Stone (CQRS)
50
• Entity state is still fetched from the
database (read)
- 3rd Normal Form
- Now database is a cache
• Entities hold events triggered
- Use a trait or a base class
• Repositories now only persist a bunch
of events to your queue (no updates)
- You will only send messages to
RabbitMQ or your queue
51
Max
Performance!
A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017
Buenosvinos
Maturity Model
53
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
I want it all!
54
What’s remaining to
get to Event Sourcing?
55
• Entities state is not loaded from the
database, is reconstituted from the
Events from the Event Store.
• Migrate Entities one at a time.
• Enjoy!
Buenosvinos
Maturity Model
56
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
Thank you
for your attention.
https://joind.in/talk/21555
@buenosvinos

More Related Content

PPT
Graphql presentation
PDF
Hexagonal architecture for java applications
PDF
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
PDF
Spring GraphQL
PDF
Completable future
PDF
TDD and BDD and ATDD
PDF
Introduction to GraphQL
PDF
Jenkins
Graphql presentation
Hexagonal architecture for java applications
Hexagonal Architecture - PHP Barcelona Monthly Talk (DDD)
Spring GraphQL
Completable future
TDD and BDD and ATDD
Introduction to GraphQL
Jenkins

What's hot (20)

PDF
Introduction to K6
PDF
The Secrets of Hexagonal Architecture
PPTX
GraphQL Introduction
PDF
Asynchronous API in Java8, how to use CompletableFuture
PDF
Real Life Clean Architecture
PDF
The Apollo and GraphQL Stack
PDF
Playwright: A New Test Automation Framework for the Modern Web
PDF
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
PPTX
Introduction to GraphQL
PPTX
Introduction to graphQL
PDF
GraphQL Fundamentals
PDF
From Generator to Fiber the Road to Coroutine in PHP
PDF
Zero-Downtime Deployment with Kubernetes, SpringBoot & Flyway
PDF
Introduction to GitHub Actions
PPTX
Software architecture for high traffic website
PDF
Hexagonal architecture - message-oriented software design
PPTX
Cucumber presenation
PDF
A GitOps Kubernetes Native CICD Solution with Argo Events, Workflows, and CD
ODP
An Introduction To Jenkins
PDF
Test Automation Interview Questions and Answers | Edureka
Introduction to K6
The Secrets of Hexagonal Architecture
GraphQL Introduction
Asynchronous API in Java8, how to use CompletableFuture
Real Life Clean Architecture
The Apollo and GraphQL Stack
Playwright: A New Test Automation Framework for the Modern Web
Anatomy of a Spring Boot App with Clean Architecture - Spring I/O 2023
Introduction to GraphQL
Introduction to graphQL
GraphQL Fundamentals
From Generator to Fiber the Road to Coroutine in PHP
Zero-Downtime Deployment with Kubernetes, SpringBoot & Flyway
Introduction to GitHub Actions
Software architecture for high traffic website
Hexagonal architecture - message-oriented software design
Cucumber presenation
A GitOps Kubernetes Native CICD Solution with Argo Events, Workflows, and CD
An Introduction To Jenkins
Test Automation Interview Questions and Answers | Edureka
Ad

Viewers also liked (16)

PDF
Webpack Encore Symfony Live 2017 San Francisco
PDF
API Platform and Symfony: a Framework for API-driven Projects
PDF
A Journey from Hexagonal Architecture to Event Sourcing
PDF
PHP 7 – What changed internally? (PHP Barcelona 2015)
PDF
SymfonyCon 2017 php7 performances
PDF
Merging two big Symfony based applications - SymfonyCon 2017
PDF
Behat Best Practices with Symfony
PPTX
The reviewer checklist
PDF
Web Performance 2017: Myths and Truths (php[world] 2017)
PDF
Create a PHP Library the right way
PDF
Developing applications for performance
PDF
Inheritance: Vertical or Horizontal
PPTX
Essential Tools for Modern PHP
PDF
Leveraging a distributed architecture to your advantage
PDF
Advanced MySQL Query Optimizations
PDF
MySQL 8.0 Preview: What Is Coming?
Webpack Encore Symfony Live 2017 San Francisco
API Platform and Symfony: a Framework for API-driven Projects
A Journey from Hexagonal Architecture to Event Sourcing
PHP 7 – What changed internally? (PHP Barcelona 2015)
SymfonyCon 2017 php7 performances
Merging two big Symfony based applications - SymfonyCon 2017
Behat Best Practices with Symfony
The reviewer checklist
Web Performance 2017: Myths and Truths (php[world] 2017)
Create a PHP Library the right way
Developing applications for performance
Inheritance: Vertical or Horizontal
Essential Tools for Modern PHP
Leveraging a distributed architecture to your advantage
Advanced MySQL Query Optimizations
MySQL 8.0 Preview: What Is Coming?
Ad

Similar to A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017 (20)

PPTX
Road From Hex. Architecture to Event Sourcing
PDF
De Arquitectura Hexagonal a Event Sourcing
PPTX
Real-world software design practices when developing ASP.NET web systems by B...
PDF
PDF
Fighting legacy with hexagonal architecture and frameworkless php
PDF
Advanced web application architecture - PHP Barcelona
PPTX
AppliFire Blue Print Design Guidelines
PPTX
LevelsConf 2018 Event Sourcing - Dasith Wijesiriwardena
PDF
Cqrs journey guide
PDF
Diving into event-sourcing and event-driven architectures
PPTX
Lets focus on business value
PPTX
How do we drive tech changes
PPTX
Domain driven design
PPTX
Novelty in Non-Greenfield
PPTX
Go Faster - Remove Inhibitors to Rapid Innovation
PPTX
Pragmatic Approach to Microservices and Cell-based Architecture
PPTX
CQRS recipes or how to cook your architecture
PDF
Software Architecture - All you need to know
PDF
Adam boczek 2015 agile architecture in 10 steps v1.0
PDF
Adam boczek 2015 agile architecture in 10 steps v1.0
Road From Hex. Architecture to Event Sourcing
De Arquitectura Hexagonal a Event Sourcing
Real-world software design practices when developing ASP.NET web systems by B...
Fighting legacy with hexagonal architecture and frameworkless php
Advanced web application architecture - PHP Barcelona
AppliFire Blue Print Design Guidelines
LevelsConf 2018 Event Sourcing - Dasith Wijesiriwardena
Cqrs journey guide
Diving into event-sourcing and event-driven architectures
Lets focus on business value
How do we drive tech changes
Domain driven design
Novelty in Non-Greenfield
Go Faster - Remove Inhibitors to Rapid Innovation
Pragmatic Approach to Microservices and Cell-based Architecture
CQRS recipes or how to cook your architecture
Software Architecture - All you need to know
Adam boczek 2015 agile architecture in 10 steps v1.0
Adam boczek 2015 agile architecture in 10 steps v1.0

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
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
PDF
Php Barcelona Workshop2008 Motores De Workflow En Php Guia
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
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
Php Barcelona Workshop2008 Motores De Workflow En Php Guia

Recently uploaded (20)

PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PPTX
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
PPTX
Welding lecture in detail for understanding
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
Sustainable Sites - Green Building Construction
PPTX
Internet of Things (IOT) - A guide to understanding
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PDF
Automation-in-Manufacturing-Chapter-Introduction.pdf
PPTX
Construction Project Organization Group 2.pptx
PPT
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
PDF
R24 SURVEYING LAB MANUAL for civil enggi
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
UNIT 4 Total Quality Management .pptx
PPTX
web development for engineering and engineering
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PDF
Well-logging-methods_new................
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
CH1 Production IntroductoryConcepts.pptx
TFEC-4-2020-Design-Guide-for-Timber-Roof-Trusses.pdf
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
MET 305 2019 SCHEME MODULE 2 COMPLETE.pptx
Welding lecture in detail for understanding
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
Sustainable Sites - Green Building Construction
Internet of Things (IOT) - A guide to understanding
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Automation-in-Manufacturing-Chapter-Introduction.pdf
Construction Project Organization Group 2.pptx
CRASH COURSE IN ALTERNATIVE PLUMBING CLASS
R24 SURVEYING LAB MANUAL for civil enggi
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
UNIT 4 Total Quality Management .pptx
web development for engineering and engineering
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Well-logging-methods_new................

A Journey from Hexagonal Architecture to Event Sourcing - SymfonyCon Cluj 2017