SlideShare a Scribd company logo
DDD ❤️ Actor
Model and Actor
Model ❤️ Elixir
Everybody needs somebody to love
DDD ❤️ Actor ❤️ Elixir
GPad
Born to be a developer with an interest in distributed system.
I have developed with many languages like C++, C#, js and ruby. I had fallen in
love with functional programming, especially with elixir and erlang.
● Twitter: https://twitter.com/gpad619
● Github: https://github.com/gpad/
● Medium: https://medium.com/@gpad
CTO & founder of coders51
DDD ❤️ Actor ❤️ Elixir
Schedule
What is DDD?
What is Actor Model?
What is Elixir?
Why they love each other?
Examples
What is DDD?
DDD ❤️ Actor ❤️ Elixir
What is DDD?
From wikipedia:
Domain-driven design (DDD) is an approach to software development for
complex needs by connecting the implementation to an evolving model.
The premise of domain-driven design is the following:
● placing the project's primary focus on the core domain and domain logic;
● basing complex designs on a model of the domain;
● initiating a creative collaboration between technical and domain experts
to iteratively refine a conceptual model that addresses particular domain
problems.
DDD ❤️ Actor ❤️ Elixir
Aggregate
Commands & Events
Process Manager/Policy
Read Model
What is DDD? - Building Blocks
DDD ❤️ Actor ❤️ Elixir
Aggregate
A collection of objects that are bound together by a root entity, otherwise
known as an aggregate root. The aggregate root guarantees the consistency
of changes being made within the aggregate by forbidding external objects
from holding references to its members.
Change State
Keep transaction consistency
Transaction boundary
DDD ❤️ Actor ❤️ Elixir
Commands
Actions that can be executed on an Aggregate.
They can fail and they produce a result.
They often (always ?!?) produce an event.
The Aggregate emits events.
DDD ❤️ Actor ❤️ Elixir
Events
Data emitted by Aggregate when it changes state.
It’s something that has already happened.
They can only be listened.
Who does listen the events?
DDD ❤️ Actor ❤️ Elixir
Process Manager (Policy)
The Process Manager listens the events and decide what to do.
It’s often where the logic resides.
It generates commands on Aggregate using its internal “policy”.
DDD ❤️ Actor ❤️ Elixir
Read Model
Projection of data that can be used to read data.
It listens the events and decide to build a projection of different events.
It can be always rebuild using the passed events.
It’s a projection!!!
DDD ❤️ Actor ❤️ Elixir
DDD - Recap
We model our domain using Aggregate that change state in a “transactional
way”.
We use the “command” to change the state of the aggregate in a transactional
way.
When the Aggregate changes the state it emits one or more events.
The read models listen the events and build some projections to return data
to the user.
The policies listen the events to take some decisions and “do something”.
What is the Elephant in the room?
Concurrency
DDD ❤️ Actor ❤️ Elixir
Concurrency
A lot of commands received, often by the same aggregate.
A lot of events emitted and processed.
A lot of events listened by read models and policies.
Events, commands (messages?!?) …
DDD ❤️ Actor ❤️ Elixir
Concurrency
A lot of messages (events, commands) received and emitted concurrently by
the same aggregate.
Can we use threads?
What is Actor Model?
DDD ❤️ Actor ❤️ Elixir
What is Actor Model?
From wikipedia:
The actor model in computer science is a mathematical model of concurrent
computation that treats "actors" as the universal primitives of concurrent
computation.
In response to a message that it receives, an actor can: make local decisions,
create more actors, send more messages, and determine how to respond to the
next message received.
Actors may modify their own private state, but can only affect each other indirectly
through messaging (obviating lock-based synchronization).
DDD ❤️ Actor ❤️ Elixir
What is Actor Model?
An actor is a computational entity that, in response to a message it receives,
can concurrently:
● send a finite number of messages to other actors;
● create a finite number of new actors;
● designate the behavior to be used for the next message it receives.
DDD ❤️ Actor ❤️ Elixir
What is Actor Model?
Always from wikipedia:
What is Elixir?
DDD ❤️ Actor ❤️ Elixir
What is Elixir
From wikipedia:
Elixir is a functional, concurrent, general-purpose programming language that
runs on the Erlang virtual machine (BEAM).
Elixir builds on top of Erlang and shares the same abstractions for building
distributed, fault-tolerant applications.
Elixir also provides productive tooling and an extensible design. The latter is
supported by compile-time metaprogramming with macros and polymorphism
via protocols.
DDD ❤️ Actor ❤️ Elixir
What is Elixir
It’s a young language.
It works, very well!❤️!❤️!
It’s based on a old language.
DDD ❤️ Actor ❤️ Elixir
Who is using Elixir?
From wikipedia:
Elixir is used by companies such as PagerDuty, Discord, E-MetroTel, Pinterest,
Moz, Bleacher Report, The Outline, Inverse and Divvy, and for building
embedded systems.
But wait ...
DDD ❤️ Actor ❤️ Elixir
Who is using Elixir?
Elixir ❤️ Erlang, Who is using erlang?
WhatsApp, T-Mobile, Motorola, Ericsson, Cisco, ...
RabbitMQ, Ejabberd, Riak, CouchDB …
It’s used when stopping is not an option ...
DDD ❤️ Actor ❤️ Elixir
What is Elixir?
From https://elixir-lang.org/:
Elixir is a dynamic, functional language designed for building scalable and
maintainable applications.
Elixir leverages the Erlang VM, known for running low-latency, distributed and
fault-tolerant systems, while also being successfully used in web development and
the embedded software domain.
DDD ❤️ Actor ❤️ Elixir
What is Elixir?
Dynamic → We can’t declare new types
Functional Language → Immutable (rebinding…)
Has a lot of nice features like:
● Pattern Matching
● |>
● Metaprogramming
● Debugging
● ...
Example!!!
DDD ❤️ Actor ❤️ Elixir
Is Elixir/Erlang an implementation of Actor Model?
From erlang mailing list:
Erlang does *not* implement Actors but processes with links/monitors mailboxes
and messages, which are not equivalent to actors.
Processes: sequence of function calls interspersed with (selective) receives that pick
out something out of the mailbox.
Actor: has to handle every message immediately, the actions a message triggers
are happening concurrently, nothing longer running or sequential allowed.
DDD ❤️ Actor ❤️ Elixir
Is Elixir/Erlang an implementation of Actor Model?
Hewitt says himself that Erlang does not implement Actors:
Erlang imposes the overhead that messages sent between two Erlang Actors
are delivered in the order they are sent.
Instead of using exception handling, Erlang Actors rely on process failure
propagating between processes and their spawned processes.
Instead of using garbage collection to recover storage and processing of
unreachable Actors, each Erlang Actor must perform an internal termination or
be killed. However, data structures within a process are garbage collected
DDD ❤️ Actor ❤️ Elixir
Is Elixir/Erlang an implementation of Actor Model?
Robert Virding wrote:
We had never heard of the actor model, at least I hadn't. We had other inputs,
amongst others Eripascal which an internal Ericsson version of Pascal which had
processes and messages.
…
And of course OSes which embody a lot of the ideas we were after, but in such a
way that they were/are way to heavy for what we were after. In many ways an
Erlang system does have an OS feeling about it.
DDD ❤️ Actor ❤️ Elixir
Is Elixir/Erlang an implementation of Actor Model?
Robert Virding wrote:
We were trying to solve THE problem and this was the best solution we could come
with. It was purely pragmatic. We definitely took ideas from other inputs but not
from the Actor model.
DDD ❤️ Actor ❤️ Elixir
Is Elixir/Erlang an implementation of Actor Model?
Joe Armstrong wrote:
Q: What sources DID you draw from (other than the predecessor languages at
Ericsson), are there any that you'd consider primary influences?
A: Prolog and Smalltalk in equal measure. Pattern matching and syntax was
inspired by Prolog. Messaging from Smalltalk. We took a few ideas on guarded
commands from Dijkstra.
The message queues were largely inspired by SDL and occam (SDL has a graphic
notation very similar to selective receive) Links were invented by Mike Williams and
based on the idea of a C-wire (a form of electrical circuit breaker).
DDD ❤️ Actor ❤️ Elixir
Is Elixir/Erlang an implementation of Actor Model?
Joe Armstrong wrote:
It's funny that the "sending message to an object" way of describing Java and
Smalltalk, Objective-C, C++ etc. objects has persisted despite the fact that this is
manifestly not what happens (which is a function call).
In Erlang we really do send a message to an object (well a process actually) - so
Erlang is probably the only OO language there is :-)
DDD ❤️ Actor ❤️ Elixir
What is Actor Model? - Recap
An actor is a computational entity that, in response to a message it receives,
can concurrently:
● send a finite number of messages to other actors;
● create a finite number of new actors;
● designate the behavior to be used for the next message it receives.
DDD ❤️ Actor ❤️ Elixir
What is Actor Model? - Recap
Erlang is not a formal implementation of the Actor model.
Probably it’s something similar (better??).
Probably it’s the best OO language out there.
Probably it’s the best language out there.
❤️
DDD ❤️ Actor ❤️ Elixir
DDD ❤️ Actor ❤️ Elixir
DDD ❤️ Actor ❤️ Elixir
Aggregate
Commands/Events
Policy
Read Model
Process (GenServer)
FP → Message
Process (GenStateMachine)
Process (GenServer/GenStateMachine)
Example
WARNING!!!
DDD ❤️ Actor ❤️ Elixir
WARNING!!!
This is an example!!!!
It’s a “dumb” solution!!!
Don’t copy & paste this code!!!
DDD ❤️ Actor ❤️ Elixir
Recap
Elixir fits very well with the DDD concepts.
Elixir give you the ability to focus on your problems.
You don’t need to think about lock/mutex etc …
It’s Fun and Full of Love.
DDD ❤️ Actor ❤️ Elixir
References
DDD, CQRS/ES (google is your friend), vlingo
Actor Models
Erlang mailing list
Elixir language, Elixir book, Erlang book, More advanced
Example
End - Thanks!❤️!❤️!

