Slide 1

Slide 1 text

© 2020, Domain Driven Design Taiwan Community Kim Kao, Co-Organizer Domain Driven Design Taiwan Community 27 June, 2020 Microservices Bounded Context And everything in Between @YiKaiKao Kim Kao @Vladikk

Slide 2

Slide 2 text

© 2020, Domain Driven Design Taiwan Community Kim, Kao (高翊凱) • A father of 2 • Love Softball / Baseball • Passionate facilitator • Domain Driven Design Taiwan Community Co-Organizer • Solutions Architect @AWS – Big Serverless Fan !!!

Slide 3

Slide 3 text

© 2020, Domain Driven Design Taiwan Community 95% of the words are spent extolling the benefits of “modularity” and that little, if any, is said about how to achieve it Glenford J. Myers

Slide 4

Slide 4 text

© 2020, Domain Driven Design Taiwan Community Sales & Campain in company

Slide 5

Slide 5 text

© 2020, Domain Driven Design Taiwan Community Product Marketing Strategy Creatives Campaigns Sales Agent Profits Optimization

Slide 6

Slide 6 text

© 2020, Domain Driven Design Taiwan Community Decomposition Strategies Design Heuristics Ubiquitous Language at first ~

Slide 7

Slide 7 text

© 2020, Domain Driven Design Taiwan Community

Slide 8

Slide 8 text

© 2020, Domain Driven Design Taiwan Community Conflicting models Different contexts Dividing the lamguage/model Bounded Context

Slide 9

Slide 9 text

© 2020, Domain Driven Design Taiwan Community Bounded Contexts Marketing Sales Funnel Campaign Placement Landing Page Agency Insertion Order Lead Contact CDR Conversion Desk Campaign Proposition Message Lead

Slide 10

Slide 10 text

© 2020, Domain Driven Design Taiwan Community Decomposition Strategy #1: Bounded Contexts Marketing Service Sales Service

Slide 11

Slide 11 text

© 2020, Domain Driven Design Taiwan Community Marketing Sales Billing Creative Catalog Campaign Management Ads Optimization Identity & Access Contracts Telephony CRM Sales Optimization Commissions Desks Identity & Access

Slide 12

Slide 12 text

© 2020, Domain Driven Design Taiwan Community Business (Sub) Domains

Slide 13

Slide 13 text

© 2020, Domain Driven Design Taiwan Community Business Domain: Customer Acquisition Bounded Context: Marketing Bounded Context: Sales SubDomain: Creative Catalog SubDomain: Campaigns Mgt SubDomain: Ads Optimization SubDomain: Contracts Mgt SubDomain: CRM SubDomain: Sales Optimization SubDomain: Commissions SubDomain: Desk Mgt

Slide 14

Slide 14 text

© 2020, Domain Driven Design Taiwan Community Decomposition Strategy #2: Subdomains Campaign Management service Content Catalog Service Desk Management Service CRM Service Users Service Billing Service

Slide 15

Slide 15 text

© 2020, Domain Driven Design Taiwan Community Marketing Billing Creative Catalog Campaign Management Ads Optimization Identity & Access Contracts Campaign Management Campaign Placement Funnel Banner Website Asset Target Market Landing Page

Slide 16

Slide 16 text

© 2020, Domain Driven Design Taiwan Community Decomposition Strategy #3: Entities Website Asset Target Market Broker Distribution Order

Slide 17

Slide 17 text

© 2020, Domain Driven Design Taiwan Community Quick wrap - Decomposition Strategies Bounded Contexts Subdomains Business Entities and Processes

Slide 18

Slide 18 text

© 2020, Domain Driven Design Taiwan Community Website Funnel Campaign Placement Bounded Contexts? Subdomains? Entities?

Slide 19

Slide 19 text

© 2020, Domain Driven Design Taiwan Community Bounded Contexts == Microservices ?

Slide 20

Slide 20 text

© 2020, Domain Driven Design Taiwan Community LEAD? Campaign Manager Sales Agent 12345… ABCDE…

Slide 21

Slide 21 text

© 2020, Domain Driven Design Taiwan Community Marketing Sales Landing Page Campaign Placement Agency Lead Funnel Contact CDR Conversion Proposition Desk Message Insertion Order Lead

Slide 22

Slide 22 text

© 2020, Domain Driven Design Taiwan Community Marketing Sales Landing Page Campaign Placement Agency Lead Funnel Contact CRM Conversion Proposition Desk Message Insertion Order Lead

Slide 23

Slide 23 text

© 2020, Domain Driven Design Taiwan Community Marketing Support Sales Lead Lead Identity & Access Campaign Mgt Optimization Contracts Desks Telephony Billing Creative Catalog CRM Commissions Optimization

Slide 24

Slide 24 text

© 2020, Domain Driven Design Taiwan Community Bounded Contexts Decomposition #2 Bounded Contexts Decomposition #1 Bounded Contexts Decomposition #3

Slide 25

Slide 25 text

© 2020, Domain Driven Design Taiwan Community Bounded Context Consistency boundary of the language / model Define the biggest valid monoliths Required decomposition boundary

Slide 26

Slide 26 text

© 2020, Domain Driven Design Taiwan Community Choose which context to be microservice ?

Slide 27

Slide 27 text

© 2020, Domain Driven Design Taiwan Community What’s the microservice candidate?

Slide 28

Slide 28 text

© 2020, Domain Driven Design Taiwan Community Service “A service is a unit of functionality exposed to the world” – Juval Lowy “A mechanism to enable access to one or more capabilities, where the access is provided using a prescribed interface” - OASIS

Slide 29

Slide 29 text

© 2020, Domain Driven Design Taiwan Community Service Interface “Any mechanism for getting data in or out of the service” – Randy Shoup

Slide 30

Slide 30 text

© 2020, Domain Driven Design Taiwan Community Service Interface Asynchronous: • Producing events • Consuming events Synchronous: • Request / Response • Bulk ETL

Slide 31

Slide 31 text

© 2020, Domain Driven Design Taiwan Community Service Interface “Any mechanism for getting data in or out of the service” – Randy Shoup

Slide 32

Slide 32 text

© 2020, Domain Driven Design Taiwan Community Service Interface

Slide 33

Slide 33 text

© 2020, Domain Driven Design Taiwan Community A microservice is a service with a micro interface

Slide 34

Slide 34 text

© 2020, Domain Driven Design Taiwan Community Microservice = Microinterface Reducing coupling between services Limits reasons for change Easier to understand Better fault isolation More autonomy between services

Slide 35

Slide 35 text

© 2020, Domain Driven Design Taiwan Community Microservice & Databases Microservices should own its database No external access Access through Microservice’s API only Database = infinite interface!

Slide 36

Slide 36 text

© 2020, Domain Driven Design Taiwan Community 1 Method = Perfect Microservice !!??

Slide 37

Slide 37 text

© 2020, Domain Driven Design Taiwan Community

Slide 38

Slide 38 text

© 2020, Domain Driven Design Taiwan Community

Slide 39

Slide 39 text

© 2020, Domain Driven Design Taiwan Community

Slide 40

Slide 40 text

© 2020, Domain Driven Design Taiwan Community The threshold upon which a system can be decomposed into microservices is defined by the use cases of the system that the microservices are a part of.

Slide 41

Slide 41 text

© 2020, Domain Driven Design Taiwan Community Cost Of Change Monolith Microservices Distributed Monolith

Slide 42

Slide 42 text

© 2020, Domain Driven Design Taiwan Community Cost Of Change Big Ball of Mud Bounded Contexts Distributed Big Ball of Mud Microservices

Slide 43

Slide 43 text

