Slide 1

Slide 1 text

The Myth of the Modular Monolith Eileen M. Uchitelle Rails World 2024

Slide 2

Slide 2 text

Eileen M. Uchitelle @eileencodes eileencodes.com

Slide 3

Slide 3 text

Ruby & Rails Infra at Shopify

Slide 4

Slide 4 text

Rails Core Team since 2017

Slide 5

Slide 5 text

2010 🧍 My 14 years of Rails Small & large companies

Slide 6

Slide 6 text

2010 2024 My 14 years of Rails Small & large companies 🌎 🧍

Slide 7

Slide 7 text

2010 My 14 years of Rails New & legacy applications 👧

Slide 8

Slide 8 text

2010 2024 👧 My 14 years of Rails New & legacy applications 👵

Slide 9

Slide 9 text

2010 👩💻 My 14 years of Rails New developers & DHH

Slide 10

Slide 10 text

2010 2024 My 14 years of Rails New developers & DHH 🏎 👩💻

Slide 11

Slide 11 text

2014 My 14 years of Rails Applications I've worked on

Slide 12

Slide 12 text

2014 2022 My 14 years of Rails Applications I've worked on

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

2014 2024 My 14 years of Rails Applications I've worked on 2017

Slide 15

Slide 15 text

💩💻

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

The Myth of the Modular Monolith

Slide 22

Slide 22 text

Common problems in large monoliths

Slide 23

Slide 23 text

Common problems: Architectural

Slide 24

Slide 24 text

Architectural ‣ Lack of organization and structure

Slide 25

Slide 25 text

Architectural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries

Slide 26

Slide 26 text

Common problems: Operational

Slide 27

Slide 27 text

Operational ‣ Flaky tests and slow CI Architectural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries

Slide 28

Slide 28 text

Operational ‣ Flaky tests and slow CI ‣ Scalability of deployments Architectural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries

Slide 29

Slide 29 text

Common problems: Organizational

Slide 30

Slide 30 text

Operational ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational ‣ Dif fi cult to assign and fi nd owners Architectural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries

Slide 31

Slide 31 text

Operational ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational ‣ Dif fi cult to assign and fi nd owners ‣ Onboarding new hires takes too long Architectural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries

Slide 32

Slide 32 text

"I can't hold the whole app in my head!"

Slide 33

Slide 33 text

*slaps roof of head*

Slide 34

Slide 34 text

*slaps roof of head* This bad boy can fi t so many models.

Slide 35

Slide 35 text

"I can't hold the whole app in my head!"

Slide 36

Slide 36 text

Operational ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational ‣ Dif fi cult to assign and fi nd owners ‣ Onboarding new hires is dif fi cult Architectural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries

Slide 37

Slide 37 text

What is a modular monolith?

Slide 38

Slide 38 text

Modular monolith: Use the same language.

Slide 39

Slide 39 text

Modular monolith: Use the same infrastructure.

Slide 40

Slide 40 text

Modular monolith: Path to package isolation.

Slide 41

Slide 41 text

How to implement a modular monolith

Slide 42

Slide 42 text

📁 app 📁 models 📄 dog.rb 📄 cat.rb 📄 tree.rb 📄 flower.rb 📁 controllers 📄 dogs_controller.rb 📄 cats_controller.rb Fur & Foliage Application

Slide 43

Slide 43 text

📁 packages 📁 pets 📄 dog.rb 📄 cat.rb 📁 app 📁 models 📁 plants 📄 tree.rb 📄 flower.rb 📁 app 📁 models

Slide 44

Slide 44 text

📁 packages 📁 pets 📄 dog.rb 📄 cat.rb 📁 app 📁 models 📁 plants 📄 tree.rb 📄 flower.rb 📁 app 📁 models

Slide 45

Slide 45 text

📁 packages 📁 pets 📄 dog.rb 📄 cat.rb 📁 app 📁 models 📁 plants 📄 tree.rb 📄 flower.rb 📁 app 📁 models

Slide 46

Slide 46 text

📁 packages 📁 pets 📄 dog.rb 📄 cat.rb 📁 app 📁 models 📁 plants 📄 tree.rb 📄 flower.rb 📁 app 📁 models

Slide 47

Slide 47 text

How to enforce monolith boundaries

Slide 48

Slide 48 text

Packwerk: github.com/Shopify/ packwerk

Slide 49

Slide 49 text

# packages/pets/package.yml metadata: stewards: - "@FurAndFoliage/pets" slack_channels: - "#help-pets" - "#team-pets" enforce_dependencies: strict dependencies: - packages/plants

Slide 50

Slide 50 text

# packages/pets/package_todo.yml packages/billing: "::Billing::Subscriptions::TestHelper": violations: - dependency files: - packages/pets/test/helpers/dog_test_helper.rb packages/stores: "::Store::TimelineEvent": violations: - dependency files: - packages/pets/app/models/dog.rb - packages/pets/app/controllers/dogs_controller.rb

Slide 51

Slide 51 text

The problem with full isolation

Slide 52