More Related Content

What's hot

Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton PatternMudasir Qazi
 
老派浪漫:用 Kotlin 寫 Command Line 工具
老派浪漫:用 Kotlin 寫 Command Line 工具老派浪漫:用 Kotlin 寫 Command Line 工具
老派浪漫:用 Kotlin 寫 Command Line 工具Shengyou Fan
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonJonathan Simon
 
18CSMP68 VTU Mobile Application Develeopment Lab Manual by Nithin, VVCE, Mysuru
18CSMP68 VTU Mobile Application Develeopment Lab Manual by Nithin, VVCE, Mysuru18CSMP68 VTU Mobile Application Develeopment Lab Manual by Nithin, VVCE, Mysuru
18CSMP68 VTU Mobile Application Develeopment Lab Manual by Nithin, VVCE, MysuruNithin Kumar,VVCE, Mysuru
 
z/OSMF Workflow Editor Lab - Try it out on your z/OSMF system
z/OSMF Workflow Editor Lab - Try it out on your z/OSMF systemz/OSMF Workflow Editor Lab - Try it out on your z/OSMF system
z/OSMF Workflow Editor Lab - Try it out on your z/OSMF systemMarna Walle
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Patternsahilrk911
 
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Sameer Rathoud
 
[NHN NEXT] Java 강의 - Week1
[NHN NEXT] Java 강의 - Week1[NHN NEXT] Java 강의 - Week1
[NHN NEXT] Java 강의 - Week1Young-Ho Cho
 
