Slide 1

Slide 1 text

Mariusz Gil DISCOVERING UNKNOWN WITH @mariuszgil

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

https://www.tripled.io/img/DDD-books.jpg

Slide 4

Slide 4 text

CAPTURE The knowledge @mariuszgil

Slide 5

Slide 5 text

Embed Into code @mariuszgil

Slide 6

Slide 6 text

Protect From the world @mariuszgil

Slide 7

Slide 7 text

The critical complexity of most software projects is in understanding the domain itself Eric Evans @mariuszgil

Slide 8

Slide 8 text

Given… when… then… @mariuszgil

Slide 9

Slide 9 text

Initial idea

Slide 10

Slide 10 text

Reality

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

Meet& tELL your STORY @mariuszgil

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

@mariuszgil

Slide 17

Slide 17 text

@mariuszgil

Slide 18

Slide 18 text

Reservation requested @mariuszgil

Slide 19

Slide 19 text

Reservation requested Reservation accepted @mariuszgil

Slide 20

Slide 20 text

Reservation requested Reservation accepted Availability and Limits checked @mariuszgil

Slide 21

Slide 21 text

Reservation requested Reservation accepted Availability and Limits checked @mariuszgil

Slide 22

Slide 22 text

Reservation requested Reservation accepted Availability and Limits checked @mariuszgil

Slide 23

Slide 23 text

Reservation requested Reservation accepted Availability and Limits checked customer @mariuszgil

Slide 24

Slide 24 text

Reservation requested Reservation accepted Availability and Limits checked customer Reservation rejected How to handle rejections? @mariuszgil

Slide 25

Slide 25 text

Reservation requested Reservation accepted Availability and Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed @mariuszgil

Slide 26

Slide 26 text

Reservation requested Reservation accepted Availability and Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed agent @mariuszgil

Slide 27

Slide 27 text

Airline ticket Api gateway Reservation requested Reservation accepted Availability and Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed agent @mariuszgil

Slide 28

Slide 28 text

Airline ticket Api gateway Reservation requested Availability and Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Reservation accepted @mariuszgil

Slide 29

Slide 29 text

Airline ticket Api gateway Reservation requested Availability and Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Confirmation Delivered Reservation accepted @mariuszgil

Slide 30

Slide 30 text

Airline ticket Api gateway Reservation requested Availability and Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Confirmation Delivered Reservation accepted $ $ @mariuszgil

Slide 31

Slide 31 text

Airline ticket Api gateway Reservation requested Availability and Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Confirmation Delivered Reservation accepted $ $ How to handle service Downtimes? @mariuszgil

Slide 32

Slide 32 text

Airline ticket Api gateway Reservation requested Availability and Limits checked customer Reservation rejected How to handle rejections? Similar offer Proposed agent Email gateway Confirmation Delivered Reservation accepted $ $ How to handle service Downtimes? Some customers Have phones Only! @mariuszgil

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

Bad decisions Cost a lot… @mariuszgil

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

It’s DEVELoper (mis)understanding Not expert knowledge That get’s released in production Alberto Brandolini @mariuszgil

Slide 49

Slide 49 text

Big picture Event storming @mariuszgil

Slide 50

Slide 50 text

Design level Event storming @mariuszgil

Slide 51

Slide 51 text

Aggregate Event Actor Command / Decision Read model External System Policy @mariuszgil Command Query

Slide 52

Slide 52 text

@mariuszgil https://docs.axoniq.io/reference-guide/v/3.3/part-i-getting-started/architecture-overview

Slide 53

Slide 53 text

Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits reached Account upgraded to higher status @mariuszgil

Slide 54

Slide 54 text

Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits reached Account upgraded to higher status Register loyalty points @mariuszgil

Slide 55

Slide 55 text

Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits reached Account Status upgraded Register loyalty points Upgrade account status @mariuszgil

Slide 56

Slide 56 text

Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits reached Account Status upgraded Register loyalty points Upgrade account status required points Levels Account upgrading policy @mariuszgil

Slide 57

Slide 57 text

Payment Registered Loyalty points registered Loyalty points calculated Upgrade limits reached Account Status upgraded Register loyalty points Upgrade account status required points Levels Account upgrading policy Reservations and payments history c.service @mariuszgil

Slide 58

Slide 58 text

Payment Registered Loyalty points calculated Upgrade limits reached Account Status upgraded Upgrade account status required points Levels Account upgrading policy Loyalty account Loyalty points registered Register loyalty points Reservations and payments history c.service @mariuszgil

Slide 59

Slide 59 text

Payment Registered Loyalty points calculated Upgrade limits reached Account Status upgraded Upgrade account status required points Levels Account upgrading policy Loyalty account Loyalty points registered Register loyalty points Reservations and payments history c.service @mariuszgil

Slide 60

Slide 60 text

Outcomes @mariuszgil

Slide 61

Slide 61 text

Possible implementation Solution @mariuszgil There are many of them!!!!!!

Slide 62

Slide 62 text

business domain logic application logic infrastructure

Slide 63

Slide 63 text

business logic application logic infrastructure

Slide 64

