Save 37% off PRO during our Black Friday Sale! »

Models, Modules, and Microservices

Models, Modules, and Microservices

Talk last held on W-JAX 2019

575ca492bac55e895d0e1c86f7d709fe?s=128

Henning Schwentner

November 05, 2019
Tweet

Transcript

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

  2. None
  3. None
  4. None
  5. H3NN1NG

  6. Schw3ntn3r

  7. @hschwentner

  8. None
  9. Foto: Steindy/Wikipedia

  10. None
  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. @hschwentner Do I get a car for this?

  18. None
  19. None
  20. 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
  21. @hschwentner How do we design a program for that?

  22. None
  23. @hschwentner #dddesign

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

  25. @hschwentner Vong Domain her

  26. -DRIVEN DESIGN

  27. Software Domain

  28. None
  29. None
  30. None
  31. CUSTOMER SIGNS CONTRACT 3 RISK MANAGER CONTRACT VOTES 7 <<Entity>>

    LeasingContract sign() vote()
  32. <<Entity>> LeasingContract sign() vote()

  33. Object orientation

  34. <<Entity>> LeasingContract sign() vote() extend() terminate() sell_to_refinance() ...

  35. @hschwentner The One Big Model

  36. None
  37. None
  38. @hschwentner Reality: Not one big model But several mixed models

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

  40. None
  41. None
  42. @hschwentner “Whoever uses a canonical model has lost control over

    his life.” – Karl Lagerfeld
  43. @hschwentner »Wer ein unternehmensweites Modell einsetzt, hat die Kontrolle über

    sein Leben verloren« – Karl Lagerfeld
  44. @hschwentner Why is that?

  45. None
  46. None
  47. @hschwentner Too Big to be understood as a whole

  48. None
  49. None
  50. @hschwentner Model?

  51. A tool to understand the world

  52. ?

  53. ?

  54. ?

  55. None
  56. None
  57. None
  58. None
  59. 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
  60. <<Entity>> LeasingContract sign() vote() ✘

  61. <<Entity>> LeasingContract sign() <<Entity>> LeasingContract vote()

  62. <<Entity>> LeasingContract sign() <<Entity>> LeasingContract vote() SALES RISK MANAGEMENT

  63. Bounded Context

  64. <<Entity>> LeasingContract sign() <<Entity>> LeasingContract vote() SALES RISK MANAGEMENT

  65. None
  66. @hschwentner Clear Boundaries

  67. None
  68. @hschwentner Code Team Database

  69. @hschwentner Strategic Design

  70. None
  71. None
  72. None
  73. None
  74. Team Head Team Tail Team Body Team Legs

  75. Team Emma Team Berta Team Erna Team Lisl

  76. <<Entity>> LeasingContract sign() <<Entity>> LeasingContract vote()

  77. @hschwentner Implementing Multiple Models

  78. @hschwentner JVM: Packages Jigsaw-Modules

  79. @hschwentner .NET: DLLs

  80. @hschwentner PHP: Namespaces

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

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

  83. @hschwentner Multiple Models in Java

  84. @hschwentner How?

  85. Packages

  86. @hschwentner 1 bounded context = 1 package

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

    LeasingContract { /*...*/ }
  88. <<Entity>> LeasingContract sign() <<Entity>> LeasingContract vote() <<package>> leasingninja.sales <<package>> leasingninja.riskmanagement

  89. Problems: * No real encapsulation * No nesting * only

    a logical group of classes
  90. Only public and package private

  91. But: all classes of a bounded context in one package

    -> already quite ok
  92. @hschwentner Project Jigsaw

  93. @hschwentner Real capsule

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

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

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

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

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

  99. RISK MANAGE-MENT SALES

  100. Rule: reverse domain names

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

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

  103. @hschwentner Modular JAR

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

  105. @hschwentner Multiple Models in .NET

  106. @hschwentner How?

  107. Assembly

  108. @hschwentner 1 bounded context = 1 DLL

  109. namespace Leasingninja.Sales { class LeasingContract { /*...*/ } } namespace

    Leasingninja.Riskmanagement; { class LeasingContract { /*...*/ } }
  110. <<Entity>> LeasingContract sign() <<Entity>> LeasingContract vote() <<Assembly>> Leasingninja.Sales <<Assembly>> Leasingninja.Riskmanagement

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

  112. @hschwentner namespace Leasingninja.Sales.UI {} namespace Leasingninja.Sales.Application {} namespace Leasingninja.Sales.Domain {}

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

    namespace Leasingninja.Sales.Infrastructure {} namespace Leasingninja.Sales {}
  114. @hschwentner namespace Leasingninja.Sales.Domain { [Entity] internal class LeasingContract { /*...*/

    } } namespace Leasingninja.Sales { [DomainEvent] public class ContractSigned { /*...*/ } }
  115. Leasingninja.Sales Leasingninja.Sales.UI Leasingninja.Sales.Application Leasingninja.Sales.Domain Leasingninja.Sales.Infrastructure Interface Not accessible from outside

  116. RISK MANAGE-MENT SALES

  117. @hschwentner Multiple Models in PHP

  118. @hschwentner How?

  119. Namespace

  120. @hschwentner 1 bounded context = 1 namespace

  121. <?php namespace Leasingninja\Sales; class LeasingContract { /*...*/ } > <?php

    namespace Leasingninja\Riskmanagement; class LeasingContract { /*...*/ } >
  122. FQCN (Fully qualified class name = full namespace + class

    name)
  123. <<Entity>> LeasingContract sign() <<Entity>> LeasingContract vote() <<Namespace>> Leasingninja.Sales <<Namespace>> Leasingninja.Riskmanagement

  124. Problems: * No encapsulation * only a logical group of

    classes
  125. But: all classes of a bounded context in one namespace

    -> better than nothing
  126. @hschwentner Architecture inside a Bounded Context

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

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

    Leasingninja\Sales;
  129. Leasingninja.Sales Leasingninja.Sales.UI Leasingninja.Sales.Application Leasingninja.Sales.Domain Leasingninja.Sales.Infrastructure Interface (should) not be accessible

    from outside
  130. Convention: Access only 1 dot 2 dot only in same

    BC
  131. RISK MANAGE-MENT SALES

  132. None
  133. @hschwentner Multiple Models with Microservices

  134. None
  135. None
  136. None
  137. Distributed System

  138. 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.
  139. Verticals Self-Contained Systems Microservices

  140. None
  141. None
  142. Micro- service A Presentation Domain Infrastructure Application Micro- service B

    Direct Access to DB Micro- service C
  143. None
  144. None
  145. None
  146. @hschwentner Independent Deployability

  147. Team Emma Team Berta Team Erna Team Lisl

  148. Team Emma Team Berta Team Erna Team Lisl

  149. Team Emma Team Berta Team Erna Team Lisl

  150. RISK MANAGE-MENT SALES

  151. RISK MANAGE-MENT

  152. RISK MANAGE-MENT SALES

  153. @hschwentner Core Domain

  154. Team Emma Team Berta Team Erna Team Lisl

  155. Team Emma Team Berta Team Erna Team Lisl

  156. None
  157. None
  158. RISK MANAGE-MENT SALES

  159. None
  160. @hschwentner How to split the monolith

  161. 1) How should it be? 2) How is it? 3)

    How to move the “is” to the “ideal”? RISK MANAGE- MENT SALES
  162. 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)
  163. <<Entity>> LeasingContract sign() vote() SALES RISK MANAGEMENT <<Entity>> LeasingContract sign()

    vote() BIG BALL OF MUD <<Entity>> LeasingContract sign() vote()
  164. @hschwentner Always Microservices?

  165. Simon Brown

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

    Of Mud
  167. None
  168. @hschwentner Consulting

  169. @hschwentner Team organization

  170. None
  171. None
  172. None
  173. “Organizations which design systems are constrained to produce designs which

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

    produce designs which are copies of the communication structures of these organizations.”
  175. “The organization of the software and the organization of the

    software team will be congruent.” Eric Raymond
  176. “If you have four groups working on a compiler, you'll

    get a 4-pass compiler.” Eric Raymond
  177. @hschwentner Conclusion

  178. 1. Model your domain 2. Split => several models (3.

    Distribute models)
  179. Strategic Design must Microservices can

  180. @hschwentner Further Reading

  181. @hschwentner LeasingNinja.io

  182. @hschwentner speakerdeck.com/hschwentner

  183. Foto: H. Schwentner

  184. Foto: H. Schwentner

  185. Foto: Amazon

  186. None
  187. None
  188. 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
  189. @hschwentner What now?

  190. @hschwentner Consulting

  191. None
  192. Workshop Domain-Driven Design concrete wps.de/ddd

  193. @hschwentner Foto: Henning Schwentner

  194. None
  195. None
  196. None
  197. @hschwentner FEEDBACK

  198. None
  199. None
  200. None
  201. None
  202. None
  203. None
  204. Henning Schwentner @hschwentner hs@wps.de DDD DDD Slides: speakerdeck.com/hschwentner Book: leanpub.com/domainstorytelling