SlideShare une entreprise Scribd logo
1  sur  126
Télécharger pour lire hors ligne
From Functional to
Reactive
patterns in domain modeling
Debasish Ghosh
@debasishg
Tuesday, 6 October 15
Tuesday, 6 October 15
Domain Modeling
Tuesday, 6 October 15
Domain Modeling(Functional)
Tuesday, 6 October 15
Domain Modeling
(Responsive)
(Functional)
Tuesday, 6 October 15
Domain Modeling
(Responsive)
(Functional)
(Elastic)
Tuesday, 6 October 15
Domain Modeling
(Responsive)
(Functional)
(Elastic) (Resilient)
Tuesday, 6 October 15
Domain Modeling
(Responsive)
(Functional)
(Elastic) (Resilient)
(Reactive)
Tuesday, 6 October 15
What is a domain model ?
A domain model in problem solving and software engineering is a
conceptual model of all the topics related to a specific problem. It
describes the various entities, their attributes, roles, and
relationships, plus the constraints that govern the problem domain.
It does not describe the solutions to the problem.
Wikipedia (http://en.wikipedia.org/wiki/Domain_model)
Tuesday, 6 October 15
The Functional Lens ..
“domain API evolution through algebraic
composition”
Tuesday, 6 October 15
The Functional Lens ..
“domain API evolution through algebraic
composition”
(Reactive)
Tuesday, 6 October 15
Agenda
• Formalizing a domain model
• Domain model algebra
• From functional to algebraically reactive
• Beyond algebra
• Actors and domain models
• Reactive streams - typesafe & compositional
Tuesday, 6 October 15
Tuesday, 6 October 15
Tuesday, 6 October 15
Your domain model is a
function
Tuesday, 6 October 15
Your domain model is a
function
Tuesday, 6 October 15
Your domain model is a
collection of functions
Tuesday, 6 October 15
Your domain model is a
collection of functions
some simpler models are ..
Tuesday, 6 October 15
https://msdn.microsoft.com/en-us/library/jj591560.aspx
Tuesday, 6 October 15
A Bounded Context
• has a consistent vocabulary
• a set of domain behaviors modeled as
functions on domain objects implemented
as types
• related behaviors grouped as modules
Tuesday, 6 October 15
Domain Model = ∪(i) Bounded Context(i)
Tuesday, 6 October 15
Domain Model = ∪(i) Bounded Context(i)
Bounded Context = { f(x) | p(x) ∈ Domain Rules }
Tuesday, 6 October 15
Domain Model = ∪(i) Bounded Context(i)
Bounded Context = { f(x) | p(x) ∈ Domain Rules }
• domain function
• on an object of type x
• composes with other functions
• closed under composition
• business rules
Tuesday, 6 October 15
• Functions / Morphisms
• Types / Sets
• Composition
• Rules / Laws
Tuesday, 6 October 15
• Functions / Morphisms
• Types / Sets
• Composition
• Rules / Laws
algebra
Tuesday, 6 October 15
Domain Model Algebra
Tuesday, 6 October 15
Domain Model Algebra
(algebra of types, functions & laws)
Tuesday, 6 October 15
Domain Model Algebra
(algebra of types, functions & laws)
explicit
• types
• type constraints
• expression in terms of other generic algebra
Tuesday, 6 October 15
Domain Model Algebra
(algebra of types, functions & laws)
explicit
verifiable
• types
• type constraints
• expression in terms of other generic algebra
• type constraints
• more constraints if you have DT
• algebraic property based testing
Tuesday, 6 October 15
close
debit
open
...
Domain
Behaviors
Tuesday, 6 October 15
Amount
Account
Balance
Customer
...
...
...
close
debit
open
...
Domain
Behaviors
Domain Types
Tuesday, 6 October 15
Amount
Account
Balance
Customer
...
...
...
close
debit
open
...
market
regulations
tax laws
brokerage
commission
rates
...
Domain
Behaviors
Domain TypesDomain Rules
Tuesday, 6 October 15
Amount
Account
Balance
Customer
...
...
...
close
debit
open
...
market
regulations
tax laws
brokerage
commission
rates
...
Domain
Behaviors
Domain TypesDomain Rules
Monoid Monad ...
Generic Algebraic
Structures
Tuesday, 6 October 15
Amount
Account
Balance
Customer
...
...
...
close
debit
open
...
market
regulations
tax laws
brokerage
commission
rates
...
Domain
Behaviors
Domain TypesDomain Rules
Monoid Monad ...
Generic Algebraic
Structures
Domain Algebra
Tuesday, 6 October 15
Domain Model = ∪(i) Bounded Context(i)
Bounded Context = { f(x) | p(x) ∈ Domain Rules }
• domain function
• on an object of type x
• composes with other functions
• closed under composition
• business rules
Domain Algebra
Domain Algebra
Tuesday, 6 October 15
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
Algebra is the binding
contract
Bounded Context
Tuesday, 6 October 15
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
Algebra is the binding
contract
Bounded Context
Reactive
Tuesday, 6 October 15
Conference
Reservations
Program
Management
Badge Printing
Domain Algebra A
Domain Algebra B
Domain Algebra C
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
Tuesday, 6 October 15
• Algebras don’t unify across bounded
contexts
• Decoupled in space and time
• Separate vocabulary
• Types break down
Tuesday, 6 October 15
Conference
Reservations
Program
Management
Badge Printing
Domain Algebra A
Domain Algebra B
Domain Algebra C
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
Protocols
Tuesday, 6 October 15
Conference
Reservations
Program
Management
Badge Printing
Domain Algebra A
Domain Algebra B
Domain Algebra C
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
Protocols
Reactive
Tuesday, 6 October 15
Being Reactive
Elasticity
(responsive under
varying load)
Resilience
(responsive in the
face of failures)
Message-driven
(loose coupling,
isolation thru
async message
passing)
Responsive
(through bounded
latency)
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type AccountOp[A] = NonEmptyList[String] / A
def open(no: String, name: String, rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType): AccountOp[Account]
def close(no: String, closeDate: Option[Date]): AccountOp[Account]
def debit(no: String, amount: Amount): AccountOp[Account]
def credit(no: String, amount: Amount): AccountOp[Account]
//..
}
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type AccountOp[A] = NonEmptyList[String] / A
def open(no: String, name: String, rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType): AccountOp[Account]
def close(no: String, closeDate: Option[Date]): AccountOp[Account]
def debit(no: String, amount: Amount): AccountOp[Account]
def credit(no: String, amount: Amount): AccountOp[Account]
//..
}
Module Name
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type AccountOp[A] = NonEmptyList[String] / A
def open(no: String, name: String, rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType): AccountOp[Account]
def close(no: String, closeDate: Option[Date]): AccountOp[Account]
def debit(no: String, amount: Amount): AccountOp[Account]
def credit(no: String, amount: Amount): AccountOp[Account]
//..
}
Module Name Parameterized on types
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type AccountOp[A] = NonEmptyList[String] / A
def open(no: String, name: String, rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType): AccountOp[Account]
def close(no: String, closeDate: Option[Date]): AccountOp[Account]
def debit(no: String, amount: Amount): AccountOp[Account]
def credit(no: String, amount: Amount): AccountOp[Account]
//..
}
Module Name Parameterized on types
Operation return type - either
a successfully constructed type
or a list of errors
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type AccountOp[A] = NonEmptyList[String] / A
def open(no: String, name: String, rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType): AccountOp[Account]
def close(no: String, closeDate: Option[Date]): AccountOp[Account]
def debit(no: String, amount: Amount): AccountOp[Account]
def credit(no: String, amount: Amount): AccountOp[Account]
//..
}
Module Name Parameterized on types
Operation return type - either
a successfully constructed type
or a list of errors
Operations - domain behaviors
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type AccountOp[A] = NonEmptyList[String] / A
def open(no: String, name: String, rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType): AccountOp[Account]
def close(no: String, closeDate: Option[Date]): AccountOp[Account]
def debit(no: String, amount: Amount): AccountOp[Account]
def credit(no: String, amount: Amount): AccountOp[Account]
//..
}
Module Name Parameterized on types
Operation return type - either
a successfully constructed type
or a list of errors
Operations - domain behaviors explicit & verifiable algebra
Tuesday, 6 October 15
• Parametric - parameterized on types
• Statically Typed
• Modular and hence unit testable
• Composable
Tuesday, 6 October 15
def transfer(from: String, to: String, amount: Amount)
: AccountOp[(Account, Account)] = for {
a <- debit(from, amount)
b <- credit(to, amount)
} yield ((a, b))
Composable
Tuesday, 6 October 15
Composable
trait BankingService[Account, Amount, Balance]
extends AccountService[Account, Amount, Balance]
with InterestPostingService[Account, Amount]
with InterestCalculation[Account, Amount]
with TaxCalculation[Amount]
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type AccountOp[A] = NonEmptyList[String] / A
def open(
no: String,
name: String,
rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType
): AccountRepository => AccountOp[Account]
//..
}
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type AccountOp[A] = NonEmptyList[String] / A
def open(
no: String,
name: String,
rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType
): AccountRepository => AccountOp[Account]
//..
}
change the algebra to add
functionality
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type Valid[A] = NonEmptyList[String] / A
type AccountOp[A] = Kleisli[Valid, AccountRepository, A]
def open(
no: String,
name: String,
rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType
): AccountOp[Account]
//..
}
more algebra, more
functionality, more succinct
Tuesday, 6 October 15
• Design should not have any contention or
central bottlenecks that tend to hamper
the progress of the system
Being Reactive
Tuesday, 6 October 15
• If your domain service publishes APIs that
does blocking calls to underlying databases
and blocks the central thread of user
interaction, you face the specter of
unbounded latency
Being Reactive
Tuesday, 6 October 15
Blocking Kills
Tuesday, 6 October 15
Blocking Kills
Make your APIs elastic enough so that the perceived
response to the user is not affected by the current
load on the system
Tuesday, 6 October 15
Elasticity
(responsive under
varying load)
Resilience
(responsive in the
face of failures)
Message-driven
(loose coupling,
isolation thru
async message
passing)
Responsive
(through bounded
latency)
Tuesday, 6 October 15
• Without foregoing the benefits of algebraic
reasoning with types
Being Reactive
Tuesday, 6 October 15
Enter Futures ..
Tuesday, 6 October 15
Enter Futures ..
• A future is the essence of asynchronous non
blocking computation
Tuesday, 6 October 15
Enter Futures ..
• A future is the essence of asynchronous non
blocking computation
• Futures compose
Tuesday, 6 October 15
Enter Futures ..
• A future is the essence of asynchronous non
blocking computation
• Futures compose
• Futures have an algebra
Tuesday, 6 October 15
Enter Futures ..
• A future is the essence of asynchronous non
blocking computation
• Futures compose
• Futures have an algebra
• Organize concurrent code around futures
safely and in a compositional way
Tuesday, 6 October 15
• In our use case we would like to augment
our domain algebra with future based APIs
• Just like an Either or a Kleisli, we
would like to have asynchrony as yet another
stackable effect within our computation
Goals towards Reactive
API
Tuesday, 6 October 15
Stacking of Effects
Tuesday, 6 October 15
Stacking of Effects
Tuesday, 6 October 15
type Response[A] = String / Option[A]
val count: Response[Int] = some(10).right
for {
maybeCount <- count
} yield {
for {
c <- maybeCount
// use c
} yield c
}
Monad Transformers
Tuesday, 6 October 15
type Response[A] = String / Option[A]
val count: Response[Int] = some(10).right
for {
maybeCount <- count
} yield {
for {
c <- maybeCount
// use c
} yield c
}
type Error[A] = String / A
type Response[A] = OptionT[Error, A]
val count: Response[Int] = 10.point[Response]
for {
c <- count
// use c : c is an Int here
} yield (())
Monad Transformers
Tuesday, 6 October 15
type Response[A] = String / Option[A]
val count: Response[Int] = some(10).right
for {
maybeCount <- count
} yield {
for {
c <- maybeCount
// use c
} yield c
}
type Error[A] = String / A
type Response[A] = OptionT[Error, A]
val count: Response[Int] = 10.point[Response]
for{
c <- count
// use c : c is an Int here
} yield (())
Monad Transformers
richer algebra
Tuesday, 6 October 15
Monad Transformers
• collapses the stack and gives us a single
monad to deal with
• order of stacking is important though
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type Valid[A] = EitherT[Future, NonEmptyList[String], A]
type AccountOp[A] = Kleisli[Valid, AccountRepository, A]
def open(
no: String,
name: String,
rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType
): AccountOp[Account]
//..
}
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type Valid[A] = EitherT[Future, NonEmptyList[String], A]
type AccountOp[A] = Kleisli[Valid, AccountRepository, A]
def open(
no: String,
name: String,
rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType
): AccountOp[Account]
//..
}
Tuesday, 6 October 15
Tuesday, 6 October 15
trait AccountService[Account, Amount, Balance] {
type Valid[A] = EitherT[Future, NonEmptyList[String], A]
type AccountOp[A] = Kleisli[Valid, AccountRepository, A]
def open(
no: String,
name: String,
rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType
): AccountOp[Account]
//..
}
Reactive ..
Algebraically
Tuesday, 6 October 15
class AccountServiceInterpreter
extends AccountService[Account, Amount, Balance] {
def open(no: String,
name: String,
rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType) =
kleisli[Valid, AccountRepository, Account] { (repo:
AccountRepository) =>
EitherT {
Future {
repo.query(no) match {
//..
}
}
}
}
//..
}
Tuesday, 6 October 15
class AccountServiceInterpreter
extends AccountService[Account, Amount, Balance] {
def open(no: String,
name: String,
rate: Option[BigDecimal],
openingDate: Option[Date],
accountType: AccountType) =
kleisli[Valid, AccountRepository, Account] { (repo:
AccountRepository) =>
EitherT {
Future {
repo.query(no) match {
//..
}
}
}
}
//..
}
normal logic
Tuesday, 6 October 15
We introduced a whole new effect of
asynchrony to implement reactive traits in our
domain model API algebra & implementation
just by composing with another type without
any change in the core domain logic.This is
the essence of typed functional programming.
We have types that model effects functionally
and we can just stack them up in the proper
order that we need.
Tuesday, 6 October 15
Advantages
• We are still in the statically typed land even
with asynchronous behaviors baked into
our APIs
• We can reason about our program
statically
• We can compose asynchronous
components to form larger abstractions
Tuesday, 6 October 15
for {
_ <- open(..)
_ <- credit(..)
d <- debit(..)
} yield d
Reactive & algebraic patterns in
domain modeling
Tuesday, 6 October 15
for {
_ <- open(..)
_ <- credit(..)
d <- debit(..)
} yield d
Reactive & algebraic patterns in
domain modeling
• Compositional by types
Tuesday, 6 October 15
for {
_ <- open(..)
_ <- credit(..)
d <- debit(..)
} yield d
Reactive & algebraic patterns in
domain modeling
• Compositional by types
• Individual operations
sequential as they thread
through the comprehension
Tuesday, 6 October 15
for {
_ <- open(..)
_ <- credit(..)
d <- debit(..)
} yield d
Reactive & algebraic patterns in
domain modeling
• Compositional by types
• Individual operations
sequential as they thread
through the comprehension
• Composed operation doesn’t
block the main thread of
execution
Tuesday, 6 October 15
Reactive & algebraic patterns in
domain modeling
Tuesday, 6 October 15
trait PortfolioService {
type PFOperation[A] = Kleisli[Future, AccountRepository, Seq[A]]
def getCurrencyPortfolio(no: String, asOf: Date)
: PFOperation[Balance]
def getEquityPortfolio(no: String, asOf: Date)
: PFOperation[Balance]
def getFixedIncomePortfolio(no: String, asOf: Date)
: PFOperation[Balance]
}
Reactive & algebraic patterns in
domain modeling
Tuesday, 6 October 15
val ccyPF: Future[Seq[Balance]] =
getCurrencyPortfolio(accountNo, asOf)(AccountRepository)
val eqtPF: Future[Seq[Balance]] =
getEquityPortfolio(accountNo, asOf)(AccountRepository)
val fixPF: Future[Seq[Balance]] =
getFixedIncomePortfolio(accountNo, asOf)(AccountRepository)
val portfolio: Future[Portfolio] = for {
c <- ccyPF
e <- eqtPF
f <- fixPF
} yield CustomerPortfolio(accountNo, asOf, c ++ e ++ f)
Reactive & algebraic patterns in
domain modeling
Tuesday, 6 October 15
Be Algebraic, as long as
you can ..
Tuesday, 6 October 15
Beyond Algebra -
Reactive Protocols
Tuesday, 6 October 15
Conference
Reservations
Program
Management
Badge Printing
Domain Algebra A
Domain Algebra B
Domain Algebra C
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
Protocols
Reactive
Tuesday, 6 October 15
Conference
Reservations
Program
Management
Badge Printing
Domain Algebra A
Domain Algebra B
Domain Algebra C
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
• Ubiquitous language
• Entities
•Value Objects
• Functions on objects
• Domain Rules
• Schema
• Operations
Protocols
ReactiveElasticity
(responsive under
varying load)
Resilience
(responsive in the
face of failures)
Message-driven
(loose coupling,
isolation thru
async message
passing)
Responsive
(through bounded
latency)
Tuesday, 6 October 15
Asynchronous Messaging
Tuesday, 6 October 15
Asynchronous Messaging
Tuesday, 6 October 15
Asynchronous Messaging
Tuesday, 6 October 15
Asynchronous Messaging
Tuesday, 6 October 15
Actors and Domain
Models
Tuesday, 6 October 15
Actors and Domain
Models
Powerful
Tuesday, 6 October 15
Actors and Domain
Models
Powerful
Un-algebraically Powerful
Tuesday, 6 October 15
Actors and Domain
Models
Powerful
Un-algebraically Powerful
Gain power at one semantic level but
lose the power of reasoning
Tuesday, 6 October 15
Using actors indiscriminately
throughout your domain model
makes algebraic reasoning hard
Tuesday, 6 October 15
fork:
A => Future[A]
map:
(A => B) => (Future[A] => Future[B])
join:
Future[Future[A]] => Future[A]
Tuesday, 6 October 15
receive: Any => Unit
Tuesday, 6 October 15
Use the least powerful abstraction
that does the job
Tuesday, 6 October 15
For domain model resilience,
choose futures over actors when you
can ..
Tuesday, 6 October 15
• As an implementation artifact to protect
shared mutable state
• Centralized failure management
Actors and Domain
Models
Tuesday, 6 October 15
import scala.collection.mutable.{ Map => MMap }
class Summarizer extends Actor with ActorSubscriber with Logging {
private val balance = MMap.empty[String, Balance]
def receive = {
case OnNext(data: Transaction) => updateBalance(data)
case LogSummaryBalance => logger.info("Balance: " + balance)
}
def updateBalance(data: Transaction) =
balance.get(data.accountNo).fold {
balance += ..
} { b =>
balance += ..
}
}
shared mutable state here
updated
Tuesday, 6 October 15
Centralized Failure
Management
• Supervisor hierarchies that manages failures
• Kill, restart, suspend / resume
• No more messy failure handling code
scattered throughout
• Requires careful upfront design though
Tuesday, 6 October 15
Being Reactive
Elasticity
(responsive under
varying load)
Resilience
(responsive in the
face of failures)
Message-driven
(loose coupling,
isolation thru
async message
passing)
Responsive
(through bounded
latency)
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
untyped
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
untyped
non-compositional
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
untyped
non-compositional
un-algebraic
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
untyped
non-compositional
un-algebraic
higher
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
untyped
non-compositional
un-algebraic
higher
dsl
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
untyped
non-compositional
un-algebraic
higher
dsl
flow as first class
abstraction
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
untyped
non-compositional
un-algebraic
higher
dsl
flow as first class
abstraction
separate definition from execution
Tuesday, 6 October 15
Modeling Domain
Workflows
Actor
Actor Actor
Actor Actor
Actormessage
message
message
message
message
message
message
low level
untyped
non-compositional
un-algebraic
higher
dsl
flow as first class
abstraction
separate definition from execution
Reactive Streams
Tuesday, 6 October 15
Akka Streams
Source
Pipeline starts here. Source[+Out, +Mat] takes data
from input & has a single output
Sink Pipeline ends here. Sink[+In, +Mat] has a single input
to be written into
Flow
Basic transformation abstraction. Flow[-In, +Out,
+Mat] has 1 input & 1 output. Mat is the actor
materializer
Runnable
Graph
The entire topology ready to run
Tuesday, 6 October 15
Business Use Case - The Domain Model
Tuesday, 6 October 15
Implementation topology with Akka
Streams
Tuesday, 6 October 15
val graph = FlowGraph.closed(netTxnSink) { implicit b => ns =>
import FlowGraph.Implicits._
val accountBroadcast = b.add(Broadcast[Account](2))
val txnBroadcast = b.add(Broadcast[Transaction](2))
val merge = b.add(Merge[Transaction](2))
val accounts = Flow[String].map(queryAccount(_, AccountRepository))
val bankingTxns = Flow[Account].mapConcat(getBankingTransactions)
val settlementTxns =
Flow[Account].mapConcat(getSettlementTransactions)
val validation = Flow[Transaction].map(validate)
accountNos ~> accounts ~> accountBroadcast ~> bankingTxns
~> merge ~> validation ~> txnBroadcast ~> ns
accountBroadcast ~> settlementTxns ~> merge
txnBroadcast ~> audit
}
Tuesday, 6 October 15
graph.run()
Tuesday, 6 October 15
https://www.manning.com/books/functional-and-reactive-
domain-modeling
Tuesday, 6 October 15
ThankYou!
Tuesday, 6 October 15
Tuesday, 6 October 15

