Arquitecturas basadas en eventos tales como Event Sourcing tienen múltiples beneficios: escalabilidad, gestión de la complejidad, auditoría, etc. Pero llegar a ellas es duro. Nos faltan conocimientos, experiencia y coraje.
En esta charla, mostraré algunos trucos y consejos para evolucionar vuestra arquitectura actual hacia Event Sourcing paso a paso. Empezaremos desde una aplicación con arquitectura hexagonal y acabaremos a las puertas de Event Sourcing.
Unraveling Multimodality with Large Language Models.pdf
De Arquitectura Hexagonal a Event Sourcing
1. De Arquitectura Hexagonal
a Event Sourcing
Carlos Buenosvinos (@buenosvinos)
Bilbostack, 26 de Enero, 2019
Bilbao
2.
3. Carlos Buenosvinos
@buenosvinos
3
VP Technology @ XING
Consultor y Formador como Hobby
+10 años como CTO, VPs, Director
Equipos de hasta 100 personas
E-Commerce, E-Learning,
Payments, Classifieds, Recruiting
Atrápalo (500M EUR),
PCComponentes (300M EUR)
18. 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
8
19. New App Old App
Matching by
URL
Moving Away:
Middleware Approach
https://carlosbuenosvinos.com/migrating-progressively-to-symfony-without-pain-with-stackphp/
20. 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
2
0
21.
22.
23.
24.
25.
26.
27.
28. 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
28
29.
30.
31.
32. 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
32
34. 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
34
40. 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!!
40
51. 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.
51
62. 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!)
62
70. 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
70
71.
72. Our Main Database is nothing
but a Cache (Can we get rid
of it? How much does it
cost?)
72