Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

ABOUT ME ABOUT ME Developer/Cra ing So ware Coach/ DDD Expert/Trainer Co-organizer of So ware Cra ers Montréal meetup Co-organizer of SOCRATES Canada unconference more details on : https://ksouf.com 2 / 32

Slide 3

Slide 3 text

3 / 32

Slide 4

Slide 4 text

4 / 32

Slide 5

Slide 5 text

I remain convinced that it is much easier to partition an existing, "brownfield" system than to do so up front with a new, greenfield system. -- Sam Newman (Author of building microservices) 5 / 32

Slide 6

Slide 6 text

If you can’t build a well-structured monolith, what makes you think you can build a well-structured set of microservices? -- Simon Brown (Author of So ware Architecture for Developers) 6 / 32

Slide 7

Slide 7 text

source microservices.io -- Chris Richardson (Author of microservices Patterns) 7 / 32

Slide 8

Slide 8 text

DOMAIN DRIVEN DESIGN TO THE RESCUE DOMAIN DRIVEN DESIGN TO THE RESCUE STRATEGIC DESIGN TO BE PRECISE STRATEGIC DESIGN TO BE PRECISE Extract your Microservice from the monolith based on business capabilities Create New Feature on new Bounded Context (Bubble Context) Use some Context Mapping Patterns for communication 8 / 32

Slide 9

Slide 9 text

ANTI-CORRUPTION LAYER (ACL) ANTI-CORRUPTION LAYER (ACL) 9 / 32

Slide 10

Slide 10 text

OPEN HOST SERVICE (OHS) OPEN HOST SERVICE (OHS) 10 / 32

Slide 11

Slide 11 text

More details on: Applied Domain Driven Design On Legacy Code 11 / 32

Slide 12

Slide 12 text

Don't Make Microservices communicate with each other (Directly)!! 12 / 32

Slide 13

Slide 13 text

UNLESS YOU WANT THIS!!! UNLESS YOU WANT THIS!!! 13 / 32

Slide 14

Slide 14 text

14 / 32

Slide 15

Slide 15 text

HOW WE DO AVOID IT? HOW WE DO AVOID IT? Service registry: every instance of service is registered and can be found only by the registry Microservices publish messages to the bus to chain actions Microservices consumes from queues that subscribed to specific event of the messaging bus Messages are used for asynchronous commands Registry is used to find API's (REST for the most) for querying 15 / 32

Slide 16

Slide 16 text

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

Slide 17

Slide 17 text

16 / 32

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

CHOREOGRAPHY-BASED SAGA PATTERN CHOREOGRAPHY-BASED SAGA PATTERN 18 / 32

Slide 20

Slide 20 text

BACK-END FOR FRONT-END (BFF) BACK-END FOR FRONT-END (BFF) Don't expose your Microservices directly Use 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

Slide 21

Slide 21 text

BFF: GENERAL PURPOSE API BFF: GENERAL PURPOSE API source samnewman.io 20 / 32

Slide 22

Slide 22 text

BFF: SPECIFIC PURPOSE API BFF: SPECIFIC PURPOSE API source samnewman.io 21 / 32

Slide 23

Slide 23 text

USE CONTRACTS TESTING FOR API USE 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

Slide 24

Slide 24 text

CONSUMER DRIVEN CONTRACTS TESTING CONSUMER DRIVEN CONTRACTS TESTING 23 / 32

Slide 25

Slide 25 text

USE MICRO FRONTEND USE MICRO FRONTEND 24 / 32

Slide 26

Slide 26 text

INDUSTRIALIZE YOUR APPLICATIONS INDUSTRIALIZE YOUR APPLICATIONS Create 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

Slide 27

Slide 27 text

LOGGING LOGGING Use Centralized logs solution Use structured logs Log your input/output of your Microservice Use Correlation Id to monitor cross Microservices requests 26 / 32

Slide 28

Slide 28 text

MONITORING MONITORING Implement always a health check for your Microservice Centralize your metrics in one simple dashboard Use alerting system when any weird behavior 27 / 32

Slide 29

Slide 29 text

PROVISIONING/CONFIGURATION MANAGEMENT PROVISIONING/CONFIGURATION MANAGEMENT Use 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 as code. 28 / 32

Slide 30

Slide 30 text

SECRETS MANAGEMENT SECRETS MANAGEMENT Separate your Secrets from your configuration in a secrets server (Vault Server) Use key rotation technique to change keys periodically to prevent that a key is compromised 29 / 32

Slide 31

Slide 31 text

WARP-UP WARP-UP Don't start with microservices Use Strategic Design of Domain Driven Design and Strangler Pattern to split your monolith don't make microservices communicate directly (Service Registry for API Query, Messaging BUS for Command) Use Consumer Driven Contracts Technique instead of End to End Testing Centralize your cutting-edge concern (logging, monitoring, secrets, configuration, infrastructure) Automate as much as possible (infrastructure provisioning, config management, secrets management,build & deployment, ..) 30 / 32

Slide 32

Slide 32 text

BEFORE FINISHING: I DID NOT INVENTED ALL THESE BEFORE FINISHING: I DID NOT INVENTED ALL THESE TECHNIQUES!!! TECHNIQUES!!! Domain Driven Design Microservices Patterns (The Book) Twelve Factor DevOps Practices 31 / 32

Slide 33

Slide 33 text

THANK YOU FOR ATTENDING THANK YOU FOR ATTENDING Questions ? twitter: @khaledsouf 32 / 32