DDD in a Clojure Event Driven Application Gilles

  • Slides: 24
Download presentation
DDD in a Clojure Event -Driven Application Gilles Philippart Senior Software Engineer @Funding Circle

DDD in a Clojure Event -Driven Application Gilles Philippart Senior Software Engineer @Funding Circle

Overview ● Context ● What is DDD ? ● Patterns we use ● Summary

Overview ● Context ● What is DDD ? ● Patterns we use ● Summary ● Q&A 2

Event-Driven Architecture App B App A App C 3

Event-Driven Architecture App B App A App C 3

How to create a well thought-out, effective, extensible design ?

How to create a well thought-out, effective, extensible design ?

5

5

Domain-Driven Design A set of tools to help designing and implementing complex software 6

Domain-Driven Design A set of tools to help designing and implementing complex software 6

DDD levels Strategic Design • • • Deals with large models Think about what

DDD levels Strategic Design • • • Deals with large models Think about what matters most Divide work between teams and integrate Tactical Design Manages complexity and ensure clarity of behavior within the domain model 7

Strategic Patterns Bounded Context A bounded context is a part of your problem space.

Strategic Patterns Bounded Context A bounded context is a part of your problem space. Things inside a context may have a different meaning in another one. 8

Bounded Contexts REPAYMENTS PROCESSING LEGACY INVESTOR LOAN SERVICING DISTRIBUTION MONEY MOVEMENTS 9

Bounded Contexts REPAYMENTS PROCESSING LEGACY INVESTOR LOAN SERVICING DISTRIBUTION MONEY MOVEMENTS 9

Strategic Patterns Ubiquitous Language A language that is developed by the team working in

Strategic Patterns Ubiquitous Language A language that is developed by the team working in the Bounded Context and is spoken by every member of the team that creates the software model 10

Ubiquitous Language • • • Shared understanding of the verbs and nouns Bring domain

Ubiquitous Language • • • Shared understanding of the verbs and nouns Bring domain experts and developers Event Storming session

Strategic Patterns Context Mapping Context Maps define both team relationships and technical mechanisms that

Strategic Patterns Context Mapping Context Maps define both team relationships and technical mechanisms that exist between two integrating Bounded Contexts Published Language Open Host Service Anticorruption Layer Conformist Customer-Supplier Big Ball of Mud Shared Kernel 12

Customer-supplier and ACL REPAYMENTS PROCESSING LEGACY U D LOAN SERVICING U AC L D

Customer-supplier and ACL REPAYMENTS PROCESSING LEGACY U D LOAN SERVICING U AC L D U INVESTOR D D U REPAYMENT DISTRIBUTION U D MONEY MOVEMENTS 13

Published Language • • • Use PL agnostic schemas (Avro) Publish the language in

Published Language • • • Use PL agnostic schemas (Avro) Publish the language in a visible place Control its evolution

Loan Manager 3 1. CHECK 2. APPLY 3. UPDATE Repayment. Released Repayment. Reversed LOAN

Loan Manager 3 1. CHECK 2. APPLY 3. UPDATE Repayment. Released Repayment. Reversed LOAN STATE Default. Requested Repayment. Paid Reversal. Applied 1 2 4 Loan. Defaulted LOAN STORE 15

Tactical Patterns Aggregate ● Objects bound together by a root entity ● Keeps model

Tactical Patterns Aggregate ● Objects bound together by a root entity ● Keeps model in valid state Loan Original Schedule Entry 1 Repayments Entry n Rep. 1 Rep. n 16

Tactical Patterns Event Sourcing ● Keeps track of what happened in the aggregate ●

Tactical Patterns Event Sourcing ● Keeps track of what happened in the aggregate ● State is a reduction of event application { } + Loan. Originated {lent: 100} + Repayment. Paid {amount: 10} + Repayment. Paid {amount: 80} { remaining 100 status: live} { remaining 90 status: live} { remaining 80 status: live} { remaining 0 status: pre-paid} 17

Implementation with Clojure and Kafka

Implementation with Clojure and Kafka

Implementation with Clojure and Kafka

Implementation with Clojure and Kafka

Tactical Patterns Hexagonal Architecture P P ● Separate the domain logic & infra ●

Tactical Patterns Hexagonal Architecture P P ● Separate the domain logic & infra ● Domain is “functional core” layer P P P ● Communicates with external world via ports and adapters 20

How we built our hexagons core-infra topology core-domain topology events loan changelog loan aggregate

How we built our hexagons core-infra topology core-domain topology events loan changelog loan aggregate NO SIDE EFFECTS repayment paid topology loan store SIDE EFFECTS repayment reversed 21

Use lein-modules Infra Domain kafka clj-time stuartsierra/component clj-uuid 22

Use lein-modules Infra Domain kafka clj-time stuartsierra/component clj-uuid 22

Conclusion ● Learn Domain-Driven-Design ● Bounded Context separates domains ● Published Language helps communicate

Conclusion ● Learn Domain-Driven-Design ● Bounded Context separates domains ● Published Language helps communicate ● Aggregate controls change ● Event Sourcing keeps history ● Hexagonal Architecture untangles concerns DDD patterns solve specific problems, do not apply blindly 23