Contenu connexe

Tendances

Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed worldDebasish Ghosh
 
Domain Modeling in a Functional World
Domain Modeling in a Functional WorldDomain Modeling in a Functional World
Domain Modeling in a Functional WorldDebasish Ghosh
 
Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingDebasish Ghosh
 
Mining Functional Patterns
Mining Functional PatternsMining Functional Patterns
Mining Functional PatternsDebasish Ghosh
 
Dependency Injection in Scala - Beyond the Cake Pattern
Dependency Injection in Scala - Beyond the Cake PatternDependency Injection in Scala - Beyond the Cake Pattern
Dependency Injection in Scala - Beyond the Cake PatternDebasish Ghosh
 
Approximation Data Structures for Streaming Applications
Approximation Data Structures for Streaming ApplicationsApproximation Data Structures for Streaming Applications
Approximation Data Structures for Streaming ApplicationsDebasish Ghosh
 
Value objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progressValue objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progressBrendan Eich
 
Session 2 - Objective-C basics
Session 2 - Objective-C basicsSession 2 - Objective-C basics
Session 2 - Objective-C basicsVu Tran Lam
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Vu Tran Lam
 
JavaScript objects and functions
JavaScript objects and functionsJavaScript objects and functions
JavaScript objects and functionsVictor Verhaagen
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Gostrikr .
 
