61
Beyond the buzzword: a reac%ve web applica*on in prac*ce Manuel Bernhardt - @elmanu Enterprise Java User Group Linz - September 2016 Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Beyond the buzzword: a reactive web-appliction in practice

Embed Size (px)

Citation preview

Page 1: Beyond the buzzword: a reactive web-appliction in practice

Beyond the buzzword:

a reac%ve web applica*on in prac*ce

Manuel Bernhardt - @elmanu

Enterprise Java User Group Linz - September 2016

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 2: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 3: Beyond the buzzword: a reactive web-appliction in practice

Agenda

1. Reac've applica'ons: why, what

2. Small Reac've Web Applica'on

3. Deployment & Load tes'ng

If you have a ques-on, shoot!

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 4: Beyond the buzzword: a reactive web-appliction in practice

Manuel Bernhardt

• I help mid-sized telecommunica4ons and technology companies ge7ng started with reac4ve microservice-based systems to speed up and scale IT delivery

• h=p://manuel.bernhardt.io

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 5: Beyond the buzzword: a reactive web-appliction in practice

Manuel Bernhardt

• I help mid-sized telecommunica4ons and technology companies ge7ng started with reac4ve microservice-based systems to speed up and scale IT delivery

• h=p://manuel.bernhardt.io

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 6: Beyond the buzzword: a reactive web-appliction in practice

Reac%ve applica%ons: why, what

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 7: Beyond the buzzword: a reactive web-appliction in practice

Root cause 1:evolu&on of so+ware architecture

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 8: Beyond the buzzword: a reactive web-appliction in practice

"Good old days" architecture

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 9: Beyond the buzzword: a reactive web-appliction in practice

"3 $er" architecture

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 10: Beyond the buzzword: a reactive web-appliction in practice

"Cloud" architecture

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 11: Beyond the buzzword: a reactive web-appliction in practice

"Microservices" architecture

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 12: Beyond the buzzword: a reactive web-appliction in practice

=> Increasing amount of network I/O

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 13: Beyond the buzzword: a reactive web-appliction in practice

=> Increasing amount of network I/O

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 14: Beyond the buzzword: a reactive web-appliction in practice

Root cause 2: evolu.on of hardware

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 15: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 16: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 17: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 18: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 19: Beyond the buzzword: a reactive web-appliction in practice

Why reac)ve ?

1. Distributed systems are the rule, not the excep1on

2. Programming needs to acknowledge the existance of many hardware threads, the lost opportunity of not using it & the cost of locking

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 20: Beyond the buzzword: a reactive web-appliction in practice

What reac)ve ?

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 21: Beyond the buzzword: a reactive web-appliction in practice

Reac%ve systems are distributed systems

