SlideShare a Scribd company logo
Presenters: Raja Chattopadhyay and Sovon Nath
May 2017
Responsive
ResilientElastic
Message
Driven
Akka is a toolkit used to build applications that are:
§ Concurrent
§ Distributed
§ Fault tolerant
Reactive Programming in Akka
§ Concurrent
systems are able
to process
multiple tasks at
the same time
§ Challenge with
concurrency is
sharing mutable
state.
§ Akka implements
concurrency using
the Actor model
Actor System
Actor 1
Actor 2
ActorRef
class MyActor extends Actor{
def receive = {
case msg =>
println(s"Message received : $msg")
}
}
§ Actor Ref: Each actor is represented by an actor ref.You never get
access to an Actor instance. An actor reference lets you send
messages to the actor
§ Message Dispatcher: The dispatcher enqueues incoming
messages in the mailbox.
§ Mailbox: It’s the piece which connects sender and receiver. Each
actor will have one mail box.
External
Actor Ref
Actor
Message
Dispatcher
Mailbox
Send Message
Dispatch
Runs
Invoke
Supervisor Actor
Child
Actor 1
Actor
Behavior 1
Child
Actor 2
Creates /
Supervises
Sends
message
Actor
Behavior 2Become
Actors can perform the following
actions:
• Send
• Create
• Become
• Supervise
A top level actor can be created
form the ActorSystem and child
actors can be created from another
actors
Sends
message
Reactive Programming in Akka
§ Akka’s philosophy for fault tolerance is “let it crash”.
§ A supervisor doesn’t try to fix the actor or its state. It tries to recover from the
state and deploys a strategy:
§ Resume
§ Restart
§ Stop
§ Escalate
Unlike supervisors, any actor can monitor another actor by calling the watch method
on the ActorRef.The only message that they receive is if the actor terminates.
There can be three events in a lifecycle of an actor:
§ Start
§ Restart
§ Stop
Below are the lifecycle hooks:
class MyActor extends Actor{
override def preStart(): Unit = {
println("Overriding the pre start")
super.preStart()
}
}
Start/Stop Restart
Start Stop
Pre Start Post Stop
StartStopRestart
Pre StartPost StopPre restart Post restart
New
Instance
§ Persistent actors have their states
persisted. Actors are extended from the
PersistentActor
§ It comes with a few built in persistence
plugin: in-memory heap based journal,
local file-system based snapshot-store and
DB based journal.
§ Persistent actors have a persistentId, which
is used to identify the events of an actor
§ A persistent actor can act in two ways:
either recover from events or process
commands
class RetrieveBalance extends PersistentActor {
override def persistenceId = ”1234”
def receiveCommand = …
def receiveRecover = …
}
External
Actor
Actor
Journal
Command
Save Event Event saved
Send Response
Generate
Event
Apply the
Event
Reactive Programming in Akka
§ Members apply for a credit card
§ To approve a credit card, we will look into their bureau details, verification status
and then make a decision (ex ‘Approved’ or ‘Declined’)
§ To gather the information, we will call various actors
Decision App
Actor
Retrieve
Bureau Details
Actor
Retrieve
Verification
Status Actor
Finalize
Decision Actor
Decision Saga
Actor
RetrieveBureau
DetailsActor
RetrieveVerifica
tionStatusActor
FinalizeDecisio
nActorCredit card
Application
Decision Saga
Actor
RetrieveBureau
DetailsActor
RetrieveVerifica
tionStatusActor
FinalizeDecisio
nActor
1
2
Lagom REST:
Will be used to
create an APIs
Akka:
Will be used to
create &
communicate
with actors
Cassandra:
Will be used to
store events
Reactive Programming in Akka
§ Remoting is a way to scale out.This is
achieved by running actors on various
nodes.The nodes interact with each
other using akka-remote module.
§ Remoting provides location
transparency, i.e. the caller is not aware
of the location of the actor. Remote
actors will be called as if, they are local
actors.
§ Remote actors can be referred either by
§ Locally creating the actor and then
deploying it remotely
§ Look up the actor by its path
Sender System (JVM)
Netty
Serialization
Actor Selection
Actor
Receiving System (JVM)
Actor
Serialization
Netty
§ Routers are needed to route messages to different
destination actors.These could be for Performance or
Content of the Message.
§ Akka provides built in router functions.The actor that
represents the router, loads the routing function. Built-
in routers come in two flavors:
§ Pool – The router is responsible for creating the routees
and removing them from the list when they terminate.
§ Group – The routees are created by the system.The
routers use the actor selection to find the routee.
§ Some of the inbuilt routing functions available are:
§ Round Robin
§ Smallest mail box
§ Broadcast
§ Scatter-Gather
Router
Actor
Actor 1
Actor 2
Actor 3
§ Cluster is a collection of nodes
§ Each node has an actor system.The actor
systems have the same name to be a part of the
cluster.
§ A list of member nodes are maintained in the
cluster state
§ The clusters can have two kinds of special
nodes called leader node and seed node.
§ Cluster Sharding – Used to distribute actor
instances over a number of nodes and being
able to determine where they are, by using
their persistence ids.
§ Cluster Singleton – This allows us to indicate
that a single component should only be
running on any one node at a given point of
time.
Joining
Down
Leaving
Exiting
Up
Removed
Unreachable
Join
(leader action)
Leave
(leader action)
(leader action)
(failure detection)
(failure detection)
(failure detection)
(failure detection)
§ Sample Applications
§ Actors using Scala
§ https://github.com/richmondtechies/scalaactors
§ Java Reference Applications with AKKA
§ https://github.com/richmondtechies/decision-app
§ https://github.com/richmondtechies/rewards-update-lagom
§ Reference material:
§ http://akka.io/docs
§ Connect with us:
§ raja.chattopadhyay@capitlone.com
§ sovon.nath@capitalone.com

