SlideShare ist ein Scribd-Unternehmen logo
1 von 45
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!❤️!❤️!

Weitere ähnliche Inhalte

Was ist angesagt?

Making the business case for DevOps
Making the business case for DevOpsMaking the business case for DevOps
Making the business case for DevOpsMartin Croker
 
Netflix in the Cloud at SV Forum
Netflix in the Cloud at SV ForumNetflix in the Cloud at SV Forum
Netflix in the Cloud at SV ForumAdrian Cockcroft
 
DevOps for Databricks
DevOps for DatabricksDevOps for Databricks
DevOps for DatabricksDatabricks
 
Learn to Use Databricks for Data Science
Learn to Use Databricks for Data ScienceLearn to Use Databricks for Data Science
Learn to Use Databricks for Data ScienceDatabricks
 
Introduction to Azure Databricks
Introduction to Azure DatabricksIntroduction to Azure Databricks
Introduction to Azure DatabricksJames Serra
 
Getting Started with Architecture Decision Records
Getting Started with Architecture Decision RecordsGetting Started with Architecture Decision Records
Getting Started with Architecture Decision RecordsMichael Keeling
 
Data analytics introduction
Data analytics introductionData analytics introduction
Data analytics introductionamiyadash
 
97 Things Every Cloud Engineer Should Know.pdf
97 Things Every Cloud Engineer Should Know.pdf97 Things Every Cloud Engineer Should Know.pdf
97 Things Every Cloud Engineer Should Know.pdfمنیزہ ہاشمی
 
MLOps Virtual Event: Automating ML at Scale
MLOps Virtual Event: Automating ML at ScaleMLOps Virtual Event: Automating ML at Scale
MLOps Virtual Event: Automating ML at ScaleDatabricks
 
.conf Go 2022 - Observability Session
.conf Go 2022 - Observability Session.conf Go 2022 - Observability Session
.conf Go 2022 - Observability SessionSplunk
 
Next Generation Data Integration with Azure Data Factory
Next Generation Data Integration with Azure Data FactoryNext Generation Data Integration with Azure Data Factory
Next Generation Data Integration with Azure Data FactoryTom Kerkhove
 
Freddie Mac & KPMG Case Study – Advanced Machine Learning Data Integration wi...
Freddie Mac & KPMG Case Study – Advanced Machine Learning Data Integration wi...Freddie Mac & KPMG Case Study – Advanced Machine Learning Data Integration wi...
Freddie Mac & KPMG Case Study – Advanced Machine Learning Data Integration wi...DataWorks Summit
 
Compassionate (Yet Candid) Code Reviews
Compassionate (Yet Candid) Code ReviewsCompassionate (Yet Candid) Code Reviews
Compassionate (Yet Candid) Code ReviewsApril Wensel
 
Achieve Extreme Simplicity and Superior Price/Performance with Greenplum Buil...
Achieve Extreme Simplicity and Superior Price/Performance with Greenplum Buil...Achieve Extreme Simplicity and Superior Price/Performance with Greenplum Buil...
Achieve Extreme Simplicity and Superior Price/Performance with Greenplum Buil...VMware Tanzu
 
Data Quality Patterns in the Cloud with Azure Data Factory
Data Quality Patterns in the Cloud with Azure Data FactoryData Quality Patterns in the Cloud with Azure Data Factory
Data Quality Patterns in the Cloud with Azure Data FactoryMark Kromer
 
Getting started with Site Reliability Engineering (SRE)
Getting started with Site Reliability Engineering (SRE)Getting started with Site Reliability Engineering (SRE)
Getting started with Site Reliability Engineering (SRE)Abeer R
 
Data and AI summit: data pipelines observability with open lineage
Data and AI summit: data pipelines observability with open lineageData and AI summit: data pipelines observability with open lineage
Data and AI summit: data pipelines observability with open lineageJulien Le Dem
 
DevSecOps Singapore introduction
DevSecOps Singapore introductionDevSecOps Singapore introduction
DevSecOps Singapore introductionStefan Streichsbier
 

