SlideShare a Scribd company logo
1 of 32
Flow Based Programming and 
Reactive Programming with node.js 
Sven Beauprez
2 
Who am I? 
● Independent Enterprise Solution Architect 
– Specialized in SOA and EAI 
– Strong background in Java web development since '90s 
● Steering member of IoT BE 
● Steering member of JavaPolis/Devoxx 2002 – 2009 
● Keep in touch 
– sven.beauprez@prorabel.com 
– https://www.linkedin.com/in/svenbeauprez
3 
Node.js main characterisitcs 
● … runs as a single process 
– Does not start a new process for each new request, which would mean a lot of overhead 
● … runs applications in a single thread 
– Does not start a new thread for each new request, which means less complex code and 
avoiding race conditions 
● … is asynchronous 
– Can handle multiple requests at one time without blocking new requests by using 
I/O eventing, callbacks and an event loop 
● … is ideal for I/O intensive tasks, but less for CPU intensive 
– CPU intensive tasks within the application would block the process and must be 
offloaded in worker threads/processes 
In other words a perfect fit for IoT where the main tasks 
on the edges and in the fog is collecting sensor data
4 
Node.js event loop* 
waiting waiting 
Event Loop 
(single thread) 
Incoming 
request 
Query DB 
(offloaded) 
Process 
result 
Write log 
(offloaded) Respond 
Thread Pool 
& Async I/O 
Filesystem 
Network 
Other 
Event 
Queue 
*http://kunkle.org/nodejs-explained-pres
5 
Node.js callback hell 
callback 1 
callback 2 
callback 3 
● Naive example of a node.js application 
Confusing, this gives even wrong result
6 
Node.js promises 
● Also called futures, deffereds, eventuals,... 
● A promise is an object (proxy) that represents the result of an asynchronous 
function call 
var promise = doSomethingAync() 
promise.then(onFulfilled, onRejected) 
● Biggest advantage of promises is that they can be chained to avoid callback hell 
readFile().then(readAnotherFile).then(doSomethingElse).then(...) 
● Promises can return any other value and the next 'onFulfilled' will be passed the 
value as argument 
readFile().then(function (buf) {return JSON.parse(buf.toString())}) 
.then(function (data) {// do something with `data`}) 
Promises are a simple form of dataflow programming
7 
What is dataflow? 
● Traditionally a program is modeled as a series of operations 
happening in a specific order, in other words how to do 
computations. 
Source: http://www.autobild.de/
8 
What is dataflow? 
● Dataflow programming emphasizes the movement of data 
and models programs as a series of connection. It describes 
what computation should be performed. 
Source: http://commons.wikimedia.org/wiki/File:Hyundai_car_assembly_line.jpg
9 
Flow Based Programming (FBP) 
● Describes a graph of nodes, which exchange messages 
containing data via the edges. The edges are defined outside 
the nodes, in others words nodes have no control on where 
the data comes from and where it goes to
10 
FBP: Unix Pipes 
● Unix pipes are an example of linear flow based 
programming while a stream of data follows the pipes and 
the different 'smaller' dedictated applications run in parallel 
ps aux | grep myApp | grep -v grep | awk '{print $2}' | xargs kill
11 
FBP: Yahoo Pipes 
Source: https://pipes.yahoo.com/pipes/pipe.info?_id=ZKJobpaj3BGZOew9G8evXg
12 
FBP: Enterprise Application Integration 
http://www.eaipatterns.com/Chapter1.html
13 
FBP: Node-RED
14 
FBP: Node-RED 
● According to the founders: 
– A light-weight, edge of network, application builder 
– Easy to use, drag and drop interface 
– A tool that allows the developer to focus on the task at hand 
● My definition: 
– A network of connected light-weight nodes to process stream(s) of 
edge generated events via message passing
15 
FBP: Node-RED 
● Messages are JSON objects 
“payload : “Hello world!” 
“topic” : “foo” 
……
16 
FBP: Node-RED 
● Different categories of nodes are defined: 
– Input: to process incoming events 
● Example: Inject trigger, HTTP, TCP, UDP, websocket, MQTT, 
file, Datastore, social (Twitter), … and custom nodes 
– Output: to serve or send outgoing events 
● Example: Debug, HTTP, TCP, UDP, websocket, MQTT, file, 
Datastore, social (Twitter), … and custom nodes 
– Functions: to manipulate messages and message payloads 
● Transform, filter, map, analyse, …
17 
FBP: Node-RED – Function node 
● Generic Function node: 
– Runs user-defined javascript code in a sandbox 
– Returns (forward) custom build messages with payloads 
● return msg; 
● return [msg1, msg2, msg3]; 
● return [msg1, [msgA, msgB]];
18 
FBP: Node-RED – Function Context 
● Each node has its own context to save state between calls 
– Since node.js is single threaded, no race conditions can occur and 
the state is always correct and up to date
19 
FBP: Node-RED – Custom Nodes 
● Custom nodes are defined via a pair of files: 
– .js : 
● defines what the node does 
● runs on the server 
– .html : 
● defines the node's properties, edit dialog and help text 
● runs in a browser 
● When configuration needs to be shared between nodes, eg. IN node and the 
related OUT node share the same IP address, a special config node can be defined 
– A dependeny on the config node is added in the custom node
20 
FBP: Node-RED 
Demo
21 
(Functional) Reactive Programming (FRP) 
● What if 
C = A + B 
meant C always equals A plus B, at any time?
22 
FRP: spreadsheets are reactive 
● The functions in a cell/chart react on changes in another cell
23 
FRP: dynamic values 
● In reactive programming, datatypes represent a value “over 
time”* 
– An example is getting coördinates of the mouse 
x = <mouse-x> 
y = <mouse-y> 
in reactive programming, the assignment needs to be made only 
once and the variables/properties will always be up to date with 
the latest values 
– All following computations based on these variables will also be 
values that change over time 
minX = x - 16; 
minY = y - 16; 
maxX = x + 16; 
maxY = y + 16; 
//draw 32x32 box around mouse pointer 
rectangle(minX, minY, maxX, maxY) 
*http://stackoverflow.com/a/1028642
24 
FRP: bacon.js how does it look like? 
http://jsfiddle.net/njs3szqe/
25 
FRP: bacon.js 'c = a + b', always 
http://jsfiddle.net/Lpe77wjk/
26 
FRP: 'functional' reactive programming 
● 'Functional' means that building blocks of functional programming are used 
– Ideas are borrowed from languages such as Haskell, Lisp, Scheme,... 
● Higher order functions are used extensively all over the place 
– Higher order = takes one or more functions as input and/or outputs a function 
– Examples: 
● Map, filter, scan, combine, takeWhile,... 
● See https://github.com/baconjs/bacon.js/ for an exhaustive list supported by 
bacon 
● See https://github.com/ReactiveX/RxJava/wiki/Observable for visual 
representation of many of these functions
27 
FRP: higher order function map() 
● Transform items emitted by a stream/property by applying a 
function to each of them 
https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#map
28 
FRP: higher order function filter() 
● Filter items emitted by a stream 
https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#filter
29 
FRP: higher order function scan() 
● Apply a function to each item emitted by a stream and emit 
each successive value 
https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#scan
30 
FRP: higher order function takeWhile() 
● Emit items emitted by a stream as long as a specified 
condition is true, then skip the remainder 
https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#takewhile-and-takewhilewithindex
FRP: Applying FRP in IoT – Bacon.js & Tessel 
31
32 
Q&A

More Related Content

What's hot

DB Monitoring 개념 및 활용 (박명규)
DB Monitoring 개념 및 활용 (박명규)DB Monitoring 개념 및 활용 (박명규)
DB Monitoring 개념 및 활용 (박명규)WhaTap Labs
 
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to KnowOracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to KnowFrank Munz
 
Designing APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignLaunchAny
 
Building Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisBuilding Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisFIWARE
 
Kong API Gateway
Kong API Gateway Kong API Gateway
Kong API Gateway Chris Mague
 
Building modern data lakes
Building modern data lakes Building modern data lakes
Building modern data lakes Minio
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample applicationAntoine Rey
 
파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄SeongHyun Ahn
 
Domain Driven Data: Apache Kafka® and the Data Mesh
Domain Driven Data: Apache Kafka® and the Data MeshDomain Driven Data: Apache Kafka® and the Data Mesh
Domain Driven Data: Apache Kafka® and the Data Meshconfluent
 
Clean architecture
Clean architectureClean architecture
Clean architectureLieven Doclo
 
From capabilities to services modelling for business-it alignment v.2
From capabilities to services   modelling for business-it alignment v.2From capabilities to services   modelling for business-it alignment v.2
From capabilities to services modelling for business-it alignment v.2Trond Hjorteland
 
Microservices Integration Patterns with Kafka
Microservices Integration Patterns with KafkaMicroservices Integration Patterns with Kafka
Microservices Integration Patterns with KafkaKasun Indrasiri
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootMikalai Alimenkou
 
Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Toshiaki Maki
 
Enterprise Software Architecture styles
Enterprise Software Architecture stylesEnterprise Software Architecture styles
Enterprise Software Architecture stylesAraf Karsh Hamid
 
Declarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingDeclarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingFlorian Stefan
 
Introduction to the Container Network Interface (CNI)
Introduction to the Container Network Interface (CNI)Introduction to the Container Network Interface (CNI)
Introduction to the Container Network Interface (CNI)Weaveworks
 

What's hot (20)

DB Monitoring 개념 및 활용 (박명규)
DB Monitoring 개념 및 활용 (박명규)DB Monitoring 개념 및 활용 (박명규)
DB Monitoring 개념 및 활용 (박명규)
 
cilium-public.pdf
cilium-public.pdfcilium-public.pdf
cilium-public.pdf
 
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to KnowOracle Service Bus 12c (12.2.1) What You Always Wanted to Know
Oracle Service Bus 12c (12.2.1) What You Always Wanted to Know
 
Designing APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven DesignDesigning APIs and Microservices Using Domain-Driven Design
Designing APIs and Microservices Using Domain-Driven Design
 
Models for hierarchical data
Models for hierarchical dataModels for hierarchical data
Models for hierarchical data
 
Building Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEisBuilding Your Own IoT Platform using FIWARE GEis
Building Your Own IoT Platform using FIWARE GEis
 
Kong API Gateway
Kong API Gateway Kong API Gateway
Kong API Gateway
 
Building modern data lakes
Building modern data lakes Building modern data lakes
Building modern data lakes
 
Spring Framework Petclinic sample application
Spring Framework Petclinic sample applicationSpring Framework Petclinic sample application
Spring Framework Petclinic sample application
 
파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄
 
Domain Driven Data: Apache Kafka® and the Data Mesh
Domain Driven Data: Apache Kafka® and the Data MeshDomain Driven Data: Apache Kafka® and the Data Mesh
Domain Driven Data: Apache Kafka® and the Data Mesh
 
Clean architecture
Clean architectureClean architecture
Clean architecture
 
From capabilities to services modelling for business-it alignment v.2
From capabilities to services   modelling for business-it alignment v.2From capabilities to services   modelling for business-it alignment v.2
From capabilities to services modelling for business-it alignment v.2
 
SDDC Strategy 1.3
SDDC Strategy 1.3SDDC Strategy 1.3
SDDC Strategy 1.3
 
Microservices Integration Patterns with Kafka
Microservices Integration Patterns with KafkaMicroservices Integration Patterns with Kafka
Microservices Integration Patterns with Kafka
 
Hexagonal architecture with Spring Boot
Hexagonal architecture with Spring BootHexagonal architecture with Spring Boot
Hexagonal architecture with Spring Boot
 
Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1Introduction to Spring WebFlux #jsug #sf_a1
Introduction to Spring WebFlux #jsug #sf_a1
 
Enterprise Software Architecture styles
Enterprise Software Architecture stylesEnterprise Software Architecture styles
Enterprise Software Architecture styles
 
Declarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingDeclarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive Programming
 
Introduction to the Container Network Interface (CNI)
Introduction to the Container Network Interface (CNI)Introduction to the Container Network Interface (CNI)
Introduction to the Container Network Interface (CNI)
 

Viewers also liked

An introduction to workflow-based programming with Node-RED
An introduction to workflow-based programming with Node-REDAn introduction to workflow-based programming with Node-RED
An introduction to workflow-based programming with Node-REDBoris Adryan
 
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)Mr.Nukoon Phimsen
 
Supercharge your IOT toolbox with MQTT and Node-RED
Supercharge your IOT toolbox with MQTT and Node-REDSupercharge your IOT toolbox with MQTT and Node-RED
Supercharge your IOT toolbox with MQTT and Node-REDSimen Sommerfeldt
 
Web of Things (wiring web objects with Node-RED)
Web of Things (wiring web objects with Node-RED)Web of Things (wiring web objects with Node-RED)
Web of Things (wiring web objects with Node-RED)Francesco Collova'
 
AT&T Hack Dallas Node-RED Tutorial
AT&T Hack Dallas Node-RED TutorialAT&T Hack Dallas Node-RED Tutorial
AT&T Hack Dallas Node-RED TutorialStefania Kaczmarczyk
 
Using bluemix predictive analytics service in Node-RED
Using bluemix predictive analytics service in Node-REDUsing bluemix predictive analytics service in Node-RED
Using bluemix predictive analytics service in Node-REDLionel Mommeja
 
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14Boris Adryan
 
Using Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsAniruddha Chakrabarti
 
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud Computing
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud ComputingIDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud Computing
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud ComputingOpen Data Center Alliance
 
Node red for Raspberry Pi
Node red for Raspberry PiNode red for Raspberry Pi
Node red for Raspberry PiAnshu Pandey
 
Node-RED Interoperability Test
Node-RED Interoperability TestNode-RED Interoperability Test
Node-RED Interoperability TestBoris Adryan
 
MQTT と Quickstart と NodeRED
MQTT と Quickstart と NodeREDMQTT と Quickstart と NodeRED
MQTT と Quickstart と NodeREDK Kimura
 
Node red with Arduino
Node red with ArduinoNode red with Arduino
Node red with ArduinoAnshu Pandey
 
IAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-REDIAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-REDPeterNiblett
 
TampereJS Meetup: Node-RED by Mika Karaila, Valmet
TampereJS Meetup: Node-RED by Mika Karaila, ValmetTampereJS Meetup: Node-RED by Mika Karaila, Valmet
TampereJS Meetup: Node-RED by Mika Karaila, ValmetSointu Karjalainen
 
Distributed Data Flow for the Web of Things: Distributed Node-RED
Distributed Data Flow for the Web of Things: Distributed Node-REDDistributed Data Flow for the Web of Things: Distributed Node-RED
Distributed Data Flow for the Web of Things: Distributed Node-REDMichael Blackstock
 
Nio100 demo box
Nio100 demo boxNio100 demo box
Nio100 demo box和得 王
 

Viewers also liked (20)

An introduction to workflow-based programming with Node-RED
An introduction to workflow-based programming with Node-REDAn introduction to workflow-based programming with Node-RED
An introduction to workflow-based programming with Node-RED
 
01 Node-RED Basic
01 Node-RED Basic01 Node-RED Basic
01 Node-RED Basic
 
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
02 Raspberry Pi GPIO Interface on Node-RED (Some correction)
 
Supercharge your IOT toolbox with MQTT and Node-RED
Supercharge your IOT toolbox with MQTT and Node-REDSupercharge your IOT toolbox with MQTT and Node-RED
Supercharge your IOT toolbox with MQTT and Node-RED
 
Web of Things (wiring web objects with Node-RED)
Web of Things (wiring web objects with Node-RED)Web of Things (wiring web objects with Node-RED)
Web of Things (wiring web objects with Node-RED)
 
AT&T Hack Dallas Node-RED Tutorial
AT&T Hack Dallas Node-RED TutorialAT&T Hack Dallas Node-RED Tutorial
AT&T Hack Dallas Node-RED Tutorial
 
Using bluemix predictive analytics service in Node-RED
Using bluemix predictive analytics service in Node-REDUsing bluemix predictive analytics service in Node-RED
Using bluemix predictive analytics service in Node-RED
 
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14
Wiring the Internet of Things with Node-RED, @IoTConf talk, September '14
 
Using Node-RED for building IoT workflows
Using Node-RED for building IoT workflowsUsing Node-RED for building IoT workflows
Using Node-RED for building IoT workflows
 
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud Computing
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud ComputingIDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud Computing
IDF 2011: ODCA & Developing a Usage Model Roadmap for Cloud Computing
 
Node red for Raspberry Pi
Node red for Raspberry PiNode red for Raspberry Pi
Node red for Raspberry Pi
 
Node-RED Interoperability Test
Node-RED Interoperability TestNode-RED Interoperability Test
Node-RED Interoperability Test
 
node.js dao
node.js daonode.js dao
node.js dao
 
MQTT と Quickstart と NodeRED
MQTT と Quickstart と NodeREDMQTT と Quickstart と NodeRED
MQTT と Quickstart と NodeRED
 
Node red with Arduino
Node red with ArduinoNode red with Arduino
Node red with Arduino
 
IAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-REDIAB3948 Wiring the internet of things with Node-RED
IAB3948 Wiring the internet of things with Node-RED
 
TampereJS Meetup: Node-RED by Mika Karaila, Valmet
TampereJS Meetup: Node-RED by Mika Karaila, ValmetTampereJS Meetup: Node-RED by Mika Karaila, Valmet
TampereJS Meetup: Node-RED by Mika Karaila, Valmet
 
Distributed Data Flow for the Web of Things: Distributed Node-RED
Distributed Data Flow for the Web of Things: Distributed Node-REDDistributed Data Flow for the Web of Things: Distributed Node-RED
Distributed Data Flow for the Web of Things: Distributed Node-RED
 
Node red workshop
Node red workshopNode red workshop
Node red workshop
 
Nio100 demo box
Nio100 demo boxNio100 demo box
Nio100 demo box
 

Similar to Flow Base Programming with Node-RED and Functional Reactive Programming with Baconjs

Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overviewjessesanford
 
Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Anton Mishchuk
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukElixir Club
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed AssafAhmed Assaf
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsPiyush Katariya
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginnersEnoch Joshua
 
Easy deployment & management of cloud apps
Easy deployment & management of cloud appsEasy deployment & management of cloud apps
Easy deployment & management of cloud appsDavid Cunningham
 
Informix Expedition Through Connectivity
Informix Expedition Through ConnectivityInformix Expedition Through Connectivity
Informix Expedition Through ConnectivityKevin Smith
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJSDicoding
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performanceAndrew Rota
 
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...OpenNebula Project
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questionstechievarsity
 
Node js
Node jsNode js
Node jshazzaz
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009Bhasker Kode
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIYoni Davidson
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...Codemotion
 

Similar to Flow Base Programming with Node-RED and Functional Reactive Programming with Baconjs (20)

Dragoncraft Architectural Overview
Dragoncraft Architectural OverviewDragoncraft Architectural Overview
Dragoncraft Architectural Overview
 
Nodejs
NodejsNodejs
Nodejs
 
Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.Flowex - Railway Flow-Based Programming with Elixir GenStage.
Flowex - Railway Flow-Based Programming with Elixir GenStage.
 
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton MishchukFlowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
Flowex: Flow-Based Programming with Elixir GenStage - Anton Mishchuk
 
Introduction to node.js By Ahmed Assaf
Introduction to node.js  By Ahmed AssafIntroduction to node.js  By Ahmed Assaf
Introduction to node.js By Ahmed Assaf
 
JavaScript for Enterprise Applications
JavaScript for Enterprise ApplicationsJavaScript for Enterprise Applications
JavaScript for Enterprise Applications
 
NodeJS guide for beginners
NodeJS guide for beginnersNodeJS guide for beginners
NodeJS guide for beginners
 
Easy deployment & management of cloud apps
Easy deployment & management of cloud appsEasy deployment & management of cloud apps
Easy deployment & management of cloud apps
 
Informix Expedition Through Connectivity
Informix Expedition Through ConnectivityInformix Expedition Through Connectivity
Informix Expedition Through Connectivity
 
High Performance NodeJS
High Performance NodeJSHigh Performance NodeJS
High Performance NodeJS
 
React native
React nativeReact native
React native
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
OpenNebulaConf 2016 - Measuring and tuning VM performance by Boyan Krosnov, S...
 
Top 30 Node.js interview questions
Top 30 Node.js interview questionsTop 30 Node.js interview questions
Top 30 Node.js interview questions
 
Node js
Node jsNode js
Node js
 
hover.in at CUFP 2009
hover.in at CUFP 2009hover.in at CUFP 2009
hover.in at CUFP 2009
 
Node.js an Exectutive View
Node.js an Exectutive ViewNode.js an Exectutive View
Node.js an Exectutive View
 
carrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-APIcarrow - Go bindings to Apache Arrow via C++-API
carrow - Go bindings to Apache Arrow via C++-API
 
Dojo (QCon 2007 Slides)
Dojo (QCon 2007 Slides)Dojo (QCon 2007 Slides)
Dojo (QCon 2007 Slides)
 
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
ClojureScript - Making Front-End development Fun again - John Stevenson - Cod...
 

Recently uploaded

Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced HorizonsVision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced HorizonsRoxana Stingu
 
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024Jan Löffler
 
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdfLESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdfmchristianalwyn
 
Bio Medical Waste Management Guideliness 2023 ppt.pptx
Bio Medical Waste Management Guideliness 2023 ppt.pptxBio Medical Waste Management Guideliness 2023 ppt.pptx
Bio Medical Waste Management Guideliness 2023 ppt.pptxnaveenithkrishnan
 
Zero-day Vulnerabilities
Zero-day VulnerabilitiesZero-day Vulnerabilities
Zero-day Vulnerabilitiesalihassaah1994
 
Check out the Free Landing Page Hosting in 2024
Check out the Free Landing Page Hosting in 2024Check out the Free Landing Page Hosting in 2024
Check out the Free Landing Page Hosting in 2024Shubham Pant
 
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...APNIC
 
Introduction to ICANN and Fellowship program by Shreedeep Rayamajhi.pdf
Introduction to ICANN and Fellowship program  by Shreedeep Rayamajhi.pdfIntroduction to ICANN and Fellowship program  by Shreedeep Rayamajhi.pdf
Introduction to ICANN and Fellowship program by Shreedeep Rayamajhi.pdfShreedeep Rayamajhi
 
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDSTYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDSedrianrheine
 
Computer 10 Lesson 8: Building a Website
Computer 10 Lesson 8: Building a WebsiteComputer 10 Lesson 8: Building a Website
Computer 10 Lesson 8: Building a WebsiteMavein
 
Presentation2.pptx - JoyPress Wordpress
Presentation2.pptx -  JoyPress WordpressPresentation2.pptx -  JoyPress Wordpress
Presentation2.pptx - JoyPress Wordpressssuser166378
 
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASSLESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASSlesteraporado16
 

Recently uploaded (12)

Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced HorizonsVision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
Vision Forward: Tracing Image Search SEO From Its Roots To AI-Enhanced Horizons
 
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
WordPress by the numbers - Jan Loeffler, CTO WebPros, CloudFest 2024
 
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdfLESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
LESSON 5 GROUP 10 ST. THOMAS AQUINAS.pdf
 
Bio Medical Waste Management Guideliness 2023 ppt.pptx
Bio Medical Waste Management Guideliness 2023 ppt.pptxBio Medical Waste Management Guideliness 2023 ppt.pptx
Bio Medical Waste Management Guideliness 2023 ppt.pptx
 
Zero-day Vulnerabilities
Zero-day VulnerabilitiesZero-day Vulnerabilities
Zero-day Vulnerabilities
 
Check out the Free Landing Page Hosting in 2024
Check out the Free Landing Page Hosting in 2024Check out the Free Landing Page Hosting in 2024
Check out the Free Landing Page Hosting in 2024
 
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
Benefits of doing Internet peering and running an Internet Exchange (IX) pres...
 
Introduction to ICANN and Fellowship program by Shreedeep Rayamajhi.pdf
Introduction to ICANN and Fellowship program  by Shreedeep Rayamajhi.pdfIntroduction to ICANN and Fellowship program  by Shreedeep Rayamajhi.pdf
Introduction to ICANN and Fellowship program by Shreedeep Rayamajhi.pdf
 
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDSTYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
TYPES AND DEFINITION OF ONLINE CRIMES AND HAZARDS
 
Computer 10 Lesson 8: Building a Website
Computer 10 Lesson 8: Building a WebsiteComputer 10 Lesson 8: Building a Website
Computer 10 Lesson 8: Building a Website
 
Presentation2.pptx - JoyPress Wordpress
Presentation2.pptx -  JoyPress WordpressPresentation2.pptx -  JoyPress Wordpress
Presentation2.pptx - JoyPress Wordpress
 
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASSLESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
LESSON 10/ GROUP 10/ ST. THOMAS AQUINASS
 

Flow Base Programming with Node-RED and Functional Reactive Programming with Baconjs

  • 1. Flow Based Programming and Reactive Programming with node.js Sven Beauprez
  • 2. 2 Who am I? ● Independent Enterprise Solution Architect – Specialized in SOA and EAI – Strong background in Java web development since '90s ● Steering member of IoT BE ● Steering member of JavaPolis/Devoxx 2002 – 2009 ● Keep in touch – sven.beauprez@prorabel.com – https://www.linkedin.com/in/svenbeauprez
  • 3. 3 Node.js main characterisitcs ● … runs as a single process – Does not start a new process for each new request, which would mean a lot of overhead ● … runs applications in a single thread – Does not start a new thread for each new request, which means less complex code and avoiding race conditions ● … is asynchronous – Can handle multiple requests at one time without blocking new requests by using I/O eventing, callbacks and an event loop ● … is ideal for I/O intensive tasks, but less for CPU intensive – CPU intensive tasks within the application would block the process and must be offloaded in worker threads/processes In other words a perfect fit for IoT where the main tasks on the edges and in the fog is collecting sensor data
  • 4. 4 Node.js event loop* waiting waiting Event Loop (single thread) Incoming request Query DB (offloaded) Process result Write log (offloaded) Respond Thread Pool & Async I/O Filesystem Network Other Event Queue *http://kunkle.org/nodejs-explained-pres
  • 5. 5 Node.js callback hell callback 1 callback 2 callback 3 ● Naive example of a node.js application Confusing, this gives even wrong result
  • 6. 6 Node.js promises ● Also called futures, deffereds, eventuals,... ● A promise is an object (proxy) that represents the result of an asynchronous function call var promise = doSomethingAync() promise.then(onFulfilled, onRejected) ● Biggest advantage of promises is that they can be chained to avoid callback hell readFile().then(readAnotherFile).then(doSomethingElse).then(...) ● Promises can return any other value and the next 'onFulfilled' will be passed the value as argument readFile().then(function (buf) {return JSON.parse(buf.toString())}) .then(function (data) {// do something with `data`}) Promises are a simple form of dataflow programming
  • 7. 7 What is dataflow? ● Traditionally a program is modeled as a series of operations happening in a specific order, in other words how to do computations. Source: http://www.autobild.de/
  • 8. 8 What is dataflow? ● Dataflow programming emphasizes the movement of data and models programs as a series of connection. It describes what computation should be performed. Source: http://commons.wikimedia.org/wiki/File:Hyundai_car_assembly_line.jpg
  • 9. 9 Flow Based Programming (FBP) ● Describes a graph of nodes, which exchange messages containing data via the edges. The edges are defined outside the nodes, in others words nodes have no control on where the data comes from and where it goes to
  • 10. 10 FBP: Unix Pipes ● Unix pipes are an example of linear flow based programming while a stream of data follows the pipes and the different 'smaller' dedictated applications run in parallel ps aux | grep myApp | grep -v grep | awk '{print $2}' | xargs kill
  • 11. 11 FBP: Yahoo Pipes Source: https://pipes.yahoo.com/pipes/pipe.info?_id=ZKJobpaj3BGZOew9G8evXg
  • 12. 12 FBP: Enterprise Application Integration http://www.eaipatterns.com/Chapter1.html
  • 14. 14 FBP: Node-RED ● According to the founders: – A light-weight, edge of network, application builder – Easy to use, drag and drop interface – A tool that allows the developer to focus on the task at hand ● My definition: – A network of connected light-weight nodes to process stream(s) of edge generated events via message passing
  • 15. 15 FBP: Node-RED ● Messages are JSON objects “payload : “Hello world!” “topic” : “foo” ……
  • 16. 16 FBP: Node-RED ● Different categories of nodes are defined: – Input: to process incoming events ● Example: Inject trigger, HTTP, TCP, UDP, websocket, MQTT, file, Datastore, social (Twitter), … and custom nodes – Output: to serve or send outgoing events ● Example: Debug, HTTP, TCP, UDP, websocket, MQTT, file, Datastore, social (Twitter), … and custom nodes – Functions: to manipulate messages and message payloads ● Transform, filter, map, analyse, …
  • 17. 17 FBP: Node-RED – Function node ● Generic Function node: – Runs user-defined javascript code in a sandbox – Returns (forward) custom build messages with payloads ● return msg; ● return [msg1, msg2, msg3]; ● return [msg1, [msgA, msgB]];
  • 18. 18 FBP: Node-RED – Function Context ● Each node has its own context to save state between calls – Since node.js is single threaded, no race conditions can occur and the state is always correct and up to date
  • 19. 19 FBP: Node-RED – Custom Nodes ● Custom nodes are defined via a pair of files: – .js : ● defines what the node does ● runs on the server – .html : ● defines the node's properties, edit dialog and help text ● runs in a browser ● When configuration needs to be shared between nodes, eg. IN node and the related OUT node share the same IP address, a special config node can be defined – A dependeny on the config node is added in the custom node
  • 21. 21 (Functional) Reactive Programming (FRP) ● What if C = A + B meant C always equals A plus B, at any time?
  • 22. 22 FRP: spreadsheets are reactive ● The functions in a cell/chart react on changes in another cell
  • 23. 23 FRP: dynamic values ● In reactive programming, datatypes represent a value “over time”* – An example is getting coördinates of the mouse x = <mouse-x> y = <mouse-y> in reactive programming, the assignment needs to be made only once and the variables/properties will always be up to date with the latest values – All following computations based on these variables will also be values that change over time minX = x - 16; minY = y - 16; maxX = x + 16; maxY = y + 16; //draw 32x32 box around mouse pointer rectangle(minX, minY, maxX, maxY) *http://stackoverflow.com/a/1028642
  • 24. 24 FRP: bacon.js how does it look like? http://jsfiddle.net/njs3szqe/
  • 25. 25 FRP: bacon.js 'c = a + b', always http://jsfiddle.net/Lpe77wjk/
  • 26. 26 FRP: 'functional' reactive programming ● 'Functional' means that building blocks of functional programming are used – Ideas are borrowed from languages such as Haskell, Lisp, Scheme,... ● Higher order functions are used extensively all over the place – Higher order = takes one or more functions as input and/or outputs a function – Examples: ● Map, filter, scan, combine, takeWhile,... ● See https://github.com/baconjs/bacon.js/ for an exhaustive list supported by bacon ● See https://github.com/ReactiveX/RxJava/wiki/Observable for visual representation of many of these functions
  • 27. 27 FRP: higher order function map() ● Transform items emitted by a stream/property by applying a function to each of them https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#map
  • 28. 28 FRP: higher order function filter() ● Filter items emitted by a stream https://github.com/ReactiveX/RxJava/wiki/Filtering-Observables#filter
  • 29. 29 FRP: higher order function scan() ● Apply a function to each item emitted by a stream and emit each successive value https://github.com/ReactiveX/RxJava/wiki/Transforming-Observables#scan
  • 30. 30 FRP: higher order function takeWhile() ● Emit items emitted by a stream as long as a specified condition is true, then skip the remainder https://github.com/ReactiveX/RxJava/wiki/Conditional-and-Boolean-Operators#takewhile-and-takewhilewithindex
  • 31. FRP: Applying FRP in IoT – Bacon.js & Tessel 31