Slide 1

Slide 1 text

Microservices vs The distributed monolith Christopher Riley PHP Scotland 2016 1

Slide 2

Slide 2 text

Introduction

Slide 3

Slide 3 text

Monolith vs Microservices 2

Slide 4

Slide 4 text

Key features of a monolith architecture • A monolith is a single app combining multiple business functions. 3

Slide 5

Slide 5 text

Key features of a monolith architecture • A monolith is a single app combining multiple business functions. • A monolith is deployed and scaled as a whole. 3

Slide 6

Slide 6 text

Key features of a monolith architecture • A monolith is a single app combining multiple business functions. • A monolith is deployed and scaled as a whole. • A monolith is developed on a single technology stack. 3

Slide 7

Slide 7 text

Key features of a microservice architecture • A microservice should have one responsibility. 4

Slide 8

Slide 8 text

Key features of a microservice architecture • A microservice should have one responsibility. • Each microservice should be independent. 4

Slide 9

Slide 9 text

Key features of a microservice architecture • A microservice should have one responsibility. • Each microservice should be independent. • A microservice should have a defined API. 4

Slide 10

Slide 10 text

Key features of a microservice architecture • A microservice should have one responsibility. • Each microservice should be independent. • A microservice should have a defined API. • Smart endpoints, dumb pipes 4

Slide 11

Slide 11 text

Advantages of microservices • Improved modularisation of code 5

Slide 12

Slide 12 text

Advantages of microservices • Improved modularisation of code • Allows diverse technology stacks 5

Slide 13

Slide 13 text

Advantages of microservices • Improved modularisation of code • Allows diverse technology stacks • Independent deployment and scaling 5

Slide 14

Slide 14 text

Advantages of microservices • Improved modularisation of code • Allows diverse technology stacks • Independent deployment and scaling • Smaller code base 5

Slide 15

Slide 15 text

Disadvantages of microservices • Availability 6

Slide 16

Slide 16 text

Disadvantages of microservices • Availability • Knowledge siloing 6

Slide 17

Slide 17 text

Disadvantages of microservices • Availability • Knowledge siloing • Testing of whole system is complex 6

Slide 18

Slide 18 text

Disadvantages of microservices • Availability • Knowledge siloing • Testing of whole system is complex • Orchestration of system is harder 6

Slide 19

Slide 19 text

The Distributed Monolith

Slide 20

Slide 20 text

Don’t panic 6

Slide 21

Slide 21 text

The common library

Slide 22

Slide 22 text

What makes this so bad? • Microservices loose their independence. 7

Slide 23

Slide 23 text

What makes this so bad? • Microservices loose their independence. • The common library becomes huge. 7

Slide 24

Slide 24 text

What makes this so bad? • Microservices loose their independence. • The common library becomes huge. • The common library becomes unstable. 7

Slide 25

Slide 25 text

What makes this so bad? • Microservices loose their independence. • The common library becomes huge. • The common library becomes unstable. • Discourages technological diversity. 7

Slide 26

Slide 26 text

What is the solution? • Small focused libraries 8

Slide 27

Slide 27 text

What is the solution? • Small focused libraries • Only include what is required 8

Slide 28

Slide 28 text

What is the solution? • Small focused libraries • Only include what is required • Composer can help you 8

Slide 29

Slide 29 text

What is the solution? • Small focused libraries • Only include what is required • Composer can help you • Sometimes you just have to copy + paste 8

Slide 30

Slide 30 text

Interdependent deployments

Slide 31

Slide 31 text

What makes this so bad? • Live demo! 9

Slide 32

Slide 32 text

What makes this so bad? • Live demo! • Each simultaneous deployment increases risk 9

Slide 33

Slide 33 text

What makes this so bad? • Live demo! • Each simultaneous deployment increases risk • What about rollbacks? 9

Slide 34

Slide 34 text

What is the solution? • API versioning 10

Slide 35

Slide 35 text

What is the solution? • API versioning • Feature flags 10

Slide 36

Slide 36 text

What is the solution? • API versioning • Feature flags • Automation 10

Slide 37

Slide 37 text

Temporal coupling

Slide 38

Slide 38 text

Booking a ticket 11

Slide 39

Slide 39 text

Booking a ticket 11

Slide 40

Slide 40 text

Booking a ticket 11

Slide 41

Slide 41 text

Booking a ticket 11

Slide 42

Slide 42 text

Booking a ticket 11

Slide 43

Slide 43 text

Booking a ticket 11

Slide 44

Slide 44 text

Booking a ticket 11

Slide 45

Slide 45 text

Booking a ticket 11

Slide 46

Slide 46 text

Booking a ticket 11

Slide 47

Slide 47 text

What makes this so bad? • Performance 12

Slide 48

Slide 48 text

What makes this so bad? • Performance • Services must wait for a response 12

Slide 49

Slide 49 text

What makes this so bad? • Performance • Services must wait for a response • What happens when something fails? 12

Slide 50

Slide 50 text

Distributed transactions are HARD! 12

Slide 51

Slide 51 text

Summing up

Slide 52

Slide 52 text

Decoupling microservices • Avoid “nanoservices” 13

Slide 53

Slide 53 text

Decoupling microservices • Avoid “nanoservices” • Define clear boundaries 13

Slide 54

Slide 54 text

Decoupling microservices • Avoid “nanoservices” • Define clear boundaries • Communicate asynchronously 13

Slide 55

Slide 55 text

Event driven architecture

Slide 56

Slide 56 text

A familiar model 14

Slide 57

Slide 57 text

Event sourcing example 15

Slide 58

Slide 58 text

Event driven architecture 16

Slide 59

Slide 59 text

Projections • Turn events into read models 17

Slide 60

Slide 60 text

Projections • Turn events into read models • Need to be able to recover after downtime 17

Slide 61

Slide 61 text

Projections • Turn events into read models • Need to be able to recover after downtime • Can be rebuilt 17

Slide 62

Slide 62 text

Process managers • Handle business logic around events 18

Slide 63

Slide 63 text

Process managers • Handle business logic around events • A state machine 18

Slide 64

Slide 64 text

Process managers • Handle business logic around events • A state machine • Be careful with replays 18

Slide 65

Slide 65 text

Event replays 19

Slide 66

Slide 66 text

Event replays 20

Slide 67

Slide 67 text

Advantages of event driven architecture • Decouples microservices 21

Slide 68

Slide 68 text

Advantages of event driven architecture • Decouples microservices • Scales well 21

Slide 69

Slide 69 text

Advantages of event driven architecture • Decouples microservices • Scales well • Easier to change 21

Slide 70

Slide 70 text

Advantages of event driven architecture • Decouples microservices • Scales well • Easier to change • No distributed transactions 21

Slide 71

Slide 71 text

Conclusions

Slide 72

Slide 72 text

Every architectural decision involves tradeoffs 21

Slide 73

Slide 73 text

Start big 21

Slide 74

Slide 74 text

Favour autonomy over the single responsibility principal 21

Slide 75

Slide 75 text

Embrace eventual consistency 21

Slide 76

Slide 76 text

Thanks • @giveupalready • https://github.com/carnage • https://carnage.github.io • http://joind.in/talk/d65df 22