Datatype in JavaScript
Datatype in JavaScriptDatatype in JavaScript
Datatype in JavaScriptRajat Saxena
 
JS Fest 2019. Mauricio Palma. You can’t read this sentence - A11y automation
JS Fest 2019. Mauricio Palma. You can’t read this sentence - A11y automationJS Fest 2019. Mauricio Palma. You can’t read this sentence - A11y automation
JS Fest 2019. Mauricio Palma. You can’t read this sentence - A11y automationJSFestUA
 
DIDUCE: ICSE-2002 presentation
DIDUCE: ICSE-2002 presentationDIDUCE: ICSE-2002 presentation
DIDUCE: ICSE-2002 presentationhangal
 
Programming for Problem Solving Unit 1
Programming for Problem Solving Unit 1Programming for Problem Solving Unit 1
Programming for Problem Solving Unit 1Dhiviya Rose
 

Tendances (20)

Power of functions in a typed world
Power of functions in a typed worldPower of functions in a typed world
Power of functions in a typed world
 
Domain Modeling in a Functional World
Domain Modeling in a Functional WorldDomain Modeling in a Functional World
Domain Modeling in a Functional World
 
Functional and Algebraic Domain Modeling
Functional and Algebraic Domain ModelingFunctional and Algebraic Domain Modeling
Functional and Algebraic Domain Modeling
 
