Go Reactive 
Building Responsive, Resilient, 
Elastic & Message-Driven Systems 
Jonas Bonér 
CTO Typesafe 
@jboner
The rules of the game 
have changed
3 
Yesterday Today
3 
Yesterday Today 
Single machines Clusters of machines
3 
Yesterday Today 
Single machines Clusters of machines 
Single core processors Multicore processors
3 
Yesterday Today 
Single machines Clusters of machines 
Single core processors Multicore processors 
Expensive RAM Cheap RAM
3 
Yesterday Today 
Single machines Clusters of machines 
Single core processors Multicore processors 
Expensive RAM Cheap RAM 
Expensive disk Cheap disk
3 
Yesterday Today 
Single machines Clusters of machines 
Single core processors Multicore processors 
Expensive RAM Cheap RAM 
Expensive disk Cheap disk 
Slow networks Fast networks
3 
Yesterday Today 
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
3 
Yesterday Today 
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
3 
Yesterday Today 
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
Reactive 
“Readily responsive to a stimulus” 
- Merriam Webster
The Principles of Reactive Systems 
Reactive 
Applications 
6
http://reactivemanifesto.org
Responsive 
“Quick to respond or react appropriately” 
- Merriam Webster
9 
The system should 
always be responsive
9 
The system should 
always be responsive 
1. Blue skies 
2. Heavy load 
3. Failures
Resilient 
“The ability of a substance or object to spring back into shape” 
“The capacity to recover quickly from difficulties” 
- Merriam Webster
Think Vending Machine
Think Vending Machine 
Coffee 
Programmer Machine
Think Vending Machine 
Coffee 
Inserts coins 
Programmer Machine
Think Vending Machine 
Coffee 
Inserts coins 
Add more coins 
Programmer Machine
Think Vending Machine 
Coffee 
Inserts coins 
Add more coins 
Programmer Machine 
Gets coffee
Think Vending Machine 
Coffee 
Programmer Machine
Think Vending Machine 
Coffee 
Inserts coins 
Programmer Machine
Think Vending Machine 
Coffee 
Inserts coins 
Out of coffee beans error 
Programmer Machine
Think Vending Machine 
Coffee 
Inserts coins 
Out of coffee beans error WRONG 
Programmer Machine
Think Vending Machine 
Coffee 
Inserts coins 
Programmer Machine
Think Vending Machine 
Coffee 
Inserts coins 
Out of 
coffee beans 
failure 
Programmer Machine
Think Vending Machine 
Service 
Guy 
Coffee 
Inserts coins 
Out of 
coffee beans 
failure 
Programmer Machine
Think Vending Machine 
Service 
Guy 
Coffee 
Inserts coins 
Out of 
coffee beans 
failure 
Programmer Machine 
Adds 
more 
beans
Think Vending Machine 
Service 
Guy 
Coffee 
Inserts coins 
Programmer Machine 
Gets coffee 
Out of 
coffee beans 
failure 
Adds 
more 
beans
The Right Way 
Client Service
The Right Way 
Request 
Client Service
The Right Way 
Request 
Client Service 
Response
The Right Way 
Request 
Validation Error 
Client Service 
Response
The Right Way 
Request 
Validation Error 
Client Service 
Response 
Application 
Failure
The Right Way 
Supervisor 
Request 
Validation Error 
Client Service 
Response 
Application 
Failure
The Right Way 
Supervisor 
Request 
Validation Error 
Client Service 
Response 
Application 
Failure 
Manages 
Failure
Resilience Is 
By Design
Use Bulkheads 
1. Isolate the failure 
2. Compartmentalize 
3. Manage failure locally 
4. Avoid cascading failures
Use Bulkheads 
1. Isolate the failure 
2. Compartmentalize 
3. Manage failure locally 
4. Avoid cascading failures
Enter Supervision
Supervisor hierarchies 
A 
Foo Bar 
B 
C 
B 
E 
A 
D 
C 
Automatic and mandatory supervision
Supervisor hierarchies 
A 
Foo Bar 
B 
C 
E 
A 
D 
C 
Automatic and mandatory supervision 
B
Supervision in Akka 
Every single actor has a 
default supervisor strategy. 
Which is usually sufficient. 
But it can be overridden. 
19
Supervision in Akka 
class Supervisor extends AbstractActor { 
private SupervisorStrategy strategy = new OneForOneStrategy( 
10, Duration.create(1, TimeUnit.MINUTES), 
DirectiveBuilder. 
match(ArithmeticException.class, e -> resume()). 
match(NullPointerException.class, e -> restart()). 
matchAny( e -> escalate()). 
build()); 
… // rest of actor omitted 
} 
} 
19
Resilience requires a 
Message-Driven 
Architecture
Elastic 
“Capable of ready change or easy expansion or contraction” 
- Merriam Webster
UP Scale
UP Scale 
and down
1. Minimize Contention 
2. Maximize Locality of Reference 
23 
We need to
Common points of 
contention 
Physical Application
25 
GO
Async 
25 
GO
26 
Never
26 
Neevveerr
Block 
26 
Neevveerr
27 
NOTHING share
Needs to be async and non-blocking 
28 
all the way down…
Needs to be async and non-blocking 
28 
all the way down…
29 
Single Writer Principle
29 
Single Writer Principle 
Producers IO device 
SERIAL & 
CONTENDED
29 
Single Writer Principle 
Producers IO device 
SERIAL & 
CONTENDED 
Producers Actor or Queue IO device 
BATCHED & 
UNCONTENDED
The Role of Immutable State 
30
The Role of Immutable State 
30
The Role of Immutable State 
• Great to represent facts 
• Messages and Events 
• Database snapshots 
• Representing the succession of time 
30
The Role of Immutable State 
• Great to represent facts 
• Messages and Events 
• Database snapshots 
• Representing the succession of time 
• Mutable State is ok if local and contained 
• Allows Single-threaded processing 
• Allows single writer principle 
• Feels more natural 
• Publish the results to the world as Immutable State 
30
Divide & Conquer 
31
32 
Pipelining
ON DEMAND 
33 
scale
Scale 
OUT
Scale 
OUT 
and in
• Mobile 
• Cloud Services, REST etc. 
• NOSQL DBs 
• Big Data 
35 
Distributed Computing 
is the 
new normal
What is the essence of 
distributed systems? 
36
What is the essence of 
distributed systems? 
To try to overcome that 
1. Information travels at the speed of light 
2. Independent things fail independently 
36
No difference 
Between a 
Slow node 
Dead node 
37 
and a
The network is 
38
The network is 
38 
Inherently Unreliable 
http://aphyr.com/posts/288-the-network-is-reliable
39 
Graveyard of distributed systems
39 
Graveyard of distributed systems 
• Distributed Shared Mutable State 
EVIL N 
• (where N is number of nodes)
39 
Graveyard of distributed systems 
• Distributed Shared Mutable State 
EVIL N 
• (where N is number of nodes) 
• Serializable Distributed Transactions
39 
Graveyard of distributed systems 
• Distributed Shared Mutable State 
EVIL N 
• (where N is number of nodes) 
• Serializable Distributed Transactions 
• Synchronous RPC
39 
Graveyard of distributed systems 
• Distributed Shared Mutable State 
EVIL N 
• (where N is number of nodes) 
• Serializable Distributed Transactions 
• Synchronous RPC 
• Guaranteed Delivery
39 
Graveyard of distributed systems 
• Distributed Shared Mutable State 
EVIL N 
• (where N is number of nodes) 
• Serializable Distributed Transactions 
• Synchronous RPC 
• Guaranteed Delivery 
• Distributed Objects 
• “Sucks like an inverted hurricane” - Martin Fowler
Instead 
40
Instead 
Embrace the Network 
40 
and be done with it 
Use 
Asynchronous 
Message 
Passing
TRANSPARENCY 
41 
location
42
42 
Scaling Up and Out is essentially 
the same thing
Elasticity requires a 
Message-Driven 
Architecture
Asynchronous 
Message-Passing 
is the enabler
45 
Typesafe Reactive Platform 
• Purely asynchronous and non-blocking 
web framework 
• No container required, no inherent 
bottlenecks in session management 
• Actors are lightweight, isolated and and 
communicate via asynchronous message 
passing 
• Supervision and clustering in support of 
fault tolerance 
• Asynchronous and immutable 
programming constructs 
• Composable abstractions enabling 
simpler concurrency and parallelism
Typesafe Activator 
http://typesafe.com/platform/getstarted
47 
Finance Internet/Social Media Mfg/Hardware Government Retail
Go Reactive 
Building Responsive, Resilient, 
Elastic & Message-Driven Systems 
Jonas Bonér 
CTO Typesafe 
@jboner

