Reactive Design Patterns
Tools of the Trade
Jamie Allen
Sr. Director of Global Services
Reactive Design Patterns
@jamie_allen
Reactive Design Patterns
Implications are massive, change is unavoidable
Users are demanding richer
and more personalized
experiences.
Yet, at the same time,
expecting blazing fast load
time.
Users
Mobile and HTML5; Data and
compute clouds; scaling on
demand.
Modern application
technologies are fueling the
always-on, real-time user
expectation.
Applications
Businesses are being pushed
to react to these changing
user expectations…
...and embrace
modern application
requirements.
Businesses
Reactive Design Patterns
Reactive applications share four traits
Reactive Design Patterns
Amdahl's Law
Reactive Design Patterns
Reactive Design Patterns
Cost of Not Being Reactive
• Cost to your wallet and the environment
• No ability to recover from failure
• No ability to be responsive to our users
Reactive Design Patterns
Functional Programming is Key
• We want to be asynchronous and non-blocking
• We need to ensure that our data is protected without locks
• Functional programming is critical to meeting these needs
• Declarative
• Immutable
• Referentially transparent
• Pure functions that only have inputs and outputs
Reactive Design Patterns
Backpressure is required
• How can a system withstand variance in load?
• What does the system communicate to users of the application
when it is overwhelmed?
• Companies can lose tremendous amounts of money by not being
able to respond to users at all times
Reactive Design Patterns
Tools of the Trade
All code can be found at https://github.com/ReactiveDesignPatterns/Chapter-2
Reactive Design Patterns
Tools of the Trade: Event Loops
• Leverage green threads to provide asynchronous semantics
• The core concept of Node.js and Vert.x
• Powerful abstraction for performance and potentially scalability
• Limited with respect to resilience
• One error can take down multiple events
• Node.js can only be restarted via init.d or system.d
• Need to be able to recapture events lost, if important
• Limited with respect to communication
• Node processes can fork another process, but can't talk to it without IPC
• Callback model leads to tangled code
Reactive Design Patterns
Node.js Example
var http = require('http');
var counter = 0;
http.createServer(function (req, res) {
counter++;
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Sending response: ' + counter + ' via callback!n');
}).listen(8888, '127.0.0.1');
console.log('Server up on 127.0.0.1:8888, send requests!');
Reactive Design Patterns
Tools of the Trade: CSP
• Communicating Sequential Processes
• Decouples the sender and receiver by leveraging a "channel"
• The underlying principle behind Go's Channels and Clojure's
core.async
• Theoretically able to statically verify a deadlock will occur at
compilation time, though no popular implementation does currently
does this
• No inherent ability to send messages in a distributed environment
• No supervision for fault tolerance
Reactive Design Patterns
Go Example
package main
import (
"fmt"
"time"
)
func main() {
iterations := 10
myChannel := make(chan int)
go producer(myChannel, iterations)
go consumer(myChannel, iterations)
time.Sleep(500 * time.Millisecond)
}
func producer(myChannel chan int, iterations int) {
for i := 1; i <= iterations; i++ {
fmt.Println("Sending: ", i)
myChannel <- i
}
}
func consumer(myChannel chan int, iterations int) {
for i := 1; i <= iterations; i++ {
recVal := <-myChannel
fmt.Println("Received: ", recVal)
}
}
Reactive Design Patterns
Futures
• Allow you to define behavior that will be executed on another thread
at some time
• In some languages, responses can be handled with callbacks or
higher-order functions (map, flatMap), and can be composed into
complex interactions
• Not supervised, but do allow explicit fault tolerance via failure
callback definition
Reactive Design Patterns
Java8 CompletableFuture Example
package org.reactivedesignpatterns.chapter2.future;
import java.util.concurrent.CompletableFuture;
import java.util.function.Supplier;
public class ParallelRetrievalExample {
final CacheRetriever cacheRetriever;
final DBRetriever dbRetriever;
ParallelRetrievalExample(CacheRetriever cacheRetriever,
DBRetriever dbRetriever) {
this.cacheRetriever = cacheRetriever;
this.dbRetriever = dbRetriever;
}
public Object retrieveCustomer(final long id) {
final CompletableFuture<Object> cacheFuture = CompletableFuture
.supplyAsync(() -> {
return cacheRetriever.getCustomer(id);
});
final CompletableFuture<Object> dbFuture = CompletableFuture
.supplyAsync(() -> {
return dbRetriever.getCustomer(id);
});
return CompletableFuture.anyOf(cacheFuture, dbFuture);
}
}
Reactive Design Patterns
Tools of the Trade: CPS and Dataflow
• Take asynchronous operations and compose them into steps of
execution, like a pipeline
• Application logic looks synchronous and clean, compiled into code
that executes asynchronously
• Maintains order of execution
• Do not scale across machines
• Can be supervised, but failure handling can depend on tool you
choose
• The platform matters
• Green threads/processes (aka fibers) mean less context switching, but
also more complex management of failures
Reactive Design Patterns
Tools of the Trade: Reactive Extensions
(RX)
• Combine the Iterator and Observer patterns into the Observable
• Excellent mechanism for handling streams of data
• Fault tolerance depends on implementation
• Reactive Streams (http://www.reactive-streams.org/)
• Introduced the requirement for handling backpressure in overwhelmed
systems, as well as a test kit to prove compliance.
• Consortium includes Lightbend, Pivotal, Netflix, RedHat, Twitter and
more
• Interoperability is a core abstraction
Reactive Design Patterns
RxJava Example
package org.reactivedesignpatterns.chapter2.rxjava;
import rx.Observable;
import rx.functions.Action1;
public class RxJavaExample {
RxJavaExample() {
}
public void observe(String[] strings) {
Observable.from(strings).subscribe((s) -> {
System.out.println("Received " + s);
});
}
}
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
@RunWith(JUnit4.class)
public class RxJavaExampleTest {
final RxJavaExample rxJavaExample = new RxJavaExample();
@Test
public void testRxJava() {
String[] strings = { "a", "b", "c" };
rxJavaExample.observe(strings);
}
}
Reactive Design Patterns
Tools of the Trade: Actors
• Individual entities that can only communicate by passing messages
• Excellent for isolating mutable state and protecting it without locks
• Location transparency
• Supervision
• Well-suited for creating state machines
• Several implementations, most popular are Erlang and Akka
• Best suited for the physical boundaries in your application
Reactive Design Patterns
Akka Example
class MySupervisor extends Actor {
// Define how to handle failures in a child
override def supervisorStrategy = OneForOneStrategy() {
case badJson: InvalidJsonException => {
saveInvalidJson(badJson)
Resume
}
case _: BadConnection => Escalate
case _ => Restart
}
// Create the child under me
val child = context.actorOf(Props[JsonHandlerAndPersister])
// Handle any messages I may receive
def receive = {
case _ =>
}
}
Reactive Design Patterns
Regardless of the
tools you choose,
find ways to build
message-driven,
elastic and resilient
applications that
are responsive to
your users
Questions
?

More Related Content

PPTX
20160524 ibm fast data meetup
PPTX
20160520 The Future of Services
PPT
Sneaking Scala through the Back Door
PDF
Building Information Systems using Event Modeling (Bobby Calderwood, Evident ...
PDF
Stream Collections - Scala Days
PDF
Cloudstate - Towards Stateful Serverless
PDF
The Future of Services: Building Asynchronous, Resilient and Elastic Systems
PDF
Digital Transformation with Kubernetes, Containers, and Microservices
20160524 ibm fast data meetup
20160520 The Future of Services
Sneaking Scala through the Back Door
Building Information Systems using Event Modeling (Bobby Calderwood, Evident ...
Stream Collections - Scala Days
Cloudstate - Towards Stateful Serverless
The Future of Services: Building Asynchronous, Resilient and Elastic Systems
Digital Transformation with Kubernetes, Containers, and Microservices

What's hot (20)

PDF
Effective Akka v2
PPTX
CQRS Evolved - CQRS + Akka.NET
PDF
Syncromatics Akka.NET Case Study
PDF
Model-driven and low-code development for event-based systems | Bobby Calderw...
PPTX
Building FoundationDB
PPTX
Growing into a proactive Data Platform
PPTX
Real-Time Design Patterns
PPTX
Akka for big data developers
DOCX
Net App Architect/Systems Admin
PPTX
FoundationDB - NoSQL and ACID
PPTX
Micro Services Architecture
PPTX
Measure() or die()
PPTX
Liveperson DLD 2015
PDF
Telling the LivePerson Technology Story at Couchbase [SF] 2013
PDF
Transformation During a Global Pandemic | Ashish Pandit and Scott Lee, Univer...
PPTX
NoSQL and ACID
KEY
Stuff About CQRS
PDF
3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ)
PDF
Event Sourcing - Greg Young
PDF
How would ESBs look like, if they were done today.
Effective Akka v2
CQRS Evolved - CQRS + Akka.NET
Syncromatics Akka.NET Case Study
Model-driven and low-code development for event-based systems | Bobby Calderw...
Building FoundationDB
Growing into a proactive Data Platform
Real-Time Design Patterns
Akka for big data developers
Net App Architect/Systems Admin
FoundationDB - NoSQL and ACID
Micro Services Architecture
Measure() or die()
Liveperson DLD 2015
Telling the LivePerson Technology Story at Couchbase [SF] 2013
Transformation During a Global Pandemic | Ashish Pandit and Scott Lee, Univer...
NoSQL and ACID
Stuff About CQRS
3 Ways to Deliver an Elastic, Cost-Effective Cloud Architecture (ANZ)
Event Sourcing - Greg Young
How would ESBs look like, if they were done today.
Ad

Viewers also liked (11)

PDF
NoFlo - Flow-Based Programming for Node.js
PDF
Teasing talk for Flow-based programming made easy with PyF 2.0
PDF
Functional Reactive Programming by Gerold Meisinger
PPTX
Vert.x v3 - high performance polyglot application toolkit
PPTX
vert.x - asynchronous event-driven web applications on the JVM
PDF
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
PPTX
Vert.x vs akka
PDF
Flow Base Programming with Node-RED and Functional Reactive Programming with ...
PPTX
Building Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
PDF
Let it Flow - Introduction to Functional Reactive Programming
PDF
[Lightning talk] Next generation computing with fpga
NoFlo - Flow-Based Programming for Node.js
Teasing talk for Flow-based programming made easy with PyF 2.0
Functional Reactive Programming by Gerold Meisinger
Vert.x v3 - high performance polyglot application toolkit
vert.x - asynchronous event-driven web applications on the JVM
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
Vert.x vs akka
Flow Base Programming with Node-RED and Functional Reactive Programming with ...
Building Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
Let it Flow - Introduction to Functional Reactive Programming
[Lightning talk] Next generation computing with fpga
Ad

Similar to 20160609 nike techtalks reactive applications tools of the trade (20)

PPT
Reactive programming with examples
PPTX
Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
PPTX
Reactive applications tools of the trade huff po
PDF
Reactive - Is it really a Magic Pill?
PPTX
Reactive Design Pattern
PDF
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
PDF
Reactive: Programming -> Systems -> Architecture
PDF
NGRX Apps in Depth
PDF
Get Reactive: Microservices, Programming, and Systems
PDF
Reactive Programming or Reactive Systems? (spoiler: both)
PDF
Reactive systems
PDF
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
PDF
Reactive applications
PDF
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
PDF
Reactive programming
PDF
Moving towards Reactive Programming
PPTX
Reactive for the Impatient - Mary Grygleski
PDF
Reactive Applications in Java
PDF
Reactive applications Linux Day 2013
PDF
Intro To Reactive Programming
Reactive programming with examples
Reactive Fast Data & the Data Lake with Akka, Kafka, Spark
Reactive applications tools of the trade huff po
Reactive - Is it really a Magic Pill?
Reactive Design Pattern
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Reactive: Programming -> Systems -> Architecture
NGRX Apps in Depth
Get Reactive: Microservices, Programming, and Systems
Reactive Programming or Reactive Systems? (spoiler: both)
Reactive systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
Reactive applications
Reactive Design Patterns: a talk by Typesafe's Dr. Roland Kuhn
Reactive programming
Moving towards Reactive Programming
Reactive for the Impatient - Mary Grygleski
Reactive Applications in Java
Reactive applications Linux Day 2013
Intro To Reactive Programming

More from shinolajla (14)

PPTX
20180416 reactive is_a_product_rs
PDF
20180416 reactive is_a_product
PPTX
20161027 scala io_keynote
PDF
20160520 what youneedtoknowaboutlambdas
PDF
20160317 lagom sf scala
PPTX
20150411 mutability matrix of pain scala
PDF
20140228 fp and_performance
PDF
Effective akka scalaio
PDF
Cpu Caches
PDF
Real world akka recepies v3
PDF
Effective actors japanesesub
PDF
Effective Actors
PPTX
Taxonomy of Scala
PPTX
CPU Caches
20180416 reactive is_a_product_rs
20180416 reactive is_a_product
20161027 scala io_keynote
20160520 what youneedtoknowaboutlambdas
20160317 lagom sf scala
20150411 mutability matrix of pain scala
20140228 fp and_performance
Effective akka scalaio
Cpu Caches
Real world akka recepies v3
Effective actors japanesesub
Effective Actors
Taxonomy of Scala
CPU Caches

Recently uploaded (20)

PDF
A review of recent deep learning applications in wood surface defect identifi...
PPTX
Final SEM Unit 1 for mit wpu at pune .pptx
PDF
Credit Without Borders: AI and Financial Inclusion in Bangladesh
PDF
STKI Israel Market Study 2025 version august
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Consumable AI The What, Why & How for Small Teams.pdf
PDF
sbt 2.0: go big (Scala Days 2025 edition)
PPT
What is a Computer? Input Devices /output devices
PDF
A proposed approach for plagiarism detection in Myanmar Unicode text
PPT
Module 1.ppt Iot fundamentals and Architecture
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PPTX
Benefits of Physical activity for teenagers.pptx
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PPTX
Chapter 5: Probability Theory and Statistics
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
DOCX
search engine optimization ppt fir known well about this
PPTX
2018-HIPAA-Renewal-Training for executives
PDF
Getting started with AI Agents and Multi-Agent Systems
A review of recent deep learning applications in wood surface defect identifi...
Final SEM Unit 1 for mit wpu at pune .pptx
Credit Without Borders: AI and Financial Inclusion in Bangladesh
STKI Israel Market Study 2025 version august
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
Hindi spoken digit analysis for native and non-native speakers
Consumable AI The What, Why & How for Small Teams.pdf
sbt 2.0: go big (Scala Days 2025 edition)
What is a Computer? Input Devices /output devices
A proposed approach for plagiarism detection in Myanmar Unicode text
Module 1.ppt Iot fundamentals and Architecture
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
Benefits of Physical activity for teenagers.pptx
sustainability-14-14877-v2.pddhzftheheeeee
Chapter 5: Probability Theory and Statistics
A comparative study of natural language inference in Swahili using monolingua...
Taming the Chaos: How to Turn Unstructured Data into Decisions
search engine optimization ppt fir known well about this
2018-HIPAA-Renewal-Training for executives
Getting started with AI Agents and Multi-Agent Systems

20160609 nike techtalks reactive applications tools of the trade

  • 1. Reactive Design Patterns Tools of the Trade Jamie Allen Sr. Director of Global Services
  • 3. Reactive Design Patterns Implications are massive, change is unavoidable Users are demanding richer and more personalized experiences. Yet, at the same time, expecting blazing fast load time. Users Mobile and HTML5; Data and compute clouds; scaling on demand. Modern application technologies are fueling the always-on, real-time user expectation. Applications Businesses are being pushed to react to these changing user expectations… ...and embrace modern application requirements. Businesses
  • 4. Reactive Design Patterns Reactive applications share four traits
  • 7. Reactive Design Patterns Cost of Not Being Reactive • Cost to your wallet and the environment • No ability to recover from failure • No ability to be responsive to our users
  • 8. Reactive Design Patterns Functional Programming is Key • We want to be asynchronous and non-blocking • We need to ensure that our data is protected without locks • Functional programming is critical to meeting these needs • Declarative • Immutable • Referentially transparent • Pure functions that only have inputs and outputs
  • 9. Reactive Design Patterns Backpressure is required • How can a system withstand variance in load? • What does the system communicate to users of the application when it is overwhelmed? • Companies can lose tremendous amounts of money by not being able to respond to users at all times
  • 10. Reactive Design Patterns Tools of the Trade All code can be found at https://github.com/ReactiveDesignPatterns/Chapter-2
  • 11. Reactive Design Patterns Tools of the Trade: Event Loops • Leverage green threads to provide asynchronous semantics • The core concept of Node.js and Vert.x • Powerful abstraction for performance and potentially scalability • Limited with respect to resilience • One error can take down multiple events • Node.js can only be restarted via init.d or system.d • Need to be able to recapture events lost, if important • Limited with respect to communication • Node processes can fork another process, but can't talk to it without IPC • Callback model leads to tangled code
  • 12. Reactive Design Patterns Node.js Example var http = require('http'); var counter = 0; http.createServer(function (req, res) { counter++; res.writeHead(200, {'Content-Type': 'text/plain'}); res.end('Sending response: ' + counter + ' via callback!n'); }).listen(8888, '127.0.0.1'); console.log('Server up on 127.0.0.1:8888, send requests!');
  • 13. Reactive Design Patterns Tools of the Trade: CSP • Communicating Sequential Processes • Decouples the sender and receiver by leveraging a "channel" • The underlying principle behind Go's Channels and Clojure's core.async • Theoretically able to statically verify a deadlock will occur at compilation time, though no popular implementation does currently does this • No inherent ability to send messages in a distributed environment • No supervision for fault tolerance
  • 14. Reactive Design Patterns Go Example package main import ( "fmt" "time" ) func main() { iterations := 10 myChannel := make(chan int) go producer(myChannel, iterations) go consumer(myChannel, iterations) time.Sleep(500 * time.Millisecond) } func producer(myChannel chan int, iterations int) { for i := 1; i <= iterations; i++ { fmt.Println("Sending: ", i) myChannel <- i } } func consumer(myChannel chan int, iterations int) { for i := 1; i <= iterations; i++ { recVal := <-myChannel fmt.Println("Received: ", recVal) } }
  • 15. Reactive Design Patterns Futures • Allow you to define behavior that will be executed on another thread at some time • In some languages, responses can be handled with callbacks or higher-order functions (map, flatMap), and can be composed into complex interactions • Not supervised, but do allow explicit fault tolerance via failure callback definition
  • 16. Reactive Design Patterns Java8 CompletableFuture Example package org.reactivedesignpatterns.chapter2.future; import java.util.concurrent.CompletableFuture; import java.util.function.Supplier; public class ParallelRetrievalExample { final CacheRetriever cacheRetriever; final DBRetriever dbRetriever; ParallelRetrievalExample(CacheRetriever cacheRetriever, DBRetriever dbRetriever) { this.cacheRetriever = cacheRetriever; this.dbRetriever = dbRetriever; } public Object retrieveCustomer(final long id) { final CompletableFuture<Object> cacheFuture = CompletableFuture .supplyAsync(() -> { return cacheRetriever.getCustomer(id); }); final CompletableFuture<Object> dbFuture = CompletableFuture .supplyAsync(() -> { return dbRetriever.getCustomer(id); }); return CompletableFuture.anyOf(cacheFuture, dbFuture); } }
  • 17. Reactive Design Patterns Tools of the Trade: CPS and Dataflow • Take asynchronous operations and compose them into steps of execution, like a pipeline • Application logic looks synchronous and clean, compiled into code that executes asynchronously • Maintains order of execution • Do not scale across machines • Can be supervised, but failure handling can depend on tool you choose • The platform matters • Green threads/processes (aka fibers) mean less context switching, but also more complex management of failures
  • 18. Reactive Design Patterns Tools of the Trade: Reactive Extensions (RX) • Combine the Iterator and Observer patterns into the Observable • Excellent mechanism for handling streams of data • Fault tolerance depends on implementation • Reactive Streams (http://www.reactive-streams.org/) • Introduced the requirement for handling backpressure in overwhelmed systems, as well as a test kit to prove compliance. • Consortium includes Lightbend, Pivotal, Netflix, RedHat, Twitter and more • Interoperability is a core abstraction
  • 19. Reactive Design Patterns RxJava Example package org.reactivedesignpatterns.chapter2.rxjava; import rx.Observable; import rx.functions.Action1; public class RxJavaExample { RxJavaExample() { } public void observe(String[] strings) { Observable.from(strings).subscribe((s) -> { System.out.println("Received " + s); }); } } import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.JUnit4; @RunWith(JUnit4.class) public class RxJavaExampleTest { final RxJavaExample rxJavaExample = new RxJavaExample(); @Test public void testRxJava() { String[] strings = { "a", "b", "c" }; rxJavaExample.observe(strings); } }
  • 20. Reactive Design Patterns Tools of the Trade: Actors • Individual entities that can only communicate by passing messages • Excellent for isolating mutable state and protecting it without locks • Location transparency • Supervision • Well-suited for creating state machines • Several implementations, most popular are Erlang and Akka • Best suited for the physical boundaries in your application
  • 21. Reactive Design Patterns Akka Example class MySupervisor extends Actor { // Define how to handle failures in a child override def supervisorStrategy = OneForOneStrategy() { case badJson: InvalidJsonException => { saveInvalidJson(badJson) Resume } case _: BadConnection => Escalate case _ => Restart } // Create the child under me val child = context.actorOf(Props[JsonHandlerAndPersister]) // Handle any messages I may receive def receive = { case _ => } }
  • 22. Reactive Design Patterns Regardless of the tools you choose, find ways to build message-driven, elastic and resilient applications that are responsive to your users