SlideShare a Scribd company logo
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

PDF
Flowex - Railway Flow-Based Programming with Elixir GenStage.
PDF
Flow-based programming with Elixir
PDF
Multi-language FBP with flowex
PDF
Intro to elixir metaprogramming
PPSX
What's new in c# 5.0 net ponto
PPTX
Python component in mule
PDF
Engineering Efficiency in LINE
PDF
Fun with java 8
Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flow-based programming with Elixir
Multi-language FBP with flowex
Intro to elixir metaprogramming
What's new in c# 5.0 net ponto
Python component in mule
Engineering Efficiency in LINE
Fun with java 8

What's hot (20)

PPTX
PPTX
Php Loop
PPTX
Steps for c program execution
PPT
C introduction
PDF
Railway Oriented Programming
PPTX
My final requirement
PPTX
Switch case and looping new
PDF
Client side scripting
PPTX
Function overloading in c++
PDF
topic_perlcgi
PDF
A la découverte de TypeScript
PPTX
My first program in c, hello world !
PPTX
Functional Programming in Java
PPTX
Common Programming Errors
PPTX
Switch case and looping
PDF
GOCON Autumn (Story of our own Monitoring Agent in golang)
PDF
Introduction to Elm
PDF
How do i - create a native interface
PPTX
Macasu, gerrell c.
PPTX
C# 6 and 7 and Futures 20180607
Php Loop
Steps for c program execution
C introduction
Railway Oriented Programming
My final requirement
Switch case and looping new
Client side scripting
Function overloading in c++
topic_perlcgi
A la découverte de TypeScript
My first program in c, hello world !
Functional Programming in Java
Common Programming Errors
Switch case and looping
GOCON Autumn (Story of our own Monitoring Agent in golang)
Introduction to Elm
How do i - create a native interface
Macasu, gerrell c.
C# 6 and 7 and Futures 20180607
Ad

Viewers also liked (20)

PDF
Bottleneck in Elixir Application - Alexey Osipenko
PDF
GenStage and Flow - Jose Valim
PDF
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
PPTX
Phoenix: Inflame the Web - Alex Troush
PDF
Build Your Own Real-Time Web Service with Elixir Phoenix
PDF
Distributed system in Elixir
PDF
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
PDF
Real World Elixir Deployment
PDF
Building Elixir App Release with Distillery and Docker
PDF
Spark as a distributed Scala
PPTX
ELIXIR Webinar: Introducing TeSS
PDF
Big Data eBook
PDF
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
PPTX
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
PPTX
Control flow in_elixir
PDF
Spring IO for startups
PDF
The Lost Tales of Platform Design (February 2017)
PPTX
Proteome array - antibody based proteome arrays
PDF
Elixir & Phoenix 推坑
PPTX
Anatomy of an elixir process and Actor Communication
Bottleneck in Elixir Application - Alexey Osipenko
GenStage and Flow - Jose Valim
Magic Clusters and Where to Find Them 2.0 - Eugene Pirogov
Phoenix: Inflame the Web - Alex Troush
Build Your Own Real-Time Web Service with Elixir Phoenix
Distributed system in Elixir
Elixir – Peeking into Elixir's Processes, OTP and Supervisors
Real World Elixir Deployment
Building Elixir App Release with Distillery and Docker
Spark as a distributed Scala
ELIXIR Webinar: Introducing TeSS
Big Data eBook
WEB MINING: PATTERN DISCOVERY ON THE WORLD WIDE WEB - 2011
나프다 웨비너 1604: Elixir와 함수형 프로그래밍을 이용한 웹 개발
Control flow in_elixir
Spring IO for startups
The Lost Tales of Platform Design (February 2017)
Proteome array - antibody based proteome arrays
Elixir & Phoenix 推坑
Anatomy of an elixir process and Actor Communication
Ad

Similar to Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk (20)

PDF
Multi language FBP with Flowex by Anton Mishchuk
PDF
Anton Mishchuk - Multi-language FBP with Flowex
PDF
Functional Programming With Elixir
PDF
Intro to elixir and phoenix
PDF
(Functional) reactive programming (@pavlobaron)
PDF
Elixir and OTP Apps introduction
PPTX
PDF
Flow Base Programming with Node-RED and Functional Reactive Programming with ...
PPTX
Introduction to functional programming, with Elixir
PDF
Programming Elixir 13 Functional Concurrent Pragmatic Fun Dave Thomas
PDF
Buy ebook Functional Reactive Programming 1st Edition Stephen Blackheath chea...
PPTX
A sip of elixir
PPTX
Talking to your organization about Elixir
PDF
Learning Elixir as a Rubyist
ODP
Elixir and elm - the perfect couple
PDF
Programming Elixir Functional Concurrent Pragmatic Fun 1st Edition Dave Thomas
PDF
Flow based programming in golang
PDF
Phoenix for Rails Devs
PDF
Using Flow-based programming to write tools and workflows for Scientific Comp...
Multi language FBP with Flowex by Anton Mishchuk
Anton Mishchuk - Multi-language FBP with Flowex
Functional Programming With Elixir
Intro to elixir and phoenix
(Functional) reactive programming (@pavlobaron)
Elixir and OTP Apps introduction
Flow Base Programming with Node-RED and Functional Reactive Programming with ...
Introduction to functional programming, with Elixir
Programming Elixir 13 Functional Concurrent Pragmatic Fun Dave Thomas
Buy ebook Functional Reactive Programming 1st Edition Stephen Blackheath chea...
A sip of elixir
Talking to your organization about Elixir
Learning Elixir as a Rubyist
Elixir and elm - the perfect couple
Programming Elixir Functional Concurrent Pragmatic Fun 1st Edition Dave Thomas
Flow based programming in golang
Phoenix for Rails Devs
Using Flow-based programming to write tools and workflows for Scientific Comp...