DLL(dynamic link library)
DLL(dynamic link library)DLL(dynamic link library)
DLL(dynamic link library)pooja_doshi
 
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...Shengyou Fan
 
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?Kai Wähner
 
Как писать красивый код или основы SOLID
Как писать красивый код или основы SOLIDКак писать красивый код или основы SOLID
Как писать красивый код или основы SOLIDPavel Tsukanov
 
Capella Days 2021 | How I pack my suitcase
Capella Days 2021 | How I pack my suitcaseCapella Days 2021 | How I pack my suitcase
Capella Days 2021 | How I pack my suitcaseObeo
 

What's hot (20)

ADO.NET
ADO.NETADO.NET
ADO.NET
 
Design Pattern - Singleton Pattern
Design Pattern - Singleton PatternDesign Pattern - Singleton Pattern
Design Pattern - Singleton Pattern
 
老派浪漫:用 Kotlin 寫 Command Line 工具
老派浪漫:用 Kotlin 寫 Command Line 工具老派浪漫:用 Kotlin 寫 Command Line 工具
老派浪漫:用 Kotlin 寫 Command Line 工具
 
Introduction to Design Patterns and Singleton
Introduction to Design Patterns and SingletonIntroduction to Design Patterns and Singleton
Introduction to Design Patterns and Singleton
 
