SlideShare a Scribd company logo
Akka
Rahul Shukla
rahul.shukla@synerzip.com
Why ?
Application requirements have changed
New requirements
Apps in the 60s-90s were written for Apps today are written for
Single machines Clusters of machines
Single core processors Multicore processors
Expensive RAM Cheap RAM
Expensive disk Cheap disk
Slow networks Fast networks
Few concurrent users Lots of concurrent users
Small data sets Large data sets
Latency in seconds Latency in milliseconds
As a matter of necessity,businesses are going
Reactive
Akka (1)
Responsive
● Real-time, engaging, rich and collaborative
○ Create an open and ongoing dialog with users
○ More efficient workflow; inspires a feeling of connectedness
○ Fully Reactive enabling push instead of pull
Elastic
● Scalability and elasticity to embrace the Cloud
○ Leverage all cores via asynchronous programming
○ Clustered servers support joining and leaving of nodes
○ More cost-efficient utilization of hardware
Resilient
● Failure is embraced as a natural state in the app lifecycle
○ Resilience is a first-class construct
○ Failure is detected, isolated, and managed
○ Applications self heal
Message-Driven
● Loosely coupled architecture, easier to extend, maintain, evolve
○ Asynchronous and non-blocking
○ Concurrent by design, immutable state
○ Lower latency and higher throughput
What?
Introducing Akka
The name comes from the goddess in the Sami
(native swedes) mythology that represented all
the wisdom and beauty in the world.
It is also the name of a beautiful mountain in
Laponia in the north part of Sweden
● Message - Driven
● Concurrency
● Scalability (Elastic)
● Fault Tolerance (Resilient)
Vision
Manage System Overload
Scale Up & Scale Out
Program at higher level
● Never think in terms of shared state, state visibility, threads,
locks, concurrent collections, thread notifications etc.
● Low level concurrency plumbing BECOMES SIMPLE
WORKFLOW - you only think about how messages flow in
the system
● You get high CPU utilization, low latency, high throughput
and scalability - FOR FREE as part of the model
● Proven and superior model for detecting and recovering
from errors
Distributable by Design
● Actors are location transparent & distributable by design
● Scale UP and OUT for free as part of the model
● You get the PERFECT FABRIC for the CLOUD
○ elastic & dynamic
○ fault-tolerant & self-healing
○ adaptive load-balancing, cluster rebalancing & actor
migration
○ build extremely loosely coupled and dynamic systems
that can change and adapt at runtime
How
Can we achieve this ?
Actor
What is an Actor ?
● Akka's unit of code organization is called an Actor
● Actors helps you create concurrent, scalable and fault-
tolerant applications
● Like Java EE servlets and session beans, Actors is a model
for organizing your code that keeps many “policy
decisions” separate from the business logic
● Actors may be new to many in the Java community, but
they are a tried-and-true concept (Hewitt 1973) used for
many years in telecom systems with 9 nines uptime
What can I use Actors for ?
● In different scenarios, an Actor may be an alternative to: -
○ a thread
○ an object instance or component
○ a callback or listener
○ a singleton or service
○ a router, load-balancer or pool
○ a Java EE Session Bean or Message-Driven Bean
Carl Hewitt’s definition
- The fundamental unit of computation that embodies:
- Processing
- Storage
- Communication
- 3 axioms - When an Actor receives a message it can:
- Create new Actors
- Send messages to Actors it knows
- Designate how it should handle the next message it
receives
Let’s Code
Define an actor
Scala : import akka.actor._
import bank.Bank.Balance
object Bank {
case class Balance(number: String)
def props(name: String): Props = { return Props(Bank(name)) }
}
case class Bank(name: String) extends AbstractLoggingActor {
def balance(number: String) = { //Do Something }
override def receive = {
case Balance(number) => balance(number)
}
}
Define an actor
Java : public class Bank extends AbstractLoggingActor {
public static Props props(String name) {
return Props.create(Bank.class, () -> new Bank(name));
}
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return ReceiveBuilder
.match(Balance.class, b -> balance(b.number))
.build();}
private void balance(String number) {
//DO Something
}
}
Create an actor
• CREATE - creates a new instance of an Actor
• Extremely lightweight (2.7 Million per Gb RAM)
• Very strong encapsulation - encapsulates:
- state
- behavior
- message queue
• State & behavior is indistinguishable from each other
• Only way to observe state is by sending an actor a
message and see how it reacts
Create an actor
Scala : val system = ActorSystem("Bank")
val bank = system.actorOf(Bank.props("Central Bank"),”CBNK”)
Java :
ActorSystem system = ActorSystem.create("Bank");
ActorRef bank = system.actorOf(Bank.props("Central Bank"),”CBNK”);
Actors hierarchies
Bank
User System
/Bank
CBNK /Bank/user/CBNK
/Bank/system/Bank/user
SEND
• SEND - sends a message to an Actor
• Asynchronous and Non-blocking - Fire-forget
• Everything happens Reactively
- An Actor is passive until a message is sent to it,which
triggers something within the Actor
- Messages is the Kinetic Energy in an Actor system
- Actors can have lots of buffered Potential Energy but
can't do anything with it until it is triggered by a
message
• EVERYTHING is asynchronous and lockless
SEND
Scala : bank ! Bank.Balance(“12345”)
Java : bank.tell(new Bank.Balance(“12345”), ActorRef.noSender());
SEND
Anatomy of an Actor
● Each actor is represented by an ActorRef
● Each actor is has a mailbox and a dispatcher
● Only one message at a time is passed to the actor
REPLY
Scala : override def receive = {
case Balance(number) => sender ! "Message"
}
Java :
@Override
public PartialFunction<Object, BoxedUnit> receive() {
return ReceiveBuilder
.match(Balance.class, b -> sender().tell(“Message”,self()))
.build();}
SUPERVISE (Fault Tolerance)
SUPERVISE - manage another Actor’s failures
● Error handling in actors is handle by letting Actors
monitor (supervise) each other for failure
● This means that if an Actor crashes, a notification will
be sent to his supervisor, who can react upon the
failure
● This provides clean separation of processing and
error handling
Supervise
Scala : override def supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10,
withinTimeRange = 1 minute) {
case _: Account.OverdrawException => Resume
case _: Exception => Restart
}
Java :
@Override
public SupervisorStrategy supervisorStrategy() {
return new OneForOneStrategy(DeciderBuilder
.match(Account.OverdrawException.class, c -> SupervisorStrategy.
resume())
.match(Exception.class, c -> SupervisorStrategy.escalate())
.build());
}
Manage Failure
Scala : @throws[Exception](classOf[Exception])
override def preStart(): Unit = ???
@throws[Exception](classOf[Exception])
override def postRestart(reason: Throwable): Unit = ???
@throws[Exception](classOf[Exception])
override def postStop(): Unit = ???
Manage Failure
Java : @Override
public void preRestart(Throwable reason, Option<Object> message) throws
Exception {
// Handle here
}
@Override
public void postRestart(Throwable reason) throws Exception {
// Handle here
}
@Override
public void postStop() throws Exception {
// Handle here
}
Supervisor Strategies
● Akka ships with two highly configurable supervisor
strategies:
○ OneForOneStrategy: Only the faulty child is
affected when it fails
○ AllForOneStrategy: All children are affected when
one child fails
Supervisor Strategy Directives
● Resume: Simply resume message processing
● Restart:
○ Transparently replace affected actor(s) with new
instance(s)
○ Then resume message processing
● Stop: Stop affected actor(s)
● Escalate: Delegate the decision to the supervisor's
parent
Load Balancing (Elastic)
Concurrency vs. Parallelism
● Two or more tasks are concurrent, if the order in which
they get executed in time is not predetermined
● In other words, concurrency introduces non-determinism
● Concurrent tasks may or may not get executed in parallel
● Concurrent programming is primarily concerned with the
complexity that arises due to non-deterministic control
flow
● Parallel programming aims at improving throughput and
making control flow deterministic
Akka (1)
Routers
Scala : context.actorOf(RoundRobinPool(5).props(SomeActor.props()),"some-actor")
Java :
getContext().actorOf(new RoundRobinPool(5).props(SomeActor.props()),"
some-actor");
Routing Strategies provided by Akka
● RandomRoutingLogic
● RoundRobinRoutingLogic
● SmallestMailboxRoutingLogic
● ConsistentHashingRoutingLogic
● BroadcastRoutingLogic
● ScatterGatherFirstCompletedRoutingLogic
● To write your own routing strategy, extend RoutingLogic:
● Attention: The implementation must be thread-safe!
Thanks

More Related Content

What's hot

Redux workshop
Redux workshopRedux workshop
Redux workshop
Imran Sayed
 
Intro to React
Intro to ReactIntro to React
Intro to React
Eric Westfall
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
Mohammed Fazuluddin
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
洪 鹏发
 
State Models for React with Redux
State Models for React with ReduxState Models for React with Redux
State Models for React with Redux
Stephan Schmidt
 
Ngrx: Redux in angular
Ngrx: Redux in angularNgrx: Redux in angular
Ngrx: Redux in angular
Saadnoor Salehin
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
Christoffer Noring
 
ReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to AwesomenessReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to Awesomeness
Ronny Haase
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
Eric Deng
 
Getting Started with NgRx (Redux) Angular
Getting Started with NgRx (Redux) AngularGetting Started with NgRx (Redux) Angular
Getting Started with NgRx (Redux) Angular
Gustavo Costa
 
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Marcin Mieszek
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobX
Darko Kukovec
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
Remo Jansen
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
Arno Lordkronos
 
Scaling React and Redux at IOOF
Scaling React and Redux at IOOFScaling React and Redux at IOOF
Scaling React and Redux at IOOF
Vivian Farrell
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
Visual Engineering
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
Emanuele DelBono
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
ANKUSH CHAVAN
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
Ritesh Mehrotra
 
React – Structure Container Component In Meteor
 React – Structure Container Component In Meteor React – Structure Container Component In Meteor
React – Structure Container Component In Meteor
Designveloper
 

What's hot (20)

Redux workshop
Redux workshopRedux workshop
Redux workshop
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
React JS - A quick introduction tutorial
React JS - A quick introduction tutorialReact JS - A quick introduction tutorial
React JS - A quick introduction tutorial
 
[Final] ReactJS presentation
[Final] ReactJS presentation[Final] ReactJS presentation
[Final] ReactJS presentation
 
State Models for React with Redux
State Models for React with ReduxState Models for React with Redux
State Models for React with Redux
 
Ngrx: Redux in angular
Ngrx: Redux in angularNgrx: Redux in angular
Ngrx: Redux in angular
 
Ngrx slides
Ngrx slidesNgrx slides
Ngrx slides
 
ReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to AwesomenessReactJS - A quick introduction to Awesomeness
ReactJS - A quick introduction to Awesomeness
 
20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native20180518 QNAP Seminar - Introduction to React Native
20180518 QNAP Seminar - Introduction to React Native
 
Getting Started with NgRx (Redux) Angular
Getting Started with NgRx (Redux) AngularGetting Started with NgRx (Redux) Angular
Getting Started with NgRx (Redux) Angular
 
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
Mobx for Dummies - Yauheni Nikanowich - React Warsaw #5
 
React state management with Redux and MobX
React state management with Redux and MobXReact state management with Redux and MobX
React state management with Redux and MobX
 
React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥React + Redux + TypeScript === ♥
React + Redux + TypeScript === ♥
 
Introduction to React JS
Introduction to React JSIntroduction to React JS
Introduction to React JS
 
Scaling React and Redux at IOOF
Scaling React and Redux at IOOFScaling React and Redux at IOOF
Scaling React and Redux at IOOF
 
Workshop 22: React-Redux Middleware
Workshop 22: React-Redux MiddlewareWorkshop 22: React-Redux Middleware
Workshop 22: React-Redux Middleware
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
React-JS Component Life-cycle Methods
React-JS Component Life-cycle MethodsReact-JS Component Life-cycle Methods
React-JS Component Life-cycle Methods
 
Its time to React.js
Its time to React.jsIts time to React.js
Its time to React.js
 
React – Structure Container Component In Meteor
 React – Structure Container Component In Meteor React – Structure Container Component In Meteor
React – Structure Container Component In Meteor
 

Viewers also liked

Journey to the Modern App with Containers, Microservices and Big Data
Journey to the Modern App with Containers, Microservices and Big DataJourney to the Modern App with Containers, Microservices and Big Data
Journey to the Modern App with Containers, Microservices and Big Data
Lightbend
 
RM nº 070 2017-MINEDU. Cumplimiento de calendarización año escolar 2017
RM nº 070 2017-MINEDU. Cumplimiento de calendarización año escolar 2017RM nº 070 2017-MINEDU. Cumplimiento de calendarización año escolar 2017
RM nº 070 2017-MINEDU. Cumplimiento de calendarización año escolar 2017
lancelott
 
Ganges-Kobadak Irrigation Project
Ganges-Kobadak Irrigation ProjectGanges-Kobadak Irrigation Project
Ganges-Kobadak Irrigation Project
Seemanto
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Mario Fusco
 
Teesta Barrage Project
Teesta Barrage ProjectTeesta Barrage Project
Teesta Barrage Project
M A Rouf Badsha
 
Ignite Presentation
Ignite PresentationIgnite Presentation
Ignite Presentation
Hope Cunningham
 
Frases de Psicologia
Frases de PsicologiaFrases de Psicologia
Frases de Psicologia
Maria Cristina Santos Araujo
 
AXIS BANK INTERNSHIP
AXIS BANK INTERNSHIPAXIS BANK INTERNSHIP
AXIS BANK INTERNSHIP
Harmanjeet Singh Sandhu
 
Use Cases for Elastic Search Percolator
Use Cases for Elastic Search PercolatorUse Cases for Elastic Search Percolator
Use Cases for Elastic Search Percolator
Maxim Shelest
 
Webcast presentation 1-28-2014
Webcast presentation   1-28-2014Webcast presentation   1-28-2014
Webcast presentation 1-28-2014
visainc
 
Test chaside
Test chasideTest chaside
Test chaside
TUTORIAprepa10
 
Akka and the Zen of Reactive System Design
Akka and the Zen of Reactive System DesignAkka and the Zen of Reactive System Design
Akka and the Zen of Reactive System Design
Lightbend
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaExploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Lightbend
 
Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)
Jonas Bonér
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
Jonas Bonér
 
