by Oleg Nizhnikov from Evolution gaming
by Oleg Nizhnikov from Evolution gaming
by Oleg Nizhnikov from Evolution gaming
System Design
taken from microservices.io/patterns/microservices
Modules
Business processes
Industry
Electical circuits
Box
Box
Input
Output
Morphism
Domain
Codomain
Category
Box
Input
Output
Monoidal Category
Box A
Input A
Output A
Horizontal Composition
Box B
Output B
Input B
Box A
Input A
Horizontal Composition
Box B
Output B
Wiring
Box B•A
Box A
Input A
Output A
Vertical Composition
Box B
Output B
Input B
Box A
Vertical Composition
Box B
Box A ⊗ B
id-Box
Identity
Braiding \ Symmetry
Box B
X-box
Box A
General Composition
Box B
Box A % B
Box A
General Composition
Box B
Directed Acyclic Graph
A
B
C
D
E
Composed Graph
A
B
C
D
E
Box
Input
Output
Injections
Box A
Green Input
Injections
Orange Input
Purple Output
Cian Output
Green Output
Box A
Green Input
Monoidal Functor
Orange Input
Purple Output
Cian Output
Green Output
Box F(A)
F(Green)
F(Orange)
F(Purple)
F(Cian)
F(Green)
Box A
Composition Preservation
Box B
Box F(A)
Box F(B)
Box A
Composition Preservation
Box B
Box F(B) • F(A)
Box A
Composition Preservation
Box B
Box F(B • A)
Composition Preservation
Box F(Id)
Composition Preservation
Box Id
Symmetry Preservation
Box B
F(X)-Box
Symmetry Preservation
Box B
X-Box
Vertical Composition Preservation
Box A
Box B
F(A) ⊗ F(B)
Vertical Composition Preservation
Box A
Box B
F(A ⊗ B)
General composition preservation
A
B
C
D
E
General composition preservation
A
B
C
D
E
Box A
Between Functors
Box B
F(A)
G(B)
Box A
Natural link Between Functors
Box B
F(A)
G(B)
ζ: F ⟶ G
Box A
Natural link Between Functors
Box B
F(B • A)
G(id)
ζ: F ⟶ G
Box A
Natural link Between Functors
Box B
F(A)
G(B)
ζ: F ⟶ G
Box A
Natural link Between Functors
Box B
F(id)
G(B • A)
ζ: F ⟶ G
Box A
Natural link Between Functors
Box B
F(A)
G(B)
ζ: F ⟶ G
Example
Universe 1:
Scala Functions and Serializable Types
Example
Universe 2:
Microservices
Universe 1:
Scala Functions and Serializable Types
Example
Universe 2:
Microservices
Deploy
as
JSON
REST
service
Universe 1:
Scala Functions and Serializable Types
Example
Universe 2:
Microservices
Deploy
as
JSON
REST
service
Deploy
as
Protobuf
batch
service
Universe 1:
Scala Functions and Serializable Types
Example
Deploy
as
JSON
REST
service
Deploy
as
Protobuf
batch
service
Poll JSON REST service
continiusly
collecting batches
Universe 2:
Microservices
Universe 1:
Scala Functions and Serializable Types
Optic
To-Box
From-Box
in X
out X
out Y
in Y
Middle State M
Optic horizontal composition
To-Box A
From-Box A
in X
out X
out Y
in Y
Middle State M
To-Box B
From-Box B
in Y
out Y
out Z
in Z
Middle State N
Optic horizontal composition
To-Box A
From-Box A
in X
out X
Y
Middle State M
To-Box B
From-Box B
Y
out Z
in Z
Middle State N
Optic vertical composition
To-Box A
From-Box A
in X
out X
out Y
in Y
Middle State M
To-Box B
From-Box B
in U
out U
out V
in V
Middle State N
Optic vertical composition
To-Box A
From-Box A
in X
out X
out Y
in Y
Middle State M
To-Box B
From-Box B
in U
out U
out V
in V
Middle State N
Optic: example
Apply operation
Undo operation
request
source request
response
source response
Additional data
initial state
result state
initial state
result state
SAGA Optics
Create Order
Book items
Create payment method
Pay
Deliver
Validate address
Pack
Box A
Input X
Output Y
def A(x: X): Y
Box
in U
Monoidal Category
Box A
in V
out X
out Y
out Z
def A(u: U, v: V): (X, Y, Z)
in U
Monoidal Category
Box A
in V
def A(u: U, v: V): ()
Box A
General Composition
Box B
Box С
def C(s: S, t: T, u: U): (X, Y) =
val (x, v, w) = A(s, t)
val y = B(w, v, u)
return (x, y)
S
T
U
X
W
V
Y
General Composition
def paymentSaga(
orderData: OrderData,
paymentInfo: PayInfo,
address: Address
) : DeliveryFinished = {
val order = createOrder(orderData)
val booked = bookItems(order)
val payM = createPayMethod(paymentInfo)
val paidItems = pay(booked, payM)
val packedOrder = pack(paidItems)
val validAddress = validateAddress
deliver(packedOrder, validAddress)
}
Create Order
Book items
Create payment method
Pay
Deliver
Validate address
Pack