20160609 nike techtalks reactive applications tools of the trade

23
Reactive Design Patterns Tools of the Trade Jamie Allen Sr. Director of Global Services

Transcript of 20160609 nike techtalks reactive applications tools of the trade

PowerPoint Presentation

Reactive Design PatternsTools of the TradeJamie AllenSr. Director of Global Services

1

@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

3

Reactive applications share four traits

Reactive Design Patterns

4

Amdahl's Law

Reactive Design Patterns

Reactive Design Patterns

Cost of Not Being ReactiveCost to your wallet and the environmentNo ability to recover from failureNo ability to be responsive to our users

Reactive Design Patterns

Functional Programming is KeyWe want to be asynchronous and non-blockingWe need to ensure that our data is protected without locksFunctional programming is critical to meeting these needsDeclarativeImmutableReferentially transparentPure functions that only have inputs and outputs

Reactive Design Patterns

Backpressure is requiredHow 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 TradeAll code can be found at https://github.com/ReactiveDesignPatterns/Chapter-2

Reactive Design Patterns

Tools of the Trade: Event LoopsLeverage green threads to provide asynchronous semanticsThe core concept of Node.js and Vert.xPowerful abstraction for performance and potentially scalabilityLimited with respect to resilienceOne error can take down multiple eventsNode.js can only be restarted via init.d or system.dNeed to be able to recapture events lost, if importantLimited with respect to communicationNode processes can fork another process, but can't talk to it without IPCCallback model leads to tangled code

Reactive Design Patterns

Node.js Examplevar 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: CSPCommunicating Sequential ProcessesDecouples the sender and receiver by leveraging a "channel"The underlying principle behind Go's Channels and Clojure's core.asyncTheoretically able to statically verify a deadlock will occur at compilation time, though no popular implementation does currently does thisNo inherent ability to send messages in a distributed environmentNo supervision for fault tolerance

Reactive Design Patterns

Go Examplepackage 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 { 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

Reactive Design Patterns

Questions?

23