18CSMP68 VTU Mobile Application Develeopment Lab Manual by Nithin, VVCE, Mysuru
18CSMP68 VTU Mobile Application Develeopment Lab Manual by Nithin, VVCE, Mysuru18CSMP68 VTU Mobile Application Develeopment Lab Manual by Nithin, VVCE, Mysuru
18CSMP68 VTU Mobile Application Develeopment Lab Manual by Nithin, VVCE, Mysuru
 
z/OSMF Workflow Editor Lab - Try it out on your z/OSMF system
z/OSMF Workflow Editor Lab - Try it out on your z/OSMF systemz/OSMF Workflow Editor Lab - Try it out on your z/OSMF system
z/OSMF Workflow Editor Lab - Try it out on your z/OSMF system
 
Bridge Design Pattern
Bridge Design PatternBridge Design Pattern
Bridge Design Pattern
 
Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)Singleton Pattern (Sole Object with Global Access)
Singleton Pattern (Sole Object with Global Access)
 
Chapter 13
Chapter 13Chapter 13
Chapter 13
 
[NHN NEXT] Java 강의 - Week1
[NHN NEXT] Java 강의 - Week1[NHN NEXT] Java 강의 - Week1
[NHN NEXT] Java 강의 - Week1
 
Spring AOP
Spring AOPSpring AOP
Spring AOP
 
Context diagram
Context diagramContext diagram
Context diagram
 
DLL(dynamic link library)
DLL(dynamic link library)DLL(dynamic link library)
DLL(dynamic link library)
 
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
[JCConf 2023] 從 Kotlin Multiplatform 到 Compose Multiplatform:在多平台間輕鬆共用業務邏輯與 U...
 
Recyclerview in action
Recyclerview in action Recyclerview in action
Recyclerview in action
 
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
Spoilt for Choice: How to Choose the Right Enterprise Service Bus (ESB)?
 
UML
UMLUML
UML
 
Как писать красивый код или основы SOLID
Как писать красивый код или основы SOLIDКак писать красивый код или основы SOLID
Как писать красивый код или основы SOLID
 
Capella Days 2021 | How I pack my suitcase
Capella Days 2021 | How I pack my suitcaseCapella Days 2021 | How I pack my suitcase
Capella Days 2021 | How I pack my suitcase
 
Implementation Model
Implementation ModelImplementation Model
Implementation Model
 

Similar to DDD loves Actor Model and Actor Model loves Elixir

Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016Codemotion
 
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Codemotion
 
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...Codemotion
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholisticoscon2007
 
Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Yauheni Akhotnikau
 
The Holistic Programmer
The Holistic ProgrammerThe Holistic Programmer
The Holistic ProgrammerAdam Keys
 
Actors, Fault tolerance and OTP
Actors, Fault tolerance and OTPActors, Fault tolerance and OTP
Actors, Fault tolerance and OTPDhananjay Nene
 
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023Pedro Vicente
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebPublitory
 
What is the deal with Elixir?
What is the deal with Elixir?What is the deal with Elixir?
What is the deal with Elixir?George Coffey
 
Object-Oriented Concepts
Object-Oriented ConceptsObject-Oriented Concepts
Object-Oriented ConceptsAbdalla Mahmoud
 
