Slide 1

Slide 1 text

Guillermo Aguirre - April 2023 Applying Microservices Patterns to a Modular Monolith

Slide 2

Slide 2 text

Guillermo Aguirre - RailsConf 2023 Welcome!

Slide 3

Slide 3 text

Guillermo Aguirre - RailsConf 2023 About me @guillermoap @guillermoap_ @guillermo.aguirre Guillermo Aguirre /gee-SHER-moh ah-GHEE-rreh/

Slide 4

Slide 4 text

Guillermo Aguirre - RailsConf 2023 Where I work

Slide 5

Slide 5 text

Guillermo Aguirre - RailsConf 2023 Agenda

Slide 6

Slide 6 text

Guillermo Aguirre - RailsConf 2023 Agenda My journey

Slide 7

Slide 7 text

Guillermo Aguirre - RailsConf 2023 Agenda My journey Our Domain

Slide 8

Slide 8 text

Guillermo Aguirre - RailsConf 2023 Agenda My journey Our Domain Pattern explanations

Slide 9

Slide 9 text

Guillermo Aguirre - RailsConf 2023 Agenda My journey Our Domain Pattern explanations Example App

Slide 10

Slide 10 text

Guillermo Aguirre - RailsConf 2023 Agenda My journey Our Domain Pattern explanations Example App Demo

Slide 11

Slide 11 text

Applying Microservices Patterns to a Modular Monolith My journey

Slide 12

Slide 12 text

Applying Microservices Patterns to a Modular Monolith My journey MVPs

Slide 13

Slide 13 text

Applying Microservices Patterns to a Modular Monolith My journey MVPs Big monoliths

Slide 14

Slide 14 text

Applying Microservices Patterns to a Modular Monolith My journey MVPs Big monoliths Microservices

Slide 15

Slide 15 text

Applying Microservices Patterns to a Modular Monolith Monoliths The good

Slide 16

Slide 16 text

Applying Microservices Patterns to a Modular Monolith Monoliths Widely used The good

Slide 17

Slide 17 text

Applying Microservices Patterns to a Modular Monolith Monoliths Nothing wrong with them Widely used The good

Slide 18

Slide 18 text

Applying Microservices Patterns to a Modular Monolith Monoliths My experience

Slide 19

Slide 19 text

Applying Microservices Patterns to a Modular Monolith 1 | class User < ApplicationRecord ... | ... 2473 | end Monoliths My experience

Slide 20

Slide 20 text

Applying Microservices Patterns to a Modular Monolith Monoliths The bad

Slide 21

Slide 21 text

Applying Microservices Patterns to a Modular Monolith Long deployment times Monoliths The bad

Slide 22

Slide 22 text

Applying Microservices Patterns to a Modular Monolith Long deployment times Monoliths The bad Tightly coupled code

Slide 23

Slide 23 text

Applying Microservices Patterns to a Modular Monolith Long deployment times Monoliths The bad Tightly coupled code => Harder to maintain & extend

Slide 24

Slide 24 text

Applying Microservices Patterns to a Modular Monolith Microservices The good

Slide 25

Slide 25 text

Applying Microservices Patterns to a Modular Monolith Smaller cohesive teams Microservices The good

Slide 26

Slide 26 text

Applying Microservices Patterns to a Modular Monolith Smaller cohesive teams Distributed Microservices The good

Slide 27

Slide 27 text

Applying Microservices Patterns to a Modular Monolith Microservices My experience

Slide 28

Slide 28 text

Applying Microservices Patterns to a Modular Monolith Data inconsistencies Microservices My experience

Slide 29

Slide 29 text

Applying Microservices Patterns to a Modular Monolith Data inconsistencies Hot- f ix issues in production Microservices My experience

Slide 30

Slide 30 text

Applying Microservices Patterns to a Modular Monolith Microservices The bad

Slide 31

Slide 31 text

Applying Microservices Patterns to a Modular Monolith Signi f icantly higher infrastructure complexity Microservices The bad

Slide 32

Slide 32 text

Applying Microservices Patterns to a Modular Monolith Signi f icantly higher infrastructure complexity Distributed mess Microservices The bad

Slide 33

Slide 33 text

