reactive ddd - qcon san francisco · monolith to microservices @vaughnvernon. bbom to bc—how?...

68
Reactive DDD When Concurrent Waxes Fluent Copyright © 2018 Vaughn Vernon. All rights reserved.

Upload: others

Post on 25-May-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Reactive DDDWhen Concurrent

Waxes Fluent

Copyright © 2018 Vaughn Vernon. All rights reserved.

Page 2: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Where We Are

@VaughnVernon

Page 3: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Blocking

@VaughnVernon

BehaviorHTTP Request-Response

Database...

Page 4: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Anemic DomainModel

@VaughnVernon

Page 5: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Anemic Domain Model@Entitypublic class Client { @Id private String id; @Column private String name; @Column private String address1; @Column private String address2; @Column private String city; @Column private String stateOrProv; ...}

@VaughnVernon

Page 6: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Going To

@VaughnVernon

Page 7: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

Event Driven

Page 8: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

Page 9: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Reactive but...Language Investment

Model FluencyType SafetyTestability

@VaughnVernon

Page 10: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Reactive DDD

@VaughnVernon

Page 11: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Fluent?

@VaughnVernon

Page 12: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Protocol

@VaughnVernon

public interface Progress { ... void submitFor(Client client, ...); void denyPricing(Money suggestedPrice); void verifyPricing(); ...}

Page 13: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Fluent

@VaughnVernon

proposal.submitFor(client, expectations)

Page 14: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Fluent

@VaughnVernon

stage.actorOf(from(userId), User.class) .andThenInto(user -> user.with(new Contact(...))) .otherwiseConsume(noUser -> Response.of(NotFound)) .andThenConsume(user -> Response.of(Ok, user));

Page 15: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Reactive?

@VaughnVernon

proposal.submitFor(client, expectations)

Page 16: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Type Safe?

@VaughnVernon

proposal.submitFor( Client.from(clientId), Expectations.of( Summary.has(summary), Description.has(description), Keywords.are(keywords), completedBy, Step.from(steps), price));

Page 17: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Uncertainty (1)

@VaughnVernon

Page 18: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Uncertainty (2)

@VaughnVernon

Page 19: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Model

@VaughnVernon

public final class ProposalEntity extends EventSourced implements Proposal {

public Client client; public Expectations expectations; ...}

Page 20: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Model

@VaughnVernon

public final class ProposalEntity extends EventSourced implements Proposal {

public Client client; public Expectations expectations; public Progress progress; ...}

Page 21: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Model It

@VaughnVernon

public final class Progress { public static Progress None = ... public static Progress Submitted = ...

private final Set<Spec> specs;

protected Progress verifiedForPricing() { return newWith(Spec.PricingVerified); } ...}

Page 22: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Everyone Is GoingMicroservices

@VaughnVernon

Page 23: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

So We Want to Go Microservices

@VaughnVernon

Page 24: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Business Wants

@VaughnVernon

Page 25: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

You Want

@VaughnVernon

Page 26: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Definitions

@VaughnVernon

de•scrip•tion (dĭ-skrĭpˈshən)►

n. The act, process, or technique of describing.

n. A statement or an account describing something:published a description of the journey; gave a vividdescription of the game.

n. A pictorial representation: Monet's ethereal descriptionsof haystacks and water lilies.

Page 27: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Legacy

@VaughnVernon

Page 28: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Legacy: Monolith

@VaughnVernon

Page 29: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Legacy: BBoM

@VaughnVernon

Page 30: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Microservice

@VaughnVernon

?

Page 31: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

100LoC

Page 32: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

400LoC

Page 33: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

1000?

Page 34: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

100 LoC Now

@VaughnVernon

Page 35: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Dependencies?

@VaughnVernon

Page 36: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

ONLY $400/mo!

@VaughnVernon

Page 37: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

100 Then * $400/mo

@VaughnVernon

Page 38: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

And...

@VaughnVernon

Page 39: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Complex System

@VaughnVernon

2,000,000 LoC?

5,000,000 LoC?

Page 40: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

2,000,000 LoC

@VaughnVernon

2MM / 100 = 20,000 MS

20K * $400/mo = $8MM/mo

$8MM * 12 = $96MM/yr

Page 41: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

5,000,000 LoC

@VaughnVernon

5MM / 100 = 50,000 MS

50K * $400/mo = $20MM/mo

$20MM * 12 = $240MM/yr

Page 42: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Bounded Context

@VaughnVernon

Page 43: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

IdentifyStrategic Drivers

"Our problem is that oursoftware implementsordinary business processbut stops short of seekingstrategic advantage."

Page 44: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Tell!public class Client extends Entity { public void name(String name) { ... } public void address(PostalAddress address) { ... } public void relocateTo(PostalAddress address) { ... } public void telephone(Telephone telephone) { ... } ...}

Page 45: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Explicit, Testable,Less Code

public class Client { public void relocateTo(PostalAddress address) { this.postalAddress = address; emit(new ClientRelocated(...)); }}

public class ClientTests { public void testThatClientRelocates() { ... }}

Page 46: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Bounded Context

@VaughnVernon

Page 47: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Monolith toMicroservices

@VaughnVernon

Page 48: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

BBoM To BC—How?

@VaughnVernon

Page 49: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Rewrite

@VaughnVernon

Page 50: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Eat an Elephant

@VaughnVernon

One bite at a time.

● Change-driven● Value-driven● Test-driven

Page 51: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Event Driven

@VaughnVernon

Page 52: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Strangler (1)

@VaughnVernon

Page 53: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Strangler (2)

@VaughnVernon

● Debezium: http://debezium.io/● Oracle Golden Gate

Page 54: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Restructured (1)

@VaughnVernon

Page 55: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Restructured (2)

@VaughnVernon

Page 56: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Restructured (3)

@VaughnVernon

Page 57: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

Page 58: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

Page 59: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

Page 60: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

@VaughnVernon

Page 61: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Reactive Rework

@VaughnVernon

Page 62: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Reactive DDD

@VaughnVernon

Page 63: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Architecture

@VaughnVernon

Page 64: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

vlingo/actors

@VaughnVernon

Page 65: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

vlingo/http

@VaughnVernon

Page 66: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

vlingo/lattice

@VaughnVernon

Page 67: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

vlingo/streams

@VaughnVernon

Page 68: Reactive DDD - QCon San Francisco · Monolith to Microservices @VaughnVernon. BBoM To BC—How? @VaughnVernon. Rewrite @VaughnVernon. Eat an Elephant @VaughnVernon One bite at a time

Contact: [email protected]

Open SourceReactive Platform

Web: vlingo.io

@VaughnVernon