Slide 1

Slide 1 text

TAMING MONOLITHS WITHOUT MICROSERVICES Kelly Sutton — Rubyconf AU 2019

Slide 2

Slide 2 text

Overview I. About Me II. Breaking the Monolith III. Tactics IV. Wrap Up kellysutton.com

Slide 3

Slide 3 text

Part I: About Me

Slide 4

Slide 4 text

About Me

Slide 5

Slide 5 text

About Greta

Slide 6

Slide 6 text

About Greta

Slide 7

Slide 7 text

About Greta

Slide 8

Slide 8 text

About Greta

Slide 9

Slide 9 text

But that’s not why we’re here kellysutton.com

Slide 10

Slide 10 text

We’re here to talk about Rails projects that push the limits kellysutton.com

Slide 11

Slide 11 text

kellysutton.com

Slide 12

Slide 12 text

Time Geography Money People kellysutton.com

Slide 13

Slide 13 text

Correctness > Performance kellysutton.com

Slide 14

Slide 14 text

What goes wrong, when things get too big kellysutton.com

Slide 15

Slide 15 text

Part II: Breaking the Monolith

Slide 16

Slide 16 text

The Swamp kellysutton.com

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

kellysutton.com

Slide 19

Slide 19 text

kellysutton.com

Slide 20

Slide 20 text

The Swamp Payroll HR Benefits Infra kellysutton.com

Slide 21

Slide 21 text

“Let’s Extract a Service!” kellysutton.com

Slide 22

Slide 22 text

Photo by Thomas Halfmann kellysutton.com

Slide 23

Slide 23 text

The Swamp Payroll HR Benefits Infra kellysutton.com

Slide 24

Slide 24 text

The Swamp Payroll HR Benefits Infra kellysutton.com

Slide 25

Slide 25 text

The Swamp Payroll HR Benefits Infra HR v2 kellysutton.com

Slide 26

Slide 26 text

The Swamp Payroll HR Benefits Infra HR v2 kellysutton.com

Slide 27

Slide 27 text

The Swamp Payroll Old HR Benefits Infra HR v2 kellysutton.com

Slide 28

Slide 28 text

But there is a better way

Slide 29

Slide 29 text

kellysutton.com

Slide 30

Slide 30 text

Employee HR Payroll kellysutton.com

Slide 31

Slide 31 text

Employee HR Payroll kellysutton.com

Slide 32

Slide 32 text

Employee HR Payroll employee.last_name kellysutton.com

Slide 33

Slide 33 text

HR Payroll kellysutton.com

Slide 34

Slide 34 text

HR Payroll kellysutton.com

Slide 35

Slide 35 text

HR Payroll Employee PayrollEmployee kellysutton.com

Slide 36

Slide 36 text

HR Payroll Employee PayrollEmployee kellysutton.com

Slide 37

Slide 37 text

HR Payroll Employee PayrollEmployee payroll_employee.last_name kellysutton.com

Slide 38

Slide 38 text

HR Payroll kellysutton.com

Slide 39

Slide 39 text

HR Payroll kellysutton.com

Slide 40

Slide 40 text

Value Objects HR Payroll kellysutton.com

Slide 41

Slide 41 text

Conceptual Compression

Slide 42

Slide 42 text

Conceptual Expansion

Slide 43

Slide 43 text

Part III: Tactics

Slide 44

Slide 44 text

Recommendation #1 Mind and Avoid Circular Dependencies kellysutton.com

Slide 45

Slide 45 text

As your Rails code base grows, question bidirectional relationships kellysutton.com

Slide 46

Slide 46 text

1 # app/models/company.rb 2 class Company < ApplicationRecord 3 has_many :employees 4 end 5 6 # app/models/employee.rb 7 class Employee < ApplicationRecord 8 belongs_to :company 9 end kellysutton.com

Slide 47

Slide 47 text

1 # app/models/company.rb 2 class Company < ApplicationRecord 3 has_many :employees 4 end 5 6 # app/models/employee.rb 7 class Employee < ApplicationRecord 8 belongs_to :company 9 end Do we need this? kellysutton.com

Slide 48

Slide 48 text

Company Employee kellysutton.com

Slide 49

Slide 49 text

Company Employee kellysutton.com

Slide 50

Slide 50 text

Recommendation #2 Use Value Objects to Traverse Edges kellysutton.com

Slide 51

Slide 51 text

1 # app/services/company_signed_up.rb 2 class CompanySignedUp 3 def self.call(company) 4 CompanyMailer.welcome_email(company) 5 StatsTracker.company_signed_up(company) 6 end 7 end kellysutton.com

Slide 52

Slide 52 text

1 # app/services/company_signed_up.rb 2 class CompanySignedUp 3 def self.call(company) 4 user_first_name = company.admin_first_name 5 email = company.admin_email 6 7 CompanyMailer.welcome_email(email, user_first_name) 8 StatsTracker.company_signed_up(company.id) 9 end 10 end kellysutton.com

Slide 53

Slide 53 text

Recommendation #3 Avoid Callbacks kellysutton.com

Slide 54

Slide 54 text

1 # app/models/company.rb 2 class Company < ApplicationRecord 3 after_create :send_update_email, if: :has_email? 4 5 private 6 7 def send_update_email 8 CompanyMailer.welcome_email(self) 9 end 10 end kellysutton.com

Slide 55

Slide 55 text

Company CompanyMailer kellysutton.com

Slide 56

Slide 56 text

1 # app/services/create_company.rb 2 class CreateCompany 3 def self.call(company_params) 4 company = Company.create!(company_params) 5 6 CompanyMailer.welcome_email(company) 7 end 8 end kellysutton.com

Slide 57

Slide 57 text

Company CompanyMailer CreateCompany kellysutton.com

Slide 58

Slide 58 text

Recommendation #4 Move slowly! kellysutton.com

Slide 59

Slide 59 text

Part IV: Wrap Up kellysutton.com

Slide 60

Slide 60 text

–Kent Beck “Make the hard change easy (this may be hard), then make the easy change.” kellysutton.com

Slide 61

Slide 61 text

Thanks! Slides and more available at kellysutton.com

Slide 62

Slide 62 text

References • Bernhardt, Gary. “Boundaries.” 2012. • Bernhardt, Gary. “Functional Core, Imperative Shell.” 2012. • Evans, Eric. “Domain-Driven Design: Tackling Complexity in the Heart of Software.” 2003. • Fowler, Martin, et al. “Refactoring: Improving the Design of Existing Code.” 1999. • Feathers, Michael. “Working Effectively with Legacy Code.” 2004. • Hickey, Rich. “Simple Made Easy.” 2011. • Hickey, Rich. “The Value of Values.” 2012. • Scott, James C. “Seeing Like a State.” 1999. • Searls, Justin. “My Preferred Method of TDD.” 2017 • Spolsky, Joel. “Things You Should Never Do, Part I.” 2006.

Slide 63

Slide 63 text

Special Thanks • Noa Elad • Matan Zruya • Sihui Huang • Natalie Wong • Karlo Hoa • Amelie Meyer-Robinson • Quentin Balin