An introduction to

Actors
Akka
with

Johan Andrén
johan.andren@mejsla.se | @apnylle
Moores law
2,6 billions

1 million

2300

1971

1990

today
Oh, No Problems!
Oh No, Problems!
•
•
•
•
•
•

Race conditions
Data corruption
Deadlocks
Thread contention
Livelocks
Priority Inversion
Concurrency is HARD
•
•
•
•

To write
To test
To debug
To reason about

We need a better model!
B

C

D

A

F

E
event driven
systems with

ACTORS
State

Inbox

The only way to
interact from
outside

Behaviour
•
•
•
•
•

Single execution flow model
No shared _mutable_ state
Lightweight
Loose coupling
Easy to test
Actor A

Actor B
One way communication
Actor A

Actor B
React, don’t wait
Actor A

Actor B
Load balancing
Actor A

Actor B1
router

Actor B2
Pipe/Filter
Actor A

Actor F
(filter)

Actor B
Parallellize
Actor C1

Actor A

Actor B
(chef)

Actor C2

Actor C2
•
•
•

No work, no thread used!
Async - never actively wait
Loose coupling
JVM

B

C

D

A

F

E
JVM 1

B

C

JVM 2

D

A

F

E
The same same
•
•
•

Two actors on one core
Two actors on separate cores
Two actors on separate servers
Error handling
in Actor systems
Traditional model
•
•
•

Leaking information between tiers
Impossible to detect simultaneous
errors
The receiver does not know how to
handle the errors!
Error handling with Actors
(parent)

Actor A

Actor X

Actor Z
Error handling with Actors
(parent)

Actor A

Actor X

Actor Z
Error handling with Actors
Actor A

Actor X

Actor Z
”Supervision”
•
•
•
•

Compartmentilization
What goes back is explicit
Separating error handling and
business logic
Can detect simultaneous errors
But

Wait, there is more!
•
•
•
•
•

STM
Remoting
Clustring with no SPoF
MQs integration
Eventbus

Website: akka.io
Try it out!

Typesafe Activator

typesafe.com
Recap
•
•
•
•

Simple but powerful model
Lightweight and fast
Loose coupling
Resiliency

Johan Andrén
johan.andren@mejsla.se | @apnylle
Questions?

Johan Andrén
johan.andren@mejsla.se | @apnylle

Introduction to Akka