More Related Content

Similar to Reactive Programming in Akka (20)

PDF
Reactive programming with akka
Webdesign Factory
 
PDF
Building Stateful Microservices With Akka
Yaroslav Tkachenko
 
PDF
Build Cloud Applications with Akka and Heroku
Salesforce Developers
 
PDF
Introduction to Actor Model and Akka
Yung-Lin Ho
 
PPTX
Akka Actors
Dylan Forciea
 
PDF
Akka-intro-training-public.pdf
BernardDeffarges
 
PDF
Actor-based concurrency in a modern Java Enterprise
Alexander Lukyanchikov
 
PDF
Advanced akka features
Grzegorz Duda
 
PDF
Akka (1)
Rahul Shukla
 
PDF
Effective Akka v2
shinolajla
 
PDF
Actor Model Akka Framework
Harinath Krishnamoorthy
 
PPTX
Akka.Net Overview
Geoffrey Vandiest
 
PDF
Building Massively Scalable application with Akka 2.0
Knoldus Inc.
 
PDF
Akka actorstotherescue nirmalya sengupta
apgionline
 
PDF
Akka lsug skills matter
Skills Matter
 
PDF
Scaling Web Apps with Akka
Maciej Matyjas
 
PDF
Effective Akka v2.0 - Jamie Allen
JAXLondon_Conference
 
PDF
Akka Remoting and Clustering: an Introduction
Roberto Casadei
 
PDF
Introduction to Akka
Knoldus Inc.
 
PDF
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Lightbend
 
Reactive programming with akka
Webdesign Factory
 
Building Stateful Microservices With Akka
Yaroslav Tkachenko
 
Build Cloud Applications with Akka and Heroku
Salesforce Developers
 
Introduction to Actor Model and Akka
Yung-Lin Ho
 
Akka Actors
Dylan Forciea
 
Akka-intro-training-public.pdf
BernardDeffarges
 
Actor-based concurrency in a modern Java Enterprise
Alexander Lukyanchikov
 
Advanced akka features
Grzegorz Duda
 
Akka (1)
Rahul Shukla
 
Effective Akka v2
shinolajla
 
Actor Model Akka Framework
Harinath Krishnamoorthy
 
Akka.Net Overview
Geoffrey Vandiest
 
Building Massively Scalable application with Akka 2.0
Knoldus Inc.
 
Akka actorstotherescue nirmalya sengupta
apgionline
 
Akka lsug skills matter
Skills Matter
 
Scaling Web Apps with Akka
Maciej Matyjas
 
Effective Akka v2.0 - Jamie Allen
JAXLondon_Conference
 
Akka Remoting and Clustering: an Introduction
Roberto Casadei
 
Introduction to Akka
Knoldus Inc.
 
Akka A to Z: A Guide To The Industry’s Best Toolkit for Fast Data and Microse...
Lightbend
 

More from DevFest DC (12)

PDF
Push Notifications Or: How I Learned to Stop Worrying and Love NotificationCo...
DevFest DC
 
PDF
Containers, microservices and azure
DevFest DC
 
PDF
Programming Google apps with the G Suite APIs
DevFest DC
 
PDF
Snowflakes in the Cloud Real world experience on a new approach for Big Data
DevFest DC
 
PDF
Well, That Escalated Quickly: Anomaly Detection with Elastic Machine Learning
DevFest DC
 
PDF
Why uri storage and the modern android app
DevFest DC
 
PDF
Myths of Angular 2: What Angular Really Is
DevFest DC
 