(they're a subset thereof)

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 22: Beyond the buzzword: a reactive web-appliction in practice

What's the main difference between a distributed system and a non-

distributed system?

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 23: Beyond the buzzword: a reactive web-appliction in practice

What's the main difference between a distributed system and a non-

distributed system?

Distributed systems fail much more o-en (and in much stranger ways)

than non-distributed onesEnterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 24: Beyond the buzzword: a reactive web-appliction in practice

FailureFailure is a first-class ci.zen in reac.ve systems. They're designed for failure.

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 25: Beyond the buzzword: a reactive web-appliction in practice

Handling failure

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 26: Beyond the buzzword: a reactive web-appliction in practice

Handling failure• checked excep*ons are a terrible idea in the context of reac*ve /

distributed systems

• languages, tools and pa<erns for streamlining failure handling: Func*onal Programming, Futures, Message Passing

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 27: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 28: Beyond the buzzword: a reactive web-appliction in practice

Don't try to hide the network!• CORBA, RPC & friends: trying to abstract away the network

• what happens when the network call

• ... fails

• ... is slow

• ... is some%mes slow

• ... someAmes fails, someAmes doesn't

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 29: Beyond the buzzword: a reactive web-appliction in practice

Don't try to hide the network!

• ignoring of the Fallacies of Distributed Compu8ng (Deutsch & Gosling)

• ignoring the CAP theorem

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 30: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 31: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 32: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 33: Beyond the buzzword: a reactive web-appliction in practice

Reac%ve architectural pa/ern

h"p://www.reac,vemanifesto.org

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 34: Beyond the buzzword: a reactive web-appliction in practice

Reac%ve Systems - Conclusion

• Reac&ve Systems are designed for failure

• Reac&ve Systems are distributed, replicated accross several nodes (can scale up and down)

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 35: Beyond the buzzword: a reactive web-appliction in practice

Let's build a small Reac0ve Web Applica0on

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 36: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 37: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 38: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 39: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 40: Beyond the buzzword: a reactive web-appliction in practice

Actors

• lightweight objects

• send and receive messages (mailbox)

• can have children (supervision)

"Long-lived" async computa5on

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 41: Beyond the buzzword: a reactive web-appliction in practice

CODING

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 42: Beyond the buzzword: a reactive web-appliction in practice

Futuresscala.concurrent.Future[T]

• holds a value of type T

• can either fail or succeed

• async code does not block a thread while wai8ng for comple8on

"Short-lived" async computa6on

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 43: Beyond the buzzword: a reactive web-appliction in practice

Pipeakka.pattern.pipe

• bridge between Futures and Actors

• implemented as anonymous actor

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 44: Beyond the buzzword: a reactive web-appliction in practice

Pipeakka.pattern.pipe

• bridge between Futures and Actors

• implemented as anonymous actor

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 45: Beyond the buzzword: a reactive web-appliction in practice

Circuit Breakerakka.pattern.CircuitBreaker

• helpful when dealing with legacy / slow systems & prevents cascading failure

• like an electric circuit breaker, trips when there's a surge

• trips a=er a given number of failures, for a given >meout, then a?empts reset

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 46: Beyond the buzzword: a reactive web-appliction in practice

DeploymentEnterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 47: Beyond the buzzword: a reactive web-appliction in practice

Deployment• stand-alone vs. "elas/c deployment"

• elas/c, fault-tolerant is not trivial

• use a managed service / solu/on

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 48: Beyond the buzzword: a reactive web-appliction in practice

Deployment

• Lightbend ConductR

• automated cluster management for Play / Akka / ... applica>ons

• automated node failure & network par++on resolu+on

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 49: Beyond the buzzword: a reactive web-appliction in practice

Deployment

• fully managed opera0ons

• auto scalability feature (horizontal & ver0cal)

• a<rac0ve pricing

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 50: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 51: Beyond the buzzword: a reactive web-appliction in practice

Load tes)ngEnterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 52: Beyond the buzzword: a reactive web-appliction in practice

Gatling

• open-source load tes0ng framework

• built with Scala, Akka and Ne=y

• two phases: record and run

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 53: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 54: Beyond the buzzword: a reactive web-appliction in practice

Gatling simula,on file// ...setUp( scn.inject( nothingFor(4 seconds), rampUsers(100) over(10 seconds), atOnceUsers(10), constantUsersPerSec(2) during(15 seconds) randomized, splitUsers(500) into ( rampUsers(50) over(10 seconds) ) separatedBy(2 seconds) ).protocols(httpProtocol))

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 55: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 56: Beyond the buzzword: a reactive web-appliction in practice

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 57: Beyond the buzzword: a reactive web-appliction in practice

Bees with machine guns

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 58: Beyond the buzzword: a reactive web-appliction in practice

Configuring all the things

• Installing Python & bees with machine guns

• AWS console (keys, security group w/ SSH access)

• boto config file

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 59: Beyond the buzzword: a reactive web-appliction in practice

Configuring all the things

~/.boto

[Credentials]aws_access_key_id = foobar1aws_secret_access_key = foobar2

[Boto]debug = 2

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 60: Beyond the buzzword: a reactive web-appliction in practice

A"ack!

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

Page 61: Beyond the buzzword: a reactive web-appliction in practice

Thank you!Ques%ons & Comments ?

• h#p://manuel.bernhardt.io

[email protected]

• @elmanu

Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu