SlideShare a Scribd company logo
Building
Reactive System
with Akka
Nguyen Tung LamSepteni Technology
Scala Hanoi Meetup 2018
Who am I?
● Facebook: https://www.facebook.com/lam.nguyentung
● Email: lam_nt@septeni-technology.jp
● UET - VNU
● Java/Scala developer
Agenda
● Reactive System: What/Why ?
● How to build the “Reactive System” ?
○ Akka Framework
○ Actor model
○ Demo
What is the “Reactive System” ?
What is the “Reactive System” ?
ReactiveX
Reactive
Why we need the “Reactive System” ?
In the past
● Nodes: 10s
● Response time: x seconds
● Maintenance downtime: hours
● Data volume: Gbs
Today
● Nodes: 1000x
● Response time: milliseconds
● Maintenance downtimes:
○ zero ->100% up time
● Data volume: TBs -> PBs
What is Tumblr's technology stack?
Reactive System are
Responsive
● The system responds in a timely manner if at all possible.
● Realtime user interface
● Recover quickly from failures
○ Software
○ Hardware
○ Network
● Needed:
○ Loose coupling
○ Supervisor hierarchies
Resilient
● The system stays responsive under varying workload.
● The system can react to changes in the input rate by increasing
or decreasing the resources allocated to service these inputs.
Elastic
Message Driven
● The system rely on asynchronous message-passing to establish a
boundary between components that ensures
○ loose coupling
○ Isolation
○ location transparency.
How to build the “Reactive System” ?
What is the Akka?
https://akka.io/
- A framework and runtime engine for building reactive system on
JVM
- Implement the Actor model
- Simple concurrent & Distributed systems
- Resilient by design
- Elastic & Decentralized
- Higher performance
- 50 million msg/sec on a single machine
- 2.5 million actors per GB of heap
- Written in Scala language, has Scala and Java binding
Why we need the Actor model ?
Object Oriented Programming
● Encapsulation: Internal data of an object is not accessible directly from the outside.
Object Oriented Programming (Next)
● Using lock to solve the problem
● But:
○ Lock seriously limit concurrency (Caller thread is blocked, it
cannot do any other work)
○ Deadlock?
Actor Model
● Actor are asynchronous and non-blocking
○ Communicate only via message passing
○ Lock-free concurrency
○ Have a mailbox for inbound messages
○ Always process message in order
Actor Model
Actor Model
● Actor live in hierarchy
○ Actor can create other actors
○ Used for supervising: Fault tolerance
● Actor have a reference
○ Using actor ref (phone number)
How to create the Actor with Akka?
case class Greeting(who: String)
class GreetingActor extends Actor with ActorLogging {
override def receive: Receive = {
case Greeting(who) => println(s"Hello $who")
}
}
object Main extends App {
val system = ActorSystem("MySystem")
val greeter = system.actorOf(Props[GreetingActor], name = "greeter")
greeter ! Greeting("Scala")
}
Simple example
Java vs Scala
Resilience: Dealing with failure
● Supervision
○ Restart
○ Resume
○ Stop
○ Escalate
● Supervisor strategies
○ One-for-one
○ All-for-one
Akka Supervision
class WorkerActor extends Actor {
override def receive: Receive = {
case Greeting(who) =>
println(s"Hello $who")
case Crash(exception) =>
crash(exception)
}
def crash(how: String): Unit = {
how match {
case "arithmetic" => throw new
ArithmeticException
case "null" => throw new
NullPointerException
case "illegal" => throw new
IllegalArgumentException
case _ => throw new Exception
}
}
class MasterActor extends Actor {
override def receive: Receive = {
case Create(props, name) =>
context.actorOf(props, name)
}
override val supervisorStrategy:
SupervisorStrategy = {
AllForOneStrategy(maxNrOfRetries =
5, withinTimeRange = 10 seconds) {
case _: ArithmeticException =>
Resume
case _: NullPointerException =>
Restart
case _: IllegalArgumentException
=> Stop
case _: Exception => Escalate
}
Elasticity: Create multiple instance of Actor
● Define a router
val router: ActorRef =
context.actorOf(RoundRobinPool(5).props(Props[WorkerActor]), "router")
● Configuration file
akka.actor.deployment {
/parent/router1 {
router = round-robin-pool
nr-of-instances = 5
}
}
Elastic: Create multiple instance of Actor
val router = {
val routees =
Vector.fill(NUMBER_OF_WORKER) {
val r =
context.actorOf(Props(classOf[ExecuteOp
erationRuleWorker], ioContextManager))
context watch r
ActorRefRoutee(r)
}
Router(AccountIdRoutingLogic(),
routees)
}
class AccountIdRoutingLogic extends
RoutingLogic {
val next = new AtomicLong
override def select(message: Any,
routees: immutable.IndexedSeq[Routee]):
Routee =
if (routees.nonEmpty) {
val size = routees.size
val operationRuleMessage =
message.asInstanceOf[ExecuteOperationRule
]
val index =
operationRuleMessage.account.identifier.v
alue
routees((index % size).toInt)
} else {
NoRoutee
}
}
Elasticity: Actor Cluster
Elasticity: Actor Cluster
akka {
actor {
provider = cluster
}
cluster {
seed-nodes = ["akka.tcp://AkkaClusterDemo@127.0.0.1:2551"]
# roles = ["role"]
}
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = ${args.host}
port = ${args.port}
}
}
}
Thanks you!

More Related Content

PPTX
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
PDF
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 
PDF
Asynchronous javascript
Eman Mohamed
 
PDF
Load test REST APIs using gatling
Jayaram Sankaranarayanan
 
PDF
Gatling Performance Workshop
Sai Krishna
 
PDF
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
PDF
Effective java item 80 prefer executors, tasks, and streams to threads
Isaac Liao
 
PDF
Callable and runnable objects in ruby
Rahul Bajaj
 
An introduction to Object Oriented JavaScript
TO THE NEW | Technology
 
Reactive programming using rx java & akka actors - pdx-scala - june 2014
Thomas Lockney
 
Asynchronous javascript
Eman Mohamed
 
Load test REST APIs using gatling
Jayaram Sankaranarayanan
 
Gatling Performance Workshop
Sai Krishna
 
Streams, Streams Everywhere! An Introduction to Rx
Andrzej Sitek
 
Effective java item 80 prefer executors, tasks, and streams to threads
Isaac Liao
 
Callable and runnable objects in ruby
Rahul Bajaj
 

What's hot (20)

PDF
What is in that image
Debarko De
 
PDF
A low Overhead Per Object Write Barrier for Smalltalk
ESUG
 
PPTX
Advanced Javascript
Dhruvin Shah
 
ODP
JavaScript global object, execution contexts & closures
HDR1001
 
PDF
Advanced JavaScript - Internship Presentation - Week6
Devang Garach
 
PDF
Three Lessons about Gatling and Microservices
Dragos Manolescu
 
PPTX
Reactive
Pranav E K
 
PDF
Clojure & Scala
Diego Pacheco
 
PPTX
Gatling Tool in Action at Devoxx 2012
slandelle
 
PDF
Dynamically Composing Collection Operations through Collection Promises
Marcus Denker
 
PPT
Final keyword in java
Lovely Professional University
 
ODP
Drilling the Async Library
Knoldus Inc.
 
ODP
Introduction of Object Oriented JavaScript
NexThoughts Technologies
 
PDF
Gatling @ Scala.Io 2013
slandelle
 
PPTX
Gatling overview
Viral Jain
 
PPT
Asynchronous Programming in C# - Part 1
Mindfire Solutions
 
PDF
Angular Testing
Kourosh Sajjadi
 
PDF
SubScript: A Process Algebra extension progress and perspectives
Anatolii Kmetiuk
 
PPTX
Introduction to RxJS
Abul Hasan
 
PPTX
Node
Ankit Chawla
 
What is in that image
Debarko De
 
A low Overhead Per Object Write Barrier for Smalltalk
ESUG
 
Advanced Javascript
Dhruvin Shah
 
JavaScript global object, execution contexts & closures
HDR1001
 
Advanced JavaScript - Internship Presentation - Week6
Devang Garach
 
Three Lessons about Gatling and Microservices
Dragos Manolescu
 
Reactive
Pranav E K
 
Clojure & Scala
Diego Pacheco
 
Gatling Tool in Action at Devoxx 2012
slandelle
 
Dynamically Composing Collection Operations through Collection Promises
Marcus Denker
 
Final keyword in java
Lovely Professional University
 
Drilling the Async Library
Knoldus Inc.
 
Introduction of Object Oriented JavaScript
NexThoughts Technologies
 
Gatling @ Scala.Io 2013
slandelle
 
Gatling overview
Viral Jain
 
Asynchronous Programming in C# - Part 1
Mindfire Solutions
 
Angular Testing
Kourosh Sajjadi
 
SubScript: A Process Algebra extension progress and perspectives
Anatolii Kmetiuk
 
Introduction to RxJS
Abul Hasan
 
Ad

Similar to Building Reactive System with Akka (20)

PDF
Reactive Programming With Akka - Lessons Learned
Daniel Sawano
 
PDF
Akka (1)
Rahul Shukla
 
PDF
Introduction to Actor Model and Akka
Yung-Lin Ho
 
PDF
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Jonas Bonér
 
ODP
Reactive programming with scala and akka
Knoldus Inc.
 
PDF
Introducing Akka
Meetu Maltiar
 
PDF
Reactive programming with akka
Sovon Nath
 
PDF
Reactive Programming in Akka
DevFest DC
 
PDF
Spring Boot Microservices vs Akka Actor Cluster
OpenCredo
 
PDF
Reactive programming with akka
Webdesign Factory
 
PDF
Akka in Action: Heiko Seeburger
JAX London
 
PDF
Building Stateful Microservices With Akka
Yaroslav Tkachenko
 
PDF
Agile Lab_BigData_Meetup_AKKA
Paolo Platter
 
PDF
Akka lsug skills matter
Skills Matter
 
PDF
Scaling Web Apps with Akka
Maciej Matyjas
 
PPTX
Орхан Гасимов: "Reactive Applications in Java with Akka"
Anna Shymchenko
 
PDF
Actor-based concurrency in a modern Java Enterprise
Alexander Lukyanchikov
 
PDF
Basics of Akka
佑介 九岡
 
PDF
Designing Reactive Systems with Akka
Thomas Lockney
 
PDF
Akka Made Our Day
Daniel Sawano
 
Reactive Programming With Akka - Lessons Learned
Daniel Sawano
 
Akka (1)
Rahul Shukla
 
Introduction to Actor Model and Akka
Yung-Lin Ho
 
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Jonas Bonér
 
Reactive programming with scala and akka
Knoldus Inc.
 
Introducing Akka
Meetu Maltiar
 
Reactive programming with akka
Sovon Nath
 
Reactive Programming in Akka
DevFest DC
 
Spring Boot Microservices vs Akka Actor Cluster
OpenCredo
 
Reactive programming with akka
Webdesign Factory
 
Akka in Action: Heiko Seeburger
JAX London
 
Building Stateful Microservices With Akka
Yaroslav Tkachenko
 
Agile Lab_BigData_Meetup_AKKA
Paolo Platter
 
Akka lsug skills matter
Skills Matter
 
Scaling Web Apps with Akka
Maciej Matyjas
 
Орхан Гасимов: "Reactive Applications in Java with Akka"
Anna Shymchenko
 
Actor-based concurrency in a modern Java Enterprise
Alexander Lukyanchikov
 
Basics of Akka
佑介 九岡
 
Designing Reactive Systems with Akka
Thomas Lockney
 
Akka Made Our Day
Daniel Sawano
 
Ad

Recently uploaded (20)

PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
PDF
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
PDF
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
PDF
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
PDF
REPORT: Heating appliances market in Poland 2024
SPIUG
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
PPTX
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
PPTX
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
PDF
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
PPTX
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PDF
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Cloud-Migration-Best-Practices-A-Practical-Guide-to-AWS-Azure-and-Google-Clou...
Artjoker Software Development Company
 
Presentation about Hardware and Software in Computer
snehamodhawadiya
 
How Open Source Changed My Career by abdelrahman ismail
a0m0rajab1
 
Advances in Ultra High Voltage (UHV) Transmission and Distribution Systems.pdf
Nabajyoti Banik
 
REPORT: Heating appliances market in Poland 2024
SPIUG
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
OA presentation.pptx OA presentation.pptx
pateldhruv002338
 
cloud computing vai.pptx for the project
vaibhavdobariyal79
 
Data_Analytics_vs_Data_Science_vs_BI_by_CA_Suvidha_Chaplot.pdf
CA Suvidha Chaplot
 
AI and Robotics for Human Well-being.pptx
JAYMIN SUTHAR
 
Software Development Methodologies in 2025
KodekX
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
Responsible AI and AI Ethics - By Sylvester Ebhonu
Sylvester Ebhonu
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
Trying to figure out MCP by actually building an app from scratch with open s...
Julien SIMON
 

Building Reactive System with Akka

