Slide 1

Slide 1 text

HOW TO AVOID BUILDING A DISTRIBUTED MONOLITH Felipe Dornelas

Slide 2

Slide 2 text

As a business, I want to adapt to change fast… 2

Slide 3

Slide 3 text

FAST FEEDBACK CYCLE 3 ▫︎Release ▫︎Learn ▫︎Adapt

Slide 4

Slide 4 text

CONTINUOUS DELIVERY 4 ▫︎Fast and frequent deploys ▫︎Automated tests ▫︎Automated infrastructure

Slide 5

Slide 5 text

THE BIG MONOLITH 5 ▫︎Big codebase ▫︎Tests take a lot of time to run ▫︎Hard to deploy isolated changes

Slide 6

Slide 6 text

THE BIG ORGANIZATION 6 ▫︎Several teams ▫︎Teams might be distributed ▫︎Communication overhead

Slide 7

Slide 7 text

Breaking this app seems to be a good idea, right? 7

Slide 8

Slide 8 text

Let’s build a Services Oriented Architecture (SOA)… 8

Slide 9

Slide 9 text

Behold, the Distributed Monolith™! (it’s a monolith, but distributed) 9

Slide 10

Slide 10 text

Has anyone here survived a failed SOA implementation? 10

Slide 11

Slide 11 text

THE DISTRIBUTED MONOLITH 11 ▫︎Changes to one part…

Slide 12

Slide 12 text

THE DISTRIBUTED MONOLITH 12 ▫︎Break the entire system…

Slide 13

Slide 13 text

"Making changes in lots of different places is slower, and deploying lots of services at once is risky — both of which we want to avoid.” — Sam Newman 13

Slide 14

Slide 14 text

I heard Microservices are the next big thing now… 14

Slide 15

Slide 15 text

Microservices = SOA done right (Pssst… don’t tell anyone) 15

Slide 16

Slide 16 text

The first rule of Microservices is: Do not build Microservices, unless… 16

Slide 17

Slide 17 text

WHEN TO BREAK THE MONOLITH 17 ▫︎Big codebase ▫︎Large team ▫︎Tests take a long time to run ▫︎Hard to deploy isolated changes ▫︎Too much overhead

Slide 18

Slide 18 text

WE ARE GOING TO TALK ABOUT 18 ▫︎How to model services ▫︎Integration techniques ▫︎Organizational alignment

Slide 19

Slide 19 text

HOW TO MODEL SERVICES 19

Slide 20

Slide 20 text

LOOSE COUPLING 20 ▫︎We want to deploy changes in isolation

Slide 21

Slide 21 text

HIGH COHESION 21 ▫︎We want to change related behavior in one place

Slide 22

Slide 22 text

BOUNDED CONTEXTS 22 ▫︎We want to find boundaries within our problem domain

Slide 23

Slide 23 text

THE CELL ANALOGY 23 Boundary (Membrane) Hidden Model (Nucleus) Shared Model (Nutrients)

Slide 24

Slide 24 text

It’s all about aligning your services into business capabilities 24

Slide 25

Slide 25 text

BOUNDED CONTEXTS 25 Warehouse Finance

Slide 26

Slide 26 text

SHARED MODEL 26

Slide 27

Slide 27 text

NESTED BOUNDED CONTEXTS 27

Slide 28

Slide 28 text

NESTED BOUNDED CONTEXTS 28 Order fulfilment Inventory Goods receiving Warehouse Domain

Slide 29

Slide 29 text

SEAMS 29 ▫︎Portion of the code that can be treated in isolation ▫︎Should be aligned with business capabilities

Slide 30

Slide 30 text

SEAMS 30 ▫︎Group code by bounded contexts - com.example.finance - com.example.warehouse - com.example.warehouse.order - com.example.warehouse.goods - com.example.warehouse.inventory

Slide 31

Slide 31 text

PREMATURE DECOMPOSITION 31 ▫︎Do not create services until you understand the domain very well

Slide 32

Slide 32 text

BREAKING THE MONOLITH 32 Seam being extracted into service

Slide 33

Slide 33 text

COARSE TO GRANULAR 33

Slide 34

Slide 34 text

NESTED BOUNDED CONTEXTS 34

Slide 35

Slide 35 text

EXPOSED BOUNDED CONTEXTS 35

Slide 36

Slide 36 text

AVOID TECHNICAL SEAMS 36 ▫︎Ex: exceptions, services, utils…

Slide 37

Slide 37 text

AVOID TECHNICAL SEAMS 37 ▫︎Ex: backend, database service ▫︎Layered system ▫︎Onion architecture

Slide 38

Slide 38 text

AVOID ANEMIC SERVICES 38 ▫︎Ex: CRUD-only ▫︎Start with coarse-grained services ▫︎Break them down only if necessary

Slide 39

Slide 39 text

INTEGRATION 39

Slide 40

Slide 40 text

"Making changes in lots of different places is slower, and deploying lots of services at once is risky — both of which we want to avoid.” — Sam Newman 40

Slide 41

Slide 41 text

41 AVOID BREAKING CHANGES

Slide 42

Slide 42 text

42 HIDE IMPLEMENTATION DETAILS

Slide 43

Slide 43 text

43 TECHNOLOGY AGNOSTIC APIS

Slide 44

Slide 44 text

INTEGRATION TECHNOLOGIES 44 ▫︎RPC ▫︎REST ▫︎Database ▫︎Message Queues

