SlideShare a Scribd company logo
1 of 52
Download to read offline
Flowex - Flow-Based
Programming with
Elixir GenStage
Elixir Club 5, Kyiv, January 28, 2017
- Ruby developer at Matic Insurance
- Elixir fan
- Author and maintainer of
ESpec BDD test framework
github: antonmi
Hello!
I am Anton Mishchuk
2
The problem
◎ There are some problems in
“conventional programing”:
- code is procedural and sequential
- parallelism is not native
- hierarchical structure of program
- visualisation is more about structure
◎ We need alternative approaches for
building our programs to make software
better!
3
My previous FBP talk
4
http://www.slideshare.net/AntonMishchuk
/flowbased-programming-with-elixir
The goal of the talk
◎ Discuss a special case of Flow-Based
Programming: “Railway FBP” (R-FBP)
◎ Present Flowex library which helps to
create R-FBP abstractions
◎ Show that Elixir GenStage is not only about
data-processing but about software design
5
What will be about
◎ Flow-Based Programming (FBP)
◎ Railway Oriented Programming (ROP)
◎ Railway FBP
◎ Flowex library
Lots of pictures!
6
1.
Flow-Based
Programming
Basic concepts
7
“
FBP - a programming paradigm
that defines applications as
networks of "black box" processes,
which exchange data across
predefined connections by
message passing
J. Paul Morrison, Flow-Based Programming, 2nd Edition
8
FBP diagram
A
B
D
C
IN 1
IN 1
IN 1
IN 2
IN 1
IN 2
OUT 1
OUT 2
OUT 1
OUT 1
OUT 1
9
Express a problem in terms of
transforms on streams of data
http://www.jpaulmorrison.com/fbp/FBPnew.ppt
10
Design pros
◎ Independent and reusable components
◎ Clean interfaces
◎ Simple to reconfigure
◎ Minimizes side-effects
◎ Designer can sit at one “station”, or can
follow an item through system
http://www.jpaulmorrison.com/fbp/FBPnew.ppt
11
“Native parallelism”
12
2.
Railway Oriented
Programming
Design pattern
13
Express a problem in terms of
sequence of functions calls
request
|> validate_request
|> get_user
|> update_db_from_request
|> send_email
|> return_http_message
14
Define common interface for
successful and error cases
◎ For example use:
{:ok, "data"} or {:error, "Failure reason"}
◎ Each function returns {:ok, "data"} or
{:error, "Failure reason"}
◎ If function is called with {:error, "Failure
reason"} it just bypasses it
15
Define interface to bypass errors
http://fsharpforfunandprofit.com/rop/
16
So the program is a railway
from input to output
http://fsharpforfunandprofit.com/rop/
17
Elixir Plug is a good example!
◎ Each “plug” function receives and returns a
“connection structure” %Plug.Conn{}
◎ %Plug.Conn{} contains:
assigns, cookies, halted, host, method,
params, resp_body, resp_cookies, status,
and many other attributes
18
3.
Railway FBP
ROP + FBP
19
Let’s transform each part of
“Railway” into FBP component!
20
Place each function into separate process
validate send_emailupdate_db
That is the idea!
21
Why Elixir?
22
GenStage
◎ Easiest way to implement a chain of
communicating processes
◎ Back-pressure mechanism
producer consumer
Subscribe
Ask
Events
23
Metaprogramming
◎ Simple way for sharing functionality
◎ Ability to create expressive DSL
24
4.
Flowex
Railway FBP
25
Consider an example!
26
Calculate (number + 1) * 2 - 3
27
Note, the functions are cool!
◎ They have the same interface
◎ They operate with predefined struct
We can join them into pipeline:
28
Let’s add some Flowex magic!
29
… and rename the module to FunPipeline
30
“use Flowex.Pipeline”
◎ Adds ‘pipe’ macro which allows to mark
functions “to be placed” into separate
Genstage
◎ Defines ‘start’ and ‘stop’ functions for
creating and destroying “Flowex pipelines”
◎ Defines ‘run’ function to perform
calculations
31
Start FunPipeline!
32
FunPipeline instance
add_one minus_threemult_by_twoproducer consumer
Supervisor
Elixir GenStages
33
%Flowex.Pipeline{} struct
◎ module - the name of the module
◎ in_name - unique name of 'producer'
◎ out_name - unique name of 'consumer'
◎ sup_pid - pid of the pipeline supervisor
34
Run calculations via “run”
Using FunPipeline.run/2 function
Note, ‘a’, ‘b’ and ‘c’ were set!
35
Run calculations using Flowex.Client
Using Flowex.Client module
36
How it works in details
add_one
minus_three
mult_by_two
producer
consumer
Flowex.Client
%FunPipeline{number: 2}
%Flowex.IP{
struct: %FunPipeline{number: 2},
...}
number: 2
number: 2
number: 3
number: 6
number: 3
number: 3
self()
%FunPipeline{number: 3}
37
What is sync and what is async?
Client
Asynchronous
communicationself()
Synchronous
communication
38
Is there no parallelism?
39
There can be a lot of clients!
Client
Client
Client
40
Bottlenecks.
What if there is very slow
process in the pipeline?
41
Just small changes in the code
42
And you get this
add_one
minus_three
mult_by_twoproducer consumer
mult_by_two
minus_three
mult_by_two
43
Reusable components with
“module pipelines”
44
Module must implement just two functions
Like Elixir Plug module
45
Pipeline module
46
Conclusion
47
Why it is cool!
48
It is easy to understand
◎ Pipelines explicitly define a
structure of data will be processed
◎ Pipelines explicitly define a
way the data will come
◎ Pipelines explicitly define a
parallel executors structure
49
It is easy to maintain and reuse
◎ There is a predefined set of working
processes (components) in a program
◎ Each component is isolated
◎ Pipelines can (and should) reuse
components
50
It is about controlled parallelism
◎ One can controll number of clients
supplying data to a pipeline
◎ One can control the number of processes
available for each component
51
Thank you! Questions?
52
You can star the project here:
https://github.com/antonmi/flowex

More Related Content

What's hot

Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented ProgrammingScott Wlaschin
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++Jenish Patel
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Calvin Cheng
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++Learn By Watch
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programmingNico Ludwig
 
MVVM with Kotlin: Making iOS and Android apps as similar as possible
MVVM with Kotlin: Making iOS and Android apps as similar as possibleMVVM with Kotlin: Making iOS and Android apps as similar as possible
MVVM with Kotlin: Making iOS and Android apps as similar as possibleQuickBird Studios GmbH
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript FundamentalsSrdjan Strbanovic
 
Php Loop
Php LoopPhp Loop
Php Looplotlot
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping newaprilyyy
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.gerrell
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextUnfold UI
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and loopingChaAstillas
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New featuresSon Nguyen
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)aeden_brines
 