Cs8392 u1-1-oop intro
Cs8392 u1-1-oop introCs8392 u1-1-oop intro
Cs8392 u1-1-oop introRajasekaran S
 
How does intellisense work?
How does intellisense work?How does intellisense work?
How does intellisense work?Adam Friedman
 
Concurrent Applications with F# Agents
Concurrent Applications with F# AgentsConcurrent Applications with F# Agents
Concurrent Applications with F# AgentsRachel Reese
 
Developing Actors in Azure with .net
Developing Actors in Azure with .netDeveloping Actors in Azure with .net
Developing Actors in Azure with .netMarco Parenzan
 

Similar to DDD loves Actor Model and Actor Model loves Elixir (20)

Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
Un actor (model) per amico - Alessandro Melchiori - Codemotion Milan 2016
 
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
Beyond JavaScript Frameworks: Writing Reliable Web Apps With Elm - Erik Wende...
 
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
Erik Wendel - Beyond JavaScript Frameworks: Writing Reliable Web Apps With El...
 
Actor Model & Reactive Manifesto
Actor Model & Reactive ManifestoActor Model & Reactive Manifesto
Actor Model & Reactive Manifesto
 
Erlang, an overview
Erlang, an overviewErlang, an overview
Erlang, an overview
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
 
Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?Actor Model and C++: what, why and how?
Actor Model and C++: what, why and how?
 
The Holistic Programmer
The Holistic ProgrammerThe Holistic Programmer
The Holistic Programmer
 
Actors, Fault tolerance and OTP
Actors, Fault tolerance and OTPActors, Fault tolerance and OTP
Actors, Fault tolerance and OTP
 
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
A Multiplatform, Multi-Tenant Challenge - Droidcon Lisbon 2023
 
Elm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and WebElm & Elixir: Functional Programming and Web
Elm & Elixir: Functional Programming and Web
 
Introdução à Elixir
Introdução à ElixirIntrodução à Elixir
Introdução à Elixir
 
Java 3 rd sem. 2012 aug.ASSIGNMENT
Java 3 rd sem. 2012 aug.ASSIGNMENTJava 3 rd sem. 2012 aug.ASSIGNMENT
Java 3 rd sem. 2012 aug.ASSIGNMENT
 
What is the deal with Elixir?
What is the deal with Elixir?What is the deal with Elixir?
What is the deal with Elixir?
 
Object-Oriented Concepts
Object-Oriented ConceptsObject-Oriented Concepts
Object-Oriented Concepts
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Cs8392 u1-1-oop intro
Cs8392 u1-1-oop introCs8392 u1-1-oop intro
Cs8392 u1-1-oop intro
 
How does intellisense work?
How does intellisense work?How does intellisense work?
How does intellisense work?
 
Concurrent Applications with F# Agents
Concurrent Applications with F# AgentsConcurrent Applications with F# Agents
Concurrent Applications with F# Agents
 
Developing Actors in Azure with .net
Developing Actors in Azure with .netDeveloping Actors in Azure with .net
Developing Actors in Azure with .net
 

More from Gianluca Padovani

More from Gianluca Padovani (16)

A Gentle introduction to microservices
A Gentle introduction to microservicesA Gentle introduction to microservices
A Gentle introduction to microservices
 
Beam me up, scotty (PUG Roma)
Beam me up, scotty (PUG Roma)Beam me up, scotty (PUG Roma)
Beam me up, scotty (PUG Roma)
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Tdd is not about testing
Tdd is not about testingTdd is not about testing
Tdd is not about testing
 
From a web application to a distributed system
From a web application to a distributed systemFrom a web application to a distributed system
From a web application to a distributed system
 
Beam way of life
Beam way of lifeBeam way of life
Beam way of life
 
Cook your KV
Cook your KVCook your KV
Cook your KV
 
System integration through queues
System integration through queuesSystem integration through queues
System integration through queues
 
Beam me up, Scotty
Beam me up, ScottyBeam me up, Scotty
Beam me up, Scotty
 
Docker e git lab
Docker e git labDocker e git lab
Docker e git lab
 