Slide 45

Slide 45 text

RPC 45 ▫︎Ex: SOAP, Thrift, Protocol Buffers ▫︎Hides the complexity of a remote call ▫︎Generates client stubs ▫︎Easy, but…

Slide 46

Slide 46 text

SOAP PROBLEMS 46 ▫︎Tight coupling ▫︎Changes requires all clients to be updated… ▫︎Even for not consumed data

Slide 47

Slide 47 text

SOAP PROBLEMS 47 ▫︎Network calls are transparent ▫︎But the network is not reliable!

Slide 48

Slide 48 text

TOLERANT READERS 48 ▫︎Ex: if you're consuming an XML file, only take the elements you need ▫︎Ignore anything you don’t

Slide 49

Slide 49 text

“An implementation should be conservative in its sending behavior, and liberal in its receiving behavior” — Jon Postel 49

Slide 50

Slide 50 text

Postel’s Law 50

Slide 51

Slide 51 text

REST-RPC 51 ▫︎POST /submitOrder ▫︎GET /findOrderById ▫︎GET /findOrderByUser

Slide 52

Slide 52 text

REST-RPC PROBLEMS 52 ▫︎Think about actions instead of things ▫︎Hard to align with bounded contexts ▫︎Not uniform ▫︎OK in some cases…

Slide 53

Slide 53 text

REST 53 ▫︎GET /orders?user=john_doe ▫︎GET /orders/12345678 ▫︎POST /orders ▫︎PUT /orders/12345678

Slide 54

Slide 54 text

REST BENEFITS 54 ▫︎Think about resources (things) ▫︎Aligned with bounded contexts

Slide 55

Slide 55 text

REST BENEFITS 55 ▫︎Addressability ▫︎Statelessness ▫︎Connectedness ▫︎Uniform Interface

Slide 56

Slide 56 text

AVOID SHARED DATABASES 56

Slide 57

Slide 57 text

SHARED DATABASE PROBLEMS 57 ▫︎Tight coupling ▫︎Exposes implementation details ▫︎Technology lock-in

Slide 58

Slide 58 text

Services should own their data 58

Slide 59

Slide 59 text

SHARED LIBRARIES 59 ▫︎DRY - Don’t Repeat Yourself ▫︎We want to avoid duplicating system behavior and knowledge ▫︎Code reuse FTW, right?

Slide 60

Slide 60 text

SHARED LIBRARIES 60 ▫︎Potential coupling! ▫︎Updating a library might require changes to lots services at once

Slide 61

Slide 61 text

“The evils of too much coupling between services are far worse than the problems caused by code duplication” — Sam Newman 61

Slide 62

Slide 62 text

SHARED LIBRARIES 62 ▫︎Never share business logic ▫︎Use templates to bootstrap your service ▫︎OK to share that logging library… ▫︎Independent versioning

Slide 63

Slide 63 text

63 SYNCHRONOUS VS. ASYNCHRONOUS

Slide 64

Slide 64 text

64 REQUESTS VS. EVENTS

Slide 65

Slide 65 text

65 ORCHESTRATION VS. CHOREOGRAPHY

Slide 66

Slide 66 text

EXAMPLE BUSINESS PROCESS 66

Slide 67

Slide 67 text

ORCHESTRATION 67

Slide 68

Slide 68 text

CHOREOGRAPHY 68

Slide 69

Slide 69 text

"Systems that tend more toward the choreographed approach are more loosely coupled, and are more flexible and amenable to change.” — Sam Newman 69

Slide 70

Slide 70 text

SERVICES AND THE ORGANIZATION 70

Slide 71

Slide 71 text

"Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations” — M. Conway 71

Slide 72

Slide 72 text

Conway’s Law 72

Slide 73

Slide 73 text

TECHNOLOGY-ORIENTED TEAMS 73 Front-End Team Back-End Team Database Team

Slide 74

Slide 74 text

FUNCTIONAL SILOS 74 Back-End Front-End Database

Slide 75

Slide 75 text

LAYERED DISTRIBUTED SYSTEM 75

Slide 76

Slide 76 text

“I called this onion architecture, as it had lots of layers and made me cry when we had to cut through it.” — Sam Newman 76

Slide 77

Slide 77 text

FEATURE TEAMS 77

Slide 78

Slide 78 text

FEATURE TEAMS 78 ▫︎Work across several systems ▫︎Own the application lifecycle ▫︎Autonomy to make changes

Slide 79

Slide 79 text

“If you can’t feed a team with two- pizza, it’s too large.” — Jeff Bezos (Amazon) 79

Slide 80

Slide 80 text

BOUNDED CONTEXTS 80 Order fulfilment Inventory Goods receiving Warehouse Domain

Slide 81

Slide 81 text

BOUNDED CONTEXTS 81 Order fulfillment Inventory Goods receiving Warehouse Domain

Slide 82

Slide 82 text

Teams should have complete ownership of the services inside their bounded contexts 82

Slide 83

Slide 83 text

WINDOWS VISTA 83 ▫︎"The Influence of Organizational Structure On Software Quality: An Empirical Case Study"

Slide 84

Slide 84 text

84 AMAZON

Slide 85

Slide 85 text

85 NETFLIX, SPOTIFY…

Slide 86

Slide 86 text

REALSTATE.COM.AU 86

Slide 87

Slide 87 text

THE BOOK 87

Slide 88

Slide 88 text

→ felipedornelas.com THANK YOU