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

Microservices, Bounded Contexts, and Everything in Between

Microservices, Bounded Contexts, and Everything in Between

DDD eXchange 2018

Vladik Khononov

April 26, 2018
Tweet

More Decks by Vladik Khononov

Other Decks in Technology

Transcript

  1. Microservices
    Bounded Contexts
    And Everything in Between

    View Slide

  2. @vladikk
    vladikk.com

    View Slide

  3. ”95% of the words are spent extolling the benefits
    of “modularity” and that little, if anything, is said
    about how to achieve it”
    Glenford J. Myers
    Composite / Structured Design, 1974

    View Slide

  4. “MICROSERVICES FTW!!!!!!!!1”
    Me @ Internovus

    View Slide

  5. “MICROSERVICES FTW!!!!!!!!1”
    Me @ Internovus

    View Slide

  6. ”95% of the words are spent extolling the benefits
    of “modularity” and that little, if anything, is said
    about how to achieve it”
    Glenford J. Myers
    Composite / Structured Design, 1974

    View Slide

  7. View Slide

  8. View Slide

  9. Decomposition Strategies
    Bounded Contexts, Business Domains, 

    Business En66es
    Design Heuristics
    Microservices
    Wrap-up
    Example Business Domain 1
    2
    3
    4
    5

    View Slide

  10. Your Product Marketing

    Strategy
    Creatives Campaigns Sales

    Agents
    Optimization
    Profits

    View Slide

  11. Decomposi9on Strategies
    Bounded Contexts
    Subdomains
    Business Entities and Processes

    View Slide

  12. Bounded Contexts

    View Slide

  13. View Slide

  14. Domain Expert
    Software Developer

    View Slide

  15. Business Domain Expert
    Software Developer
    ???
    !!!
    Ubiquitous Language

    View Slide

  16. Campaigns Sales

    Agents
    Your Product Marketing

    Strategy
    Creatives
    Optimization
    Profits

    View Slide

  17. Sales Agent
    Campaign Manager
    ???
    !!!
    LEAD?

    View Slide

  18. Conflicting models
    Different contexts
    Dividing the language/model
    Bounded Context

    View Slide

  19. Marke9ng
    Sales
    Lead Lead
    Funnel
    Campaign
    Placement
    Landing Page
    Agency Insertion Order
    Message
    Campaign
    Proposition
    Desk
    Conversion
    Contact
    CDR
    Bounded Contexts

    View Slide

  20. Marke9ng
    Service
    Sales
    Service
    Decomposi9on Strategy #1: Bounded Contexts

    View Slide

  21. Marke9ng
    Sales
    Commissions
    Desks
    Sales

    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Ads Optimization
    Identity & Access

    View Slide

  22. Subdomains

    View Slide

  23. Business Domain: Customer Acquisi6on
    Bounded Context: Marke6ng Bounded Context: Sales
    Subdomain: Crea6ve Catalog
    Subdomain: Campaigns Mngmt
    Subdomain: Ads Op6miza6on
    Subdomain: Contracts Mngmt
    Subdomain: CRM
    Subdomain: Sales Op6miza6on
    Subdomain: Commissions
    Subdomain: Desks Mngmt

    View Slide

  24. Decomposi9on Strategy #2: Subdomains
    Campaign
    Management
    Service
    Content
    Catalog
    Service
    Desks
    Management
    Service
    CRM
    Service
    Users
    Service
    Billing
    Service

    View Slide

  25. Business En99es and Processes

    View Slide

  26. Marke9ng
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Campaign
    Management
    Campaign Placement
    Funnel
    Banner
    Landing Page
    Website
    Zone
    Asset
    Publisher
    Target Market

    View Slide

  27. Decomposi9on Strategy #3: En99es
    Website Asset Target Market
    Broker Distribu6on Customer

    View Slide

  28. Decomposi9on Strategies
    Bounded Contexts
    Subdomains
    Business Entities and Processes

    View Slide

  29. SHOW ME THE
    MICROSERVICES!

    View Slide

  30. Bounded Contexts == Microservices ?

    View Slide

  31. Sales Agent
    Campaign Manager
    ???
    !!!
    LEAD?

    View Slide

  32. Marke9ng
    Sales
    Lead Lead
    Funnel
    Campaign
    Placement
    Landing Page
    Agency Insertion Order
    Message
    Campaign
    Proposition
    Desk
    Conversion
    Contact
    CDR

    View Slide

  33. Marke9ng
    Sales
    Lead Lead
    Funnel
    Campaign
    Placement
    Landing Page
    Agency Insertion Order
    Message
    Campaign
    Proposition
    Desk
    Conversion
    Contact
    CDR

    View Slide

  34. Marke9ng
    Sales
    Commissions
    Desks
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Identity & Access
    Lead
    Lead

    View Slide

  35. Marke9ng
    Sales
    Commissions
    Desks
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Identity & Access
    Lead
    Lead

    View Slide

  36. Marke9ng
    Creative
    Catalog
    Campaign
    Management
    Optimization
    Lead
    Sales
    Commissions
    Optimization
    CRM Lead
    Desks
    Telephony
    Support
    Contracts
    Billing
    Identity & Access

    View Slide

  37. View Slide

  38. Bounded Context
    Consistency boundary of the language / model
    Define the biggest valid monoliths
    Required decomposition boundary

    View Slide

  39. Bounded Contexts == Microservices? No

    View Slide

  40. Campaign
    Management
    Campaign Placement
    Funnel
    Banner
    Landing Page
    Website
    Zone
    Asset
    Publisher
    Target Market
    Campaign
    Website
    Placement
    Funnel
    Marke9ng
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Bounded Contexts? No Subdomains? En99es?

    View Slide

  41. Microservices

    View Slide

  42. 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

    View Slide

  43. “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
    Service

    View Slide

  44. Service Interface
    “Any mechanism for getting data in or out of the service”
    - Randy Shoup

    View Slide

  45. Service Interface
    Asynchronous:
    • Producing events
    • Consuming events
    Synchronous:
    • Request / Réponse
    • Bulk ETL

    View Slide

  46. Service Interface
    “Any mechanism for getting data in or out of the service”
    - Randy Shoup

    View Slide

  47. Service Interface

    View Slide

  48. Services ➜ Microservice

    View Slide

  49. A microservice is a service with a micro interface

    View Slide

  50. Microservice = Microinterface
    Reducing coupling between services
    Limits reasons for change
    Easier to understand
    Better fault isolation
    More autonomy between services

    View Slide

  51. Microservice & Databases
    Microservices should own its database
    No external access
    Access through Microservice’s API only
    Database = infinite interface!

    View Slide

  52. But!

    View Slide

  53. 1 Method = Perfect Microservice !!??

    View Slide

  54. View Slide

  55. View Slide

  56. View Slide

  57. View Slide

  58. STAFF
    ONLY
    STAFF
    ONLY

    View Slide

  59. 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.

    View Slide

  60. Monolith Microservices Distributed

    Monolith
    Cost
    of
    Change

    View Slide

  61. Big Ball Of Mud Bounded
    Contexts
    Microservices Distributed
    Big Ball Of Mud
    Avg.
    Service
    Size

    View Slide

  62. Campaign
    Management
    Campaign Placement
    Funnel
    Banner
    Landing Page
    Website
    Zone
    Asset
    Publisher
    Target Market
    Campaign
    Website
    Placement
    Funnel
    Subdomains? En99es?

    View Slide

  63. View Slide

  64. ”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
    Composite / Structured Design, 1974

    View Slide

  65. ”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
    Composite / Structured Design, 1974

    View Slide

  66. When you design a system…, then if the features
    can be broken into … loosely bound groups of
    rela>vely closely bound features, then that
    division is a good thing to be made a part of the
    design. This is just good engineering.
    Tim Berners-Lee
    Principles of design, 1998

    View Slide

  67. Services + Good Engineering = Microservices

    View Slide

  68. 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

    View Slide

  69. A major part of this paper will be concerned with
    the ques>on of how good modularity can be
    achieved, that is, how modules can be chosen so
    as to minimize the connec5ons between them.
    Barbara Liskov
    A design methodology for reliable soIware systems, 1972

    View Slide

  70. 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.

    View Slide

  71. A microservice is a service with a micro interface.
    The threshold upon which the system can be decomposed
    is defined by the use cases of the system that the
    microservices are a part of.
    …how to evaluate?

    View Slide

  72. Design Heuris9cs

    View Slide

  73. Heuris9c #1: Decompose to Bounded Contexts
    Do not implement conflicting models in the same
    service. Always decompose to Bounded Contexts.

    View Slide

  74. Heuris9c #2: Don’t
    ”First Law of Distributed Object Design: 

    “Don’t distribute your objects”
    Mar9n Fowler

    View Slide

  75. Heuris9c #2: Don’t
    Benefits
    Addi6onal

    Complexity

    View Slide

  76. Heuris9c #2: Don’t
    Benefits Addi6onal
    Complexity

    View Slide

  77. Core
    Supporting
    Generic

    View Slide

  78. Generic Subdomains
    No competitive advantage
    Everybody is implementing in the same way
    Complex business logic

    View Slide

  79. Marke9ng
    Sales
    Commissions
    Desks
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Identity & Access
    Generic

    View Slide

  80. Heuris9c #3: Buy/Adopt Generic Subdomains
    Your
    System
    3rd party
    product

    View Slide

  81. Heuris9c #3: Buy/Adopt Generic Subdomains
    Your
    System
    3rd party
    product
    An6-Corrup6on Layer

    View Slide

  82. Core Subdomains
    Inventing something new
    Optimizing existing paractices
    Competitive advantage
    Complex business logic
    Change often

    View Slide

  83. Core Subdomains
    Inventing something new
    Optimizing existing paractices
    Competitive advantage
    Complex business logic
    Change often

    View Slide

  84. Heuris9c #4: Core Subdomains - Don’t Rush
    Adhere to subdomain’s boundaries.
    Decompose further only when you acquire
    domain knowledge.

    View Slide

  85. Suppor9ng Subdomains
    No competitive advantage
    Support the Core Subdomains
    Can’t be bought / adopted
    Simple business logic

    View Slide

  86. Marke9ng
    Sales
    Commissions
    Desks
    Sales
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Ad Optimization
    Identity & Access
    Generic Core Supporting

    View Slide

  87. Suppor9ng Subdomains
    No competitive advantage
    Support the Core Subdomains
    Can’t be bought / adopted
    Simple business logic

    View Slide

  88. Heuris9c #5: Suppor9ng Subdomains - Early
    Can be decomposed beyond the subdomain’s
    boundaries.

    View Slide

  89. Core
    Supporting
    Generic

    View Slide

  90. Heuris9c #6: Evaluate Consistency Requirements
    Method A Method B

    View Slide

  91. Heuris9c #6: Evaluate Consistency Requirements
    Concurrency control? - Same service
    Method A Method B

    Service A

    View Slide

  92. Heuris9c #6: Evaluate Consistency Requirements
    Read last write? - Two services, synchronous communication

    Service A
    Method A

    Service B
    Method B
    Sync call

    View Slide

  93. Heuris9c #6: Evaluate Consistency Requirements
    Eventual consistency? - Two services, asynchronous communication

    Service A
    Method A

    Service B
    Method B
    Asynchronous
    Communication

    View Slide

  94. Heuris9c #6: Evaluate Consistency Requirements
    Concurrency control? - Same service
    Read last write? - Two services, sync communication
    Eventual consistency? - Two services, async communication

    View Slide


  95. Service A
    Method A

    Service B
    Method B
    Asynchronous
    Communication

    View Slide

  96. Heuris9c #7: Public / Private Events
    Service
    Event Type 1
    Event Type 2
    Event Type 3
    Event Type 4
    Event Type 5
    Event Type 6
    Event Type 1000

    Private event types
    (Implementation details)
    }Public event types
    (Public interface)
    }

    View Slide

  97. Service
    EmailChanged
    PhoneNumberChanged
    AddressChanged
    ContactDetailsChanged
    Private event types
    (Implementation details)
    } Public event type
    (Public interface)
    }
    Heuris9c #7: Public / Private Events

    View Slide

  98. Heuris9c #7: Public / Private Events
    Events?

    View Slide

  99. Heuris9c #7: Public / Private Events
    Events?
    Domain
    Events
    State Change

    Events

    View Slide

  100. Heuris9c #7: Public / Private Events
    Events?
    Domain
    Events
    State Change

    Events
    Private Public

    View Slide

  101. Heuris9c #8: Make Events Explicit
    Eliminate ambiguity

    View Slide

  102. Heuris9c #8: Make Events Explicit
    Service
    AgentAssignedToLead

    View Slide

  103. Heuris9c #8: Make Events Explicit
    Service
    AgentAssignedToLead
    AgentAssignedToLead
    AgentAssignedToLead

    View Slide

  104. Heuris9c #8: Make Events Explicit
    Service
    AgentAssignedToLead
    AgentUnassigned
    AgentAssignedToLead

    View Slide

  105. Heuris9c #9: Evaluate Reasons for Change
    Service A Service B

    View Slide

  106. Same reasons for change?
    Same rate of change?
    Can be decoupled?
    Should be the same service?
    Heuris9c #9: Evaluate Reasons for Change

    View Slide

  107. Heuris9c #10: Evaluate Services’ “Doors”

    View Slide

  108. Heuris9c #10: Evaluate Services’ “Doors”
    STAFF
    ONLY
    STAFF
    ONLY

    View Slide

  109. Summary

    View Slide

  110. 1. A service is a unit of func6onality exposed to the
    world through its public interface.
    2. A microservice is a service with micro interface
    3. The “micro-interface” is rela6ve to the use cases of
    the system that the service is a part of

    View Slide

  111. Heuris6c #1: Always decompose to Bounded Contexts
    Heuris6c #2: Don’t go further, unless you have to
    Heuris6c #3: Buy/adopt generic subdomains
    Heuris6c #4: Core Subdomains - don’t rush
    Heuris6c #5: Suppor6ng Subdomains can be
    decomposed early

    View Slide

  112. Heuris6c #6: Evaluate Consistency Requirements
    Heuris6c #7: Private / Public Events
    Heuris6c #8: Explicitly Define Events
    Heuris6c #9: Evaluate Reasons for Change
    Heuris6c #10: Evaluate Services’ “Doors”

    View Slide

  113. Big Ball Of Mud Bounded
    Contexts
    Microservices Distributed
    Big Ball Of Mud
    Avg.
    Service
    Size

    View Slide

  114. Bibliography
    1. A Design Methodology for Reliable Soeware Systems, Barbara Liskov
    2. Composite/Structured Design, Glenford Myers
    3. Domain-Driven Design: Tackling Complexity in the Heart of Soeware, Eric Evans
    4. Emerging Boundaries, Mathias Veraes
    5. Implemen6ng Domain-Driven Design, Vaughn Vernon
    6. Enterprise Integra6on Paherns, Gregory Hohpe, at al
    7. Long Sad Story of Microservices, Greg Young
    8. Managing Data in Microservices, Randy Shoup
    9. Microservices, At Last Some Boundaries, Eric Evans
    10. On the Criteria to be Used in Decomposing Systems Into Modules, David Parnas
    11. Paherns of Enterprise Applica6on Architecture, Mar6n Fowler, at al
    12. Principles of Design, Tim Berners-Lee
    13. Programming WCF Services, Juval Lowy
    14. What Every Programmer Should Know About Object Oriented Design, Melir Page-Jones

    View Slide

  115. THANK YOU!
    @vladikk vladikk.com

    View Slide

  116. QUESTIONS?
    @vladikk vladikk.com

    View Slide

  117. THANK YOU!
    @vladikk vladikk.com

    View Slide