Refactoring legacy systems using events commands and bubble contexts
MichaKurzeja
248 views
89 slides
Jun 22, 2024
Slide 1 of 89
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
About This Presentation
A summary of my 5-year journey through refactoring a legacy system using events, commands, and bubble context.
Size: 11.42 MB
Language: en
Added: Jun 22, 2024
Slides: 89 pages
Slide Content
www.accesto.com
Refactoring legacy
Using events, commands and
bubble context
Michał Kurzeja, PHPers Summit 2024
Dealing with legacy
Dealing with legacy
Refactor
Do nothing Strangle
Start from scratch
Strangler pattern?
Great approach, but
not always possible
You are on Symfony 5.4?
We need to write a new
version on 6.4!
You are on Symfony 5.4?
We need to write a new
version on 6.4!
Refactor
Do nothing Strangle
Start from scratch
Selecting the right driver is essential
1.
2.
3.
0.
4.
Event/Command
approach to a rewrite
You mean CQRS
right?
Don’t care much, as
long as I have events.
Step 1. Extracting events
?
Requesting, not just
reacting
Extracting commands
Reading data
OK, but does that really
make our code better?
Reasons for a
refactor/rewrite
Bad code
1. Low level issues
2. Higher level issues
3. Not the newest FW
4. FW dead for ages
Business issues
1. Bad abstractions
2. Business is a mess too
Bad code vs
Business issues
Business focused
techniques
DDD* ?
1. Bubble context
What about writing
data?
Writing to DB directly?
Writing via API
Bubble context summary
1.Modest commitment to DDD
2.No synchronisation risk
3.Works when there is a limited range of data needed from legacy
4.Fully dependent on legacy
2. Autonomous Bubble
How to implement
the sync?
SLA vs maintenance
cost
2.1 Batch Job
2.2 Domain events
What about writing
data?
What about writing
syncing data?
Avoid writing from
two parts
Boundary can be quite low:
Task Entity:
●Id
●Title
●Description
●Status
●Member
Autonomous Bubble summary
1.Higher commitment required.
2.Data used without legacy being involved.
3.Allows to decouple new part to evolve.
4.Can be introduce as a next step for bubble context.
3. Open host
New, generic model
New, generic model
New, generic model
Another model, created for this context
New, generic model
Another model, created for this context
Let’s get back to the
two questions we
left unanswered
Why implement New
-> Legacy flows
using commands?
ACL in a command<->handler flow
●Lazy approach
●Move legacy code to handler (in legacy namespace)
●Legacy is forced to use new model
●Clean approach
●Expose a clear API (interface, facade, etc) from legacy
●Implement a client in the new part
●Handler can also be in the new part
Questions?
Pytania po prezentacji? Napisz do mnie! :) [email protected]
accesto.com/blog/
Kontakt
twitter.com/accestoPL
facebook.com/accesto