reactive domain driven design - elsassjug

144
EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC Reactive Domain Driven Design

Upload: xebia-france

Post on 15-Jun-2015

290 views

Category:

Software


0 download

DESCRIPTION

Si vous pensez que le Domain Driven Design c’est seulement pour Java EE et que le reactive programming rend le code illisible et prématurément optimisé, cette présentation va vous surprendre. Venez voir comment DDD + CQRS + EventSourcing se conjuguent parfaitement avec Akka pour construire des systèmes robustes dans un environnement concurrentiel. Par Xavier Bucchiotty, consultant chez Xebia France

TRANSCRIPT

Page 1: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Reactive

Domain Driven Design

Page 2: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

The Objective

Page 3: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

The red squadron

Page 4: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Characters

/Alliance /Red squadron

/Empire / DeathStar

Page 5: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Attackclass Alliance{ val squadrons = Set[Squadron]; ! def attack(empire){ ! val deathStar = empire.deathStar ! squadron.foreach(squadron => squadron.attack(deathStar) ) } }

Page 6: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Idle

Page 7: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var location = base; ! def attack(){ travelTo(deathStar){ … this.location = deathStar … } ! } }

Traveling

Page 8: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ val xwings = Set[Squadron]; ! def attack(deathStar){ travelTo(deathStar) ! do{ xwings.foreach(_.attack(deathStar)) }while(deathStar.alive) ! } }

Fighting

Page 9: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! def attack(deathStar){ ! deathStar.receiveTorpedoFrom(this) !!!! } }

Fighting

Page 10: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class DeathStar{ var healthPoints = 100 ! def receiveTorpedoFrom(sender){ healthPoints -= 1 if(senderWithoutTheForce){ sender.receiveTorpedoFrom(this) } } !}

Fighting

Page 11: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

User Story

As the Alliance !

I want to be informed of updates in state of my squadrons !

In order to command the retreat of a squadron if it remains only one XWing

Page 12: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Tasks

Notification from XWing to Squadron Notification from

Squadron to Alliance

Implements Squadron#retreat

Page 13: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Notification from XWing to Squadron

class XWing{ var healthPoints = 1 !!! def receiveTorpedoFrom(sender){ ! println(s”$this is dead”) } }

Page 14: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! val squadron = parent ! def receiveTorpedoFrom(sender){ squadron.remove(this) println(s”$this is dead”) } }

Notification from XWing to Squadron

Page 15: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! val squadron = parent ! def receiveTorpedoFrom(sender){ squadron.remove(this) println(s”$this is dead”) } }

Remember

No bidirectional

references

Notification from XWing to Squadron

Page 16: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! val squadron = parent ! def receiveTorpedoFrom(sender){ squadron.remove(this) println(s”$this is dead”) } } What would be

visibility of remove?

Notification from XWing to Squadron

Page 17: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! ! def receiveTorpedoFrom(sender){ println(s”$this is dead”) } ! }

Notification from XWing to Squadron

Page 18: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! val life = Promise[Unit]() ! def receiveTorpedoFrom(sender){ life.success(null) println(s”$this is dead”) } ! def endOfLife = life.future }

Notification from XWing to Squadron

Page 19: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! val life = Promise[Unit]() ! def receiveTorpedoFrom(sender){ life.success(null) println(s”$this is dead”) } ! def endOfLife = life.future }

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= xwing ) ) ! }

Notification from XWing to Squadron

Page 20: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! val life = Promise[Unit]() ! def receiveTorpedoFrom(sender){ life.success(null) println(s”$this is dead”) } ! def endOfLife = life.future }

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= xwing ) ) ! }Loosely coupled

Notification from XWing to Squadron

Page 21: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! val life = Promise[Unit]() ! def receiveTorpedoFrom(sender){ life.success(null) println(s”$this is dead”) } ! def endOfLife = life.future }

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= deadXWing ) ) ! }Loosely coupled

But we starts with

asynchronous

Notification from XWing to Squadron

Page 22: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class XWing{ var healthPoints = 1 ! val life = Promise[Unit]() ! def receiveTorpedoFrom(sender){ life.success(null) println(s”$this is dead”) } ! def endOfLife = life.future }

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= xwing ) ) ! }

