architecture chronicles about implementing microser vice · 2020. 4. 27. · domain driven design...

33
NOBODY TOLD ME ABOUT THAT NOBODY TOLD ME ABOUT THAT CHRONICLES ABOUT IMPLEMENTING MICROSERVICE CHRONICLES ABOUT IMPLEMENTING MICROSERVICE ARCHITECTURE ARCHITECTURE Khaled Souf twitter: @khaledsouf 1 / 32

Upload: others

Post on 01-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

NOBODY TOLD ME ABOUT THATNOBODY TOLD ME ABOUT THATCHRONICLES ABOUT IMPLEMENTING MICROSERVICECHRONICLES ABOUT IMPLEMENTING MICROSERVICE

ARCHITECTUREARCHITECTURE

Khaled Souf twitter: @khaledsouf

1 / 32

Page 2: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

ABOUT MEABOUT MEDeveloper/Cra�ing So�ware Coach/ DDD Expert/TrainerCo-organizer of So�ware Cra�ers Montréal meetupCo-organizer of SOCRATES Canada unconferencemore details on : https://ksouf.com

2 / 32

Page 3: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

3 / 32

Page 4: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

4 / 32

Page 5: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

I remain convinced that it is mucheasier to partition an existing,

"brownfield" system than to do so upfront with a new, greenfield system. --

Sam Newman (Author of buildingmicroservices)

5 / 32

Page 6: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

If you can’t build a well-structuredmonolith, what makes you think you

can build a well-structured set ofmicroservices? -- Simon Brown (Author

of So�ware Architecture forDevelopers)

6 / 32

Page 7: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

source microservices.io -- Chris Richardson (Author ofmicroservices Patterns)

7 / 32

Page 8: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

DOMAIN DRIVEN DESIGN TO THE RESCUE DOMAIN DRIVEN DESIGN TO THE RESCUE STRATEGIC DESIGN TO BE PRECISESTRATEGIC DESIGN TO BE PRECISE

Extract your Microservice from the monolith based on business capabilitiesCreate New Feature on new Bounded Context (Bubble Context)Use some Context Mapping Patterns for communication

8 / 32

Page 9: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

ANTI-CORRUPTION LAYER (ACL)ANTI-CORRUPTION LAYER (ACL)

9 / 32

Page 10: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

OPEN HOST SERVICE (OHS)OPEN HOST SERVICE (OHS)

10 / 32

Page 11: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

More details on: Applied Domain Driven Design OnLegacy Code

11 / 32

Page 12: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

Don't Make Microservices communicate with eachother (Directly)!!

12 / 32

Page 13: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

UNLESS YOU WANT THIS!!!UNLESS YOU WANT THIS!!!

13 / 32

Page 14: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

14 / 32

Page 15: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

HOW WE DO AVOID IT?HOW WE DO AVOID IT?Service registry: every instance of service is registered and can be found only by theregistryMicroservices publish messages to the bus to chain actionsMicroservices consumes from queues that subscribed to specific event of the messagingbusMessages are used for asynchronous commandsRegistry is used to find API's (REST for the most) for querying

15 / 32

Page 16: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

MICROSERVICE ARCHITECTURE (WITH REGISTRY &MICROSERVICE ARCHITECTURE (WITH REGISTRY &MESSAGING BUS)MESSAGING BUS)

Page 17: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

16 / 32

Page 18: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

WHAT ABOUT DATABASES?WHAT ABOUT DATABASES?Use choreography-based saga pattern (aka eventual consistency in Domain DrivenDesign).A Microservice manage his own data (shared database is Anti-Pattern).Keep two copies for starting (one in monolith/ one in microservice).

17 / 32

Page 19: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

CHOREOGRAPHY-BASED SAGA PATTERNCHOREOGRAPHY-BASED SAGA PATTERN

18 / 32

Page 20: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

BACK-END FOR FRONT-END (BFF)BACK-END FOR FRONT-END (BFF)Don't expose your Microservices directlyUse BFF as view and information aggregator for general purpose or specific customer(depends on context)Use a gateway if you're exposing BFF to something external

19 / 32

Page 21: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

BFF: GENERAL PURPOSE APIBFF: GENERAL PURPOSE API

source samnewman.io

20 / 32

Page 22: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

BFF: SPECIFIC PURPOSE APIBFF: SPECIFIC PURPOSE API

source samnewman.io

21 / 32

Page 23: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

USE CONTRACTS TESTING FOR APIUSE CONTRACTS TESTING FOR API(INSTEAD OF END TO END TESTING)(INSTEAD OF END TO END TESTING)

Let your consumer define the contract (Consumer Driven Contracts Testing)Use a contract broker to publish/verify your contracts

22 / 32

Page 24: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

CONSUMER DRIVEN CONTRACTS TESTINGCONSUMER DRIVEN CONTRACTS TESTING

23 / 32

Page 25: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

USE MICRO FRONTENDUSE MICRO FRONTEND

24 / 32

Page 26: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

INDUSTRIALIZE YOUR APPLICATIONSINDUSTRIALIZE YOUR APPLICATIONSCreate Template by Type of Project.Focus only Business Value when creating your Microservice.Define Template by used language and capabilities.Your Template should contain also you definition of build & deployment pipelines.

25 / 32

Page 27: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

LOGGINGLOGGINGUse Centralized logs solutionUse structured logsLog your input/output of your MicroserviceUse Correlation Id to monitor cross Microservices requests

26 / 32

Page 28: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

MONITORINGMONITORINGImplement always a health check for your MicroserviceCentralize your metrics in one simple dashboardUse alerting system when any weird behavior

27 / 32

Page 29: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

PROVISIONING/CONFIGURATION MANAGEMENTPROVISIONING/CONFIGURATION MANAGEMENTUse tools to manage configuration (Ansible, Saltstack, ...).build a git repository infrastructure as code to automate your provisioning.Make sure that the only possible modification of infrastructure is by modifying infra ascode.

28 / 32

Page 30: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

SECRETS MANAGEMENTSECRETS MANAGEMENTSeparate your Secrets from your configuration in a secrets server (Vault Server)Use key rotation technique to change keys periodically to prevent that a key iscompromised

29 / 32

Page 31: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

WARP-UPWARP-UPDon't start with microservicesUse Strategic Design of Domain Driven Design and Strangler Pattern to split yourmonolithdon't make microservices communicate directly (Service Registry for API Query,Messaging BUS for Command)Use Consumer Driven Contracts Technique instead of End to End TestingCentralize your cutting-edge concern (logging, monitoring, secrets, configuration,infrastructure)Automate as much as possible (infrastructure provisioning, config management, secretsmanagement,build & deployment, ..)

30 / 32

Page 32: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

BEFORE FINISHING: I DID NOT INVENTED ALL THESEBEFORE FINISHING: I DID NOT INVENTED ALL THESETECHNIQUES!!!TECHNIQUES!!!

Domain Driven DesignMicroservices Patterns (The Book)Twelve FactorDevOps Practices

31 / 32

Page 33: ARCHITECTURE CHRONICLES ABOUT IMPLEMENTING MICROSER VICE · 2020. 4. 27. · domain driven design to the rescue ... microservice architecture (with registry & messaging bus) 16

THANK YOU FOR ATTENDINGTHANK YOU FOR ATTENDINGQuestions ?twitter: @khaledsouf

32 / 32