Was ist angesagt? (20)

Making the business case for DevOps
Making the business case for DevOpsMaking the business case for DevOps
Making the business case for DevOps
 
Netflix in the Cloud at SV Forum
Netflix in the Cloud at SV ForumNetflix in the Cloud at SV Forum
Netflix in the Cloud at SV Forum
 
DevOps for Databricks
DevOps for DatabricksDevOps for Databricks
DevOps for Databricks
 
Learn to Use Databricks for Data Science
Learn to Use Databricks for Data ScienceLearn to Use Databricks for Data Science
Learn to Use Databricks for Data Science
 
Introduction to Azure Databricks
Introduction to Azure DatabricksIntroduction to Azure Databricks
Introduction to Azure Databricks
 
Getting Started with Architecture Decision Records
Getting Started with Architecture Decision RecordsGetting Started with Architecture Decision Records
Getting Started with Architecture Decision Records
 
Data analytics introduction
Data analytics introductionData analytics introduction
Data analytics introduction
 
97 Things Every Cloud Engineer Should Know.pdf
97 Things Every Cloud Engineer Should Know.pdf97 Things Every Cloud Engineer Should Know.pdf
97 Things Every Cloud Engineer Should Know.pdf
 
MLOps Virtual Event: Automating ML at Scale
MLOps Virtual Event: Automating ML at ScaleMLOps Virtual Event: Automating ML at Scale
MLOps Virtual Event: Automating ML at Scale
 
.conf Go 2022 - Observability Session
.conf Go 2022 - Observability Session.conf Go 2022 - Observability Session
.conf Go 2022 - Observability Session
 
Next Generation Data Integration with Azure Data Factory
Next Generation Data Integration with Azure Data FactoryNext Generation Data Integration with Azure Data Factory
Next Generation Data Integration with Azure Data Factory
 
Freddie Mac & KPMG Case Study – Advanced Machine Learning Data Integration wi...
Freddie Mac & KPMG Case Study – Advanced Machine Learning Data Integration wi...Freddie Mac & KPMG Case Study – Advanced Machine Learning Data Integration wi...
Freddie Mac & KPMG Case Study – Advanced Machine Learning Data Integration wi...
 
Compassionate (Yet Candid) Code Reviews
Compassionate (Yet Candid) Code ReviewsCompassionate (Yet Candid) Code Reviews
Compassionate (Yet Candid) Code Reviews
 
Achieve Extreme Simplicity and Superior Price/Performance with Greenplum Buil...
Achieve Extreme Simplicity and Superior Price/Performance with Greenplum Buil...Achieve Extreme Simplicity and Superior Price/Performance with Greenplum Buil...
Achieve Extreme Simplicity and Superior Price/Performance with Greenplum Buil...
 
DevSecOps
DevSecOpsDevSecOps
DevSecOps
 
Data Quality Patterns in the Cloud with Azure Data Factory
Data Quality Patterns in the Cloud with Azure Data FactoryData Quality Patterns in the Cloud with Azure Data Factory
Data Quality Patterns in the Cloud with Azure Data Factory
 
Getting started with Site Reliability Engineering (SRE)
Getting started with Site Reliability Engineering (SRE)Getting started with Site Reliability Engineering (SRE)
Getting started with Site Reliability Engineering (SRE)
 
Data and AI summit: data pipelines observability with open lineage
Data and AI summit: data pipelines observability with open lineageData and AI summit: data pipelines observability with open lineage
Data and AI summit: data pipelines observability with open lineage
 
DevSecOps Singapore introduction
DevSecOps Singapore introductionDevSecOps Singapore introduction
DevSecOps Singapore introduction
 
DevOps @ OpenShift Online
DevOps @ OpenShift OnlineDevOps @ OpenShift Online
DevOps @ OpenShift Online
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von Gianluca Padovani

Mehr von 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
 

Kürzlich hochgeladen

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Kürzlich hochgeladen (20)

Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

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

Hinweis der Redaktion

  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