Notification from XWing to Squadron

Page 23: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Tasks

Notification from XWing to Squadron Notification from

Squadron to Alliance

Implements Squadron#retreat

Page 24: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Alliance{ val squadrons = Seq[Squadron]() ! !!!!!!!}

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= deadXWing ) ) ! def alliance = ??? }

Notification from Squadron to Alliance

Page 25: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Alliance{ val squadrons = Seq[Squadron]() ! !!!!!!!}

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= deadXWing ) ) ! def alliance = ??? }

Remember again

No bidirectional

references

Notification from Squadron to Alliance

Page 26: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Alliance{ val squadrons = Seq[Squadron]() ! !!!!!!!}

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= deadXWing ) ) !! }

Notification from Squadron to Alliance

Page 27: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Alliance{ val squadrons = Seq[Squadron]() squadrons.foreach(squadron => squadron.listener += { updatedSquadron => { if(updatedSquadron.currentSize < 2){ updatedSquadron.retreat() } } } ) !!!!}

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= deadXWing listeners.foreach(l => l.apply(this) ) ) ) var listeners = List[Squadron => Unit] ! def currentSize = xwings.size ! def retreat = ??? }

Notification from Squadron to Alliance

Page 28: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Alliance{ val squadrons = Seq[Squadron]() squadrons.foreach(squadron => squadron.listener += { updatedSquadron => { if(updatedSquadron.currentSize < 2){ updatedSquadron.retreat() } } } ) !!!!}

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= deadXWing listeners.foreach(l => l.apply(this) ) ) ) var listeners = List[Squadron => Unit] ! def currentSize = xwings.size ! def retreat = ??? }

Notification from Squadron to Alliance

Will make

the tests

green

Page 29: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Alliance{ val squadrons = Seq[Squadron]() squadrons.foreach(squadron => squadron.listener += { updatedSquadron => { if(updatedSquadron.currentSize < 2){ updatedSquadron.retreat() } } } ) !!!!}

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map(_ => xwings -= deadXWing listeners.foreach(l => l.apply(this) ) ) ) var listeners = List[Squadron => Unit] ! def currentSize = xwings.size ! def retreat = ??? }

Notification from Squadron to Alliance

Page 30: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Tasks

Notification from Squadron to Alliance

Implements Squadron#retreat

Page 31: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var xwings = Set[XWing]() ! def retreat() = ??? !!!!!!}

Implements Squadron#retreat

Page 32: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var xwings = Set[XWing]() ! def retreat() = { travelTo(base) } !!!!!}

Implements Squadron#retreat

Page 33: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var xwings = Set[XWing]() def retreat() = { travelTo(base) } !!!!!}

Implements Squadron#retreat

That does not

stop XWings to

fire

Page 34: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var fighting = false def retreat() = { figthing = false travelTo(base) } ! def attack(deathStar){ travel(deathStar) fighting = true do { xwings.foreach(_.attack(deathStar)) } while (deathStar.alive && fighting) } }

Implements Squadron#retreat

Will make

the tests

green

Page 35: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var fighting = false def retreat() = { figthing = false travelTo(base) } ! def attack(deathStar){ travel(deathStar) fighting = true do { xwings.foreach(_.attack(deathStar)) } while (deathStar.alive && fighting) } }

Implements Squadron#retreat

But wait

we have

a shared

mutable state

Page 36: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

User Story

As the Alliance !

I want to display each modification in the status of my squadron !

In order to see evolution of the battle

Page 37: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Tasks

Get current status as String from a Squadron

Notification at the end of travels

Page 38: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map { _ => !! } ) !!!!!}

Notification at the end of travels

Page 39: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var xwings = Set[XWing]() ! xwings.foreach(xwing => xwing.endOfLife.map { _ => notifyListeners() ! } ) ! def attack(deathStar: DeathStar){ ! travelTo(deathStar) notifyListeners() ! } ! def retreat(){ travelTo(base) notifyListeners() } }

Notification at the end of travels

Will make

the tests

green

Page 40: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Tasks

Get current status as String from a Squadron

Notification at the end of travels

Page 41: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var xwings = Set[XWing]() !! !!!!!}

Get current status as String from a Squadron

Page 42: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