What's hot (20)

Railway Oriented Programming
Railway Oriented ProgrammingRailway Oriented Programming
Railway Oriented Programming
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)Functional Programming for OO Programmers (part 1)
Functional Programming for OO Programmers (part 1)
 
Inline function in C++
Inline function in C++Inline function in C++
Inline function in C++
 
Python component in mule
Python component in mulePython component in mule
Python component in mule
 
(3) cpp procedural programming
(3) cpp procedural programming(3) cpp procedural programming
(3) cpp procedural programming
 
MVVM with Kotlin: Making iOS and Android apps as similar as possible
MVVM with Kotlin: Making iOS and Android apps as similar as possibleMVVM with Kotlin: Making iOS and Android apps as similar as possible
MVVM with Kotlin: Making iOS and Android apps as similar as possible
 
My final requirement
My final requirementMy final requirement
My final requirement
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
 
Php Loop
Php LoopPhp Loop
Php Loop
 
Switch case and looping new
Switch case and looping newSwitch case and looping new
Switch case and looping new
 
Common Programming Errors
Common Programming ErrorsCommon Programming Errors
Common Programming Errors
 
Macasu, gerrell c.
Macasu, gerrell c.Macasu, gerrell c.
Macasu, gerrell c.
 
Switch case and looping jam
Switch case and looping jamSwitch case and looping jam
Switch case and looping jam
 
Client side scripting
Client side scriptingClient side scripting
Client side scripting
 
Functional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNextFunctional Programming in JavaScript & ESNext
Functional Programming in JavaScript & ESNext
 
