Share
Embed
2020-06-27 DDD Taiwan Community Microservices Bounded Context and everything in Between
This talk is redelivered from DDDDD @vladikk's session by Kim, Kao. The main concept is to figure out how to design microservices with more confidence to make decision. Also mentioned what's the essential concept on API, distributed events, and etc.
Kim Kao
June 27, 2020
Transcript
80 slides
-
© 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 -
© 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 !!! -
© 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 -
© 2020, Domain Driven Design Taiwan Community Product Marketing Strategy
Creatives Campaigns Sales Agent Profits Optimization -
© 2020, Domain Driven Design Taiwan Community Decomposition Strategies Design
Heuristics Ubiquitous Language at first ~ -
© 2020, Domain Driven Design Taiwan Community Conflicting models Different
contexts Dividing the lamguage/model Bounded Context -
© 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 -
© 2020, Domain Driven Design Taiwan Community Decomposition Strategy #1:
Bounded Contexts Marketing Service Sales Service -
© 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 -
© 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 -
© 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 -
© 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 -
© 2020, Domain Driven Design Taiwan Community Decomposition Strategy #3:
Entities Website Asset Target Market Broker Distribution Order -
© 2020, Domain Driven Design Taiwan Community Quick wrap -
Decomposition Strategies Bounded Contexts Subdomains Business Entities and Processes -
© 2020, Domain Driven Design Taiwan Community Website Funnel Campaign
Placement Bounded Contexts? Subdomains? Entities? -
© 2020, Domain Driven Design Taiwan Community LEAD? Campaign Manager
Sales Agent 12345… ABCDE… -
© 2020, Domain Driven Design Taiwan Community Marketing Sales Landing
Page Campaign Placement Agency Lead Funnel Contact CDR Conversion Proposition Desk Message Insertion Order Lead -
© 2020, Domain Driven Design Taiwan Community Marketing Sales Landing
Page Campaign Placement Agency Lead Funnel Contact CRM Conversion Proposition Desk Message Insertion Order Lead -
© 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 -
© 2020, Domain Driven Design Taiwan Community Bounded Contexts Decomposition
#2 Bounded Contexts Decomposition #1 Bounded Contexts Decomposition #3 -
© 2020, Domain Driven Design Taiwan Community Bounded Context Consistency
boundary of the language / model Define the biggest valid monoliths Required decomposition boundary -
© 2020, Domain Driven Design Taiwan Community Choose which context
to be microservice ? -
© 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 -
© 2020, Domain Driven Design Taiwan Community Service Interface “Any
mechanism for getting data in or out of the service” – Randy Shoup -
© 2020, Domain Driven Design Taiwan Community Service Interface Asynchronous:
• Producing events • Consuming events Synchronous: • Request / Response • Bulk ETL -
© 2020, Domain Driven Design Taiwan Community Service Interface “Any
mechanism for getting data in or out of the service” – Randy Shoup -
© 2020, Domain Driven Design Taiwan Community A microservice is
a service with a micro interface -
© 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 -
© 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! -
© 2020, Domain Driven Design Taiwan Community 1 Method =
Perfect Microservice !!?? -
© 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. -
© 2020, Domain Driven Design Taiwan Community Cost Of Change
Monolith Microservices Distributed Monolith -
© 2020, Domain Driven Design Taiwan Community Cost Of Change
Big Ball of Mud Bounded Contexts Distributed Big Ball of Mud Microservices -
© 2020, Domain Driven Design Taiwan Community Website Funnel Campaign
Placement Entities? Subdomains? Microservice candidate - dependens Resolve Global Complexity -
© 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 -
© 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 -
© 2020, Domain Driven Design Taiwan Community Services + Good
Engineering = Microservices -
© 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 -
© 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 -
© 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. -
© 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. -
© 2020, Domain Driven Design Taiwan Community Heuristic #2: Don’t
First Law of Distributed Object Design: “Don’t distribute your objects” Martin Fowler -
© 2020, Domain Driven Design Taiwan Community Heuristic #2: Don’t
Benefits Additional Complexity -
© 2020, Domain Driven Design Taiwan Community DDD - Subdomains
Core Supporting Generic -
© 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 … -
© 2020, Domain Driven Design Taiwan Community Heuristic #3: Buy/Adopt
Generic subdomains 3rd party product Your system Anti-Corruption Layer -
© 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 -
© 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. -
© 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 -
© 2020, Domain Driven Design Taiwan Community Heuristic #5: Supporting
Subdomains - Safe Safe to decompose beyond the subdomain’s boundaries. -
© 2020, Domain Driven Design Taiwan Community Heuristic #6: Evaluate
Consistency Requirements Method A Method B -
© 2020, Domain Driven Design Taiwan Community Heuristic #6: Evaluate
Consistency Requirements Method A Method B Conscurrency control? – Same service Service A -
© 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 -
© 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 -
© 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 -
© 2020, Domain Driven Design Taiwan Community Heuristic #7: Public
/ Private Events … … … … … … Event Type 3 Event Type 2 Event Type 1 Event Type 100 … -
© 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) -
© 2020, Domain Driven Design Taiwan Community Heuristic #7: Public
/ Private Events Events? Domain Events State Change Events Private Public -
© 2020, Domain Driven Design Taiwan Community Heuristic #8: Make
Events Explicit Service AgentAssignedToLead AgentAssignedToLead AgentAssignedToLead -
© 2020, Domain Driven Design Taiwan Community Heuristic #8: Make
Events Explicit Service AgentAssignedToLead AgentAssignedToLead AgentUnassignedToLead -
© 2020, Domain Driven Design Taiwan Community Heuristic #9: Evaluate
reasons for Change Method A Service A Method B Service B Sync Call -
© 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? -
© 2020, Domain Driven Design Taiwan Community Heuristic #10: Evaluate
Services’ “Doors” -
© 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 -
© 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” -
© 2020, Domain Driven Design Taiwan Community Cost Of Change
Big Ball of Mud Bounded Contexts Distributed Big Ball of Mud Microservices