La mia prima lezione di pozioni
La mia prima lezione di pozioniLa mia prima lezione di pozioni
La mia prima lezione di pozioni
 
Keynote meetup Elixir/Erlang 17 ottobre 2015
Keynote meetup Elixir/Erlang 17 ottobre 2015Keynote meetup Elixir/Erlang 17 ottobre 2015
Keynote meetup Elixir/Erlang 17 ottobre 2015
 
C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...C++ Actor Model - You’ve Got Mail ...
C++ Actor Model - You’ve Got Mail ...
 
Ferrara Linux Day 2011
Ferrara Linux Day 2011Ferrara Linux Day 2011
Ferrara Linux Day 2011
 
OOP vs COP
OOP vs COPOOP vs COP
OOP vs COP
 

Recently uploaded

Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Tobias Schneck
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀DianaGray10
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaCzechDreamin
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka DoktorováCzechDreamin
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2DianaGray10
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...Product School
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxAbida Shariff
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsExpeed Software
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...CzechDreamin
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Product School
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor TurskyiFwdays
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualityInflectra
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Thierry Lestable
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomCzechDreamin
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backElena Simperl
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesThousandEyes
 

Recently uploaded (20)

Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
Exploring UiPath Orchestrator API: updates and limits in 2024 🚀
 
Powerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara LaskowskaPowerful Start- the Key to Project Success, Barbara Laskowska
Powerful Start- the Key to Project Success, Barbara Laskowska
 
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová10 Differences between Sales Cloud and CPQ, Blanka Doktorová
10 Differences between Sales Cloud and CPQ, Blanka Doktorová
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2UiPath Test Automation using UiPath Test Suite series, part 2
UiPath Test Automation using UiPath Test Suite series, part 2
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
In-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT ProfessionalsIn-Depth Performance Testing Guide for IT Professionals
In-Depth Performance Testing Guide for IT Professionals
 
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
Integrating Telephony Systems with Salesforce: Insights and Considerations, B...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 