© 2020, Domain Driven Design Taiwan Community Website Funnel Campaign Placement Entities? Subdomains? Microservice candidate - dependens Resolve Global Complexity

Slide 44

Slide 44 text

© 2020, Domain Driven Design Taiwan Community “Global complexity … the complexity of the overall structure of a program or system. i.e, the degree of association or interdependence Among the major pieces of a program” Glenford J. Myers - 1978 Composite / Structured Design

Slide 45

Slide 45 text

© 2020, Domain Driven Design Taiwan Community When you design a system…, then if the features can be break into … loosely bound groups of relatively closely bound features, then that division is a good thing to be mad a part of the design. This is just good engineering. Tim Berners-Lee Principles of design, 1998

Slide 46

Slide 46 text

© 2020, Domain Driven Design Taiwan Community Services + Good Engineering = Microservices

Slide 47

Slide 47 text

© 2020, Domain Driven Design Taiwan Community Its is not only necessary to make sure your own system is designed to be made of modular parts. It is also necessary to realize that your own system… should always be designed to be a part of another larger system. Tim Berners-Lee Principles of design, 1998

Slide 48

Slide 48 text

© 2020, Domain Driven Design Taiwan Community A major part of this paper will be concerned with the question of how good modularity can be achieved, that is, how modules can be chosen to as to minimize the connections between them. Barbara Liskov A design methodology for reliable software systems, 1972

Slide 49

Slide 49 text

© 2020, Domain Driven Design Taiwan Community A microservice is a service with a micro interface. The threshold upon which a system can be decomposed Into microservices is defined by the use cases of the System that the microservices are a part of.

Slide 50

Slide 50 text

© 2020, Domain Driven Design Taiwan Community Design Heuristics

Slide 51

Slide 51 text

© 2020, Domain Driven Design Taiwan Community Heuristic #1: Decompose to Bounded Contexts Do not implement conflicting models in the same service. Always decompose to Bounded Contexts.

Slide 52

Slide 52 text

© 2020, Domain Driven Design Taiwan Community Heuristic #2: Don’t First Law of Distributed Object Design: “Don’t distribute your objects” Martin Fowler

Slide 53

Slide 53 text

© 2020, Domain Driven Design Taiwan Community Heuristic #2: Don’t Benefits Additional Complexity

Slide 54

Slide 54 text

© 2020, Domain Driven Design Taiwan Community

Slide 55

Slide 55 text

© 2020, Domain Driven Design Taiwan Community DDD - Subdomains Core Supporting Generic

Slide 56

Slide 56 text

© 2020, Domain Driven Design Taiwan Community Generic Subdomains No competitive advantage Everybody is implementing in the same way Complex business logic Services : Billing, A&A, Telepony …

Slide 57

Slide 57 text

© 2020, Domain Driven Design Taiwan Community Heuristic #3: Buy/Adopt Generic subdomains 3rd party product Your system Anti-Corruption Layer

Slide 58

Slide 58 text

© 2020, Domain Driven Design Taiwan Community Core Subdomains Inventing something new Optimizing existing practices Competitive advantage Complex business logic Change often Services : Campaign, Ad Optimization, CRM, Sales, Commissions

Slide 59

Slide 59 text

© 2020, Domain Driven Design Taiwan Community Heuristic #4: Core Subdomains – Don’t Rush Adhere to subdomain’s boundaries. Decompose further only when you acquire domain knowledge.

Slide 60

Slide 60 text

© 2020, Domain Driven Design Taiwan Community Supporting Subdomains No competitive advantage Support the Core Subdomains Can’t be bought / adopted Simple bussiness logic Services : Creative Catalog, Contracts, Desks

Slide 61

Slide 61 text

© 2020, Domain Driven Design Taiwan Community Heuristic #5: Supporting Subdomains - Safe Safe to decompose beyond the subdomain’s boundaries.

Slide 62

Slide 62 text

© 2020, Domain Driven Design Taiwan Community Heuristic #6: Evaluate Consistency Requirements Method A Method B