PDF
Android Things Robocar with TensorFlow for object recognition
DevFest DC
 
PDF
Troubleshooting & debugging production microservices in Kubernetes with Googl...
DevFest DC
 
PDF
Hack the Real World with ANDROID THINGS
DevFest DC
 
PDF
Using Cloud Vision To Watch The World’s News Imagery In Realtime: The GDELT P...
DevFest DC
 
PDF
Teaching machines to see the process of designing (datasets) with ai
DevFest DC
 
Push Notifications Or: How I Learned to Stop Worrying and Love NotificationCo...
DevFest DC
 
Containers, microservices and azure
DevFest DC
 
Programming Google apps with the G Suite APIs
DevFest DC
 
Snowflakes in the Cloud Real world experience on a new approach for Big Data
DevFest DC
 
Well, That Escalated Quickly: Anomaly Detection with Elastic Machine Learning
DevFest DC
 
Why uri storage and the modern android app
DevFest DC
 
Myths of Angular 2: What Angular Really Is
DevFest DC
 
Android Things Robocar with TensorFlow for object recognition
DevFest DC
 
Troubleshooting & debugging production microservices in Kubernetes with Googl...
DevFest DC
 
Hack the Real World with ANDROID THINGS
DevFest DC
 
Using Cloud Vision To Watch The World’s News Imagery In Realtime: The GDELT P...
DevFest DC
 
Teaching machines to see the process of designing (datasets) with ai
DevFest DC
 
Ad

Recently uploaded (20)

PDF
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
PDF
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
Cerebraix Technologies
 
PPTX
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
PDF
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
PDF
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
PPTX
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
PPTX
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
PPTX
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
PPTX
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
PPT
introduction to networking with basics coverage
RamananMuthukrishnan
 
PDF
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
PPTX
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
PDF
The Internet - By the numbers, presented at npNOG 11
APNIC
 
DOCX
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
PDF
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
PPTX
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
PDF
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
PPTX
Orchestrating things in Angular application
Peter Abraham
 
PDF
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
PPT
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
The-Hidden-Dangers-of-Skipping-Penetration-Testing.pdf.pdf
naksh4thra
 
Boardroom AI: The Next 10 Moves | Cerebraix Talent Tech
Cerebraix Technologies
 
Lec15_Mutability Immutability-converted.pptx
khanjahanzaib1
 
Cleaning up your RPKI invalids, presented at PacNOG 35
APNIC
 
AI_MOD_1.pdf artificial intelligence notes
shreyarrce
 
04 Output 1 Instruments & Tools (3).pptx
GEDYIONGebre
 
Presentation3gsgsgsgsdfgadgsfgfgsfgagsfgsfgzfdgsdgs.pptx
SUB03
 
L1A Season 1 Guide made by A hegy Eng Grammar fixed
toszolder91
 
法国巴黎第二大学本科毕业证{Paris 2学费发票Paris 2成绩单}办理方法
Taqyea
 
introduction to networking with basics coverage
RamananMuthukrishnan
 
BRKACI-1001 - Your First 7 Days of ACI.pdf
fcesargonca
 
ONLINE BIRTH CERTIFICATE APPLICATION SYSYTEM PPT.pptx
ShyamasreeDutta
 
The Internet - By the numbers, presented at npNOG 11
APNIC
 
Custom vs. Off-the-Shelf Banking Software
KristenCarter35
 
Build Fast, Scale Faster: Milvus vs. Zilliz Cloud for Production-Ready AI
Zilliz
 
Softuni - Psychology of entrepreneurship
Kalin Karakehayov
 
𝐁𝐔𝐊𝐓𝐈 𝐊𝐄𝐌𝐄𝐍𝐀𝐍𝐆𝐀𝐍 𝐊𝐈𝐏𝐄𝐑𝟒𝐃 𝐇𝐀𝐑𝐈 𝐈𝐍𝐈 𝟐𝟎𝟐𝟓
hokimamad0
 
Orchestrating things in Angular application
Peter Abraham
 
BRKACI-1003 ACI Brownfield Migration - Real World Experiences and Best Practi...
fcesargonca
 
Agilent Optoelectronic Solutions for Mobile Application
andreashenniger2
 
Ad