Mining Functional Patterns
Mining Functional PatternsMining Functional Patterns
Mining Functional Patterns
 
Dependency Injection in Scala - Beyond the Cake Pattern
Dependency Injection in Scala - Beyond the Cake PatternDependency Injection in Scala - Beyond the Cake Pattern
Dependency Injection in Scala - Beyond the Cake Pattern
 
Approximation Data Structures for Streaming Applications
Approximation Data Structures for Streaming ApplicationsApproximation Data Structures for Streaming Applications
Approximation Data Structures for Streaming Applications
 
JavaScript Data Types
JavaScript Data TypesJavaScript Data Types
JavaScript Data Types
 
Value objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progressValue objects in JS - an ES7 work in progress
Value objects in JS - an ES7 work in progress
 
Session 2 - Objective-C basics
Session 2 - Objective-C basicsSession 2 - Objective-C basics
Session 2 - Objective-C basics
 
Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)Session 3 - Object oriented programming with Objective-C (part 1)
Session 3 - Object oriented programming with Objective-C (part 1)
 
JavaScript objects and functions
JavaScript objects and functionsJavaScript objects and functions
JavaScript objects and functions
 
Reflection in Go
Reflection in GoReflection in Go
Reflection in Go
 
Datatype in JavaScript
Datatype in JavaScriptDatatype in JavaScript
Datatype in JavaScript
 
Aspdot
AspdotAspdot
Aspdot
 
Int64
Int64Int64
Int64
 
JS Fest 2019. Mauricio Palma. You can’t read this sentence - A11y automation
JS Fest 2019. Mauricio Palma. You can’t read this sentence - A11y automationJS Fest 2019. Mauricio Palma. You can’t read this sentence - A11y automation
JS Fest 2019. Mauricio Palma. You can’t read this sentence - A11y automation
 
Software Developer Training
Software Developer TrainingSoftware Developer Training
Software Developer Training
 
Overview of c (2)
Overview of c (2)Overview of c (2)
Overview of c (2)
 
DIDUCE: ICSE-2002 presentation
DIDUCE: ICSE-2002 presentationDIDUCE: ICSE-2002 presentation
DIDUCE: ICSE-2002 presentation
 
Programming for Problem Solving Unit 1
Programming for Problem Solving Unit 1Programming for Problem Solving Unit 1
Programming for Problem Solving Unit 1
 

En vedette

Domain-driven design
Domain-driven designDomain-driven design
Domain-driven designKnoldus Inc.
 
Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaVladimir Kostyukov
 
Microservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time OrganizationMicroservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time OrganizationKevin Webber
 
Fifty Shades of the Common Core for ELA: Revised
Fifty Shades of the Common Core for ELA: RevisedFifty Shades of the Common Core for ELA: Revised
Fifty Shades of the Common Core for ELA: RevisedJennifer Jones
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modelingMario Fusco
 