Omar x. avelar &amp; j. daniel mayoral conversion analogica a digital
Omar x. avelar &amp; j. daniel mayoral   conversion analogica a digitalOmar x. avelar &amp; j. daniel mayoral   conversion analogica a digital
Omar x. avelar &amp; j. daniel mayoral conversion analogica a digital
jesús cabrera
 
Understanding farmer uptake of climate-smart technologies: gender and social ...
Understanding farmer uptake of climate-smart technologies: gender and social ...Understanding farmer uptake of climate-smart technologies: gender and social ...
Understanding farmer uptake of climate-smart technologies: gender and social ...
CCAFS | CGIAR Research Program on Climate Change, Agriculture and Food Security
 
Without Resilience, Nothing Else Matters
Without Resilience, Nothing Else MattersWithout Resilience, Nothing Else Matters
Without Resilience, Nothing Else Matters
Jonas Bonér
 

Viewers also liked (18)

Journey to the Modern App with Containers, Microservices and Big Data
Journey to the Modern App with Containers, Microservices and Big DataJourney to the Modern App with Containers, Microservices and Big Data
Journey to the Modern App with Containers, Microservices and Big Data
 
RM nº 070 2017-MINEDU. Cumplimiento de calendarización año escolar 2017
RM nº 070 2017-MINEDU. Cumplimiento de calendarización año escolar 2017RM nº 070 2017-MINEDU. Cumplimiento de calendarización año escolar 2017
RM nº 070 2017-MINEDU. Cumplimiento de calendarización año escolar 2017
 
