Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2020-06-27 DDD Taiwan Community Microservices Bounded Context and everything in Between

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.

9b63847a4c413a2604e1d64e5d595dab?s=128

Kim Kao

June 27, 2020
Tweet

Transcript

  1. © 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
  2. © 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 !!!
  3. © 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
  4. © 2020, Domain Driven Design Taiwan Community Sales & Campain

    in company
  5. © 2020, Domain Driven Design Taiwan Community Product Marketing Strategy

    Creatives Campaigns Sales Agent Profits Optimization
  6. © 2020, Domain Driven Design Taiwan Community Decomposition Strategies Design

    Heuristics Ubiquitous Language at first ~
  7. © 2020, Domain Driven Design Taiwan Community

  8. © 2020, Domain Driven Design Taiwan Community Conflicting models Different

    contexts Dividing the lamguage/model Bounded Context
  9. © 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
  10. © 2020, Domain Driven Design Taiwan Community Decomposition Strategy #1:

    Bounded Contexts Marketing Service Sales Service
  11. © 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
  12. © 2020, Domain Driven Design Taiwan Community Business (Sub) Domains

  13. © 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
  14. © 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
  15. © 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
  16. © 2020, Domain Driven Design Taiwan Community Decomposition Strategy #3:

    Entities Website Asset Target Market Broker Distribution Order
  17. © 2020, Domain Driven Design Taiwan Community Quick wrap -

    Decomposition Strategies Bounded Contexts Subdomains Business Entities and Processes
  18. © 2020, Domain Driven Design Taiwan Community Website Funnel Campaign

    Placement Bounded Contexts? Subdomains? Entities?
  19. © 2020, Domain Driven Design Taiwan Community Bounded Contexts ==

    Microservices ?
  20. © 2020, Domain Driven Design Taiwan Community LEAD? Campaign Manager

    Sales Agent 12345… ABCDE…
  21. © 2020, Domain Driven Design Taiwan Community Marketing Sales Landing

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

    Page Campaign Placement Agency Lead Funnel Contact CRM Conversion Proposition Desk Message Insertion Order Lead
  23. © 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
  24. © 2020, Domain Driven Design Taiwan Community Bounded Contexts Decomposition

    #2 Bounded Contexts Decomposition #1 Bounded Contexts Decomposition #3
  25. © 2020, Domain Driven Design Taiwan Community Bounded Context Consistency

    boundary of the language / model Define the biggest valid monoliths Required decomposition boundary
  26. © 2020, Domain Driven Design Taiwan Community Choose which context

    to be microservice ?
  27. © 2020, Domain Driven Design Taiwan Community What’s the microservice

    candidate?
  28. © 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
  29. © 2020, Domain Driven Design Taiwan Community Service Interface “Any

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

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

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

  33. © 2020, Domain Driven Design Taiwan Community A microservice is

    a service with a micro interface
  34. © 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
  35. © 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!
  36. © 2020, Domain Driven Design Taiwan Community 1 Method =

    Perfect Microservice !!??
  37. © 2020, Domain Driven Design Taiwan Community

  38. © 2020, Domain Driven Design Taiwan Community

  39. © 2020, Domain Driven Design Taiwan Community

  40. © 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.
  41. © 2020, Domain Driven Design Taiwan Community Cost Of Change

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

    Big Ball of Mud Bounded Contexts Distributed Big Ball of Mud Microservices
  43. © 2020, Domain Driven Design Taiwan Community Website Funnel Campaign

    Placement Entities? Subdomains? Microservice candidate - dependens Resolve Global Complexity
  44. © 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
  45. © 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
  46. © 2020, Domain Driven Design Taiwan Community Services + Good

    Engineering = Microservices
  47. © 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
  48. © 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
  49. © 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.
  50. © 2020, Domain Driven Design Taiwan Community Design Heuristics

  51. © 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.
  52. © 2020, Domain Driven Design Taiwan Community Heuristic #2: Don’t

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

    Benefits Additional Complexity
  54. © 2020, Domain Driven Design Taiwan Community

  55. © 2020, Domain Driven Design Taiwan Community DDD - Subdomains

    Core Supporting Generic
  56. © 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 …
  57. © 2020, Domain Driven Design Taiwan Community Heuristic #3: Buy/Adopt

    Generic subdomains 3rd party product Your system Anti-Corruption Layer
  58. © 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
  59. © 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.
  60. © 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
  61. © 2020, Domain Driven Design Taiwan Community Heuristic #5: Supporting

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

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

    Consistency Requirements Method A Method B Conscurrency control? – Same service Service A
  64. © 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
  65. © 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
  66. © 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
  67. © 2020, Domain Driven Design Taiwan Community Heuristic #7: Public

    / Private Events … … … … … … Event Type 3 Event Type 2 Event Type 1 Event Type 100 …
  68. © 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)
  69. © 2020, Domain Driven Design Taiwan Community Heuristic #7: Public

    / Private Events Events? Domain Events State Change Events Private Public
  70. © 2020, Domain Driven Design Taiwan Community Heuristic #8: Make

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

    Events Explicit Service AgentAssignedToLead AgentAssignedToLead AgentUnassignedToLead
  72. © 2020, Domain Driven Design Taiwan Community Heuristic #9: Evaluate

    reasons for Change Method A Service A Method B Service B Sync Call
  73. © 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?
  74. © 2020, Domain Driven Design Taiwan Community Heuristic #10: Evaluate

    Services’ “Doors”
  75. © 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
  76. © 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”
  77. © 2020, Domain Driven Design Taiwan Community Cost Of Change

    Big Ball of Mud Bounded Contexts Distributed Big Ball of Mud Microservices
  78. © 2020, Domain Driven Design Taiwan Community Reference from Vladikk

  79. © 2020, Domain Driven Design Taiwan Community Thank You!

  80. © 2020, Domain Driven Design Taiwan Community Q&A