Slide 63

Slide 63 text

© 2020, Domain Driven Design Taiwan Community Heuristic #6: Evaluate Consistency Requirements Method A Method B Conscurrency control? – Same service Service A

Slide 64

Slide 64 text

© 2020, Domain Driven Design Taiwan Community Heuristic #6: Evaluate Consistency Requirements Conscurrency control? – Same service Method A Service A Method B Service B Sync Call

Slide 65

Slide 65 text

© 2020, Domain Driven Design Taiwan Community Heuristic #6: Evaluate Consistency Requirements Eventual Consistency? – Two Services, async communication Method A Service A Method B Service B Async communication

Slide 66

Slide 66 text

© 2020, Domain Driven Design Taiwan Community Heuristic #6: Evaluate Consistency Requirements Concurrency control? – Same Service Read last write? – Two services, sync communication Eventual consistency? – Two services, async communication

Slide 67

Slide 67 text

© 2020, Domain Driven Design Taiwan Community Heuristic #7: Public / Private Events … … … … … … Event Type 3 Event Type 2 Event Type 1 Event Type 100 …

Slide 68

Slide 68 text

© 2020, Domain Driven Design Taiwan Community Heuristic #7: Public / Private Events Service emailChanged phoneNumberChanged addressChanged contactDetailChanged Private event types (Implementation details) public event types (public interface)

Slide 69

Slide 69 text

© 2020, Domain Driven Design Taiwan Community Heuristic #7: Public / Private Events Events? Domain Events State Change Events Private Public

Slide 70

Slide 70 text

© 2020, Domain Driven Design Taiwan Community Heuristic #8: Make Events Explicit Service AgentAssignedToLead AgentAssignedToLead AgentAssignedToLead

Slide 71

Slide 71 text

© 2020, Domain Driven Design Taiwan Community Heuristic #8: Make Events Explicit Service AgentAssignedToLead AgentAssignedToLead AgentUnassignedToLead

Slide 72

Slide 72 text

© 2020, Domain Driven Design Taiwan Community Heuristic #9: Evaluate reasons for Change Method A Service A Method B Service B Sync Call

Slide 73

Slide 73 text

© 2020, Domain Driven Design Taiwan Community Heuristic #9: Evaluate reasons for Change Same reasons for change? Same rate of change? Can be decoupled? Should be the same service?

Slide 74

Slide 74 text

© 2020, Domain Driven Design Taiwan Community Heuristic #10: Evaluate Services’ “Doors”

Slide 75

Slide 75 text

© 2020, Domain Driven Design Taiwan Community Wrap it up • A service is a unit of functionality exposed to the world through its public interface • A microservice is a service with micro interface • The “Micro-interface” is relative to the use cases of the system that the service is a part of

Slide 76

Slide 76 text

© 2020, Domain Driven Design Taiwan Community Wrap it up • Heuristic #1: Always decompose to Bounded Contexts • Heuristis #2: Don’t go further, unless you have to • Heuristic #3: Buy/Adopt generic subdomains • Heuristic #4: Core subdomains – don’t rush • Heuristic #5: Supporting subdomains can be decomposed ear • Heuristic #6: Evaluate Consistency Requirements • Heuristic #7: Private / Public Events • Heuristic #8: Explicit Define Events • Heuristic #9: Evaluate Reasons for Change • Heuristic #10: Evaluate Services’ “Doors”

Slide 77

Slide 77 text

© 2020, Domain Driven Design Taiwan Community Cost Of Change Big Ball of Mud Bounded Contexts Distributed Big Ball of Mud Microservices

Slide 78

Slide 78 text

© 2020, Domain Driven Design Taiwan Community Reference from Vladikk

Slide 79

Slide 79 text

© 2020, Domain Driven Design Taiwan Community Thank You!

Slide 80

Slide 80 text

© 2020, Domain Driven Design Taiwan Community Q&A