Ganges-Kobadak Irrigation Project
Ganges-Kobadak Irrigation ProjectGanges-Kobadak Irrigation Project
Ganges-Kobadak Irrigation Project
 
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STMConcurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
Concurrency, Scalability & Fault-tolerance 2.0 with Akka Actors & STM
 
Teesta Barrage Project
Teesta Barrage ProjectTeesta Barrage Project
Teesta Barrage Project
 
Ignite Presentation
Ignite PresentationIgnite Presentation
Ignite Presentation
 
Frases de Psicologia
Frases de PsicologiaFrases de Psicologia
Frases de Psicologia
 
AXIS BANK INTERNSHIP
AXIS BANK INTERNSHIPAXIS BANK INTERNSHIP
AXIS BANK INTERNSHIP
 
Use Cases for Elastic Search Percolator
Use Cases for Elastic Search PercolatorUse Cases for Elastic Search Percolator
Use Cases for Elastic Search Percolator
 
Webcast presentation 1-28-2014
Webcast presentation   1-28-2014Webcast presentation   1-28-2014
Webcast presentation 1-28-2014
 
Test chaside
Test chasideTest chaside
Test chaside
 
Akka and the Zen of Reactive System Design
Akka and the Zen of Reactive System DesignAkka and the Zen of Reactive System Design
Akka and the Zen of Reactive System Design
 
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache KafkaExploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
 
Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)Building Reactive Systems with Akka (in Java 8 or Scala)
Building Reactive Systems with Akka (in Java 8 or Scala)
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
 