Applying Microservices Patterns to a Modular Monolith Modularization

Slide 34

Slide 34 text

Applying Microservices Patterns to a Modular Monolith Modularization

Slide 35

Slide 35 text

Applying Microservices Patterns to a Modular Monolith Monolith vs Microservices by Simon Brown Modularization

Slide 36

Slide 36 text

Applying Microservices Patterns to a Modular Monolith Monolith vs Microservices by Simon Brown Modularization

Slide 37

Slide 37 text

Applying Microservices Patterns to a Modular Monolith Monolith vs Microservices by Simon Brown Modularization

Slide 38

Slide 38 text

Applying Microservices Patterns to a Modular Monolith Cross-pollination between architectures Leverage and reuse work from the microservices world into our modular app

Slide 39

Slide 39 text

Applying Microservices Patterns to a Modular Monolith Domain for example

Slide 40

Slide 40 text

Applying Microservices Patterns to a Modular Monolith Domain for example

Slide 41

Slide 41 text

Applying Microservices Patterns to a Modular Monolith Domain for example

Slide 42

Slide 42 text

Applying Microservices Patterns to a Modular Monolith Domain for example

Slide 43

Slide 43 text

Applying Microservices Patterns to a Modular Monolith Domain for example

Slide 44

Slide 44 text

Applying Microservices Patterns to a Modular Monolith Simple architecture

Slide 45

Slide 45 text

Applying Microservices Patterns to a Modular Monolith Separating domains

Slide 46

Slide 46 text

Applying Microservices Patterns to a Modular Monolith Problems when leaving one database A 
 C 
 I 
 D Local transactions are ensured by

Slide 47

Slide 47 text

Applying Microservices Patterns to a Modular Monolith Problems when leaving one database A 
 C 
 I 
 D Atomicity 
 Consistency 
 Isolation 
 Durability Local transactions are ensured by

Slide 48

Slide 48 text

Applying Microservices Patterns to a Modular Monolith Problems when leaving one database A 
 C 
 I 
 D Atomicity 
 Consistency 
 Isolation 
 Durability Local transactions are ensured by

Slide 49

Slide 49 text

Applying Microservices Patterns to a Modular Monolith Not handling transactions

Slide 50

Slide 50 text

Applying Microservices Patterns to a Modular Monolith Not handling transactions Consistency issues

Slide 51

Slide 51 text

Applying Microservices Patterns to a Modular Monolith Not handling transactions Consistency issues Devolve into f ixing data issues in production

Slide 52

Slide 52 text

Applying Microservices Patterns to a Modular Monolith Not handling transactions Consistency issues Devolve into f ixing data issues in production Important f lows break and we have no way of noticing

Slide 53

Slide 53 text

Applying Microservices Patterns to a Modular Monolith Patterns Proven solutions to recurring problems

Slide 54

Slide 54 text

Applying Microservices Patterns to a Modular Monolith Microservices Patterns

Slide 55

Slide 55 text

Applying Microservices Patterns to a Modular Monolith Microservices Patterns

Slide 56

Slide 56 text

Applying Microservices Patterns to a Modular Monolith What patterns are we going to use?

Slide 57

Slide 57 text

Applying Microservices Patterns to a Modular Monolith What patterns are we going to use? One database per service/domain

Slide 58

Slide 58 text

Applying Microservices Patterns to a Modular Monolith What patterns are we going to use? One database per service/domain Saga

Slide 59

Slide 59 text

Applying Microservices Patterns to a Modular Monolith What patterns are we going to use? One database per service/domain Saga Transactional Outbox

Slide 60

Slide 60 text

Applying Microservices Patterns to a Modular Monolith One database per service/domain Isolation of data structure

Slide 61

Slide 61 text

Applying Microservices Patterns to a Modular Monolith One database per service/domain Private tables per service Isolation of data structure

Slide 62

Slide 62 text

Applying Microservices Patterns to a Modular Monolith One database per service/domain Private tables per service Schema per service Isolation of data structure

Slide 63

Slide 63 text

Applying Microservices Patterns to a Modular Monolith One database per service/domain Private tables per service Schema per service Database per service Isolation of data structure

Slide 64

Slide 64 text

