2. AAggeennddaa
● Reactive programming and why we need it.
● Brief introduction to Scala
● Brief introduction to Akka
● Reactive applications.
● Four principles of reactive applications.
4. PPrreesseenntt DDaayy
Till now we program like this
(new Foo).doSomething1();
(new Foo).doSomething2();
(new Foo).doSomething3();
(new Foo).printOutput
Synchronous ?
Blocking ?
Sequential ?
5. Reactive programming is completely different from the
sequential work flow. They react when something is done
Worker A
Done and react
Worker B
Done and react
Worker C
Done and react
Output
Reactive programming
14. Reactive – Parts – Event Driven
Concurrent application uses shared memory to
communicate.
Thread A Thread B
R/W R/W
Shared memory
Synchronization Non-determinism Hard to understand code
15. Reactive – Parts – Event Driven
Event driven system avoid shared memory communication
And uses message passing model throughout the
Application
Actor A Message Actor B
Continued..
16. Reactive –– PPaarrttss –– EEvveenntt DDrriivveenn
Sender Message Receiver
Loosely coupled Easier to extend Evolve
Receiver dormant till it receives message
Large number of receivers share same hardware thread
Low latency High throughput
Lower operational costs
17. Reactive –– PPaarrttss –– EEvveenntt DDrriivveenn
UI
Web Layer
Services
Database
Application must be
reactive from top to
bottom.
None of the layers
should stall.
19. Reactive –– PPaarrttss –– SSccaallaabbllee
The word scalable is defined by Merriam-
Webster as “capable of being easily expanded
or upgraded on demand”
20. Reactive –– PPaarrttss –– SSccaallaabbllee
Node 1
Actor A
Node 2
Message Actor B
Asynchronous message passing
Location transparency
The network is inherently unreliable
22. RReeaaccttiivvee –– PPaarrttss –– RReessiilliieenntt
Node 1
Actor A
Node 2
Message Actor B
Loose coupling Isolated components
Hierarchy of failure management
23. Reactive –– PPaarrttss –– RReessppoonnssiivvee
Responsive is defined by Merriam-
Webster as "quick to respond or
react appropriately".
Respond immediately
Even in event of failure
24. Reactive –– PPaarrttss –– RReessppoonnssiivvee
Response event is returned in O(1) or at least O(log n)
time regardless of load
How ?
Batching when there is high traffic
Queues bound with back pressure
Failures handled with recovery and circuit breakers
31. SSccaallaa BBaassiiccss
1. Scala method definitions
def fun(x: Int) = {
result
}
2 . def fun = result
3 .Scala variable definitions
var x: Int = expression
val x: String = expression
1. Java method definitions
Int fun(int x) {
return result
}
2. (no parameterless methods)
3. java variable definitions
Int x = expression
final String x = expression
33. SSccaallaa BBaassiiccss
pure object system
operator overloading
closures
mixin composition with traits special
treatment of interfaces
existential types
abstract
pattern matching
static members
primitive types
break and continue
Interfaces
Wildcards
raw types
enums
34. What is Akka
Akka is the framework developed by Typesafe
Right abstraction with actors for concurrent, fault-tolerant and
scalable applications
For Fault-Tolerance uses “Let It Crash” model
Abstraction for transparent distribution of load
We can Scale In and Scale Out
35. Problem Which Akka Solve
Truly highly concurrent systems
Truly scalable systems
Self-healing, fault-tolerant systems
36. Akka
Never think in terms of shared state, state visibility, threads,
locks, concurrent collections, thread notification etc
Low level concurrency becomes Simple Workflow - we only think
in terms of message flows in system
We get high CPU utilization, low latency, high throughput and
scalability - for free as part of this model
Proven and superior model for detecting and recovering from
errors
41. DDeeffiinnee aaccttoorr
Define message on which actor will react.
case object Hello
Define actor
Class HelloActor extends Actor
{
def receive = {
case Hello => println(“Hello”)
case _=> println(“I did not understand”)
}
}
45. RReessiilliieenntt
Applications which are fault tolerant, detect failure and
recover from failure are resilient.
Such system are self healed and unstoppable
46. Actor System
Guardian actor
Actor A Actor B
Actor C Actor D
Actor System can be think of as home for actors
47. Actors form parent child relationship
Guardian actor
Actor A Actor B
/A
Actor C Actor D
/A/C
/B
/B/D
54. SSccaallaabbllee
Applications which are able to scale up/down as the load
Increases or decreases are scalable.
Scaling is of two types.
1. Scaling the application on all cpu's core is called scale
up.
2. Scaling the application to multiple machine is called
scale out
57. RReessppoonnssiivvee
Bringing these three traits (event driven, resilient, and
Scalable) together make to the applications responsive
and all these four qualities together make the application
reactive.
58. Reactive ppllaattffoorrmm –– ccoommppoonneennttss
Play (Reactive we application framework built on top of
akka)
Akka Clustering
Akka persistence
Adaptive load balancing
Software Transnational memory