Reactive Programming in Akka

  • 1. Presenters: Raja Chattopadhyay and Sovon Nath May 2017
  • 3. Akka is a toolkit used to build applications that are: § Concurrent § Distributed § Fault tolerant
  • 5. § Concurrent systems are able to process multiple tasks at the same time § Challenge with concurrency is sharing mutable state. § Akka implements concurrency using the Actor model Actor System Actor 1 Actor 2 ActorRef class MyActor extends Actor{ def receive = { case msg => println(s"Message received : $msg") } }
  • 6. § Actor Ref: Each actor is represented by an actor ref.You never get access to an Actor instance. An actor reference lets you send messages to the actor § Message Dispatcher: The dispatcher enqueues incoming messages in the mailbox. § Mailbox: It’s the piece which connects sender and receiver. Each actor will have one mail box. External Actor Ref Actor Message Dispatcher Mailbox Send Message Dispatch Runs Invoke
  • 7. Supervisor Actor Child Actor 1 Actor Behavior 1 Child Actor 2 Creates / Supervises Sends message Actor Behavior 2Become Actors can perform the following actions: • Send • Create • Become • Supervise A top level actor can be created form the ActorSystem and child actors can be created from another actors Sends message
  • 9. § Akka’s philosophy for fault tolerance is “let it crash”. § A supervisor doesn’t try to fix the actor or its state. It tries to recover from the state and deploys a strategy: § Resume § Restart § Stop § Escalate Unlike supervisors, any actor can monitor another actor by calling the watch method on the ActorRef.The only message that they receive is if the actor terminates.
  • 10. There can be three events in a lifecycle of an actor: § Start § Restart § Stop Below are the lifecycle hooks: class MyActor extends Actor{ override def preStart(): Unit = { println("Overriding the pre start") super.preStart() } } Start/Stop Restart Start Stop Pre Start Post Stop StartStopRestart Pre StartPost StopPre restart Post restart New Instance
  • 11. § Persistent actors have their states persisted. Actors are extended from the PersistentActor § It comes with a few built in persistence plugin: in-memory heap based journal, local file-system based snapshot-store and DB based journal. § Persistent actors have a persistentId, which is used to identify the events of an actor § A persistent actor can act in two ways: either recover from events or process commands class RetrieveBalance extends PersistentActor { override def persistenceId = ”1234” def receiveCommand = … def receiveRecover = … } External Actor Actor Journal Command Save Event Event saved Send Response Generate Event Apply the Event
  • 13. § Members apply for a credit card § To approve a credit card, we will look into their bureau details, verification status and then make a decision (ex ‘Approved’ or ‘Declined’) § To gather the information, we will call various actors Decision App Actor Retrieve Bureau Details Actor Retrieve Verification Status Actor Finalize Decision Actor
  • 14. Decision Saga Actor RetrieveBureau DetailsActor RetrieveVerifica tionStatusActor FinalizeDecisio nActorCredit card Application Decision Saga Actor RetrieveBureau DetailsActor RetrieveVerifica tionStatusActor FinalizeDecisio nActor 1 2
  • 15. Lagom REST: Will be used to create an APIs Akka: Will be used to create & communicate with actors Cassandra: Will be used to store events
  • 17. § Remoting is a way to scale out.This is achieved by running actors on various nodes.The nodes interact with each other using akka-remote module. § Remoting provides location transparency, i.e. the caller is not aware of the location of the actor. Remote actors will be called as if, they are local actors. § Remote actors can be referred either by § Locally creating the actor and then deploying it remotely § Look up the actor by its path Sender System (JVM) Netty Serialization Actor Selection Actor Receiving System (JVM) Actor Serialization Netty
  • 18. § Routers are needed to route messages to different destination actors.These could be for Performance or Content of the Message. § Akka provides built in router functions.The actor that represents the router, loads the routing function. Built- in routers come in two flavors: § Pool – The router is responsible for creating the routees and removing them from the list when they terminate. § Group – The routees are created by the system.The routers use the actor selection to find the routee. § Some of the inbuilt routing functions available are: § Round Robin § Smallest mail box § Broadcast § Scatter-Gather Router Actor Actor 1 Actor 2 Actor 3
  • 19. § Cluster is a collection of nodes § Each node has an actor system.The actor systems have the same name to be a part of the cluster. § A list of member nodes are maintained in the cluster state § The clusters can have two kinds of special nodes called leader node and seed node. § Cluster Sharding – Used to distribute actor instances over a number of nodes and being able to determine where they are, by using their persistence ids. § Cluster Singleton – This allows us to indicate that a single component should only be running on any one node at a given point of time. Joining Down Leaving Exiting Up Removed Unreachable Join (leader action) Leave (leader action) (leader action) (failure detection) (failure detection) (failure detection) (failure detection)
  • 20. § Sample Applications § Actors using Scala § https://github.com/richmondtechies/scalaactors § Java Reference Applications with AKKA § https://github.com/richmondtechies/decision-app § https://github.com/richmondtechies/rewards-update-lagom § Reference material: § http://akka.io/docs § Connect with us: § [email protected] § [email protected]