Slide 64 text

business logic application logic infrastructure aggregate Event publishing command domain event

Slide 65

Slide 65 text

@Entity // Mark this aggregate as a JPA Entity public class MyAggregate { @Id private String id; // fields containing state... @CommandHandler public MyAggregate(CreateMyAggregateCommand command) { // ... update state apply(new MyAggregateCreatedEvent(...)); } // constructor needed by JPA protected MyAggregate() { } } Event Command / Decision

Slide 66

Slide 66 text

domain event domain event business logic application logic infrastructure domain event aggregate domain event event sourcing

Slide 67

Slide 67 text

public class MyAggregateRoot { @AggregateIdentifier private String aggregateIdentifier; // fields containing state... @CommandHandler public MyAggregateRoot(CreateMyAggregate cmd) { apply(new MyAggregateCreatedEvent(cmd.getId())); } // constructor needed for reconstruction protected MyAggregateRoot() { } @EventSourcingHandler private void handleMyAggregateCreatedEvent(MyAggregateCreatedEvent event) { // make sure identifier is always initialized properly this.aggregateIdentifier = event.getMyAggregateIdentifier(); // ... update state } } Aggregate

Slide 68

Slide 68 text

domain event domain event domain event domain event business logic application logic infrastructure domain event domain event command domain event policy process managers

Slide 69

Slide 69 text

business logic application logic infrastructure domain event command saga domain event command domain event Compensate command policy policy

Slide 70

Slide 70 text

public class OrderManagementSaga { private boolean paid = false; private boolean delivered = false; @Inject private transient CommandGateway commandGateway; @StartSaga @SagaEventHandler(associationProperty = "orderId") public void handle(OrderCreatedEvent event) { // client generated identifiers ShippingId shipmentId = createShipmentId(); InvoiceId invoiceId = createInvoiceId(); // associate the Saga with these values, before sending the commands SagaLifecycle.associateWith("shipmentId", shipmentId); SagaLifecycle.associateWith("invoiceId", invoiceId); // send the commands commandGateway.send(new PrepareShippingCommand(...)); commandGateway.send(new CreateInvoiceCommand(...)); } @SagaEventHandler(associationProperty = "shipmentId") public void handle(ShippingArrivedEvent event) { delivered = true; if (paid) { SagaLifecycle.end(); } } @SagaEventHandler(associationProperty = "invoiceId") public void handle(InvoicePaidEvent event) { paid = true; if (delivered) { SagaLifecycle.end(); } } // ... } Reactive Policy

Slide 71

Slide 71 text

read model business logic application logic infrastructure read models domain event domain event domain event domain event read model read model read model

Slide 72

Slide 72 text

business logic application logic infrastructure

Slide 73

Slide 73 text

business logic application logic infrastructure

Slide 74

Slide 74 text

business logic application logic infrastructure BUS Event

Slide 75

Slide 75 text

Event Command / Decision Event Event Aggregate

Slide 76

Slide 76 text

public class MyCommandComponentTest { private FixtureConfiguration fixture; @Before public void setUp() { fixture = new AggregateTestFixture<>(MyAggregate.class); } @Test public void testFirstFixture() { fixture.given(new MyEvent(1)) .when(new TestCommand()) .expectSuccessfulHandlerExecution() .expectEvents(new MyEvent(2)); /* } } Event Command / Decision Event Event Aggregate Given When Then

Slide 77

Slide 77 text

Command / Decision Read model Event Event Given When Then

Slide 78

Slide 78 text

Event Command / Decision Aggregate Read model Given When Then Event

Slide 79

Slide 79 text

DDD is not for you? @mariuszgil

Slide 80

Slide 80 text

Event Command / Decision Aggregate Read model Reactive Policy

Slide 81

Slide 81 text

Event Command / Decision Aggregate Read model Reactive Policy Record Inserted / Changed / Deleted Insert / Update / Delete / Truncate / … Record / Table Select / View Trigger / Procedure

Slide 82

Slide 82 text

Takeaways @mariuszgil

Slide 83

Slide 83 text

Big Picture Events Processes & Flows Hot Spots Systems Boundaries People @mariuszgil

Slide 84

Slide 84 text

Process Modeling Commands Policies Read Models Value Propositions Personas Metrics & Alerts @mariuszgil

Slide 85

Slide 85 text

Software Design Aggregates Policies Reactive Logic Read Models @mariuszgil

Slide 86

Slide 86 text

Communication! @mariuszgil

Slide 87

Slide 87 text

Building common understanding @mariuszgil

Slide 88

Slide 88 text

From production session

Slide 89

Slide 89 text

From production session

Slide 90

Slide 90 text

From alberto bandolino workshop

Slide 91

Slide 91 text

From production session

Slide 92

Slide 92 text

Software development is learning process Working code is a side effect Alberto Brandolini @mariuszgil

Slide 93

Slide 93 text

No content

Slide 94

Slide 94 text

What’s next? @mariuszgil

Slide 95

Slide 95 text

No content

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

No content

Slide 98

Slide 98 text

THANK YOU! @mariuszgil