Slide 1

Slide 1 text

JEAN-MARIE LAMODIERE Build microservices since 07/2015 @JMLamodiere MICROSERVICES? THINK TWICE! Linkvalue | Jean-Marie Lamodière 1 Les microservices, c'est pas automatique ! 1935 CP Committed to innovate LINKVALUE

Slide 2

Slide 2 text

Linkvalue | Jean-Marie Lamodière ASHAMED OF YOUR MONOLITH?  Spaghetti code  Side effects  Team velocity decreasing  Hard to refactor  Bugs 2

Slide 3

Slide 3 text

Linkvalue | Jean-Marie Lamodière 3

Slide 4

Slide 4 text

Linkvalue | Jean-Marie Lamodière 4

Slide 5

Slide 5 text

Linkvalue | Jean-Marie Lamodière PROBLEMS THEY SOLVE 1.Autonomy 2.Autonomy 3.Autonomy 5

Slide 6

Slide 6 text

Linkvalue | Jean-Marie Lamodière PROBLEMS THEY SOLVE 1.Autonomy : deployment 2.Autonomy : langage, framework 3.Autonomy : scalability 6

Slide 7

Slide 7 text

Linkvalue | Jean-Marie Lamodière 7

Slide 8

Slide 8 text

Linkvalue | Jean-Marie Lamodière WHY AUTONOMY MATTERS?  Loosely coupled organisation = less coupled systems  Quality audit on windows vista : organizational structures = most important factor!  Team accountability 8

Slide 9

Slide 9 text

Linkvalue | Jean-Marie Lamodière OTHER KEY BENEFITS  Easier for newcomers  Allows isolated POC  Teams scalability  Simpler code design  Easy refactoring 9

Slide 10

Slide 10 text

Linkvalue | Jean-Marie Lamodière WHO USES IT?  Uber  Netflix  Amazon  Ebay  Sound Cloud  Groupon 10  Guilt  Zalando  Spotify  Meetic  M6 Web  Auchan

Slide 11

Slide 11 text

Linkvalue | Jean-Marie Lamodière « Trade-offs » appears 24x in « Building Microservices » book 11

Slide 12

Slide 12 text

Linkvalue | Jean-Marie Lamodière 12

Slide 13

Slide 13 text

Linkvalue | Jean-Marie Lamodière TESTIMONY (45' talks published on )  « We had to fall back to a monolith, and retry when ready » – SAMUEL ROZE PHP Tour 2016 • Prenons soin de nos microservices  « I wish I had known... » – MATT RANNEY GOTO 2016 • What I Wish I Had Known Before Scaling Uber to 1000 Services 13

Slide 14

Slide 14 text

Linkvalue | Jean-Marie Lamodière 14

Slide 15

Slide 15 text

Linkvalue | Jean-Marie Lamodière WHAT IS SO COMPLEX ?  Boundaries : hard to find / change  Huuuge dev-ops stack  Distributed system  Failure handling  Monitoring  End-to-end testing 15

Slide 16

Slide 16 text

Linkvalue | Jean-Marie Lamodière 16

Slide 17

Slide 17 text

Linkvalue | Jean-Marie Lamodière BOUNDARIES : WHERE TO SPLIT?  Splitting = hard to change  Size ? Small enough, not smaller  Splitting by technical layers? no!  Things that should change together (« S » in S.O.L.I.D.)  Loose coupling, high cohesion 17

Slide 18

Slide 18 text

Linkvalue | Jean-Marie Lamodière DDD* TO THE RESCUE! (* Domain Driven Design) Toolset to help domain experts and developers to refine and share domain knowledge, reflect it in the code base, and prioritize efforts. 18

Slide 19

Slide 19 text

Linkvalue | Jean-Marie Lamodière MAKE THE IMPLICIT, EXPLICIT! 19 Copyright @DDDreboot ;)

Slide 20

Slide 20 text

Linkvalue | Jean-Marie Lamodière SPLIT BY BOUNDED CONTEXT  Bounded context = Team sharing the same « ubiquitous language » (same terms)  Vertical, business-focus slice 20

Slide 21

Slide 21 text

Linkvalue | Jean-Marie Lamodière WHEN TO SPLIT ?  When ready : technical stack chosen, architectural decisions taken, devs and ops willing to go, autonomous 2 pizza feature teams  When sure of a splitting point  Start with a monolith (!) to find them 21

Slide 22

Slide 22 text

Linkvalue | Jean-Marie Lamodière CONWAY'S LAW « Organizations which design systems are constrained to produce designs which are copies of the communication structures of these organizations » 22

Slide 23

Slide 23 text

Linkvalue | Jean-Marie Lamodière 2ND LAW OF CONSULTING (Gerald Weinberg) 23

Slide 24

Slide 24 text

Linkvalue | Jean-Marie Lamodière SPLITTING STRATEGY  Implement double-writing (microservice or legacy side)  Publish needed messages  One-shot data import script  Assert data is sync  Read from microservice 24

Slide 25

Slide 25 text

Linkvalue | Jean-Marie Lamodière COMMUNICATION BETWEEN µS  No shared database!  Language agnostic (ex : rest / json)  If weakly typed (json), have a clear doc (optional? nullable?) or json-schema  Keep consistency. ex : pagination  Define minimal customer-centric api 25

Slide 26

Slide 26 text

Linkvalue | Jean-Marie Lamodière COMMUNICATION BETWEEN µS 26

Slide 27

Slide 27 text

Linkvalue | Jean-Marie Lamodière 27

Slide 28

Slide 28 text

Linkvalue | Jean-Marie Lamodière SYNCHRONOUS COMMUNICATION - PROS -  Easier to understand (= method call)  Easier transition from monolith  Instant feedback to the client 28

Slide 29

Slide 29 text

Linkvalue | Jean-Marie Lamodière SYNCHRONOUS COMMUNICATION 29 29 User Optin Other service depending on 1 optin Register Register french user Read 1 optin Read

Slide 30

Slide 30 text

Linkvalue | Jean-Marie Lamodière SYNCHRONOUS COMMUNICATION - CONS -  Fanout : 1% slow calls more probable when cascading calls  Beware of coupling !  Beware of distributed monolith !! 30

Slide 31

Slide 31 text

31 « Distributed monolith » @tiffyshindo

Slide 32

Slide 32 text

Linkvalue | Jean-Marie Lamodière ASYNCHRONOUS COMMUNICATION  Message broker  Reactive : event driven  Choregraphy over orchestration  Autonomy over authority : each service copy the data it needs  Work well with CQRS / ES 32

Slide 33

Slide 33 text

Linkvalue | Jean-Marie Lamodière ASYNCHRONOUS COMMUNICATION 33 Message broker Message broker Message broker Message broker User French user registered Optin User optins changed Other service depending on 1 optin Register Read

Slide 34

Slide 34 text

Linkvalue | Jean-Marie Lamodière COMMUNICATION TRAPS  Chatty communication = coupling feature envy, wrong splitting…  Perf overhead : define « acceptable » 34

Slide 35

Slide 35 text

Linkvalue | Jean-Marie Lamodière 35

Slide 36

Slide 36 text

Linkvalue | Jean-Marie Lamodière DESIGN FOR FAILURE  It will fail, have a plan!  Define what to do, to return  Define timeout for each call  Message hospital (dead letter queue)  Circuit breaker / back pressure  Blameless culture needed 36

Slide 37

Slide 37 text

Linkvalue | Jean-Marie Lamodière NETFLIX CHAOS MONKEY  Randomly shut down services  Cure developers optimism ;) 37

Slide 38

Slide 38 text

Linkvalue | Jean-Marie Lamodière SERVICE DISCOVERY  Each µs scales individualy : which IP should we call ?  DNS in front of a load-balancer  Kubernetes services  Docker Swarm discovery (libkv + consul/etcd/zookeeper) 38

Slide 39

Slide 39 text

Linkvalue | Jean-Marie Lamodière CAP THEOREM (Distributed Systems)  Choose 2 between consistency (C), availability (A) and partition (P)  Avoid distributed transactions  Embrase eventual consistency  Use idempotent operations  Worker to clean inconsistency 39

Slide 40

Slide 40 text

Linkvalue | Jean-Marie Lamodière 40

Slide 41

Slide 41 text

Linkvalue | Jean-Marie Lamodière MICROSERVICES CLIENTS  Libraries ok, 1 per language needed  No business logic in client : avoid anemic CRUD microservices  To call a complex api (legacy, external), build a facade service 41