Slide 52 text

The problem with full isolation

Slide 53

Slide 53 text

New Challenges: Primitive obsession.

Slide 54

Slide 54 text

# passing primitives instead of the cat AR object class Flower < ApplicationRecord def cat_can_eat?(cat_id) cat = Pets::CatGetter.find_cat(cat_id) cat && self.safe_for_cat?(cat) end end

Slide 55

Slide 55 text

New Challenges: Primitive obsession.

Slide 56

Slide 56 text

New Challenges: Ownership obsession.

Slide 57

Slide 57 text

Pets Plants X

Slide 58

Slide 58 text

New Challenges: Package obsession.

Slide 59

Slide 59 text

Canine Feline Daisy Birch Maple Aster

Slide 60

Slide 60 text

New Challenges: Code duplication.

Slide 61

Slide 61 text

New Challenges: Circular dependencies.

Slide 62

Slide 62 text

Pets Plants

Slide 63

Slide 63 text

How modularization falls short

Slide 64

Slide 64 text

Operational ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational ‣ Dif fi cult to assign and fi nd owners ‣ Onboarding new hires is dif fi cult Architectural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries

Slide 65

Slide 65 text

Architectural Cultural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries Operational Cultural ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational Cultural ‣ Dif fi cult to assign and fi nd owners ‣ Onboarding new hires is dif fi cult

Slide 66

Slide 66 text

Improve structure & organization?

Slide 67

Slide 67 text

Improve structure & organization? No.

Slide 68

Slide 68 text

Code is less tightly coupled?

Slide 69

Slide 69 text

Code is less tightly coupled? No.

Slide 70

Slide 70 text

Architectural Cultural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries Operational Cultural ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational Cultural ‣ Dif fi cult to assign and fi nd owners ‣ Onboarding new hires is dif fi cult

Slide 71

Slide 71 text

Architectural Cultural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries Operational Cultural ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational Cultural ‣ Dif fi cult to assign and fi nd owners ‣ Onboarding new hires is dif fi cult

Slide 72

Slide 72 text

CI is faster with less fl aky tests?

Slide 73

Slide 73 text

CI is faster with less fl aky tests? No.

Slide 74

Slide 74 text

Deploys are more scalable?

Slide 75

Slide 75 text

Deploys are more scalable? Not yet.

Slide 76

Slide 76 text

Architectural Cultural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries Operational Cultural ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational Cultural ‣ Dif fi cult to assign and fi nd owners ‣ Onboarding new hires is dif fi cult

Slide 77

Slide 77 text

Architectural Cultural ‣ Lack of organization and structure ‣ Tight coupling & no boundaries Operational Cultural ‣ Flaky tests and slow CI ‣ Scalability of deployments Organizational Cultural ‣ Dif fi cult to assign and fi nd owners ‣ Onboarding new hires is dif fi cult

Slide 78

Slide 78 text

Find & assigning owners is easier?

Slide 79

Slide 79 text

Find & assigning owners is easier? Somewhat.

Slide 80

Slide 80 text

Onboarding new hires is easier?

Slide 81

Slide 81 text

Onboarding new hires is easier? No.

Slide 82

Slide 82 text

Why do we have these problems?

Slide 83

Slide 83 text

You cannot solve human problems with modularity.

Slide 84

Slide 84 text

What causes these problems?

Slide 85

Slide 85 text

Causes: Pressure to ship.

Slide 86

Slide 86 text

Causes: Allowing tech debt to grow.

Slide 87

Slide 87 text

Causes: Hiring faster than you can onboard.

Slide 88

Slide 88 text

Causes: Misaligned incentives.

Slide 89

Slide 89 text

Causes: Blame-based development.

Slide 90

Slide 90 text

How do we fi x these problems?

Slide 91

Slide 91 text

Team culture: Improve developer education.

Slide 92

Slide 92 text

Team culture: Indoctrinate non-Rubyists.

Slide 93

Slide 93 text

Team culture: Reprioritize quality.

Slide 94

Slide 94 text

Team culture: Realign reward incentives.

Slide 95

Slide 95 text

When to implement modularization

Slide 96

Slide 96 text

Modularization: Start with just a few packages.

Slide 97

Slide 97 text

Modularization: Functional isolation.

Slide 98

Slide 98 text

Modularization: Don't do it prematurely.

Slide 99

Slide 99 text

Don't fall for the sunk cost fallacy.

Slide 100

Slide 100 text

Scaling large applications is hard

Slide 101

Slide 101 text

We act like the ball of mud Is inevitable.

Slide 102

Slide 102 text

These problems aren't caused by Ruby on Rails.

Slide 103

Slide 103 text

You can't engineer yourself out of a large org.

Slide 104

Slide 104 text

We want someone or something to blame.

Slide 105

Slide 105 text

Engineering culture comes from the top.

Slide 106

Slide 106 text

You cannot solve human problems with modularity.

Slide 107

Slide 107 text

Let's invest in fi xing our human problems.

Slide 108

Slide 108 text

Thank You ❤