Applying Microservices Patterns to a Modular Monolith Saga Chris Richardson - https://microservices.io/patterns/data/saga.html Eventual consistency across systems

Slide 65

Slide 65 text

Applying Microservices Patterns to a Modular Monolith Saga Chris Richardson - https://microservices.io/patterns/data/saga.html Sequence of local transactions Eventual consistency across systems

Slide 66

Slide 66 text

Applying Microservices Patterns to a Modular Monolith Transactional Outbox Chris Richardson - https://microservices.io/patterns/data/transactional-outbox.html Atomically update state and publish events

Slide 67

Slide 67 text

Applying Microservices Patterns to a Modular Monolith Transactional Outbox Chris Richardson - https://microservices.io/patterns/data/transactional-outbox.html Atomically update state and publish events

Slide 68

Slide 68 text

Applying Microservices Patterns to a Modular Monolith Modular architecture

Slide 69

Slide 69 text

Applying Microservices Patterns to a Modular Monolith Modular architecture To be able to reference a User entity indirectly, it will have the same identi f ier across domains and databases.

Slide 70

Slide 70 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 71

Slide 71 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 72

Slide 72 text

Applying Microservices Patterns to a Modular Monolith Saga f low User con f irms email

Slide 73

Slide 73 text

Applying Microservices Patterns to a Modular Monolith Saga f low User con f irms email

Slide 74

Slide 74 text

Applying Microservices Patterns to a Modular Monolith Saga f low User con f irms email We update the status_code attribute to con f irmed

Slide 75

Slide 75 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 76

Slide 76 text

Applying Microservices Patterns to a Modular Monolith Saga f low Outbox record gets created

Slide 77

Slide 77 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 78

Slide 78 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 79

Slide 79 text

Applying Microservices Patterns to a Modular Monolith Saga f low User record gets created

Slide 80

Slide 80 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 81

Slide 81 text

Applying Microservices Patterns to a Modular Monolith Saga f low Event collaboration

Slide 82

Slide 82 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 83

Slide 83 text

Applying Microservices Patterns to a Modular Monolith Saga f low Successful sequence

Slide 84

Slide 84 text

Applying Microservices Patterns to a Modular Monolith Saga f low Successful sequence Outbox record gets created

Slide 85

Slide 85 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 86

Slide 86 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 87

Slide 87 text

Applying Microservices Patterns to a Modular Monolith Saga f low Rollback sequence

Slide 88

Slide 88 text

Applying Microservices Patterns to a Modular Monolith Saga f low Rollback sequence Outbox record gets created

Slide 89

Slide 89 text

Applying Microservices Patterns to a Modular Monolith Saga f low Rollback sequence

Slide 90

Slide 90 text

Applying Microservices Patterns to a Modular Monolith Saga f low Rollback sequence Update UserRegistration to its previous waiting_for_con f irmation state

Slide 91

Slide 91 text

Applying Microservices Patterns to a Modular Monolith Saga f low Rollback sequence Update UserRegistration to its previous waiting_for_con f irmation state User record gets destroyed

Slide 92

Slide 92 text

Applying Microservices Patterns to a Modular Monolith Saga f low

Slide 93

Slide 93 text

Applying Microservices Patterns to a Modular Monolith Demo

Slide 94

Slide 94 text

Applying Microservices Patterns to a Modular Monolith Demo Implementation of the mentioned domain and app

Slide 95

Slide 95 text

Applying Microservices Patterns to a Modular Monolith Demo Implementation of the mentioned domain and app Rails multi-database support

Slide 96

Slide 96 text

Applying Microservices Patterns to a Modular Monolith Demo Implementation of the mentioned domain and app Rails multi-database support Ka f ka as a message bus

Slide 97

Slide 97 text

Applying Microservices Patterns to a Modular Monolith Demo Implementation of the mentioned domain and app Rails multi-database support Ka f ka as a message bus Ka f ka Connect as the outbox publisher

Slide 98

Slide 98 text

Applying Microservices Patterns to a Modular Monolith Demo Implementation of the mentioned domain and app Rails multi-database support Ka f ka as a message bus Ka f ka Connect as the outbox publisher Kara f ka for consumers

Slide 99

