Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Beyond the buzzword: a reactive web-appliction in practice

This talk & live-coding session gives an insight into the why, what and how of reactive applications, and web-applications in particular. The first part is theoretical, whilst the second part is a live-coding session introducing the Play Framework, Akka and the Scala programming language all whilst demonstrating reactive patterns such as Futures, Actors, Pipes and Circuit Breakers.

  • Login to see the comments

Beyond the buzzword: a reactive web-appliction in practice

  1. 1. 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
  2. 2. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  3. 3. 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
  4. 4. 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
  5. 5. 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
  6. 6. Reac%ve applica%ons: why, what Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  7. 7. Root cause 1: evolu&on of so+ware architecture Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  8. 8. "Good old days" architecture Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  9. 9. "3 $er" architecture Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  10. 10. "Cloud" architecture Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  11. 11. "Microservices" architecture Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  12. 12. => Increasing amount of network I/O Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  13. 13. => Increasing amount of network I/O Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  14. 14. Root cause 2: evolu.on of hardware Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  15. 15. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  16. 16. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  17. 17. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  18. 18. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  19. 19. 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
  20. 20. What reac)ve ? Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  21. 21. Reac%ve systems are distributed systems (they're a subset thereof) Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  22. 22. What's the main difference between a distributed system and a non- distributed system? Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  23. 23. 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 ones Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  24. 24. Failure Failure is a first-class ci.zen in reac.ve systems. They're designed for failure. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  25. 25. Handling failure Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  26. 26. 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
  27. 27. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  28. 28. 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
  29. 29. 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
  30. 30. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  31. 31. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  32. 32. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  33. 33. Reac%ve architectural pa/ern h"p://www.reac,vemanifesto.org Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  34. 34. 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
  35. 35. Let's build a small Reac0ve Web Applica0on Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  36. 36. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  37. 37. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  38. 38. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  39. 39. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  40. 40. 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
  41. 41. CODING Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  42. 42. Futures scala.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
  43. 43. Pipe akka.pattern.pipe • bridge between Futures and Actors • implemented as anonymous actor Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  44. 44. Pipe akka.pattern.pipe • bridge between Futures and Actors • implemented as anonymous actor Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  45. 45. Circuit Breaker akka.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
  46. 46. Deployment Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  47. 47. 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
  48. 48. 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
  49. 49. Deployment • fully managed opera0ons • auto scalability feature (horizontal & ver0cal) • a<rac0ve pricing Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  50. 50. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  51. 51. Load tes)ng Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  52. 52. 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
  53. 53. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  54. 54. 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
  55. 55. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  56. 56. Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  57. 57. Bees with machine guns Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  58. 58. 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
  59. 59. Configuring all the things ~/.boto [Credentials] aws_access_key_id = foobar1 aws_secret_access_key = foobar2 [Boto] debug = 2 Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  60. 60. A"ack! Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu
  61. 61. Thank you! Ques%ons & Comments ? • h#p://manuel.bernhardt.io • manuel@bernhardt.io • @elmanu Enterprise JUG September 2016 Linz - manuel.bernhardt.io - @elmanu

×