More from Elixir Club (20)

PDF
Kubernetes + Docker + Elixir - Alexei Sholik, Andrew Dryga | Elixir Club Ukraine
PDF
Integrating 3rd parties with Ecto - Eduardo Aguilera | Elixir Club Ukraine
PDF
— An async template - Oleksandr Khokhlov | Elixir Club Ukraine
PDF
BEAM architecture handbook - Andrea Leopardi | Elixir Club Ukraine
PDF
You ain't gonna need write a GenServer - Ulisses Almeida | Elixir Club Ukraine
PDF
— Knock, knock — An async templates — Who’s there? - Alexander Khokhlov | ...
PDF
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
PDF
Erlang cluster. How is it? Production experience. — Valerii Vasylkov | Elixi...
PDF
Promo Phx4RailsDevs - Volodya Sveredyuk
PDF
Web of today — Alexander Khokhlov
PDF
ElixirConf Eu 2018, what was it like? – Eugene Pirogov
PDF
Implementing GraphQL API in Elixir – Victor Deryagin
PDF
WebPerformance: Why and How? – Stefan Wintermeyer
PDF
GenServer in Action – Yurii Bodarev
PDF
Russian Doll Paradox: Elixir Web without Phoenix - Alex Rozumii
PDF
Practical Fault Tolerance in Elixir - Alexei Sholik
PDF
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
PDF
Monads are just monoids in the category of endofunctors - Ike Kurghinyan
PDF
Craft effective API with GraphQL and Absinthe - Ihor Katkov
PDF
Elixir in a service of government - Alex Troush
Kubernetes + Docker + Elixir - Alexei Sholik, Andrew Dryga | Elixir Club Ukraine
Integrating 3rd parties with Ecto - Eduardo Aguilera | Elixir Club Ukraine
— An async template - Oleksandr Khokhlov | Elixir Club Ukraine
BEAM architecture handbook - Andrea Leopardi | Elixir Club Ukraine
You ain't gonna need write a GenServer - Ulisses Almeida | Elixir Club Ukraine
— Knock, knock — An async templates — Who’s there? - Alexander Khokhlov | ...
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Erlang cluster. How is it? Production experience. — Valerii Vasylkov | Elixi...
Promo Phx4RailsDevs - Volodya Sveredyuk
Web of today — Alexander Khokhlov
ElixirConf Eu 2018, what was it like? – Eugene Pirogov
Implementing GraphQL API in Elixir – Victor Deryagin
WebPerformance: Why and How? – Stefan Wintermeyer
GenServer in Action – Yurii Bodarev
Russian Doll Paradox: Elixir Web without Phoenix - Alex Rozumii
Practical Fault Tolerance in Elixir - Alexei Sholik
Phoenix and beyond: Things we do with Elixir - Alexander Khokhlov
Monads are just monoids in the category of endofunctors - Ike Kurghinyan
Craft effective API with GraphQL and Absinthe - Ihor Katkov
Elixir in a service of government - Alex Troush

Recently uploaded (20)

PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
history of c programming in notes for students .pptx
PDF
top salesforce developer skills in 2025.pdf
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
Introduction to Artificial Intelligence
PDF
System and Network Administration Chapter 2
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
System and Network Administraation Chapter 3
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Essential Infomation Tech presentation.pptx
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
VVF-Customer-Presentation2025-Ver1.9.pptx
Adobe Illustrator 28.6 Crack My Vision of Vector Design
history of c programming in notes for students .pptx
top salesforce developer skills in 2025.pdf
Wondershare Filmora 15 Crack With Activation Key [2025
Upgrade and Innovation Strategies for SAP ERP Customers
Design an Analysis of Algorithms II-SECS-1021-03
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Odoo Companies in India – Driving Business Transformation.pdf
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Introduction to Artificial Intelligence
System and Network Administration Chapter 2
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
System and Network Administraation Chapter 3
Navsoft: AI-Powered Business Solutions & Custom Software Development
Essential Infomation Tech presentation.pptx
Reimagine Home Health with the Power of Agentic AI​
How to Migrate SBCGlobal Email to Yahoo Easily

Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk

  • 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