  • 1. Building Reactive System with Akka Nguyen Tung LamSepteni Technology Scala Hanoi Meetup 2018
  • 2. Who am I? ● Facebook: https://www.facebook.com/lam.nguyentung ● Email: [email protected] ● UET - VNU ● Java/Scala developer
  • 3. Agenda ● Reactive System: What/Why ? ● How to build the “Reactive System” ? ○ Akka Framework ○ Actor model ○ Demo
  • 4. What is the “Reactive System” ?
  • 5. What is the “Reactive System” ? ReactiveX
  • 7. Why we need the “Reactive System” ?
  • 8. In the past ● Nodes: 10s ● Response time: x seconds ● Maintenance downtime: hours ● Data volume: Gbs
  • 9. Today ● Nodes: 1000x ● Response time: milliseconds ● Maintenance downtimes: ○ zero ->100% up time ● Data volume: TBs -> PBs
  • 10. What is Tumblr's technology stack?
  • 12. Responsive ● The system responds in a timely manner if at all possible. ● Realtime user interface
  • 13. ● Recover quickly from failures ○ Software ○ Hardware ○ Network ● Needed: ○ Loose coupling ○ Supervisor hierarchies Resilient
  • 14. ● The system stays responsive under varying workload. ● The system can react to changes in the input rate by increasing or decreasing the resources allocated to service these inputs. Elastic
  • 15. Message Driven ● The system rely on asynchronous message-passing to establish a boundary between components that ensures ○ loose coupling ○ Isolation ○ location transparency.
  • 16. How to build the “Reactive System” ?
  • 17. What is the Akka? https://akka.io/ - A framework and runtime engine for building reactive system on JVM - Implement the Actor model - Simple concurrent & Distributed systems - Resilient by design - Elastic & Decentralized - Higher performance - 50 million msg/sec on a single machine - 2.5 million actors per GB of heap - Written in Scala language, has Scala and Java binding
  • 18. Why we need the Actor model ?
  • 19. Object Oriented Programming ● Encapsulation: Internal data of an object is not accessible directly from the outside.
  • 20. Object Oriented Programming (Next) ● Using lock to solve the problem ● But: ○ Lock seriously limit concurrency (Caller thread is blocked, it cannot do any other work) ○ Deadlock?
  • 21. Actor Model ● Actor are asynchronous and non-blocking ○ Communicate only via message passing ○ Lock-free concurrency ○ Have a mailbox for inbound messages ○ Always process message in order
  • 23. Actor Model ● Actor live in hierarchy ○ Actor can create other actors ○ Used for supervising: Fault tolerance ● Actor have a reference ○ Using actor ref (phone number)
  • 24. How to create the Actor with Akka?
  • 25. case class Greeting(who: String) class GreetingActor extends Actor with ActorLogging { override def receive: Receive = { case Greeting(who) => println(s"Hello $who") } } object Main extends App { val system = ActorSystem("MySystem") val greeter = system.actorOf(Props[GreetingActor], name = "greeter") greeter ! Greeting("Scala") } Simple example
  • 27. Resilience: Dealing with failure ● Supervision ○ Restart ○ Resume ○ Stop ○ Escalate ● Supervisor strategies ○ One-for-one ○ All-for-one
  • 28. Akka Supervision class WorkerActor extends Actor { override def receive: Receive = { case Greeting(who) => println(s"Hello $who") case Crash(exception) => crash(exception) } def crash(how: String): Unit = { how match { case "arithmetic" => throw new ArithmeticException case "null" => throw new NullPointerException case "illegal" => throw new IllegalArgumentException case _ => throw new Exception } } class MasterActor extends Actor { override def receive: Receive = { case Create(props, name) => context.actorOf(props, name) } override val supervisorStrategy: SupervisorStrategy = { AllForOneStrategy(maxNrOfRetries = 5, withinTimeRange = 10 seconds) { case _: ArithmeticException => Resume case _: NullPointerException => Restart case _: IllegalArgumentException => Stop case _: Exception => Escalate }
  • 29. Elasticity: Create multiple instance of Actor ● Define a router val router: ActorRef = context.actorOf(RoundRobinPool(5).props(Props[WorkerActor]), "router") ● Configuration file akka.actor.deployment { /parent/router1 { router = round-robin-pool nr-of-instances = 5 } }
  • 30. Elastic: Create multiple instance of Actor val router = { val routees = Vector.fill(NUMBER_OF_WORKER) { val r = context.actorOf(Props(classOf[ExecuteOp erationRuleWorker], ioContextManager)) context watch r ActorRefRoutee(r) } Router(AccountIdRoutingLogic(), routees) } class AccountIdRoutingLogic extends RoutingLogic { val next = new AtomicLong override def select(message: Any, routees: immutable.IndexedSeq[Routee]): Routee = if (routees.nonEmpty) { val size = routees.size val operationRuleMessage = message.asInstanceOf[ExecuteOperationRule ] val index = operationRuleMessage.account.identifier.v alue routees((index % size).toInt) } else { NoRoutee } }
  • 32. Elasticity: Actor Cluster akka { actor { provider = cluster } cluster { seed-nodes = ["akka.tcp://[email protected]:2551"] # roles = ["role"] } remote { log-remote-lifecycle-events = off netty.tcp { hostname = ${args.host} port = ${args.port} } } }

Editor's Notes

  • #7: React JS Created in 2014 with +20k sign
  • #11: https://www.quora.com/What-is-Tumblrs-technology-stack
  • #13: Responsive systems focus on providing rapid and consistent response times, establishing reliable upper bounds so they deliver a consistent quality of service.
  • #15: jamie madrox
  • #23: https://letsdobigdata.files.wordpress.com/2016/03/actormodel-2.png