$30 off During Our Annual Pro Sale. View Details »

Microservices, Boounded Contexts, and Everything in Between

Microservices, Boounded Contexts, and Everything in Between

Vladik Khononov

September 10, 2020
Tweet

More Decks by Vladik Khononov

Other Decks in Programming

Transcript

  1. vladikk doit-intl.com
    MICROSERVICES
    BOUNDED CONTEXTS
    AND EVERYTHING IN BETWEEN

    View Slide

  2. vladikk doit-intl.com
    ”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

    View Slide

  3. vladikk doit-intl.com

    View Slide

  4. vladikk doit-intl.com
    “MICROSERVICES FTW!!!!!!!!1”
    Me @ Internovus

    View Slide

  5. vladikk doit-intl.com
    “MICROSERVICES FTW!!!!!!!!1”
    Me @ Internovus

    View Slide

  6. vladikk doit-intl.com
    ”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

    View Slide

  7. vladikk doit-intl.com

    View Slide

  8. vladikk doit-intl.com

    View Slide

  9. vladikk doit-intl.com
    Decomposi)on Strategies
    Microservices
    Design Heuris)cs

    View Slide

  10. vladikk doit-intl.com
    Decomposi)on Strategies
    Microservices
    Design Heuris)cs

    View Slide

  11. vladikk doit-intl.com
    Decomposi)on Strategies
    Microservices
    Design Heuris)cs

    View Slide

  12. vladikk doit-intl.com
    INTERNOVUS
    01
    BUSINESS DOMAIN

    View Slide

  13. vladikk doit-intl.com
    Your Product Marketing
    Strategy
    Creatives Campaigns Sales
    Agents
    Optimization
    Profits

    View Slide

  14. vladikk doit-intl.com
    DECOMPOSITION
    02
    STRATEGIES

    View Slide

  15. vladikk doit-intl.com
    Bounded Contexts

    View Slide

  16. vladikk doit-intl.com

    View Slide

  17. vladikk doit-intl.com
    Domain Expert
    Software Developer

    View Slide

  18. vladikk doit-intl.com
    Business Domain Expert
    Software Developer
    ???
    !!!
    Ubiquitous Language

    View Slide

  19. vladikk doit-intl.com
    Campaigns Sales
    Agents
    Your Product Marketing
    Strategy
    Creatives
    Optimization
    Profits

    View Slide

  20. vladikk doit-intl.com
    Sales Agent
    Campaign Manager
    ???
    !!!
    LEAD?

    View Slide

  21. vladikk doit-intl.com
    Conflicting models
    Different contexts
    Dividing the language/model
    Bounded Context

    View Slide

  22. vladikk doit-intl.com
    MarkeCng
    Sales
    Lead Lead
    Funnel
    Campaign
    Placement
    Landing Page
    Agency Insertion Order
    Message
    Campaign
    Proposition
    Desk
    Conversion
    Contact
    CDR
    Bounded Contexts

    View Slide

  23. vladikk doit-intl.com
    MarkeCng
    Service
    Sales
    Service
    DecomposiCon Strategy #1: Bounded Contexts

    View Slide

  24. vladikk doit-intl.com
    MarkeCng
    Sales
    Commissions
    Desks
    Sales
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Ads Optimization
    Identity & Access

    View Slide

  25. vladikk doit-intl.com
    Business (Sub)Domains

    View Slide

  26. vladikk doit-intl.com
    Business Domain: Customer Acquisi)on
    Bounded Context: Marke)ng Bounded Context: Sales
    Subdomain: Crea)ve Catalog
    Subdomain: Campaigns Mngmt
    Subdomain: Ads Op)miza)on
    Subdomain: Contracts Mngmt
    Subdomain: CRM
    Subdomain: Sales Op)miza)on
    Subdomain: Commissions
    Subdomain: Desks Mngmt

    View Slide

  27. vladikk doit-intl.com
    DecomposiCon Strategy #2: Subomains
    Campaign
    Management
    Service
    Content
    Catalog
    Service
    Desks
    Management
    Service
    CRM
    Service
    Users
    Service
    Billing
    Service

    View Slide

  28. vladikk doit-intl.com
    Business EnCCes and Processes

    View Slide

  29. vladikk doit-intl.com
    MarkeCng
    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

  30. vladikk doit-intl.com
    DecomposiCon Strategy #3: EnCCes
    Website Asset Target Market
    Broker Distribu)on Customer

    View Slide

  31. vladikk doit-intl.com
    DecomposiCon Strategies
    Bounded Contexts
    Subdomains
    Business Entities and Processes

    View Slide

  32. vladikk doit-intl.com
    SHOW ME THE
    MICROSERVICES!

    View Slide

  33. vladikk doit-intl.com
    MarkeCng
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Campaign
    Management
    Campaign Placement
    Funnel
    Banner
    Landing Page
    Website
    Zone
    Asset
    Publisher
    Target Market
    Campaign
    Website
    Placement
    Funnel
    Bounded Contexts? Subdomains? EnCCes?

    View Slide

  34. vladikk doit-intl.com
    Bounded Contexts == Microservices ?

    View Slide

  35. vladikk doit-intl.com
    Sales Agent
    Campaign Manager
    ???
    !!!
    LEAD?

    View Slide

  36. vladikk doit-intl.com
    MarkeCng
    Sales
    Lead Lead
    Funnel
    Campaign
    Placement
    Landing Page
    Agency Insertion Order
    Message
    Campaign
    Proposition
    Desk
    Conversion
    Contact
    CDR

    View Slide

  37. vladikk doit-intl.com
    MarkeCng
    Sales
    Commissions
    Desks
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Identity & Access
    Lead
    Lead

    View Slide

  38. vladikk doit-intl.com
    MarkeCng
    Creative
    Catalog
    Campaign
    Management
    Optimization
    Lead
    Sales
    Commissions
    Optimization
    CRM Lead
    Desks
    Telephony
    Support
    Contracts
    Billing
    Identity & Access

    View Slide

  39. vladikk doit-intl.com
    Bounded Contexts
    Decomposi)on #1
    Bounded Contexts
    Decomposi)on #2
    Bounded Contexts
    Decomposi)on #3

    View Slide

  40. vladikk doit-intl.com
    Bounded Context
    Consistency boundary of the language / model
    Define the biggest valid monoliths
    Required decomposition boundary

    View Slide

  41. vladikk doit-intl.com
    Bounded Contexts == Microservices? No

    View Slide

  42. vladikk doit-intl.com
    Campaign
    Management
    Campaign Placement
    Funnel
    Banner
    Landing Page
    Website
    Zone
    Asset
    Publisher
    Target Market
    Campaign
    Website
    Placement
    Funnel
    MarkeCng
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Bounded Contexts? No Subdomains? EnCCes?

    View Slide

  43. vladikk doit-intl.com
    MICROSERVICES
    03

    View Slide

  44. vladikk doit-intl.com
    “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

  45. vladikk doit-intl.com
    Service Interface
    “Any mechanism for getting data in or out of the service”
    - Randy Shoup

    View Slide

  46. vladikk doit-intl.com
    Service Interface
    Asynchronous:
    • Producing events
    • Consuming events
    Synchronous:
    • Request / Response
    • Bulk ETL

    View Slide

  47. vladikk doit-intl.com
    Service Interface
    “Any mechanism for getting data in or out of the service”
    - Randy Shoup

    View Slide

  48. vladikk doit-intl.com
    Service Interface

    View Slide

  49. vladikk doit-intl.com
    Services ➜ Microservice

    View Slide

  50. vladikk doit-intl.com
    A microservice is a service with a micro interface

    View Slide

  51. vladikk doit-intl.com
    Microservice = Microinterface
    Reducing coupling between services
    Limits reasons for change
    Easier to understand
    Better fault isolation
    More autonomy between services

    View Slide

  52. vladikk doit-intl.com
    Microservice = Microinterface
    Reducing coupling between services
    Limits reasons for change
    Easier to understand
    Better fault isolation
    More autonomy between services

    View Slide

  53. vladikk doit-intl.com
    Microservice & Databases
    Microservices should own its database
    No external access
    Access through Microservice’s API only
    Database = infinite interface!

    View Slide

  54. vladikk doit-intl.com
    1 Method = Perfect Microservice !!??

    View Slide

  55. vladikk doit-intl.com

    View Slide

  56. vladikk doit-intl.com

    View Slide

  57. vladikk doit-intl.com

    View Slide

  58. vladikk doit-intl.com

    View Slide

  59. vladikk doit-intl.com
    STAFF
    ONLY
    STAFF
    ONLY

    View Slide

  60. vladikk doit-intl.com
    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

  61. vladikk doit-intl.com
    Monolith Microservices Distributed
    Monolith
    Cost
    of
    Change

    View Slide

  62. vladikk doit-intl.com
    Big Ball Of Mud Bounded
    Contexts
    Microservices Distributed
    Big Ball Of Mud
    Avg.
    Service
    Size

    View Slide

  63. vladikk doit-intl.com
    Campaign
    Management
    Campaign Placement
    Funnel
    Banner
    Landing Page
    Website
    Zone
    Asset
    Publisher
    Target Market
    Campaign
    Website
    Placement
    Funnel
    Subdomains? EnCCes?

    View Slide

  64. vladikk doit-intl.com

    View Slide

  65. vladikk doit-intl.com
    ”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

    View Slide

  66. vladikk doit-intl.com
    ”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, 1978

    View Slide

  67. vladikk doit-intl.com
    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

  68. vladikk doit-intl.com
    Services + Good Engineering = Microservices

    View Slide

  69. vladikk doit-intl.com
    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

  70. vladikk doit-intl.com
    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

  71. vladikk doit-intl.com
    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

  72. vladikk doit-intl.com
    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

  73. vladikk doit-intl.com
    DESIGN
    04
    HEURISTICS

    View Slide

  74. vladikk doit-intl.com
    HeurisCc #1: Decompose to Bounded Contexts
    Do not implement conflicting models in the same service.
    Always decompose to Bounded Contexts.

    View Slide

  75. vladikk doit-intl.com
    HeurisCc #2: Don’t
    First Law of Distributed Object Design:
    “Don’t distribute your objects”
    MarCn Fowler

    View Slide

  76. vladikk doit-intl.com
    HeurisCc #2: Don’t
    Benefits
    Addi)onal
    Complexity

    View Slide

  77. vladikk doit-intl.com
    MONOLITH
    SYSTEM DESIGN THAT UNDERMINES DELIVERY OF
    FUNCTIONAL OR NON-FUNCTIONAL REQUIREMENTS

    View Slide

  78. vladikk doit-intl.com
    HeurisCc #2: Don’t
    Benefits
    Addi)onal
    Complexity

    View Slide

  79. vladikk doit-intl.com
    HeurisCc #2: Don’t
    Benefits Addi)onal
    Complexity

    View Slide

  80. vladikk doit-intl.com
    Core
    Supporting
    Generic

    View Slide

  81. vladikk doit-intl.com
    Generic Subdomains
    No competitive advantage
    Everybody is implementing in the same way
    Complex business logic

    View Slide

  82. vladikk doit-intl.com
    MarkeCng
    Sales
    Commissions
    Desks
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Optimization
    Identity & Access
    Generic

    View Slide

  83. vladikk doit-intl.com
    HeurisCc #3: Buy/Adopt Generic Subdomains
    Your
    System
    3rd party
    product

    View Slide

  84. vladikk doit-intl.com
    HeurisCc #3: Buy/Adopt Generic Subdomains
    Your
    System
    3rd party
    product
    An)-Corrup)on Layer

    View Slide

  85. vladikk doit-intl.com
    Core Subdomains
    Inventing something new
    Optimizing existing paractices
    Competitive advantage
    Complex business logic
    Change often

    View Slide

  86. vladikk doit-intl.com
    MarkeCng
    Sales
    Commissions
    Desks
    Sales
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Ad Optimization
    Identity & Access
    Generic Core

    View Slide

  87. vladikk doit-intl.com
    Core Subdomains
    Inventing something new
    Optimizing existing paractices
    Competitive advantage
    Complex business logic
    Change often

    View Slide

  88. vladikk doit-intl.com
    HeurisCc #4: Core Subdomains - Don’t Rush
    Adhere to subdomain’s boundaries.
    Decompose further only when you acquire
    domain knowledge.

    View Slide

  89. vladikk doit-intl.com
    SupporCng Subdomains
    No competitive advantage
    Support the Core Subdomains
    Can’t be bought / adopted
    Simple business logic

    View Slide

  90. vladikk doit-intl.com
    MarkeCng
    Sales
    Commissions
    Desks
    Sales
    Optimization
    CRM
    Telephony
    Creative
    Catalog
    Contracts
    Billing
    Campaign
    Management
    Identity & Access
    Ad Optimization
    Identity & Access
    Generic Core Supporting

    View Slide

  91. vladikk doit-intl.com
    SupporCng Subdomains
    No competitive advantage
    Support the Core Subdomains
    Can’t be bought / adopted
    Simple business logic

    View Slide

  92. vladikk doit-intl.com
    HeurisCc #5: SupporCng Subdomains - Safe
    Safe to decompose beyond the subdomain’s
    boundaries.

    View Slide

  93. vladikk doit-intl.com
    Core
    Supporting
    Generic

    View Slide

  94. vladikk doit-intl.com
    HeurisCc #6: Evaluate Consistency Requirements
    Method A Method B

    View Slide

  95. vladikk doit-intl.com
    HeurisCc #6: Evaluate Consistency Requirements
    Concurrency control? - Same service
    Method A Method B
    Service A

    View Slide

  96. vladikk doit-intl.com
    HeurisCc #6: Evaluate Consistency Requirements
    Read last write? - Two services, synchronous communication
    Service A
    Method A
    Service B
    Method B
    Sync call

    View Slide

  97. vladikk doit-intl.com
    HeurisCc #6: Evaluate Consistency Requirements
    Eventual consistency? - Two services, asynchronous communication
    Service A
    Method A
    Service B
    Method B
    Asynchronous
    Communication

    View Slide

  98. vladikk doit-intl.com
    HeurisCc #6: Evaluate Consistency Requirements
    Concurrency control? - Same service
    Read last write? - Two services, sync communication
    Eventual consistency? - Two services, async communication

    View Slide

  99. vladikk doit-intl.com
    Service A
    Method A
    Service B
    Method B
    Asynchronous
    Communication

    View Slide

  100. vladikk doit-intl.com
    HeurisCc #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

    View Slide

  101. vladikk doit-intl.com
    HeurisCc #7: Public / Private Events
    Service
    Event Type 1
    Event Type 2
    Event Type 3
    Event Type 4
    Event Type 5
    Event Type 6
    Private event types
    (Implementation details)
    }
    Event Type 1000

    View Slide

  102. vladikk doit-intl.com
    HeurisCc #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

  103. vladikk doit-intl.com
    Service
    EmailChanged
    PhoneNumberChanged
    AddressChanged
    ContactDetailsChanged
    HeurisCc #7: Public / Private Events

    View Slide

  104. vladikk doit-intl.com
    Service
    EmailChanged
    PhoneNumberChanged
    AddressChanged
    ContactDetailsChanged
    Private event types
    (Implementation details)
    } Public event type
    (Public interface)
    }
    HeurisCc #7: Public / Private Events

    View Slide

  105. vladikk doit-intl.com
    HeurisCc #7: Public / Private Events
    Events?
    Domain
    Events
    State Change
    Events

    View Slide

  106. vladikk doit-intl.com
    HeurisCc #7: Public / Private Events
    Events?
    Domain
    Events
    State Change
    Events
    Private Public

    View Slide

  107. vladikk doit-intl.com
    HeurisCc #8: Make Events Explicit
    Eliminate ambiguity

    View Slide

  108. vladikk doit-intl.com
    HeurisCc #8: Make Events Explicit
    Service
    AgentAssignedToLead
    AgentAssignedToLead
    AgentAssignedToLead

    View Slide

  109. vladikk doit-intl.com
    HeurisCc #8: Make Events Explicit
    Service
    AgentAssignedToLead
    AgentUnassignedToLead
    AgentAssignedToLead

    View Slide

  110. vladikk doit-intl.com
    HeurisCc #9: Evaluate Reasons for Change
    Service A Service B

    View Slide

  111. vladikk doit-intl.com
    Same reasons for change?
    Same rate of change?
    Can be decoupled?
    Should be the same service?
    HeurisCc #9: Evaluate Reasons for Change

    View Slide

  112. vladikk doit-intl.com

    View Slide

  113. vladikk doit-intl.com
    HeurisCc #10: Evaluate Services’ “Doors”

    View Slide

  114. vladikk doit-intl.com
    HeurisCc #10: Evaluate Services’ “Doors”
    STAFF
    ONLY
    STAFF
    ONLY

    View Slide

  115. vladikk doit-intl.com
    WRAP UP
    05

    View Slide

  116. vladikk doit-intl.com
    1. A service is a unit of func)onality exposed to the
    world through its public interface.
    2. A microservice is a service with micro interface
    3. The “micro-interface” is rela)ve to the use cases of
    the system that the service is a part of

    View Slide

  117. vladikk doit-intl.com
    Heuris)c #1: Always decompose to Bounded Contexts
    Heuris)c #2: Don’t go further, unless you have to
    Heuris)c #3: Buy/adopt generic subdomains
    Heuris)c #4: Core subdomains - don’t rush
    Heuris)c #5: Suppor)ng subdomains can be
    decomposed early

    View Slide

  118. vladikk doit-intl.com
    Heuris)c #6: Evaluate Consistency Requirements
    Heuris)c #7: Private / Public Events
    Heuris)c #8: Explicitly Define Events
    Heuris)c #9: Evaluate Reasons for Change
    Heuris)c #10: Evaluate Services’ “Doors”

    View Slide

  119. vladikk doit-intl.com
    Big Ball Of Mud Bounded
    Contexts
    Microservices Distributed
    Big Ball Of Mud
    Avg.
    Service
    Size

    View Slide

  120. vladikk doit-intl.com
    Bibliography
    1. A Design Methodology for Reliable Soeware Systems, Barbara Liskov
    2. Designing Autonomous Teams and Services, Nick Tune & Scoh Millet
    3. Composite/Structured Design, Glenford Myers
    4. Domain-Driven Design: Tackling Complexity in the Heart of Soeware, Eric Evans
    5. Emerging Boundaries, Mathias Veraes
    6. Implemen)ng Domain-Driven Design, Vaughn Vernon
    7. Enterprise Integra)on Paherns, Gregory Hohpe, at al
    8. Long Sad Story of Microservices, Greg Young
    9. Managing Data in Microservices, Randy Shoup
    10. Microservices, At Last Some Boundaries, Eric Evans
    11. On the Criteria to be Used in Decomposing Systems Into Modules, David Parnas
    12. Paherns of Enterprise Applica)on Architecture, Mar)n Fowler, at al
    13. Principles of Design, Tim Berners-Lee
    14. Programming WCF Services, Juval Lowy
    15. What Every Programmer Should Know About Object Oriented Design, Melir Page-Jones

    View Slide

  121. https://bit.ly/2ptJ5fS
    THANK
    YOU!
    @vladikk
    vladikk.com
    https://bit.ly/31nSD9c
    http://careers.doit-intl.com

    View Slide

  122. QUESTIONS?
    @vladikk vladikk.com

    View Slide