Flowex is a set of abstractions build on top Elixir GenStage which allows writing program with Flow-Based Programming paradigm.
I would say it is a mix of FBP and so-called Railway Oriented Programming (ROP) approach.
Flowex DSL allows you to easily create "pipelines" of Elixir GenStages.
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
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
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
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
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
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