Omar x. avelar &amp; j. daniel mayoral conversion analogica a digital
Omar x. avelar &amp; j. daniel mayoral   conversion analogica a digitalOmar x. avelar &amp; j. daniel mayoral   conversion analogica a digital
Omar x. avelar &amp; j. daniel mayoral conversion analogica a digital
 
Understanding farmer uptake of climate-smart technologies: gender and social ...
Understanding farmer uptake of climate-smart technologies: gender and social ...Understanding farmer uptake of climate-smart technologies: gender and social ...
Understanding farmer uptake of climate-smart technologies: gender and social ...
 
Without Resilience, Nothing Else Matters
Without Resilience, Nothing Else MattersWithout Resilience, Nothing Else Matters
Without Resilience, Nothing Else Matters
 

Similar to Akka (1)

Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
Yaroslav Tkachenko
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
shinolajla
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
Peter Lawrey
 
Building Reactive System with Akka
Building  Reactive System with AkkaBuilding  Reactive System with Akka
Building Reactive System with Akka
Lam Nguyen
 
The Road To Redux
The Road To ReduxThe Road To Redux
The Road To Redux
Jeffrey Sanchez
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
Salesforce Developers
 
Going Reactive with Spring 5
Going Reactive with Spring 5Going Reactive with Spring 5
Going Reactive with Spring 5
Drazen Nikolic
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
Mohanraj Thirumoorthy
 
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Elixir Club
 
Rx Swift
Rx SwiftRx Swift
Rx Swift
Vincenzo Favara
 
Building stateful serverless orchestrations with Azure Durable Azure Function...
Building stateful serverless orchestrations with Azure Durable Azure Function...Building stateful serverless orchestrations with Azure Durable Azure Function...
Building stateful serverless orchestrations with Azure Durable Azure Function...
Callon Campbell
 
Getting started with React and Redux
Getting started with React and ReduxGetting started with React and Redux
Getting started with React and Redux
Paddy Lock
 
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
MSDEVMTL
 
NetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talksNetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talks
Ruslan Meshenberg
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
Walking Tree Technologies
 
Introduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with ClojurescriptIntroduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with Clojurescript
John Stevenson
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Rick Hightower
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Rick Hightower
 
Reactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.xReactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.x
Ram Maddali
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
Skills Matter
 

Similar to Akka (1) (20)

Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Building Reactive System with Akka
Building  Reactive System with AkkaBuilding  Reactive System with Akka
Building Reactive System with Akka
 
The Road To Redux
The Road To ReduxThe Road To Redux
The Road To Redux
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
Going Reactive with Spring 5
Going Reactive with Spring 5Going Reactive with Spring 5
Going Reactive with Spring 5
 
Developing Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's GuideDeveloping Microservices using Spring - Beginner's Guide
Developing Microservices using Spring - Beginner's Guide
 
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
Performance measurement methodology — Maksym Pugach | Elixir Evening Club 3
 
Rx Swift
Rx SwiftRx Swift
Rx Swift
 
Building stateful serverless orchestrations with Azure Durable Azure Function...
Building stateful serverless orchestrations with Azure Durable Azure Function...Building stateful serverless orchestrations with Azure Durable Azure Function...
Building stateful serverless orchestrations with Azure Durable Azure Function...
 
Getting started with React and Redux
Getting started with React and ReduxGetting started with React and Redux
Getting started with React and Redux
 
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
Stephane Lapointe & Alexandre Brisebois: Développer des microservices avec Se...
 
NetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talksNetflixOSS Open House Lightning talks
NetflixOSS Open House Lightning talks
 
Understanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree TechnologiesUnderstanding React hooks | Walkingtree Technologies
Understanding React hooks | Walkingtree Technologies
 
Introduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with ClojurescriptIntroduction to Functional Reactive Web with Clojurescript
Introduction to Functional Reactive Web with Clojurescript
 
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
 
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
 
Reactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.xReactive microservices with eclipse vert.x
Reactive microservices with eclipse vert.x
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
 

More from Rahul Shukla

intro-kafka
intro-kafkaintro-kafka
intro-kafka
Rahul Shukla
 
Advance RCP
Advance RCPAdvance RCP
Advance RCP
Rahul Shukla
 
Advance JFACE
Advance JFACEAdvance JFACE
Advance JFACE
Rahul Shukla
 
Jface
JfaceJface
Introduction_To_SWT_Rahul_Shukla
Introduction_To_SWT_Rahul_ShuklaIntroduction_To_SWT_Rahul_Shukla
Introduction_To_SWT_Rahul_Shukla
Rahul Shukla
 
Eclipse_Building_Blocks
Eclipse_Building_BlocksEclipse_Building_Blocks
Eclipse_Building_Blocks
Rahul Shukla
 

More from Rahul Shukla (6)

intro-kafka
intro-kafkaintro-kafka
intro-kafka
 
Advance RCP
Advance RCPAdvance RCP
Advance RCP
 
Advance JFACE
Advance JFACEAdvance JFACE
Advance JFACE
 
Jface
JfaceJface
Jface
 
Introduction_To_SWT_Rahul_Shukla
Introduction_To_SWT_Rahul_ShuklaIntroduction_To_SWT_Rahul_Shukla
Introduction_To_SWT_Rahul_Shukla
 
Eclipse_Building_Blocks
Eclipse_Building_BlocksEclipse_Building_Blocks
Eclipse_Building_Blocks
 

Akka (1)

  • 5. Apps in the 60s-90s were written for Apps today are written for Single machines Clusters of machines Single core processors Multicore processors Expensive RAM Cheap RAM Expensive disk Cheap disk Slow networks Fast networks Few concurrent users Lots of concurrent users Small data sets Large data sets Latency in seconds Latency in milliseconds
  • 6. As a matter of necessity,businesses are going Reactive
  • 8. Responsive ● Real-time, engaging, rich and collaborative ○ Create an open and ongoing dialog with users ○ More efficient workflow; inspires a feeling of connectedness ○ Fully Reactive enabling push instead of pull
  • 9. Elastic ● Scalability and elasticity to embrace the Cloud ○ Leverage all cores via asynchronous programming ○ Clustered servers support joining and leaving of nodes ○ More cost-efficient utilization of hardware
  • 10. Resilient ● Failure is embraced as a natural state in the app lifecycle ○ Resilience is a first-class construct ○ Failure is detected, isolated, and managed ○ Applications self heal
  • 11. Message-Driven ● Loosely coupled architecture, easier to extend, maintain, evolve ○ Asynchronous and non-blocking ○ Concurrent by design, immutable state ○ Lower latency and higher throughput
  • 13. The name comes from the goddess in the Sami (native swedes) mythology that represented all the wisdom and beauty in the world. It is also the name of a beautiful mountain in Laponia in the north part of Sweden
  • 14. ● Message - Driven ● Concurrency ● Scalability (Elastic) ● Fault Tolerance (Resilient) Vision
  • 16. Scale Up & Scale Out
  • 18. ● Never think in terms of shared state, state visibility, threads, locks, concurrent collections, thread notifications etc. ● Low level concurrency plumbing BECOMES SIMPLE WORKFLOW - you only think about how messages flow in the system ● You get high CPU utilization, low latency, high throughput and scalability - FOR FREE as part of the model ● Proven and superior model for detecting and recovering from errors
  • 20. ● Actors are location transparent & distributable by design ● Scale UP and OUT for free as part of the model ● You get the PERFECT FABRIC for the CLOUD ○ elastic & dynamic ○ fault-tolerant & self-healing ○ adaptive load-balancing, cluster rebalancing & actor migration ○ build extremely loosely coupled and dynamic systems that can change and adapt at runtime
  • 22. Actor What is an Actor ?
  • 23. ● Akka's unit of code organization is called an Actor ● Actors helps you create concurrent, scalable and fault- tolerant applications ● Like Java EE servlets and session beans, Actors is a model for organizing your code that keeps many “policy decisions” separate from the business logic ● Actors may be new to many in the Java community, but they are a tried-and-true concept (Hewitt 1973) used for many years in telecom systems with 9 nines uptime
  • 24. What can I use Actors for ?
  • 25. ● In different scenarios, an Actor may be an alternative to: - ○ a thread ○ an object instance or component ○ a callback or listener ○ a singleton or service ○ a router, load-balancer or pool ○ a Java EE Session Bean or Message-Driven Bean
  • 27. - The fundamental unit of computation that embodies: - Processing - Storage - Communication - 3 axioms - When an Actor receives a message it can: - Create new Actors - Send messages to Actors it knows - Designate how it should handle the next message it receives
  • 29. Define an actor Scala : import akka.actor._ import bank.Bank.Balance object Bank { case class Balance(number: String) def props(name: String): Props = { return Props(Bank(name)) } } case class Bank(name: String) extends AbstractLoggingActor { def balance(number: String) = { //Do Something } override def receive = { case Balance(number) => balance(number) } }
  • 30. Define an actor Java : public class Bank extends AbstractLoggingActor { public static Props props(String name) { return Props.create(Bank.class, () -> new Bank(name)); } @Override public PartialFunction<Object, BoxedUnit> receive() { return ReceiveBuilder .match(Balance.class, b -> balance(b.number)) .build();} private void balance(String number) { //DO Something } }
  • 31. Create an actor • CREATE - creates a new instance of an Actor • Extremely lightweight (2.7 Million per Gb RAM) • Very strong encapsulation - encapsulates: - state - behavior - message queue • State & behavior is indistinguishable from each other • Only way to observe state is by sending an actor a message and see how it reacts
  • 32. Create an actor Scala : val system = ActorSystem("Bank") val bank = system.actorOf(Bank.props("Central Bank"),”CBNK”) Java : ActorSystem system = ActorSystem.create("Bank"); ActorRef bank = system.actorOf(Bank.props("Central Bank"),”CBNK”);
  • 33. Actors hierarchies Bank User System /Bank CBNK /Bank/user/CBNK /Bank/system/Bank/user
  • 34. SEND • SEND - sends a message to an Actor • Asynchronous and Non-blocking - Fire-forget • Everything happens Reactively - An Actor is passive until a message is sent to it,which triggers something within the Actor - Messages is the Kinetic Energy in an Actor system - Actors can have lots of buffered Potential Energy but can't do anything with it until it is triggered by a message • EVERYTHING is asynchronous and lockless
  • 35. SEND Scala : bank ! Bank.Balance(“12345”) Java : bank.tell(new Bank.Balance(“12345”), ActorRef.noSender());
  • 36. SEND
  • 37. Anatomy of an Actor ● Each actor is represented by an ActorRef ● Each actor is has a mailbox and a dispatcher ● Only one message at a time is passed to the actor
  • 38. REPLY Scala : override def receive = { case Balance(number) => sender ! "Message" } Java : @Override public PartialFunction<Object, BoxedUnit> receive() { return ReceiveBuilder .match(Balance.class, b -> sender().tell(“Message”,self())) .build();}
  • 39. SUPERVISE (Fault Tolerance) SUPERVISE - manage another Actor’s failures ● Error handling in actors is handle by letting Actors monitor (supervise) each other for failure ● This means that if an Actor crashes, a notification will be sent to his supervisor, who can react upon the failure ● This provides clean separation of processing and error handling
  • 40. Supervise Scala : override def supervisorStrategy = OneForOneStrategy(maxNrOfRetries = 10, withinTimeRange = 1 minute) { case _: Account.OverdrawException => Resume case _: Exception => Restart } Java : @Override public SupervisorStrategy supervisorStrategy() { return new OneForOneStrategy(DeciderBuilder .match(Account.OverdrawException.class, c -> SupervisorStrategy. resume()) .match(Exception.class, c -> SupervisorStrategy.escalate()) .build()); }
  • 41. Manage Failure Scala : @throws[Exception](classOf[Exception]) override def preStart(): Unit = ??? @throws[Exception](classOf[Exception]) override def postRestart(reason: Throwable): Unit = ??? @throws[Exception](classOf[Exception]) override def postStop(): Unit = ???
  • 42. Manage Failure Java : @Override public void preRestart(Throwable reason, Option<Object> message) throws Exception { // Handle here } @Override public void postRestart(Throwable reason) throws Exception { // Handle here } @Override public void postStop() throws Exception { // Handle here }
  • 43. Supervisor Strategies ● Akka ships with two highly configurable supervisor strategies: ○ OneForOneStrategy: Only the faulty child is affected when it fails ○ AllForOneStrategy: All children are affected when one child fails
  • 44. Supervisor Strategy Directives ● Resume: Simply resume message processing ● Restart: ○ Transparently replace affected actor(s) with new instance(s) ○ Then resume message processing ● Stop: Stop affected actor(s) ● Escalate: Delegate the decision to the supervisor's parent
  • 46. Concurrency vs. Parallelism ● Two or more tasks are concurrent, if the order in which they get executed in time is not predetermined ● In other words, concurrency introduces non-determinism ● Concurrent tasks may or may not get executed in parallel ● Concurrent programming is primarily concerned with the complexity that arises due to non-deterministic control flow ● Parallel programming aims at improving throughput and making control flow deterministic
  • 48. Routers Scala : context.actorOf(RoundRobinPool(5).props(SomeActor.props()),"some-actor") Java : getContext().actorOf(new RoundRobinPool(5).props(SomeActor.props())," some-actor");
  • 49. Routing Strategies provided by Akka ● RandomRoutingLogic ● RoundRobinRoutingLogic ● SmallestMailboxRoutingLogic ● ConsistentHashingRoutingLogic ● BroadcastRoutingLogic ● ScatterGatherFirstCompletedRoutingLogic ● To write your own routing strategy, extend RoutingLogic: ● Attention: The implementation must be thread-safe!