Slide 99 text

Applying Microservices Patterns to a Modular Monolith

Slide 100

Slide 100 text

Applying Microservices Patterns to a Modular Monolith

Slide 101

Slide 101 text

Applying Microservices Patterns to a Modular Monolith How did we accomplish this?

Slide 102

Slide 102 text

Applying Microservices Patterns to a Modular Monolith How did we accomplish this?

Slide 103

Slide 103 text

Applying Microservices Patterns to a Modular Monolith How did we accomplish this?

Slide 104

Slide 104 text

Applying Microservices Patterns to a Modular Monolith Event consumers

Slide 105

Slide 105 text

Applying Microservices Patterns to a Modular Monolith Event consumers

Slide 106

Slide 106 text

Applying Microservices Patterns to a Modular Monolith Event consumers

Slide 107

Slide 107 text

Applying Microservices Patterns to a Modular Monolith Event consumers

Slide 108

Slide 108 text

Applying Microservices Patterns to a Modular Monolith Creating the Outbox record

Slide 109

Slide 109 text

Applying Microservices Patterns to a Modular Monolith Creating the Outbox record

Slide 110

Slide 110 text

Applying Microservices Patterns to a Modular Monolith Creating the Outbox record

Slide 111

Slide 111 text

Applying Microservices Patterns to a Modular Monolith Creating the Outbox record

Slide 112

Slide 112 text

Applying Microservices Patterns to a Modular Monolith Creating the Outbox record

Slide 113

Slide 113 text

Applying Microservices Patterns to a Modular Monolith Creating the Outbox record

Slide 114

Slide 114 text

Applying Microservices Patterns to a Modular Monolith Creating the Member record

Slide 115

Slide 115 text

Applying Microservices Patterns to a Modular Monolith Creating the Member record

Slide 116

Slide 116 text

Applying Microservices Patterns to a Modular Monolith Creating the Member record

Slide 117

Slide 117 text

Applying Microservices Patterns to a Modular Monolith Creating the Member record

Slide 118

Slide 118 text

Applying Microservices Patterns to a Modular Monolith Creating the Member record

Slide 119

Slide 119 text

Applying Microservices Patterns to a Modular Monolith Creating the Member record

Slide 120

Slide 120 text

Applying Microservices Patterns to a Modular Monolith Registration rollback

Slide 121

Slide 121 text

Applying Microservices Patterns to a Modular Monolith Registration rollback

Slide 122

Slide 122 text

Applying Microservices Patterns to a Modular Monolith Where to f ind the code github.com/ rootstrap/ rails-modular-monolith-with-ddd/ tree/ main-saga

Slide 123

Slide 123 text

Guillermo Aguirre - RailsConf 2023 What to take away Applying Microservices Patterns to a Modular Monolith

Slide 124

Slide 124 text

Guillermo Aguirre - RailsConf 2023 What to take away 3 widely used patterns Applying Microservices Patterns to a Modular Monolith

Slide 125

Slide 125 text

Guillermo Aguirre - RailsConf 2023 What to take away 3 widely used patterns Dealing with distributed transactions Applying Microservices Patterns to a Modular Monolith

Slide 126

Slide 126 text

Guillermo Aguirre - RailsConf 2023 What to take away 3 widely used patterns Dealing with distributed transactions It's possible to leverage di ff erent solutions Applying Microservices Patterns to a Modular Monolith

Slide 127

Slide 127 text

Guillermo Aguirre - RailsConf 2023 What to take away 3 widely used patterns Dealing with distributed transactions It's possible to leverage di ff erent solutions Not a silver bullet Applying Microservices Patterns to a Modular Monolith

Slide 128

Slide 128 text

Guillermo Aguirre - RailsConf 2023 What to take away 3 widely used patterns Dealing with distributed transactions It's possible to leverage di ff erent solutions Not a silver bullet Inspiring others Applying Microservices Patterns to a Modular Monolith

Slide 129

Slide 129 text

Guillermo Aguirre - RailsConf 2023 Thank you! Applying Microservices Patterns to a Modular Monolith @guillermoap @guillermoap_ @guillermo.aguirre Guillermo Aguirre /gee-SHER-moh ah-GHEE-rreh/