Javascript
JavascriptJavascript
Javascript
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
Java 8 New features
Java 8 New featuresJava 8 New features
Java 8 New features
 
My programming final proj. (1)
My programming final proj. (1)My programming final proj. (1)
My programming final proj. (1)
 

Viewers also liked

Massive concurrent modifications in web app. How to manage and test.
Massive concurrent modifications in web app. How to manage and test.Massive concurrent modifications in web app. How to manage and test.
Massive concurrent modifications in web app. How to manage and test.Anton Mishchuk
 
Flow based programming an overview
Flow based programming   an overviewFlow based programming   an overview
Flow based programming an overviewSamuel Lampa
 
Overcommit for #pivorak
Overcommit for #pivorak Overcommit for #pivorak
Overcommit for #pivorak Pivorak MeetUp
 
Digital Nomading on Rails
Digital Nomading on RailsDigital Nomading on Rails
Digital Nomading on RailsPivorak MeetUp
 
"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander SkakunovPivorak MeetUp
 
The Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievThe Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievPivorak MeetUp
 
Права інтелектуальної власності в IT сфері.
Права інтелектуальної власності  в IT сфері.Права інтелектуальної власності  в IT сфері.
Права інтелектуальної власності в IT сфері.Pivorak MeetUp
 
"Ruby meets Event Sourcing" by Anton Paisov
"Ruby meets Event Sourcing" by Anton Paisov"Ruby meets Event Sourcing" by Anton Paisov
"Ruby meets Event Sourcing" by Anton PaisovPivorak MeetUp
 
UDD: building polyglot anti-framework by Marek Piasecki
UDD: building polyglot anti-framework by Marek PiaseckiUDD: building polyglot anti-framework by Marek Piasecki
UDD: building polyglot anti-framework by Marek PiaseckiPivorak MeetUp
 
Lightweight APIs in mRuby
Lightweight APIs in mRubyLightweight APIs in mRuby
Lightweight APIs in mRubyPivorak MeetUp
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak MeetUp
 
Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Pivorak MeetUp
 
Trailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererPivorak MeetUp
 
Building component based rails applications. part 1.
Building component based rails applications. part 1.Building component based rails applications. part 1.
Building component based rails applications. part 1.Pivorak MeetUp
 
Functional Immutable CSS
Functional Immutable CSS Functional Immutable CSS
Functional Immutable CSS Pivorak MeetUp
 
“Object Oriented Ruby” by Michał Papis.
“Object Oriented Ruby” by Michał Papis.“Object Oriented Ruby” by Michał Papis.
“Object Oriented Ruby” by Michał Papis.Pivorak MeetUp
 

Viewers also liked (20)

Asynchronous Ruby
Asynchronous RubyAsynchronous Ruby
Asynchronous Ruby
 
Massive concurrent modifications in web app. How to manage and test.
Massive concurrent modifications in web app. How to manage and test.Massive concurrent modifications in web app. How to manage and test.
Massive concurrent modifications in web app. How to manage and test.
 
Espec - Elixir bdd
Espec  - Elixir bddEspec  - Elixir bdd
Espec - Elixir bdd
 
Flow based programming an overview
Flow based programming   an overviewFlow based programming   an overview
Flow based programming an overview
 
Overcommit for #pivorak
Overcommit for #pivorak Overcommit for #pivorak
Overcommit for #pivorak
 
Digital Nomading on Rails
Digital Nomading on RailsDigital Nomading on Rails
Digital Nomading on Rails
 
"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov"5 skills to master" by Alexander Skakunov
"5 skills to master" by Alexander Skakunov
 
The Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey VasilievThe Silver Bullet Syndrome by Alexey Vasiliev
The Silver Bullet Syndrome by Alexey Vasiliev
 
Права інтелектуальної власності в IT сфері.
Права інтелектуальної власності  в IT сфері.Права інтелектуальної власності  в IT сфері.
Права інтелектуальної власності в IT сфері.
 
"Ruby meets Event Sourcing" by Anton Paisov
"Ruby meets Event Sourcing" by Anton Paisov"Ruby meets Event Sourcing" by Anton Paisov
"Ruby meets Event Sourcing" by Anton Paisov
 