Concurrent Mark-Sweep Garbage Collection #jjug_ccc
Concurrent Mark-Sweep Garbage Collection #jjug_cccConcurrent Mark-Sweep Garbage Collection #jjug_ccc
Concurrent Mark-Sweep Garbage Collection #jjug_cccYuji Kubota
 
Reactive Streams 1.0.0 and Why You Should Care (webinar)
Reactive Streams 1.0.0 and Why You Should Care (webinar)Reactive Streams 1.0.0 and Why You Should Care (webinar)
Reactive Streams 1.0.0 and Why You Should Care (webinar)Legacy Typesafe (now Lightbend)
 
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...Lightbend
 

En vedette (12)

Actor Model & Reactive Manifesto
Actor Model & Reactive ManifestoActor Model & Reactive Manifesto
Actor Model & Reactive Manifesto
 
Beyond Scala Lens
Beyond Scala LensBeyond Scala Lens
Beyond Scala Lens
 
API Centric Patterns
API Centric PatternsAPI Centric Patterns
API Centric Patterns
 
Domain-driven design
Domain-driven designDomain-driven design
Domain-driven design
 
Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in Scala
 
Microservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time OrganizationMicroservices: Architecture for the Real-time Organization
Microservices: Architecture for the Real-time Organization
 
Fifty Shades of the Common Core for ELA: Revised
Fifty Shades of the Common Core for ELA: RevisedFifty Shades of the Common Core for ELA: Revised
Fifty Shades of the Common Core for ELA: Revised
 
From object oriented to functional domain modeling
From object oriented to functional domain modelingFrom object oriented to functional domain modeling
From object oriented to functional domain modeling
 
Concurrent Mark-Sweep Garbage Collection #jjug_ccc
Concurrent Mark-Sweep Garbage Collection #jjug_cccConcurrent Mark-Sweep Garbage Collection #jjug_ccc
Concurrent Mark-Sweep Garbage Collection #jjug_ccc
 
Reactive Streams 1.0.0 and Why You Should Care (webinar)
Reactive Streams 1.0.0 and Why You Should Care (webinar)Reactive Streams 1.0.0 and Why You Should Care (webinar)
Reactive Streams 1.0.0 and Why You Should Care (webinar)
 
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
Using the Actor Model with Domain-Driven Design (DDD) in Reactive Systems - w...
 
Embulk 20150411
Embulk 20150411Embulk 20150411
Embulk 20150411
 

Similaire à From functional to Reactive - patterns in domain modeling

NoSQL Now 2013 Presentation
NoSQL Now 2013 PresentationNoSQL Now 2013 Presentation
NoSQL Now 2013 PresentationArjen Schoneveld
 
Functional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 WayFunctional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 WayDebasish Ghosh
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Fwdays
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript EngineKris Mok
 
An R primer for SQL folks
An R primer for SQL folksAn R primer for SQL folks
An R primer for SQL folksThomas Hütter
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMManuel Bernhardt
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfkatarichallenge
 
Review of object orientation
Review of object orientationReview of object orientation
Review of object orientationGurbakash Phonsa
 
How Graph Databases efficiently store, manage and query connected data at s...
How Graph Databases efficiently  store, manage and query  connected data at s...How Graph Databases efficiently  store, manage and query  connected data at s...
How Graph Databases efficiently store, manage and query connected data at s...jexp
 
A Deep Dive into Javascript
A Deep Dive into JavascriptA Deep Dive into Javascript
A Deep Dive into JavascriptTiang Cheng
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptxsalutiontechnology
 
COMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptxCOMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptxFarooqTariq8
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesGanesh Samarthyam
 
Everything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus scriptEverything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus scriptBill Buchan
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageNeo4j
 
A Workshop on R
A Workshop on RA Workshop on R
A Workshop on RAjay Ohri
 

Similaire à From functional to Reactive - patterns in domain modeling (20)

NoSQL Now 2013 Presentation
NoSQL Now 2013 PresentationNoSQL Now 2013 Presentation
NoSQL Now 2013 Presentation
 
Introduction to c ++ part -1
Introduction to c ++   part -1Introduction to c ++   part -1
Introduction to c ++ part -1
 
Functional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 WayFunctional Domain Modeling - The ZIO 2 Way
Functional Domain Modeling - The ZIO 2 Way
 
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
Алексей Ященко и Ярослав Волощук "False simplicity of front-end applications"
 
Implementing a JavaScript Engine
Implementing a JavaScript EngineImplementing a JavaScript Engine
Implementing a JavaScript Engine
 
An R primer for SQL folks
An R primer for SQL folksAn R primer for SQL folks
An R primer for SQL folks
 
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVMVoxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
Voxxed Days Vienna - The Why and How of Reactive Web-Applications on the JVM
 
JavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdfJavaScript Interview Questions Part - 1.pdf
JavaScript Interview Questions Part - 1.pdf
 
Review of object orientation
Review of object orientationReview of object orientation
Review of object orientation
 
How Graph Databases efficiently store, manage and query connected data at s...
How Graph Databases efficiently  store, manage and query  connected data at s...How Graph Databases efficiently  store, manage and query  connected data at s...
How Graph Databases efficiently store, manage and query connected data at s...
 
Lecture 1 (bce-7)
Lecture   1 (bce-7)Lecture   1 (bce-7)
Lecture 1 (bce-7)
 
A Deep Dive into Javascript
A Deep Dive into JavascriptA Deep Dive into Javascript
A Deep Dive into Javascript
 
Big data analytics with R tool.pptx
Big data analytics with R tool.pptxBig data analytics with R tool.pptx
Big data analytics with R tool.pptx
 
Introduction to java and oop
Introduction to java and oopIntroduction to java and oop
Introduction to java and oop
 
COMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptxCOMP111-Week-1_138439.pptx
COMP111-Week-1_138439.pptx
 
Software Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and PracticesSoftware Architecture: Principles, Patterns and Practices
Software Architecture: Principles, Patterns and Practices
 
Everything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus scriptEverything you ever wanted to know about lotus script
Everything you ever wanted to know about lotus script
 
Angular
AngularAngular
Angular
 
The openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query LanguageThe openCypher Project - An Open Graph Query Language
The openCypher Project - An Open Graph Query Language
 
A Workshop on R
A Workshop on RA Workshop on R
A Workshop on R
 

Dernier

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?Alexandre Beguel
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsJean Silva
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxRTS corp
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldRoberto Pérez Alcolea
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingShane Coughlan
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesKrzysztofKkol1
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...OnePlan Solutions
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfRTS corp
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfmaor17
 

Dernier (20)

Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?SAM Training Session - How to use EXCEL ?
SAM Training Session - How to use EXCEL ?
 
Strategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero resultsStrategies for using alternative queries to mitigate zero results
Strategies for using alternative queries to mitigate zero results
 
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptxReal-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
Real-time Tracking and Monitoring with Cargo Cloud Solutions.pptx
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
Keeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository worldKeeping your build tool updated in a multi repository world
Keeping your build tool updated in a multi repository world
 
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full RecordingOpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
OpenChain AI Study Group - Europe and Asia Recap - 2024-04-11 - Full Recording
 
Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News UpdateVictoriaMetrics Q1 Meet Up '24 - Community & News Update
VictoriaMetrics Q1 Meet Up '24 - Community & News Update
 
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilitiesAmazon Bedrock in Action - presentation of the Bedrock's capabilities
Amazon Bedrock in Action - presentation of the Bedrock's capabilities
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
Tech Tuesday Slides - Introduction to Project Management with OnePlan's Work ...
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdfEnhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
Enhancing Supply Chain Visibility with Cargo Cloud Solutions.pdf
 
Zer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdfZer0con 2024 final share short version.pdf
Zer0con 2024 final share short version.pdf
 

From functional to Reactive - patterns in domain modeling

  • 1. From Functional to Reactive patterns in domain modeling Debasish Ghosh @debasishg Tuesday, 6 October 15
  • 9. What is a domain model ? A domain model in problem solving and software engineering is a conceptual model of all the topics related to a specific problem. It describes the various entities, their attributes, roles, and relationships, plus the constraints that govern the problem domain. It does not describe the solutions to the problem. Wikipedia (http://en.wikipedia.org/wiki/Domain_model) Tuesday, 6 October 15
  • 10. The Functional Lens .. “domain API evolution through algebraic composition” Tuesday, 6 October 15
  • 11. The Functional Lens .. “domain API evolution through algebraic composition” (Reactive) Tuesday, 6 October 15
  • 12. Agenda • Formalizing a domain model • Domain model algebra • From functional to algebraically reactive • Beyond algebra • Actors and domain models • Reactive streams - typesafe & compositional Tuesday, 6 October 15
  • 15. Your domain model is a function Tuesday, 6 October 15
  • 16. Your domain model is a function Tuesday, 6 October 15
  • 17. Your domain model is a collection of functions Tuesday, 6 October 15
  • 18. Your domain model is a collection of functions some simpler models are .. Tuesday, 6 October 15
  • 20. A Bounded Context • has a consistent vocabulary • a set of domain behaviors modeled as functions on domain objects implemented as types • related behaviors grouped as modules Tuesday, 6 October 15
  • 21. Domain Model = ∪(i) Bounded Context(i) Tuesday, 6 October 15
  • 22. Domain Model = ∪(i) Bounded Context(i) Bounded Context = { f(x) | p(x) ∈ Domain Rules } Tuesday, 6 October 15
  • 23. Domain Model = ∪(i) Bounded Context(i) Bounded Context = { f(x) | p(x) ∈ Domain Rules } • domain function • on an object of type x • composes with other functions • closed under composition • business rules Tuesday, 6 October 15
  • 24. • Functions / Morphisms • Types / Sets • Composition • Rules / Laws Tuesday, 6 October 15
  • 25. • Functions / Morphisms • Types / Sets • Composition • Rules / Laws algebra Tuesday, 6 October 15
  • 27. Domain Model Algebra (algebra of types, functions & laws) Tuesday, 6 October 15
  • 28. Domain Model Algebra (algebra of types, functions & laws) explicit • types • type constraints • expression in terms of other generic algebra Tuesday, 6 October 15
  • 29. Domain Model Algebra (algebra of types, functions & laws) explicit verifiable • types • type constraints • expression in terms of other generic algebra • type constraints • more constraints if you have DT • algebraic property based testing Tuesday, 6 October 15
  • 35. Domain Model = ∪(i) Bounded Context(i) Bounded Context = { f(x) | p(x) ∈ Domain Rules } • domain function • on an object of type x • composes with other functions • closed under composition • business rules Domain Algebra Domain Algebra Tuesday, 6 October 15
  • 36. • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations Algebra is the binding contract Bounded Context Tuesday, 6 October 15
  • 37. • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations Algebra is the binding contract Bounded Context Reactive Tuesday, 6 October 15
  • 38. Conference Reservations Program Management Badge Printing Domain Algebra A Domain Algebra B Domain Algebra C • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations Tuesday, 6 October 15
  • 39. • Algebras don’t unify across bounded contexts • Decoupled in space and time • Separate vocabulary • Types break down Tuesday, 6 October 15
  • 40. Conference Reservations Program Management Badge Printing Domain Algebra A Domain Algebra B Domain Algebra C • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations Protocols Tuesday, 6 October 15
  • 41. Conference Reservations Program Management Badge Printing Domain Algebra A Domain Algebra B Domain Algebra C • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations Protocols Reactive Tuesday, 6 October 15
  • 42. Being Reactive Elasticity (responsive under varying load) Resilience (responsive in the face of failures) Message-driven (loose coupling, isolation thru async message passing) Responsive (through bounded latency) Tuesday, 6 October 15
  • 43. trait AccountService[Account, Amount, Balance] { type AccountOp[A] = NonEmptyList[String] / A def open(no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType): AccountOp[Account] def close(no: String, closeDate: Option[Date]): AccountOp[Account] def debit(no: String, amount: Amount): AccountOp[Account] def credit(no: String, amount: Amount): AccountOp[Account] //.. } Tuesday, 6 October 15
  • 44. trait AccountService[Account, Amount, Balance] { type AccountOp[A] = NonEmptyList[String] / A def open(no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType): AccountOp[Account] def close(no: String, closeDate: Option[Date]): AccountOp[Account] def debit(no: String, amount: Amount): AccountOp[Account] def credit(no: String, amount: Amount): AccountOp[Account] //.. } Module Name Tuesday, 6 October 15
  • 45. trait AccountService[Account, Amount, Balance] { type AccountOp[A] = NonEmptyList[String] / A def open(no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType): AccountOp[Account] def close(no: String, closeDate: Option[Date]): AccountOp[Account] def debit(no: String, amount: Amount): AccountOp[Account] def credit(no: String, amount: Amount): AccountOp[Account] //.. } Module Name Parameterized on types Tuesday, 6 October 15
  • 46. trait AccountService[Account, Amount, Balance] { type AccountOp[A] = NonEmptyList[String] / A def open(no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType): AccountOp[Account] def close(no: String, closeDate: Option[Date]): AccountOp[Account] def debit(no: String, amount: Amount): AccountOp[Account] def credit(no: String, amount: Amount): AccountOp[Account] //.. } Module Name Parameterized on types Operation return type - either a successfully constructed type or a list of errors Tuesday, 6 October 15
  • 47. trait AccountService[Account, Amount, Balance] { type AccountOp[A] = NonEmptyList[String] / A def open(no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType): AccountOp[Account] def close(no: String, closeDate: Option[Date]): AccountOp[Account] def debit(no: String, amount: Amount): AccountOp[Account] def credit(no: String, amount: Amount): AccountOp[Account] //.. } Module Name Parameterized on types Operation return type - either a successfully constructed type or a list of errors Operations - domain behaviors Tuesday, 6 October 15
  • 48. trait AccountService[Account, Amount, Balance] { type AccountOp[A] = NonEmptyList[String] / A def open(no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType): AccountOp[Account] def close(no: String, closeDate: Option[Date]): AccountOp[Account] def debit(no: String, amount: Amount): AccountOp[Account] def credit(no: String, amount: Amount): AccountOp[Account] //.. } Module Name Parameterized on types Operation return type - either a successfully constructed type or a list of errors Operations - domain behaviors explicit & verifiable algebra Tuesday, 6 October 15
  • 49. • Parametric - parameterized on types • Statically Typed • Modular and hence unit testable • Composable Tuesday, 6 October 15
  • 50. def transfer(from: String, to: String, amount: Amount) : AccountOp[(Account, Account)] = for { a <- debit(from, amount) b <- credit(to, amount) } yield ((a, b)) Composable Tuesday, 6 October 15
  • 51. Composable trait BankingService[Account, Amount, Balance] extends AccountService[Account, Amount, Balance] with InterestPostingService[Account, Amount] with InterestCalculation[Account, Amount] with TaxCalculation[Amount] Tuesday, 6 October 15
  • 52. trait AccountService[Account, Amount, Balance] { type AccountOp[A] = NonEmptyList[String] / A def open( no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType ): AccountRepository => AccountOp[Account] //.. } Tuesday, 6 October 15
  • 53. trait AccountService[Account, Amount, Balance] { type AccountOp[A] = NonEmptyList[String] / A def open( no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType ): AccountRepository => AccountOp[Account] //.. } change the algebra to add functionality Tuesday, 6 October 15
  • 54. trait AccountService[Account, Amount, Balance] { type Valid[A] = NonEmptyList[String] / A type AccountOp[A] = Kleisli[Valid, AccountRepository, A] def open( no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType ): AccountOp[Account] //.. } more algebra, more functionality, more succinct Tuesday, 6 October 15
  • 55. • Design should not have any contention or central bottlenecks that tend to hamper the progress of the system Being Reactive Tuesday, 6 October 15
  • 56. • If your domain service publishes APIs that does blocking calls to underlying databases and blocks the central thread of user interaction, you face the specter of unbounded latency Being Reactive Tuesday, 6 October 15
  • 58. Blocking Kills Make your APIs elastic enough so that the perceived response to the user is not affected by the current load on the system Tuesday, 6 October 15
  • 59. Elasticity (responsive under varying load) Resilience (responsive in the face of failures) Message-driven (loose coupling, isolation thru async message passing) Responsive (through bounded latency) Tuesday, 6 October 15
  • 60. • Without foregoing the benefits of algebraic reasoning with types Being Reactive Tuesday, 6 October 15
  • 62. Enter Futures .. • A future is the essence of asynchronous non blocking computation Tuesday, 6 October 15
  • 63. Enter Futures .. • A future is the essence of asynchronous non blocking computation • Futures compose Tuesday, 6 October 15
  • 64. Enter Futures .. • A future is the essence of asynchronous non blocking computation • Futures compose • Futures have an algebra Tuesday, 6 October 15
  • 65. Enter Futures .. • A future is the essence of asynchronous non blocking computation • Futures compose • Futures have an algebra • Organize concurrent code around futures safely and in a compositional way Tuesday, 6 October 15
  • 66. • In our use case we would like to augment our domain algebra with future based APIs • Just like an Either or a Kleisli, we would like to have asynchrony as yet another stackable effect within our computation Goals towards Reactive API Tuesday, 6 October 15
  • 69. type Response[A] = String / Option[A] val count: Response[Int] = some(10).right for { maybeCount <- count } yield { for { c <- maybeCount // use c } yield c } Monad Transformers Tuesday, 6 October 15
  • 70. type Response[A] = String / Option[A] val count: Response[Int] = some(10).right for { maybeCount <- count } yield { for { c <- maybeCount // use c } yield c } type Error[A] = String / A type Response[A] = OptionT[Error, A] val count: Response[Int] = 10.point[Response] for { c <- count // use c : c is an Int here } yield (()) Monad Transformers Tuesday, 6 October 15
  • 71. type Response[A] = String / Option[A] val count: Response[Int] = some(10).right for { maybeCount <- count } yield { for { c <- maybeCount // use c } yield c } type Error[A] = String / A type Response[A] = OptionT[Error, A] val count: Response[Int] = 10.point[Response] for{ c <- count // use c : c is an Int here } yield (()) Monad Transformers richer algebra Tuesday, 6 October 15
  • 72. Monad Transformers • collapses the stack and gives us a single monad to deal with • order of stacking is important though Tuesday, 6 October 15
  • 73. trait AccountService[Account, Amount, Balance] { type Valid[A] = EitherT[Future, NonEmptyList[String], A] type AccountOp[A] = Kleisli[Valid, AccountRepository, A] def open( no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType ): AccountOp[Account] //.. } Tuesday, 6 October 15
  • 74. trait AccountService[Account, Amount, Balance] { type Valid[A] = EitherT[Future, NonEmptyList[String], A] type AccountOp[A] = Kleisli[Valid, AccountRepository, A] def open( no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType ): AccountOp[Account] //.. } Tuesday, 6 October 15
  • 76. trait AccountService[Account, Amount, Balance] { type Valid[A] = EitherT[Future, NonEmptyList[String], A] type AccountOp[A] = Kleisli[Valid, AccountRepository, A] def open( no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType ): AccountOp[Account] //.. } Reactive .. Algebraically Tuesday, 6 October 15
  • 77. class AccountServiceInterpreter extends AccountService[Account, Amount, Balance] { def open(no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType) = kleisli[Valid, AccountRepository, Account] { (repo: AccountRepository) => EitherT { Future { repo.query(no) match { //.. } } } } //.. } Tuesday, 6 October 15
  • 78. class AccountServiceInterpreter extends AccountService[Account, Amount, Balance] { def open(no: String, name: String, rate: Option[BigDecimal], openingDate: Option[Date], accountType: AccountType) = kleisli[Valid, AccountRepository, Account] { (repo: AccountRepository) => EitherT { Future { repo.query(no) match { //.. } } } } //.. } normal logic Tuesday, 6 October 15
  • 79. We introduced a whole new effect of asynchrony to implement reactive traits in our domain model API algebra & implementation just by composing with another type without any change in the core domain logic.This is the essence of typed functional programming. We have types that model effects functionally and we can just stack them up in the proper order that we need. Tuesday, 6 October 15
  • 80. Advantages • We are still in the statically typed land even with asynchronous behaviors baked into our APIs • We can reason about our program statically • We can compose asynchronous components to form larger abstractions Tuesday, 6 October 15
  • 81. for { _ <- open(..) _ <- credit(..) d <- debit(..) } yield d Reactive & algebraic patterns in domain modeling Tuesday, 6 October 15
  • 82. for { _ <- open(..) _ <- credit(..) d <- debit(..) } yield d Reactive & algebraic patterns in domain modeling • Compositional by types Tuesday, 6 October 15
  • 83. for { _ <- open(..) _ <- credit(..) d <- debit(..) } yield d Reactive & algebraic patterns in domain modeling • Compositional by types • Individual operations sequential as they thread through the comprehension Tuesday, 6 October 15
  • 84. for { _ <- open(..) _ <- credit(..) d <- debit(..) } yield d Reactive & algebraic patterns in domain modeling • Compositional by types • Individual operations sequential as they thread through the comprehension • Composed operation doesn’t block the main thread of execution Tuesday, 6 October 15
  • 85. Reactive & algebraic patterns in domain modeling Tuesday, 6 October 15
  • 86. trait PortfolioService { type PFOperation[A] = Kleisli[Future, AccountRepository, Seq[A]] def getCurrencyPortfolio(no: String, asOf: Date) : PFOperation[Balance] def getEquityPortfolio(no: String, asOf: Date) : PFOperation[Balance] def getFixedIncomePortfolio(no: String, asOf: Date) : PFOperation[Balance] } Reactive & algebraic patterns in domain modeling Tuesday, 6 October 15
  • 87. val ccyPF: Future[Seq[Balance]] = getCurrencyPortfolio(accountNo, asOf)(AccountRepository) val eqtPF: Future[Seq[Balance]] = getEquityPortfolio(accountNo, asOf)(AccountRepository) val fixPF: Future[Seq[Balance]] = getFixedIncomePortfolio(accountNo, asOf)(AccountRepository) val portfolio: Future[Portfolio] = for { c <- ccyPF e <- eqtPF f <- fixPF } yield CustomerPortfolio(accountNo, asOf, c ++ e ++ f) Reactive & algebraic patterns in domain modeling Tuesday, 6 October 15
  • 88. Be Algebraic, as long as you can .. Tuesday, 6 October 15
  • 89. Beyond Algebra - Reactive Protocols Tuesday, 6 October 15
  • 90. Conference Reservations Program Management Badge Printing Domain Algebra A Domain Algebra B Domain Algebra C • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations Protocols Reactive Tuesday, 6 October 15
  • 91. Conference Reservations Program Management Badge Printing Domain Algebra A Domain Algebra B Domain Algebra C • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations • Ubiquitous language • Entities •Value Objects • Functions on objects • Domain Rules • Schema • Operations Protocols ReactiveElasticity (responsive under varying load) Resilience (responsive in the face of failures) Message-driven (loose coupling, isolation thru async message passing) Responsive (through bounded latency) Tuesday, 6 October 15
  • 98. Actors and Domain Models Powerful Un-algebraically Powerful Tuesday, 6 October 15
  • 99. Actors and Domain Models Powerful Un-algebraically Powerful Gain power at one semantic level but lose the power of reasoning Tuesday, 6 October 15
  • 100. Using actors indiscriminately throughout your domain model makes algebraic reasoning hard Tuesday, 6 October 15
  • 101. fork: A => Future[A] map: (A => B) => (Future[A] => Future[B]) join: Future[Future[A]] => Future[A] Tuesday, 6 October 15
  • 102. receive: Any => Unit Tuesday, 6 October 15
  • 103. Use the least powerful abstraction that does the job Tuesday, 6 October 15
  • 104. For domain model resilience, choose futures over actors when you can .. Tuesday, 6 October 15
  • 105. • As an implementation artifact to protect shared mutable state • Centralized failure management Actors and Domain Models Tuesday, 6 October 15
  • 106. import scala.collection.mutable.{ Map => MMap } class Summarizer extends Actor with ActorSubscriber with Logging { private val balance = MMap.empty[String, Balance] def receive = { case OnNext(data: Transaction) => updateBalance(data) case LogSummaryBalance => logger.info("Balance: " + balance) } def updateBalance(data: Transaction) = balance.get(data.accountNo).fold { balance += .. } { b => balance += .. } } shared mutable state here updated Tuesday, 6 October 15
  • 107. Centralized Failure Management • Supervisor hierarchies that manages failures • Kill, restart, suspend / resume • No more messy failure handling code scattered throughout • Requires careful upfront design though Tuesday, 6 October 15
  • 108. Being Reactive Elasticity (responsive under varying load) Resilience (responsive in the face of failures) Message-driven (loose coupling, isolation thru async message passing) Responsive (through bounded latency) Tuesday, 6 October 15
  • 109. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message Tuesday, 6 October 15
  • 110. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level Tuesday, 6 October 15
  • 111. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level untyped Tuesday, 6 October 15
  • 112. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level untyped non-compositional Tuesday, 6 October 15
  • 113. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level untyped non-compositional un-algebraic Tuesday, 6 October 15
  • 114. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level untyped non-compositional un-algebraic higher Tuesday, 6 October 15
  • 115. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level untyped non-compositional un-algebraic higher dsl Tuesday, 6 October 15
  • 116. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level untyped non-compositional un-algebraic higher dsl flow as first class abstraction Tuesday, 6 October 15
  • 117. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level untyped non-compositional un-algebraic higher dsl flow as first class abstraction separate definition from execution Tuesday, 6 October 15
  • 118. Modeling Domain Workflows Actor Actor Actor Actor Actor Actormessage message message message message message message low level untyped non-compositional un-algebraic higher dsl flow as first class abstraction separate definition from execution Reactive Streams Tuesday, 6 October 15
  • 119. Akka Streams Source Pipeline starts here. Source[+Out, +Mat] takes data from input & has a single output Sink Pipeline ends here. Sink[+In, +Mat] has a single input to be written into Flow Basic transformation abstraction. Flow[-In, +Out, +Mat] has 1 input & 1 output. Mat is the actor materializer Runnable Graph The entire topology ready to run Tuesday, 6 October 15
  • 120. Business Use Case - The Domain Model Tuesday, 6 October 15
  • 121. Implementation topology with Akka Streams Tuesday, 6 October 15
  • 122. val graph = FlowGraph.closed(netTxnSink) { implicit b => ns => import FlowGraph.Implicits._ val accountBroadcast = b.add(Broadcast[Account](2)) val txnBroadcast = b.add(Broadcast[Transaction](2)) val merge = b.add(Merge[Transaction](2)) val accounts = Flow[String].map(queryAccount(_, AccountRepository)) val bankingTxns = Flow[Account].mapConcat(getBankingTransactions) val settlementTxns = Flow[Account].mapConcat(getSettlementTransactions) val validation = Flow[Transaction].map(validate) accountNos ~> accounts ~> accountBroadcast ~> bankingTxns ~> merge ~> validation ~> txnBroadcast ~> ns accountBroadcast ~> settlementTxns ~> merge txnBroadcast ~> audit } Tuesday, 6 October 15