class Squadron{ var xwings = Set[XWing]() ! status(“idle“) def attack(deathStar){ status(“traveling“) notifyListeners() ! travelTo(deathStar) status(“figthing“) notifyListeners() } ! … !!}

Get current status as String from a Squadron

That’s too

much,

there must be

another way

Page 43: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Backlog

Make the travel asynchronous so many squadrons can move at the same time

Persist state of squadrons to spawn them on new VM if lost

Page 44: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Domain Driven Design

Page 45: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.amazon.fr/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215

Page 46: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Technical core concepts

Aggregate

Bounded context

Page 47: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Aggregate

Bounded contexttransaction

Technical core concepts

code

scalability

Page 48: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

code scalability

Page 49: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

code scalability

Knight

Knight

Page 50: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Implementation is focused on a

bounded context of the whole domain

code scalability

Knight

Knight

Page 51: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

code scalability

Page 52: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

code scalability

Page 53: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

code scalability

Aggregate hides implementation

details

Page 54: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

code scalability

Aggregate hides implementation

details

Implementation is focused on a

bounded context of the whole domain

Page 55: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Aggregate

Bounded contexttransaction

Technical core concepts

code

scalability

Page 56: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

transaction

Page 57: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

transaction

Page 58: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

transaction

?

Page 59: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

transaction

Root entity ensures

consistency of the whole aggregate at any time

Page 60: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

transaction

!

can see 4 XWings

Page 61: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

transaction

!

can see 3 XWings

When the Alliance can see the changes?

Page 62: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

transaction

!

can see 3 XWings

From an external point of view, the

aggregate is eventually

consistent!

Page 63: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

transaction

From an external point of view, the

aggregate is eventually

consistent!

Root entity ensures

consistency of the whole aggregate at any time

Page 64: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Domain Driven Design

Page 65: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Domain Driven Design ++

EventSourcing

CQRS

Page 66: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

CQRSCommand Query Responsibility Segregation

Forget about POJOs and Java Beans

getters/setters. Do semantical methods!

You can model your domain twice! Once

per usage. !

Command ≠ Query

Page 67: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

EventSourcing

Forget about Hibernate and other ORMs.

Persists meaningful past events.

!

Command ≠ Event

Page 68: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Functional EventSourcing

Command State (Aggregate)x (Actions) Events

Decision making

Events x State (Aggregate)

apply State (Aggregate)

+

Page 69: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Functional EventSourcing

Command State (Aggregate)x (Actions) Events

Decision making

Events x State (Aggregate)

apply State (Aggregate)

You don’t even need to persist

complete aggregates state !

+

Page 70: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Functional EventSourcing

Command State (Aggregate)x Events

Decision making

Events x State (Aggregate)

apply State (Aggregate)

Page 71: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Functional EventSourcing

Command State (Aggregate)x Events

Decision making

Events x State (Aggregate)

apply State (Aggregate)

source: @thinkbeforecoding !

https://github.com/thinkbeforecoding/FsUno.Prod

Page 72: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Command ≠ EventCommand ≠ Query

Page 73: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Command

ActionsEvent

Page 74: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Command

ActionsEvent

But where are the views?

Page 75: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Reporter

And the views?

You can keep specific views

inside aggregates. You’ll bother the root for

minor subjects. Lost(red-1)

Page 76: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

And the views?

You read events log and build

ad-hoc views. !

In « real-time » or on demand.

Listener

Lost(red-1)

Page 77: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

In DDD, aggregates and entities have unique

IDs. So does the actors with paths and name

In DDD, value object are everywhere and

are immutable. So does case classes.

Immutability help reasoning in concurrent

world.

In DDD, aggregates encapsulate states,

so does actors

Page 78: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Reactive

Domain Driven Design

Page 79: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Reactive

Page 80: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.reactivemanifesto.org/

Page 81: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.reactivemanifesto.org/

asynchronous

low coupling

Page 82: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.reactivemanifesto.org/

scaling to workload

Page 83: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.reactivemanifesto.org/

sane error and failure

handling

Page 84: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.reactivemanifesto.org/

system always responds in bounded latency

Page 85: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Tasks

Let’s do a refactor with Akka

Page 86: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Aggregate

Red squadron

Page 87: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Characters