Go Reactive: Building Responsive, Resilient, Elastic & Message-Driven Systems

  • 1.
    Go Reactive BuildingResponsive, Resilient, Elastic & Message-Driven Systems Jonas Bonér CTO Typesafe @jboner
  • 3.
    The rules ofthe game have changed
  • 4.
  • 5.
    3 Yesterday Today Single machines Clusters of machines
  • 6.
    3 Yesterday Today Single machines Clusters of machines Single core processors Multicore processors
  • 7.
    3 Yesterday Today Single machines Clusters of machines Single core processors Multicore processors Expensive RAM Cheap RAM
  • 8.
    3 Yesterday Today Single machines Clusters of machines Single core processors Multicore processors Expensive RAM Cheap RAM Expensive disk Cheap disk
  • 9.
    3 Yesterday Today Single machines Clusters of machines Single core processors Multicore processors Expensive RAM Cheap RAM Expensive disk Cheap disk Slow networks Fast networks
  • 10.
    3 Yesterday Today 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
  • 11.
    3 Yesterday Today 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
  • 12.
    3 Yesterday Today 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
  • 14.
    Reactive “Readily responsiveto a stimulus” - Merriam Webster
  • 15.
    The Principles ofReactive Systems Reactive Applications 6
  • 17.
  • 18.
    Responsive “Quick torespond or react appropriately” - Merriam Webster
  • 19.
    9 The systemshould always be responsive
  • 20.
    9 The systemshould always be responsive 1. Blue skies 2. Heavy load 3. Failures
  • 21.
    Resilient “The abilityof a substance or object to spring back into shape” “The capacity to recover quickly from difficulties” - Merriam Webster
  • 22.
  • 23.
    Think Vending Machine Coffee Programmer Machine
  • 24.
    Think Vending Machine Coffee Inserts coins Programmer Machine
  • 25.
    Think Vending Machine Coffee Inserts coins Add more coins Programmer Machine
  • 26.
    Think Vending Machine Coffee Inserts coins Add more coins Programmer Machine Gets coffee
  • 27.
    Think Vending Machine Coffee Programmer Machine
  • 28.
    Think Vending Machine Coffee Inserts coins Programmer Machine
  • 29.
    Think Vending Machine Coffee Inserts coins Out of coffee beans error Programmer Machine
  • 30.
    Think Vending Machine Coffee Inserts coins Out of coffee beans error WRONG Programmer Machine
  • 31.
    Think Vending Machine Coffee Inserts coins Programmer Machine
  • 32.
    Think Vending Machine Coffee Inserts coins Out of coffee beans failure Programmer Machine
  • 33.
    Think Vending Machine Service Guy Coffee Inserts coins Out of coffee beans failure Programmer Machine
  • 34.
    Think Vending Machine Service Guy Coffee Inserts coins Out of coffee beans failure Programmer Machine Adds more beans
  • 35.
    Think Vending Machine Service Guy Coffee Inserts coins Programmer Machine Gets coffee Out of coffee beans failure Adds more beans
  • 36.
    The Right Way Client Service
  • 37.
    The Right Way Request Client Service
  • 38.
    The Right Way Request Client Service Response
  • 39.
    The Right Way Request Validation Error Client Service Response
  • 40.
    The Right Way Request Validation Error Client Service Response Application Failure
  • 41.
    The Right Way Supervisor Request Validation Error Client Service Response Application Failure
  • 42.
    The Right Way Supervisor Request Validation Error Client Service Response Application Failure Manages Failure
  • 44.
  • 46.
    Use Bulkheads 1.Isolate the failure 2. Compartmentalize 3. Manage failure locally 4. Avoid cascading failures
  • 47.
    Use Bulkheads 1.Isolate the failure 2. Compartmentalize 3. Manage failure locally 4. Avoid cascading failures
  • 48.
  • 49.
    Supervisor hierarchies A Foo Bar B C B E A D C Automatic and mandatory supervision
  • 50.
    Supervisor hierarchies A Foo Bar B C E A D C Automatic and mandatory supervision B
  • 51.
    Supervision in Akka Every single actor has a default supervisor strategy. Which is usually sufficient. But it can be overridden. 19
  • 52.
    Supervision in Akka class Supervisor extends AbstractActor { private SupervisorStrategy strategy = new OneForOneStrategy( 10, Duration.create(1, TimeUnit.MINUTES), DirectiveBuilder. match(ArithmeticException.class, e -> resume()). match(NullPointerException.class, e -> restart()). matchAny( e -> escalate()). build()); … // rest of actor omitted } } 19
  • 54.
    Resilience requires a Message-Driven Architecture
  • 55.
    Elastic “Capable ofready change or easy expansion or contraction” - Merriam Webster
  • 56.
  • 57.
  • 58.
    1. Minimize Contention 2. Maximize Locality of Reference 23 We need to
  • 59.
    Common points of contention Physical Application
  • 60.
  • 61.
  • 62.
  • 63.
  • 64.
  • 65.
  • 66.
    Needs to beasync and non-blocking 28 all the way down…
  • 67.
    Needs to beasync and non-blocking 28 all the way down…
  • 68.
  • 69.
    29 Single WriterPrinciple Producers IO device SERIAL & CONTENDED
  • 70.
    29 Single WriterPrinciple Producers IO device SERIAL & CONTENDED Producers Actor or Queue IO device BATCHED & UNCONTENDED
  • 71.
    The Role ofImmutable State 30
  • 72.
    The Role ofImmutable State 30
  • 73.
    The Role ofImmutable State • Great to represent facts • Messages and Events • Database snapshots • Representing the succession of time 30
  • 74.
    The Role ofImmutable State • Great to represent facts • Messages and Events • Database snapshots • Representing the succession of time • Mutable State is ok if local and contained • Allows Single-threaded processing • Allows single writer principle • Feels more natural • Publish the results to the world as Immutable State 30
  • 75.
  • 76.
  • 77.
  • 78.
  • 79.
  • 80.
    • Mobile •Cloud Services, REST etc. • NOSQL DBs • Big Data 35 Distributed Computing is the new normal
  • 81.
    What is theessence of distributed systems? 36
  • 82.
    What is theessence of distributed systems? To try to overcome that 1. Information travels at the speed of light 2. Independent things fail independently 36
  • 83.
    No difference Betweena Slow node Dead node 37 and a
  • 84.
  • 85.
    The network is 38 Inherently Unreliable http://aphyr.com/posts/288-the-network-is-reliable
  • 86.
    39 Graveyard ofdistributed systems
  • 87.
    39 Graveyard ofdistributed systems • Distributed Shared Mutable State EVIL N • (where N is number of nodes)
  • 88.
    39 Graveyard ofdistributed systems • Distributed Shared Mutable State EVIL N • (where N is number of nodes) • Serializable Distributed Transactions
  • 89.
    39 Graveyard ofdistributed systems • Distributed Shared Mutable State EVIL N • (where N is number of nodes) • Serializable Distributed Transactions • Synchronous RPC
  • 90.
    39 Graveyard ofdistributed systems • Distributed Shared Mutable State EVIL N • (where N is number of nodes) • Serializable Distributed Transactions • Synchronous RPC • Guaranteed Delivery
  • 91.
    39 Graveyard ofdistributed systems • Distributed Shared Mutable State EVIL N • (where N is number of nodes) • Serializable Distributed Transactions • Synchronous RPC • Guaranteed Delivery • Distributed Objects • “Sucks like an inverted hurricane” - Martin Fowler
  • 92.
  • 93.
    Instead Embrace theNetwork 40 and be done with it Use Asynchronous Message Passing
  • 94.
  • 95.
  • 96.
    42 Scaling Upand Out is essentially the same thing
  • 98.
    Elasticity requires a Message-Driven Architecture
  • 100.
  • 101.
    45 Typesafe ReactivePlatform • Purely asynchronous and non-blocking web framework • No container required, no inherent bottlenecks in session management • Actors are lightweight, isolated and and communicate via asynchronous message passing • Supervision and clustering in support of fault tolerance • Asynchronous and immutable programming constructs • Composable abstractions enabling simpler concurrency and parallelism
  • 102.
  • 103.
    47 Finance Internet/SocialMedia Mfg/Hardware Government Retail
  • 104.
    Go Reactive BuildingResponsive, Resilient, Elastic & Message-Driven Systems Jonas Bonér CTO Typesafe @jboner