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

Models, Modules, and Microservices

Models, Modules, and Microservices

Talk last held on W-JAX 2019

Henning Schwentner

November 05, 2019
Tweet

More Decks by Henning Schwentner

Other Decks in Programming

Transcript

  1. Starring With
    Directed by
    In the role of
    Also Starring

    View full-size slide

  2. @hschwentner

    View full-size slide

  3. Foto: Steindy/Wikipedia

    View full-size slide

  4. @hschwentner
    Do I get a car for this?

    View full-size slide

  5. CUSTOMER
    TELLS WISH FOR
    1
    SALESPERSON
    SIGNS
    TO
    GIVES
    FOR
    CONTRACT
    3
    RISIK MANAGER
    CONTRACT
    PASSES ON
    TO
    4
    CONTRACT
    VOTES
    CHECKS
    CALCULATES
    5
    6
    7
    CALCU-
    LATES
    TO
    8
    2
    CAR
    CREDIT
    RATING
    INSTALLMENT
    CAR
    RESALE
    VALUE
    CONTRACT

    View full-size slide

  6. @hschwentner
    How do we design a
    program for that?

    View full-size slide

  7. @hschwentner
    #dddesign

    View full-size slide

  8. @hschwentner
    Was ist das
    für 1 Design?

    View full-size slide

  9. @hschwentner
    Vong Domain her

    View full-size slide

  10. -DRIVEN DESIGN

    View full-size slide

  11. Software
    Domain

    View full-size slide

  12. CUSTOMER
    SIGNS
    CONTRACT
    3
    RISK MANAGER
    CONTRACT
    VOTES
    7
    <>
    LeasingContract
    sign()
    vote()

    View full-size slide

  13. <>
    LeasingContract
    sign()
    vote()

    View full-size slide

  14. Object orientation

    View full-size slide

  15. <>
    LeasingContract
    sign()
    vote()
    extend()
    terminate()
    sell_to_refinance()
    ...

    View full-size slide

  16. @hschwentner
    The One Big Model

    View full-size slide

  17. @hschwentner
    Reality:
    Not one big model
    But several mixed models

    View full-size slide

  18. BBOM
    Foto: Benutzer:Summi/Wikipedia/CC-BY-SA-3.0-migrated

    View full-size slide

  19. @hschwentner
    “Whoever uses a canonical model
    has lost control over his life.”
    – Karl Lagerfeld

    View full-size slide

  20. @hschwentner
    »Wer ein unternehmensweites
    Modell einsetzt, hat die Kontrolle
    über sein Leben verloren«
    – Karl Lagerfeld

    View full-size slide

  21. @hschwentner
    Why is that?

    View full-size slide

  22. @hschwentner
    Too Big
    to be understood
    as a whole

    View full-size slide

  23. @hschwentner
    Model?

    View full-size slide

  24. A tool to understand the
    world

    View full-size slide

  25. CUSTOMER
    TELLS WISH FOR
    1
    SALES-PERSON
    SIGNS
    TO
    GIVES
    FOR
    CONTRACT
    3
    RISIK MANAGER
    CONTRACT
    PASSES ON
    TO
    4
    CONTRACT
    VOTES
    CHECKS
    CALCULATES
    5
    6
    7
    CALCU-
    LATES
    TO
    8
    2
    CAR
    CREDIT
    RATING
    INSTALLMENT
    CAR
    RESALE
    VALUE
    CONTRACT
    SALES
    RISK MANAGMENT

    View full-size slide

  26. <>
    LeasingContract
    sign()
    vote()

    View full-size slide

  27. <>
    LeasingContract
    sign()
    <>
    LeasingContract
    vote()

    View full-size slide

  28. <>
    LeasingContract
    sign()
    <>
    LeasingContract
    vote()
    SALES
    RISK
    MANAGEMENT

    View full-size slide

  29. Bounded Context

    View full-size slide

  30. <>
    LeasingContract
    sign()
    <>
    LeasingContract
    vote()
    SALES
    RISK
    MANAGEMENT

    View full-size slide

  31. @hschwentner
    Clear Boundaries

    View full-size slide

  32. @hschwentner
    Code
    Team
    Database

    View full-size slide

  33. @hschwentner
    Strategic Design

    View full-size slide

  34. Team Head
    Team Tail
    Team Body
    Team Legs

    View full-size slide

  35. Team Emma
    Team Berta
    Team Erna
    Team Lisl

    View full-size slide

  36. <>
    LeasingContract
    sign()
    <>
    LeasingContract
    vote()

    View full-size slide

  37. @hschwentner
    Implementing
    Multiple Models

    View full-size slide

  38. @hschwentner
    JVM:
    Packages
    Jigsaw-Modules

    View full-size slide

  39. @hschwentner
    .NET:
    DLLs

    View full-size slide

  40. @hschwentner
    PHP:
    Namespaces

    View full-size slide

  41. @hschwentner
    JavaScript:
    Revealing Module Pattern
    TypeScript:
    Modules

    View full-size slide

  42. @hschwentner
    Generally:
    Microservices
    Self-Contained Systems
    Verticals

    View full-size slide

  43. @hschwentner
    Multiple Models in Java

    View full-size slide

  44. @hschwentner
    How?

    View full-size slide

  45. @hschwentner
    1 bounded context
    =
    1 package

    View full-size slide

  46. package leasingninja.sales;
    class LeasingContract { /*...*/ }
    package leasingninja.riskmanagement;
    class LeasingContract { /*...*/ }

    View full-size slide

  47. <>
    LeasingContract
    sign()
    <>
    LeasingContract
    vote()
    <>
    leasingninja.sales
    <>
    leasingninja.riskmanagement

    View full-size slide

  48. Problems:
    * No real encapsulation
    * No nesting
    * only a logical group of
    classes

    View full-size slide

  49. Only public and package
    private

    View full-size slide

  50. But: all classes of a bounded
    context in one package ->
    already quite ok

    View full-size slide

  51. @hschwentner
    Project Jigsaw

    View full-size slide

  52. @hschwentner
    Real capsule

    View full-size slide

  53. @hschwentner
    package leasingninja.sales.ui;
    package leasingninja.sales.domain;
    package leasingninja.sales.infrastructure;

    View full-size slide

  54. @hschwentner
    package leasingninja.sales.ui;
    package leasingninja.sales.domain;
    package leasingninja.sales.infrastructure;
    package leasingninja.sales.api;

    View full-size slide

  55. @hschwentner
    /*
    module-info.java
    */
    module leasingninja.sales {
    exports leasingninja.sales.api;
    }

    View full-size slide

  56. leasingninja.sales.api
    leasingninja.sales.*
    Interface
    Not accessible
    from outside

    View full-size slide

  57. @hschwentner
    /*
    module-info.java
    */
    module leasingninja.riskmanagement {
    requires leasingninja.sales;
    }

    View full-size slide

  58. RISK
    MANAGE-MENT
    SALES

    View full-size slide

  59. Rule:
    reverse domain names

    View full-size slide

  60. @hschwentner
    /*
    module-info.java
    */
    module de.wps.leasingninja.sales {
    exports de.wps.leasingninja.sales.api;
    }

    View full-size slide

  61. @hschwentner
    /*
    module-info.java
    */
    module de.wps.leasingninja.riskmanagement {
    requires de.wps.leasingninja.sales;
    }

    View full-size slide

  62. @hschwentner
    Modular JAR

    View full-size slide

  63. @hschwentner
    Maybe even better fitting:
    services mit
    uses/provides with

    View full-size slide

  64. @hschwentner
    Multiple Models in .NET

    View full-size slide

  65. @hschwentner
    How?

    View full-size slide

  66. @hschwentner
    1 bounded context
    =
    1 DLL

    View full-size slide

  67. namespace Leasingninja.Sales
    {
    class LeasingContract { /*...*/ }
    }
    namespace Leasingninja.Riskmanagement;
    {
    class LeasingContract { /*...*/ }
    }

    View full-size slide

  68. <>
    LeasingContract
    sign()
    <>
    LeasingContract
    vote()
    <>
    Leasingninja.Sales
    <>
    Leasingninja.Riskmanagement

    View full-size slide

  69. @hschwentner
    Architecture inside a
    Bounded Context (DLL)

    View full-size slide

  70. @hschwentner
    namespace Leasingninja.Sales.UI {}
    namespace Leasingninja.Sales.Application {}
    namespace Leasingninja.Sales.Domain {}
    namespace Leasingninja.Sales.Infrastructure {}

    View full-size slide

  71. @hschwentner
    namespace Leasingninja.Sales.UI {}
    namespace Leasingninja.Sales.Application {}
    namespace Leasingninja.Sales.Domain {}
    namespace Leasingninja.Sales.Infrastructure {}
    namespace Leasingninja.Sales {}

    View full-size slide

  72. @hschwentner
    namespace Leasingninja.Sales.Domain
    {
    [Entity]
    internal class LeasingContract { /*...*/ }
    }
    namespace Leasingninja.Sales
    {
    [DomainEvent]
    public class ContractSigned { /*...*/ }
    }

    View full-size slide

  73. Leasingninja.Sales
    Leasingninja.Sales.UI
    Leasingninja.Sales.Application
    Leasingninja.Sales.Domain
    Leasingninja.Sales.Infrastructure
    Interface
    Not accessible
    from outside

    View full-size slide

  74. RISK
    MANAGE-MENT
    SALES

    View full-size slide

  75. @hschwentner
    Multiple Models in PHP

    View full-size slide

  76. @hschwentner
    How?

    View full-size slide

  77. @hschwentner
    1 bounded context
    =
    1 namespace

    View full-size slide

  78. namespace Leasingninja\Sales;
    class LeasingContract { /*...*/ }
    >
    namespace Leasingninja\Riskmanagement;
    class LeasingContract { /*...*/ }
    >

    View full-size slide

  79. FQCN
    (Fully qualified class name =
    full namespace + class name)

    View full-size slide

  80. <>
    LeasingContract
    sign()
    <>
    LeasingContract
    vote()
    <>
    Leasingninja.Sales
    <>
    Leasingninja.Riskmanagement

    View full-size slide

  81. Problems:
    * No encapsulation
    * only a logical group of
    classes

    View full-size slide

  82. But: all classes of a bounded
    context in one namespace ->
    better than nothing

    View full-size slide

  83. @hschwentner
    Architecture inside a
    Bounded Context

    View full-size slide

  84. @hschwentner
    namespace Leasingninja\Sales\UI;
    namespace Leasingninja\Sales\Application;
    namespace Leasingninja\Sales\Domain;
    namespace Leasingninja\Sales\Infrastructure;

    View full-size slide

  85. @hschwentner
    namespace Leasingninja\Sales\UI;
    namespace Leasingninja\Sales\Application;
    namespace Leasingninja\Sales\Domain;
    namespace Leasingninja\Sales\Infrastructure;
    namespace Leasingninja\Sales;

    View full-size slide

  86. Leasingninja.Sales
    Leasingninja.Sales.UI
    Leasingninja.Sales.Application
    Leasingninja.Sales.Domain
    Leasingninja.Sales.Infrastructure
    Interface
    (should)
    not be
    accessible from
    outside

    View full-size slide

  87. Convention:
    Access only 1 dot
    2 dot only in same BC

    View full-size slide

  88. RISK
    MANAGE-MENT
    SALES

    View full-size slide

  89. @hschwentner
    Multiple Models with
    Microservices

    View full-size slide

  90. Distributed System

    View full-size slide

  91. Fallacies of distributed
    computing:
    The network is reliable.
    Latency is zero.
    Bandwidth is infinite.
    The network is secure.
    Topology doesn't change.
    There is one administrator.
    Transport cost is zero.
    The network is homogeneous.

    View full-size slide

  92. Verticals
    Self-Contained Systems
    Microservices

    View full-size slide

  93. Micro-
    service A
    Presentation
    Domain
    Infrastructure
    Application
    Micro-
    service B
    Direct Access
    to DB
    Micro-
    service C

    View full-size slide

  94. @hschwentner
    Independent Deployability

    View full-size slide

  95. Team Emma
    Team Berta
    Team Erna
    Team Lisl

    View full-size slide

  96. Team Emma
    Team Berta
    Team Erna
    Team Lisl

    View full-size slide

  97. Team Emma
    Team Berta
    Team Erna
    Team Lisl

    View full-size slide

  98. RISK
    MANAGE-MENT
    SALES

    View full-size slide

  99. RISK
    MANAGE-MENT

    View full-size slide

  100. RISK
    MANAGE-MENT
    SALES

    View full-size slide

  101. @hschwentner
    Core Domain

    View full-size slide

  102. Team Emma
    Team Berta
    Team Erna
    Team Lisl

    View full-size slide

  103. Team Emma
    Team Berta
    Team Erna
    Team Lisl

    View full-size slide

  104. RISK
    MANAGE-MENT
    SALES

    View full-size slide

  105. @hschwentner
    How to split the monolith

    View full-size slide

  106. 1) How should it be?
    2) How is it?
    3) How to move the “is” to the “ideal”?
    RISK
    MANAGE-
    MENT
    SALES

    View full-size slide

  107. 1) How should it be?
    1) Collaborative Modelling
    2) “ideal” context map
    2) How is it?
    1) Architecture Analysis
    2) As-is context map
    3) How to move the “is” to the “ideal”?
    1) Extract a supporting domain to learn
    2) Then extract core(s)

    View full-size slide

  108. <>
    LeasingContract
    sign()
    vote()
    SALES
    RISK
    MANAGEMENT
    <>
    LeasingContract
    sign()
    vote()
    BIG BALL
    OF MUD
    <>
    LeasingContract
    sign()
    vote()

    View full-size slide

  109. @hschwentner
    Always Microservices?

    View full-size slide

  110. Distributed
    Big Ball Of Mud
    Modulith Microservices
    Monolithic
    Big Ball Of Mud

    View full-size slide

  111. @hschwentner
    Consulting

    View full-size slide

  112. @hschwentner
    Team organization

    View full-size slide

  113. “Organizations which design systems
    are constrained to produce designs
    which are copies of the
    communication structures of
    these organizations.”
    Melvin Conway

    View full-size slide

  114. Melvin Conway
    (1967)
    “Organizations which design systems
    are constrained to produce designs
    which are copies of the
    communication structures of
    these organizations.”

    View full-size slide

  115. “The organization of the software and
    the organization of the software team
    will be congruent.”
    Eric Raymond

    View full-size slide

  116. “If you have four groups working on a compiler,
    you'll get a 4-pass compiler.”
    Eric Raymond

    View full-size slide

  117. @hschwentner
    Conclusion

    View full-size slide

  118. 1. Model your domain
    2. Split => several models
    (3. Distribute models)

    View full-size slide

  119. Strategic Design must
    Microservices can

    View full-size slide

  120. @hschwentner
    Further Reading

    View full-size slide

  121. @hschwentner
    LeasingNinja.io

    View full-size slide

  122. @hschwentner
    speakerdeck.com/hschwentner

    View full-size slide

  123. Foto: H. Schwentner

    View full-size slide

  124. Foto: H. Schwentner

    View full-size slide

  125. Foto: Amazon

    View full-size slide

  126. 15$ online:
    leanpub.com/domainstorytelling
    Frag mich nach
    Deiner Kopie
    Einführung mit allem
    was man wissen muss
    Überblick
    Rabatt!
    https://leanpub.com/domainstorytelling/c/wjax2019

    View full-size slide

  127. @hschwentner
    What now?

    View full-size slide

  128. @hschwentner
    Consulting

    View full-size slide

  129. Workshop
    Domain-Driven Design concrete
    wps.de/ddd

    View full-size slide

  130. @hschwentner
    Foto: Henning Schwentner

    View full-size slide

  131. @hschwentner
    FEEDBACK

    View full-size slide

  132. Henning Schwentner
    @hschwentner
    [email protected]
    DDD
    DDD
    Slides: speakerdeck.com/hschwentner
    Book: leanpub.com/domainstorytelling

    View full-size slide