Slide 42

Slide 42 text

Linkvalue | Jean-Marie Lamodière CHANGE PROOF CLIENTS  Old and new api should cohexist  Postel's law : « be conservative in what you do, be liberal in what you accept from others »  Tolerant reader (Martin Fowler) : ignore changes not impacting you 42

Slide 43

Slide 43 text

Linkvalue | Jean-Marie Lamodière CHANGE PROOF CLIENTS 43

Slide 44

Slide 44 text

Linkvalue | Jean-Marie Lamodière API GATEWAY  Avoid exposing µs to frontend  Hide spliting to new microservices  Handle authentication / roles  Pro-tips : Back-end for frontend, 1 gateway per front application 44

Slide 45

Slide 45 text

Linkvalue | Jean-Marie Lamodière API GATEWAY 45 Microservice Legacy Monolith Microservice Microservice Android API Gateway Android application Public Private ReactJS Web application ReactJS API Gateway

Slide 46

Slide 46 text

Linkvalue | Jean-Marie Lamodière 46

Slide 47

Slide 47 text

Linkvalue | Jean-Marie Lamodière TESTING A MICROSERVICE  No end-to-end testing at µs level  Stub/mock others µs in functional tests  Have consumer-driven tests  No continuous integration = no µs!  One c.i. pipeline per microservice 47

Slide 48

Slide 48 text

Linkvalue | Jean-Marie Lamodière END TO END TESTING  Test journeys (main features), not user stories (already tested)  Goal : check wiring  Should be done in each front app  Can run in production 48

Slide 49

Slide 49 text

Linkvalue | Jean-Marie Lamodière TESTING = TRUST 49 Involve a quality assurance member in your feature team

Slide 50

Slide 50 text

Linkvalue | Jean-Marie Lamodière ARCHITECT ROLE  Keep µs map up to date  Define communication between µs  Define automatic deploying, monitoring and logging strategy  Adapt to change, like a city planner  Enforce team autonomy inside a µs 50

Slide 51

Slide 51 text

Linkvalue | Jean-Marie Lamodière 51

Slide 52

Slide 52 text

Linkvalue | Jean-Marie Lamodière WHAT SHOULD µS KEEP COMMON ?  Rules : communication, logs...  Template to create new µs, but no synchronization afterward  Violate DRY accross µs !  Shared code = coupling  Priority : autonomy 52

Slide 53

Slide 53 text

Linkvalue | Jean-Marie Lamodière MONITORING / LOGGING TIPS  Pass a unique « correlation id » to each sub-calls, including messages and asynchronous calls  Make sure your APM supports each language + versions  Have a look at Sysdig.org 53

Slide 54

Slide 54 text

Linkvalue | Jean-Marie Lamodière 54  Extreme Programming  TDD / BDD  S.O.L.I.D.  Loose coupling, high cohesion  DDD  Hexagonal

Slide 55

Slide 55 text

Linkvalue | Jean-Marie Lamodière BEFORE YOU START  microservices.io  martinfowler.com /microservices/ /articles/microservices.html /articles/microservice-trade-offs.html  groups.google.com /forum/#!forum/microservices 55

Slide 56

Slide 56 text

Linkvalue | Jean-Marie Lamodière ASYNCHRONOUS COMMUNICATION  blog.christianposta.com Why Microservices Should Be Event Driven:Autonomy vs Authority  reactivemanifesto.org 56 Lightbend.com (free)

Slide 57

Slide 57 text

Linkvalue | Jean-Marie Lamodière TALKS  What I Wish I Had Known Before Scaling Uber to 1000 Services GOTO 2016 • Matt Ranney  Prenons soin de nos microservices PHP Tour 2016 • SAMUEL ROZE  Meetic backend mutation with Symfony SymfonyLive 2015 • J. Calabrese E. Broutin  Kafka event architecture at Meetic Forum PHP 2015 • B. Pineau M. Robin 57

Slide 58

Slide 58 text

Linkvalue | Jean-Marie Lamodière DDD RECOMMENDED BOOKS 58 leanpub.com (free)

Slide 59

Slide 59 text

Thank you! Linkvalue | Jean-Marie Lamodière 59 Committed to innovate LINKVALUE JEAN-MARIE LAMODIERE Build microservices since 07/2015 @JMLamodiere 1935 CP