introduction to reactive
DESCRIPTION
The slides from the first Boston Reactive Software Meetup: Introduction to ReactiveTRANSCRIPT
![Page 1: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/1.jpg)
Boston Reactive Software Meetup
![Page 2: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/2.jpg)
Presented by !
Steven Pember Principal Consultant , Technical Architect at Cantina
David Fox Principal Consultant , Technical Architect at Cantina
Introduction to Reactive
!2
![Page 3: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/3.jpg)
!3
What is Reactive?
![Page 4: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/4.jpg)
!4
What is Reactive?A buzzword
![Page 5: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/5.jpg)
!5
What is Reactive?A popular (comp) science buzzword
![Page 6: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/6.jpg)
!6
Written by Jonas Bonér with contributions by Erik Meijer, Martin Odersky, Greg Young, Martin Thompson, Roland Kuhn, James Ward and Guillaume Bort.
The Reactive Manifesto
![Page 7: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/7.jpg)
!7
1. WAY more traffic than just a few years ago
2. Users expect immediate response
3. Need 100% uptime
4. Large amounts of data
5. Need better models of concurrency
6. Old models like servlet showing their age
tl;dr
![Page 8: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/8.jpg)
!8
These are the traits they use to describe this class of software.
The Four Traits
![Page 9: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/9.jpg)
!9
Note how they play off one another to form a cohesive whole
The Four Traits
![Page 10: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/10.jpg)
!10
There should really be a couple more traits…
The Missing Traits
changeable
![Page 11: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/11.jpg)
!11
There should really be a couple more traits…
The Missing Traits
changeable
managable
![Page 12: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/12.jpg)
not just from Typesafe!
Reactive Technologies
!12
![Page 13: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/13.jpg)
!13
These are all “Reactive” technologies
![Page 14: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/14.jpg)
!14
These are all “Reactive” technologiesReactive isn’t about particular technologies,
it’s a holistic view of application architecture to support the needs of the current generation of applications
![Page 15: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/15.jpg)
!15
As developers, we need to see the whole picture of the application, from the front-end to the back-end. It’s
not enough to just use a “reactive framework”.
![Page 16: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/16.jpg)
HTTP for Akka Actors
Spray Framework
!16
![Page 17: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/17.jpg)
!17
• De-facto Actor implementation for Scala
• Replaced Scala’s actor implementation
• Team wanted to keep Scala smaller
• Better as a separate framework
• Used as basis of Play and Spray and many
other frameworks
Akka
![Page 18: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/18.jpg)
!18
• Invented in 1973 by Carl Hewitt, Peter
Bishop, and Richard Steiger at MIT's AI lab
• A design pattern for concurrency
• Encapsulates state and behavior
• Alleviates the need for locks
• Allows work to be scheduled fairly
Actor Model
![Page 19: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/19.jpg)
!19
How do actors work?
![Page 20: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/20.jpg)
!20
Message is placed into the actor’s mailbox
Actor Receives Message
![Page 21: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/21.jpg)
!21
The actor system’s scheduler schedules the actor to run in a thread. !
The actor processes a message according to its behavior
Actor Scheduled
![Page 22: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/22.jpg)
!22
The actor state is modified. !
The scheduler will continue to fairly schedule the actor to run while its mailbox has messages.
Execution Complete
![Page 23: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/23.jpg)
!23
Akka’s actors also have supervision strategies for failure
![Page 24: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/24.jpg)
!24
• By default, when an actor crashes, it will simply be restarted by the system !
• Other strategies can be employed such as: • Resume keeping state • Resume clearing state • Terminate the actor permanently • Escalate, failing the supervising actor
Supervision
![Page 25: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/25.jpg)
!25
• Finite state machine mixin • Typed actor proxy for integration with non-
actor-based code • Location transparency / clustering • Support for event/command sourcing
Other Features
![Page 26: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/26.jpg)
!26
What Are the Drawbacks?• Programming with actors is more difficult • Type safety is lost • Not as easy to compose
![Page 27: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/27.jpg)
!27
• Synchronization constructs/patterns
• Allow use of values which will be eventually
available at a later point in time
• Terms sometimes used interchangeably
• A promise is a container to write a value to
• A future is a handle used to read that value
Promises & Futures
![Page 28: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/28.jpg)
Live coding demo
Spray Framework
!28
![Page 29: Introduction to Reactive](https://reader033.vdocuments.us/reader033/viewer/2022051411/547a8b82b4af9f8f5e8b491f/html5/thumbnails/29.jpg)
!29
Cantina is a digital agency that plans, designs and builds connected experiences
and product innovations.