UDD: building polyglot anti-framework by Marek Piasecki
UDD: building polyglot anti-framework by Marek PiaseckiUDD: building polyglot anti-framework by Marek Piasecki
UDD: building polyglot anti-framework by Marek Piasecki
 
Lightweight APIs in mRuby
Lightweight APIs in mRubyLightweight APIs in mRuby
Lightweight APIs in mRuby
 
Pivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro BignyakPivorak Clojure by Dmytro Bignyak
Pivorak Clojure by Dmytro Bignyak
 
Espec |> Elixir BDD
Espec |> Elixir BDDEspec |> Elixir BDD
Espec |> Elixir BDD
 
Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.Building Component Based Rails Applications. Part 2.
Building Component Based Rails Applications. Part 2.
 
Trailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick SuttererTrailblazer Introduction by Nick Sutterer
Trailblazer Introduction by Nick Sutterer
 
GIS on Rails
GIS on RailsGIS on Rails
GIS on Rails
 
Building component based rails applications. part 1.
Building component based rails applications. part 1.Building component based rails applications. part 1.
Building component based rails applications. part 1.
 
Functional Immutable CSS
Functional Immutable CSS Functional Immutable CSS
Functional Immutable CSS
 
“Object Oriented Ruby” by Michał Papis.
“Object Oriented Ruby” by Michał Papis.“Object Oriented Ruby” by Michał Papis.
“Object Oriented Ruby” by Michał Papis.
 

Similar to Flowex - Railway Flow-Based Programming with Elixir GenStage.

Flow Base Programming with Node-RED and Functional Reactive Programming with ...
Flow Base Programming with Node-RED and Functional Reactive Programming with ...Flow Base Programming with Node-RED and Functional Reactive Programming with ...
Flow Base Programming with Node-RED and Functional Reactive Programming with ...Sven Beauprez
 
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"LogeekNightUkraine
 
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0Haytham Ghandour
 
Two C++ Tools: Compiler Explorer and Cpp Insights
Two C++ Tools: Compiler Explorer and Cpp InsightsTwo C++ Tools: Compiler Explorer and Cpp Insights
Two C++ Tools: Compiler Explorer and Cpp InsightsAlison Chaiken
 
Anton Mishchuk - Multi-language FBP with Flowex
Anton Mishchuk - Multi-language FBP with FlowexAnton Mishchuk - Multi-language FBP with Flowex
Anton Mishchuk - Multi-language FBP with FlowexElixir Club
 
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019corehard_by
 
Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Pivorak MeetUp
 
Introduction to web and php mysql
Introduction to web and php mysqlIntroduction to web and php mysql
Introduction to web and php mysqlProgrammer Blog
 
Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...Codemotion Dubai
 
Patterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesPatterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesRachel Reese
 
Make your application expressive
Make your application expressiveMake your application expressive
Make your application expressiveChristian Varela
 
Developing Rich Internet Applications with Perl and JavaScript
Developing Rich Internet Applications with Perl and JavaScriptDeveloping Rich Internet Applications with Perl and JavaScript
Developing Rich Internet Applications with Perl and JavaScriptnohuhu
 
Knowledge Sharing Session on JavaScript Source Maps & Angular Compilation
Knowledge Sharing Session on JavaScript Source Maps & Angular CompilationKnowledge Sharing Session on JavaScript Source Maps & Angular Compilation
Knowledge Sharing Session on JavaScript Source Maps & Angular CompilationMd.Zahidur Rahman
 
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
The PHP mysqlnd plugin talk - plugins an alternative to MySQL ProxyThe PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
The PHP mysqlnd plugin talk - plugins an alternative to MySQL ProxyUlf Wendel
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Eelco Visser
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects Andrey Karpov
 

Similar to Flowex - Railway Flow-Based Programming with Elixir GenStage. (20)

Phases of compiler
Phases of compilerPhases of compiler
Phases of compiler
 
Flow Base Programming with Node-RED and Functional Reactive Programming with ...
Flow Base Programming with Node-RED and Functional Reactive Programming with ...Flow Base Programming with Node-RED and Functional Reactive Programming with ...
Flow Base Programming with Node-RED and Functional Reactive Programming with ...
 
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
Oleksandr Smoktal "Parallel Seismic Data Processing Using OpenMP"
 
Java script
Java scriptJava script
Java script
 
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
 
Two C++ Tools: Compiler Explorer and Cpp Insights
Two C++ Tools: Compiler Explorer and Cpp InsightsTwo C++ Tools: Compiler Explorer and Cpp Insights
Two C++ Tools: Compiler Explorer and Cpp Insights
 
Anton Mishchuk - Multi-language FBP with Flowex
Anton Mishchuk - Multi-language FBP with FlowexAnton Mishchuk - Multi-language FBP with Flowex
Anton Mishchuk - Multi-language FBP with Flowex
 
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
The Hitchhiker's Guide to Faster Builds. Viktor Kirilov. CoreHard Spring 2019
 
Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk Multi language FBP with Flowex by Anton Mishchuk
Multi language FBP with Flowex by Anton Mishchuk
 
Introduction to web and php mysql
Introduction to web and php mysqlIntroduction to web and php mysql
Introduction to web and php mysql
 
Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...Patterns and practices for real-world event-driven microservices by Rachel Re...
Patterns and practices for real-world event-driven microservices by Rachel Re...
 
Patterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservicesPatterns and practices for real-world event-driven microservices
Patterns and practices for real-world event-driven microservices
 
Make your application expressive
Make your application expressiveMake your application expressive
Make your application expressive
 
Compose in Theory
Compose in TheoryCompose in Theory
Compose in Theory
 
Developing Rich Internet Applications with Perl and JavaScript
Developing Rich Internet Applications with Perl and JavaScriptDeveloping Rich Internet Applications with Perl and JavaScript
Developing Rich Internet Applications with Perl and JavaScript
 
LLVM
LLVMLLVM
LLVM
 
Knowledge Sharing Session on JavaScript Source Maps & Angular Compilation
Knowledge Sharing Session on JavaScript Source Maps & Angular CompilationKnowledge Sharing Session on JavaScript Source Maps & Angular Compilation
Knowledge Sharing Session on JavaScript Source Maps & Angular Compilation
 
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
The PHP mysqlnd plugin talk - plugins an alternative to MySQL ProxyThe PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
The PHP mysqlnd plugin talk - plugins an alternative to MySQL Proxy
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
 
100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects 100 bugs in Open Source C/C++ projects
100 bugs in Open Source C/C++ projects
 

Recently uploaded

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Recently uploaded (20)

The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Flowex - Railway Flow-Based Programming with Elixir GenStage.

  • 1. Flowex - Flow-Based Programming with Elixir GenStage Elixir Club 5, Kyiv, January 28, 2017
  • 2. - Ruby developer at Matic Insurance - Elixir fan - Author and maintainer of ESpec BDD test framework github: antonmi Hello! I am Anton Mishchuk 2
  • 3. The problem ◎ There are some problems in “conventional programing”: - code is procedural and sequential - parallelism is not native - hierarchical structure of program - visualisation is more about structure ◎ We need alternative approaches for building our programs to make software better! 3
  • 4. My previous FBP talk 4 http://www.slideshare.net/AntonMishchuk /flowbased-programming-with-elixir
  • 5. The goal of the talk ◎ Discuss a special case of Flow-Based Programming: “Railway FBP” (R-FBP) ◎ Present Flowex library which helps to create R-FBP abstractions ◎ Show that Elixir GenStage is not only about data-processing but about software design 5
  • 6. What will be about ◎ Flow-Based Programming (FBP) ◎ Railway Oriented Programming (ROP) ◎ Railway FBP ◎ Flowex library Lots of pictures! 6
  • 8. “ FBP - a programming paradigm that defines applications as networks of "black box" processes, which exchange data across predefined connections by message passing J. Paul Morrison, Flow-Based Programming, 2nd Edition 8
  • 9. FBP diagram A B D C IN 1 IN 1 IN 1 IN 2 IN 1 IN 2 OUT 1 OUT 2 OUT 1 OUT 1 OUT 1 9
  • 10. Express a problem in terms of transforms on streams of data http://www.jpaulmorrison.com/fbp/FBPnew.ppt 10
  • 11. Design pros ◎ Independent and reusable components ◎ Clean interfaces ◎ Simple to reconfigure ◎ Minimizes side-effects ◎ Designer can sit at one “station”, or can follow an item through system http://www.jpaulmorrison.com/fbp/FBPnew.ppt 11
  • 14. Express a problem in terms of sequence of functions calls request |> validate_request |> get_user |> update_db_from_request |> send_email |> return_http_message 14
  • 15. Define common interface for successful and error cases ◎ For example use: {:ok, "data"} or {:error, "Failure reason"} ◎ Each function returns {:ok, "data"} or {:error, "Failure reason"} ◎ If function is called with {:error, "Failure reason"} it just bypasses it 15
  • 16. Define interface to bypass errors http://fsharpforfunandprofit.com/rop/ 16
  • 17. So the program is a railway from input to output http://fsharpforfunandprofit.com/rop/ 17
  • 18. Elixir Plug is a good example! ◎ Each “plug” function receives and returns a “connection structure” %Plug.Conn{} ◎ %Plug.Conn{} contains: assigns, cookies, halted, host, method, params, resp_body, resp_cookies, status, and many other attributes 18
  • 20. Let’s transform each part of “Railway” into FBP component! 20
  • 21. Place each function into separate process validate send_emailupdate_db That is the idea! 21
  • 23. GenStage ◎ Easiest way to implement a chain of communicating processes ◎ Back-pressure mechanism producer consumer Subscribe Ask Events 23
  • 24. Metaprogramming ◎ Simple way for sharing functionality ◎ Ability to create expressive DSL 24
  • 27. Calculate (number + 1) * 2 - 3 27
  • 28. Note, the functions are cool! ◎ They have the same interface ◎ They operate with predefined struct We can join them into pipeline: 28
  • 29. Let’s add some Flowex magic! 29
  • 30. … and rename the module to FunPipeline 30
  • 31. “use Flowex.Pipeline” ◎ Adds ‘pipe’ macro which allows to mark functions “to be placed” into separate Genstage ◎ Defines ‘start’ and ‘stop’ functions for creating and destroying “Flowex pipelines” ◎ Defines ‘run’ function to perform calculations 31
  • 33. FunPipeline instance add_one minus_threemult_by_twoproducer consumer Supervisor Elixir GenStages 33
  • 34. %Flowex.Pipeline{} struct ◎ module - the name of the module ◎ in_name - unique name of 'producer' ◎ out_name - unique name of 'consumer' ◎ sup_pid - pid of the pipeline supervisor 34
  • 35. Run calculations via “run” Using FunPipeline.run/2 function Note, ‘a’, ‘b’ and ‘c’ were set! 35
  • 36. Run calculations using Flowex.Client Using Flowex.Client module 36
  • 37. How it works in details add_one minus_three mult_by_two producer consumer Flowex.Client %FunPipeline{number: 2} %Flowex.IP{ struct: %FunPipeline{number: 2}, ...} number: 2 number: 2 number: 3 number: 6 number: 3 number: 3 self() %FunPipeline{number: 3} 37
  • 38. What is sync and what is async? Client Asynchronous communicationself() Synchronous communication 38
  • 39. Is there no parallelism? 39
  • 40. There can be a lot of clients! Client Client Client 40
  • 41. Bottlenecks. What if there is very slow process in the pipeline? 41
  • 42. Just small changes in the code 42
  • 43. And you get this add_one minus_three mult_by_twoproducer consumer mult_by_two minus_three mult_by_two 43
  • 45. Module must implement just two functions Like Elixir Plug module 45
  • 48. Why it is cool! 48
  • 49. It is easy to understand ◎ Pipelines explicitly define a structure of data will be processed ◎ Pipelines explicitly define a way the data will come ◎ Pipelines explicitly define a parallel executors structure 49
  • 50. It is easy to maintain and reuse ◎ There is a predefined set of working processes (components) in a program ◎ Each component is isolated ◎ Pipelines can (and should) reuse components 50
  • 51. It is about controlled parallelism ◎ One can controll number of clients supplying data to a pipeline ◎ One can control the number of processes available for each component 51
  • 52. Thank you! Questions? 52 You can star the project here: https://github.com/antonmi/flowex