DDD loves Actor Model and Actor Model loves Elixir

  • 1. DDD ❤️ Actor Model and Actor Model ❤️ Elixir Everybody needs somebody to love
  • 2. DDD ❤️ Actor ❤️ Elixir GPad Born to be a developer with an interest in distributed system. I have developed with many languages like C++, C#, js and ruby. I had fallen in love with functional programming, especially with elixir and erlang. ● Twitter: https://twitter.com/gpad619 ● Github: https://github.com/gpad/ ● Medium: https://medium.com/@gpad CTO & founder of coders51
  • 3. DDD ❤️ Actor ❤️ Elixir Schedule What is DDD? What is Actor Model? What is Elixir? Why they love each other? Examples
  • 5. DDD ❤️ Actor ❤️ Elixir What is DDD? From wikipedia: Domain-driven design (DDD) is an approach to software development for complex needs by connecting the implementation to an evolving model. The premise of domain-driven design is the following: ● placing the project's primary focus on the core domain and domain logic; ● basing complex designs on a model of the domain; ● initiating a creative collaboration between technical and domain experts to iteratively refine a conceptual model that addresses particular domain problems.
  • 6. DDD ❤️ Actor ❤️ Elixir Aggregate Commands & Events Process Manager/Policy Read Model What is DDD? - Building Blocks
  • 7. DDD ❤️ Actor ❤️ Elixir Aggregate A collection of objects that are bound together by a root entity, otherwise known as an aggregate root. The aggregate root guarantees the consistency of changes being made within the aggregate by forbidding external objects from holding references to its members. Change State Keep transaction consistency Transaction boundary
  • 8. DDD ❤️ Actor ❤️ Elixir Commands Actions that can be executed on an Aggregate. They can fail and they produce a result. They often (always ?!?) produce an event. The Aggregate emits events.
  • 9. DDD ❤️ Actor ❤️ Elixir Events Data emitted by Aggregate when it changes state. It’s something that has already happened. They can only be listened. Who does listen the events?
  • 10. DDD ❤️ Actor ❤️ Elixir Process Manager (Policy) The Process Manager listens the events and decide what to do. It’s often where the logic resides. It generates commands on Aggregate using its internal “policy”.
  • 11. DDD ❤️ Actor ❤️ Elixir Read Model Projection of data that can be used to read data. It listens the events and decide to build a projection of different events. It can be always rebuild using the passed events. It’s a projection!!!
  • 12. DDD ❤️ Actor ❤️ Elixir DDD - Recap We model our domain using Aggregate that change state in a “transactional way”. We use the “command” to change the state of the aggregate in a transactional way. When the Aggregate changes the state it emits one or more events. The read models listen the events and build some projections to return data to the user. The policies listen the events to take some decisions and “do something”.
  • 13. What is the Elephant in the room?
  • 15. DDD ❤️ Actor ❤️ Elixir Concurrency A lot of commands received, often by the same aggregate. A lot of events emitted and processed. A lot of events listened by read models and policies. Events, commands (messages?!?) …
  • 16. DDD ❤️ Actor ❤️ Elixir Concurrency A lot of messages (events, commands) received and emitted concurrently by the same aggregate. Can we use threads?
  • 17. What is Actor Model?
  • 18. DDD ❤️ Actor ❤️ Elixir What is Actor Model? From wikipedia: The actor model in computer science is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent computation. In response to a message that it receives, an actor can: make local decisions, create more actors, send more messages, and determine how to respond to the next message received. Actors may modify their own private state, but can only affect each other indirectly through messaging (obviating lock-based synchronization).
  • 19. DDD ❤️ Actor ❤️ Elixir What is Actor Model? An actor is a computational entity that, in response to a message it receives, can concurrently: ● send a finite number of messages to other actors; ● create a finite number of new actors; ● designate the behavior to be used for the next message it receives.
  • 20. DDD ❤️ Actor ❤️ Elixir What is Actor Model? Always from wikipedia:
  • 22. DDD ❤️ Actor ❤️ Elixir What is Elixir From wikipedia: Elixir is a functional, concurrent, general-purpose programming language that runs on the Erlang virtual machine (BEAM). Elixir builds on top of Erlang and shares the same abstractions for building distributed, fault-tolerant applications. Elixir also provides productive tooling and an extensible design. The latter is supported by compile-time metaprogramming with macros and polymorphism via protocols.
  • 23. DDD ❤️ Actor ❤️ Elixir What is Elixir It’s a young language. It works, very well!❤️!❤️! It’s based on a old language.
  • 24. DDD ❤️ Actor ❤️ Elixir Who is using Elixir? From wikipedia: Elixir is used by companies such as PagerDuty, Discord, E-MetroTel, Pinterest, Moz, Bleacher Report, The Outline, Inverse and Divvy, and for building embedded systems. But wait ...
  • 25. DDD ❤️ Actor ❤️ Elixir Who is using Elixir? Elixir ❤️ Erlang, Who is using erlang? WhatsApp, T-Mobile, Motorola, Ericsson, Cisco, ... RabbitMQ, Ejabberd, Riak, CouchDB … It’s used when stopping is not an option ...
  • 26. DDD ❤️ Actor ❤️ Elixir What is Elixir? From https://elixir-lang.org/: Elixir is a dynamic, functional language designed for building scalable and maintainable applications. Elixir leverages the Erlang VM, known for running low-latency, distributed and fault-tolerant systems, while also being successfully used in web development and the embedded software domain.
  • 27. DDD ❤️ Actor ❤️ Elixir What is Elixir? Dynamic → We can’t declare new types Functional Language → Immutable (rebinding…) Has a lot of nice features like: ● Pattern Matching ● |> ● Metaprogramming ● Debugging ● ...
  • 29. DDD ❤️ Actor ❤️ Elixir Is Elixir/Erlang an implementation of Actor Model? From erlang mailing list: Erlang does *not* implement Actors but processes with links/monitors mailboxes and messages, which are not equivalent to actors. Processes: sequence of function calls interspersed with (selective) receives that pick out something out of the mailbox. Actor: has to handle every message immediately, the actions a message triggers are happening concurrently, nothing longer running or sequential allowed.
  • 30. DDD ❤️ Actor ❤️ Elixir Is Elixir/Erlang an implementation of Actor Model? Hewitt says himself that Erlang does not implement Actors: Erlang imposes the overhead that messages sent between two Erlang Actors are delivered in the order they are sent. Instead of using exception handling, Erlang Actors rely on process failure propagating between processes and their spawned processes. Instead of using garbage collection to recover storage and processing of unreachable Actors, each Erlang Actor must perform an internal termination or be killed. However, data structures within a process are garbage collected
  • 31. DDD ❤️ Actor ❤️ Elixir Is Elixir/Erlang an implementation of Actor Model? Robert Virding wrote: We had never heard of the actor model, at least I hadn't. We had other inputs, amongst others Eripascal which an internal Ericsson version of Pascal which had processes and messages. … And of course OSes which embody a lot of the ideas we were after, but in such a way that they were/are way to heavy for what we were after. In many ways an Erlang system does have an OS feeling about it.
  • 32. DDD ❤️ Actor ❤️ Elixir Is Elixir/Erlang an implementation of Actor Model? Robert Virding wrote: We were trying to solve THE problem and this was the best solution we could come with. It was purely pragmatic. We definitely took ideas from other inputs but not from the Actor model.
  • 33. DDD ❤️ Actor ❤️ Elixir Is Elixir/Erlang an implementation of Actor Model? Joe Armstrong wrote: Q: What sources DID you draw from (other than the predecessor languages at Ericsson), are there any that you'd consider primary influences? A: Prolog and Smalltalk in equal measure. Pattern matching and syntax was inspired by Prolog. Messaging from Smalltalk. We took a few ideas on guarded commands from Dijkstra. The message queues were largely inspired by SDL and occam (SDL has a graphic notation very similar to selective receive) Links were invented by Mike Williams and based on the idea of a C-wire (a form of electrical circuit breaker).
  • 34. DDD ❤️ Actor ❤️ Elixir Is Elixir/Erlang an implementation of Actor Model? Joe Armstrong wrote: It's funny that the "sending message to an object" way of describing Java and Smalltalk, Objective-C, C++ etc. objects has persisted despite the fact that this is manifestly not what happens (which is a function call). In Erlang we really do send a message to an object (well a process actually) - so Erlang is probably the only OO language there is :-)
  • 35. DDD ❤️ Actor ❤️ Elixir What is Actor Model? - Recap An actor is a computational entity that, in response to a message it receives, can concurrently: ● send a finite number of messages to other actors; ● create a finite number of new actors; ● designate the behavior to be used for the next message it receives.
  • 36. DDD ❤️ Actor ❤️ Elixir What is Actor Model? - Recap Erlang is not a formal implementation of the Actor model. Probably it’s something similar (better??). Probably it’s the best OO language out there. Probably it’s the best language out there. ❤️
  • 37. DDD ❤️ Actor ❤️ Elixir
  • 38. DDD ❤️ Actor ❤️ Elixir DDD ❤️ Actor ❤️ Elixir Aggregate Commands/Events Policy Read Model Process (GenServer) FP → Message Process (GenStateMachine) Process (GenServer/GenStateMachine)
  • 41. DDD ❤️ Actor ❤️ Elixir WARNING!!! This is an example!!!! It’s a “dumb” solution!!! Don’t copy & paste this code!!!
  • 42.
  • 43. DDD ❤️ Actor ❤️ Elixir Recap Elixir fits very well with the DDD concepts. Elixir give you the ability to focus on your problems. You don’t need to think about lock/mutex etc … It’s Fun and Full of Love.
  • 44. DDD ❤️ Actor ❤️ Elixir References DDD, CQRS/ES (google is your friend), vlingo Actor Models Erlang mailing list Elixir language, Elixir book, Erlang book, More advanced Example

Editor's Notes

  1. Open Atom on the project for 2 example files Open Atom on lib for the code that we have to show Open Console on the example
  2. Show a little of example in the shell