Refactoring legacy systems using events commands and bubble contexts

MichaKurzeja 248 views 89 slides Jun 22, 2024
Slide 1
Slide 1 of 89
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46
Slide 47
47
Slide 48
48
Slide 49
49
Slide 50
50
Slide 51
51
Slide 52
52
Slide 53
53
Slide 54
54
Slide 55
55
Slide 56
56
Slide 57
57
Slide 58
58
Slide 59
59
Slide 60
60
Slide 61
61
Slide 62
62
Slide 63
63
Slide 64
64
Slide 65
65
Slide 66
66
Slide 67
67
Slide 68
68
Slide 69
69
Slide 70
70
Slide 71
71
Slide 72
72
Slide 73
73
Slide 74
74
Slide 75
75
Slide 76
76
Slide 77
77
Slide 78
78
Slide 79
79
Slide 80
80
Slide 81
81
Slide 82
82
Slide 83
83
Slide 84
84
Slide 85
85
Slide 86
86
Slide 87
87
Slide 88
88
Slide 89
89

About This Presentation

A summary of my 5-year journey through refactoring a legacy system using events, commands, and bubble context.


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