/Alliance /Red squadron

/Empire / DeathStar

Page 88: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Actors

/Alliance /Red squadron

/Empire / DeathStar

Page 89: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Functional EventSourcing

Command State (Aggregate)x Actions Events

Decision making +

Page 90: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Messages

Attack ( DeathStarPath , Squadron )

Page 91: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Messages

Attack ( DeathStarPath , Squadron )

Page 92: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Idle

Page 93: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

Sent ( Squadron, Destination )

Travel ( Squadron, Destination )

Page 94: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

Sent ( Squadron, Destination )

Travel ( Squadron, Destination )

Page 95: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

Arrived ( Squadron, Destination )

Page 96: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

Arrived ( Squadron, Destination )

Arrived ( Squadron, Destination )

Page 97: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Fighting

Fire ( DeathStarPath )

Page 98: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Fighting

Fire ( DeathStarPath )Fire ( XWingPath )Lost ( Squadron, XWing )

Page 99: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Fire ( DeathStarPath )

Messages

Sent ( Squadron, Destination )Arrived ( Squadron, Destination )

Arrived ( Squadron, Destination )

Travel ( Squadron, Destination )

Attack ( DeathStarPath , Squadron )

Lost ( Squadron, Destination )

Fire ( XWingPath )

Page 100: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Algebras

Fire Fightingx Lost

Fighting Lostx Fighting

Page 101: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Algebras

Fire Fightingx Lost

Fighting Lostx Fighting

Akka killing feature !

receive as Partial Function

context.become()

Page 102: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Algebras

Fire Fightingx Lost

Fighting Lostx Fighting

Think about functions

validating inputs

for some outputs

Page 103: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Algebras

Fire Fightingx Lost

Fighting Lostx Fighting

Finite State Machine !

For The Win

Page 104: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Algebras

Fire Fightingx Lost

Fighting Lostx Fighting

NOW THE CODE

Page 105: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.reactivemanifesto.org/

akka-actor

akka-cluster akka-persistence

Page 106: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-actor

Idle

Attack

Page 107: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-actor

IdleAttack

Page 108: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-actor

Idle

Attack

Page 109: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-actor

Arrived

Reporter

Affected

Page 110: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-actor

Arrived Reporter

Affected

Page 111: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-actor

Reporter

Affected

Arrived

Page 112: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.reactivemanifesto.org/

akka-actor

akka-cluster akka-persistence

Page 113: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-persistence

Idle

Attack

Page 114: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

IdleAttack

akka-persistence

Page 115: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Idle

Attack

akka-persistence

Page 116: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

Sent

akka-persistence

Page 117: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Sent

Page 118: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Eventlog

Sent

Page 119: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

EventlogSent

Page 120: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Reporter

EventlogSent

Page 121: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Attack

Page 122: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Attack

Page 123: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Attack

By default at-most-once delivery

Page 124: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Attack

Page 125: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Attack

Page 126: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Attack

Page 127: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Attack

Page 128: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Page 129: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Ack

at-least-once delivery

Page 130: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Page 131: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

IFailedMasterException

Page 132: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

Page 133: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Idle

akka-persistence

EventlogSent

SentAttack

Page 134: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

EventlogAffected

Attack

Page 135: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Traveling

akka-persistence

EventlogSent

Recovery from EventLog

Page 136: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

http://www.reactivemanifesto.org/

akka-actor

akka-cluster akka-persistence

Page 137: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-cluster

Page 138: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-cluster

Page 139: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-cluster

Red squadron

Page 140: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-cluster

Red squadronBlue squadron

Green squadron

Page 141: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-cluster

Red squadronBlue squadron

Green squadron

AffectedAffected

Affected Affected

Page 142: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

akka-cluster

Red squadronBlue squadronAffectedAffected

Affected Affected

Green squadron

Page 143: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Final notesAggregate hides implementation

details

Implementation is focused on a

bounded context of the whole domain

Think about messages, Focus your attention

on interaction over data

The less actors have interlocutors, the better.

Take care about message senders.

Page 144: Reactive Domain Driven Design - elsassjug

• EBIA ALLIANCE = XEBIA + XEBIALABS + THIGA + UX REPUBLIC

Thanks

@xbucchiotty [email protected]