@ticofab
ticofab.ioSlide title
@ticofab
ticofab.ioAbout Me
Fabio Tiriticco
Scala & Akka
consultant
@ticofab
Distributed
Reactive
Systems
Reactive Programming
Actors
Async Messaging
Non-blocking IO
Streaming
Transparent clustering
Resource Provisioning
Zero-downtime deployments
Networking
Docker Containers
Service Discovery
Microservices
Reactive Community Kubernetes Community
@ticofab
ticofab.ioOutline
• Reactive Principles

• Akka

• Kubernetes

• Akka & Kubernetes

• Elasticity use cases

• Resilience use cases

• Conclusions
@ticofab
ticofab.io
Reactive Principles
@ticofab
ticofab.ioThe Reactive Manifesto
VALUE
MEANS
FORM
@ticofab
ticofab.ioThe Key to Elasticity is Distribution
Scale UP
Limited by
speed of light
and heat
dissipation
Scale OUT
🌍
@ticofab
ticofab.ioThe Key to Distribution is Location Transparency
MESSAGE DRIVEN
=
LOCATION TRANSPARENCY
=
DISTRIBUTION
@ticofab
ticofab.ioFault Tolerance vs Resilience
“A fault-tolerant component is hit but keeps going, possibly with reduced functionality”
“Upon failure, a resilient component is able to jump back to a fully functional fresh state”
@ticofab
ticofab.io
Akka
@ticofab
ticofab.ioWhat is Akka?
Reactive
Principles
Reactive
Design
Patterns
Reactive
Building
Blocks
JVM / application level
@ticofab
ticofab.ioLocation Transparency in Akka
Actor 1

“John”
“John”
name?
• can only communicate
via async messaging
• unit of computation
Akka’s building
blocks are Actors
name:
Actor 2
• contains logic & state
Actor 1

“John”
“John”
name?
name:
Actor 2
State isolation &

location transparency
Single JVM
JVM 1 JVM 2
@ticofab
ticofab.ioA Cluster of Actors
JVM
JVM
JVMJVM
JVM
Akka Cluster
Akka Cluster Sharding
@ticofab
ticofab.ioResilience in Akka
Supervisor
Actor
Actor
Every actor is created by its supervisor,
to whom failure handling is delegated
• Business logic and failure handling are
clearly decoupled ➝ easier to test

• Flexible ways to react to failure

• Failures don’t cascade to other parts
@ticofab
ticofab.ioResilience in Akka
Skynet

actor
T1000
actor
try {
walk();
} catch (OutOfLegsException e) {
}
legsAvailable = false;
pullWithArms();
T800

instance
// in T1000 actor
walk()
// in Skynet supervisor
case h: TooManyHolesException =>
Restart // or another strategy
@ticofab
ticofab.io
Kubernetes
@ticofab
ticofab.io
4 x
What is Kubernetes?
MENU
Auth Service
For those in need of security
Picture Resizer Service
Available in all sizes
Uploader Service
Sharing is caring
Order
1 x
Auth Service
2 x
Uploader Service
Service
orchestration
2 to 8 based on appetite
Picture Resizer Service
@ticofab
ticofab.ioLocation Transparency in Kubernetes
VM 1 VM 2
No need to know IP address of VMs

Use pod label or a DNS service
Pod 4
Actor 1
Pod 5
Actor 2
Actor
3
Pod 1
name: A
Pod 2
name: B
Pod 3
name: C
Pod

=

Docker image

=

JVM
@ticofab
ticofab.ioElasticity in Kubernetes
Frontend
service
Backend
service
load balancer
@ticofab
ticofab.ioResilience in Kubernetes
Frontend
service
Backend
service
load balancer
@ticofab
ticofab.io
Akka & Kubernetes
@ticofab
ticofab.ioThe Akka-Kubernetes Stack
JVM JVM
Pod Pod Pod
VM VM
Actor Actor ActorActor ActorActors
JVM

Akka node
Pods
VM

Kubernetes node
JVM Akka Cluster
@ticofab
ticofab.ioKubernetes Helps with Cluster Formation
name: akka-node-1
label: mycluster
name: akka-node-4
label: mycluster
name: akka-node-2
label: mycluster
name: akka-node-3
label: myclusterKubernetes
API
Akka Cluster Bootstrap
@ticofab
ticofab.io
Elasticity use cases
@ticofab
ticofab.ioDistributed Workload
Worker 1
Worker 2
Worker N
….Master
We want to keep track of the
processing rate according to
some custom metrics
@ticofab
ticofab.io
Load
balancer
pod
pod
pod
Distributed Workload
Worker 1 (pod)
Master
(pod)
Worker 2 (pod)
Worker N (pod)
Master

(router)
Worker
Worker
DELEGATION OF ELASTICITY
TO INFRASTRUCTURE LEVEL
Worker
Worker
+
Example:
github.com/ticofab/akka-cluster-kubernetes
COLLABORATION BETWEEN
APPLICATION AND
INFRASTRUCTURE LEVEL
Kubernetes API
@ticofab
ticofab.ioDistribute load and Manage State
https://www.lightbend.com/blog/new-white-paper-the-benefits-of-using-akka-with-kubernetes
@ticofab
ticofab.ioMy First Journey in the Reactive World (2013)
cloudmatch.github.io
@ticofab
ticofab.io
All games images ™ of Nintendo
My First Journey in the Reactive World (2013)
@ticofab
ticofab.ioEngine Requirements
📱 Hold state for each device (location, matched devices..)

🔄 Allow a FAST bi-directional channel between paired devices
2
1
@ticofab
ticofab.io
Device service instance 2
Device service instance 1
Actor-based, Stateful Microservice Architecture
Websocket
Listener
3
2
1
Device
1
Device
3
Device
2
Listener
+
@ticofab
ticofab.ioStateless Microservice Architecture
Device
1
Device
Service
instance 1
Websocket
Listener
3
2
1
Device
Service
instance 2
Device
Service
instance 3
Device
3
@ticofab
ticofab.io
Resilience use cases
@ticofab
ticofab.ioScale of Resilience
JVM Exceptions JVM Errors Hardware failure
Skynet attack

Meteorite hits
Akka
{ } Kubernetes[ ] …
@ticofab
ticofab.ioReasons for Resilience at the Application Level
Restart time
seconds
Actor
milliseconds
If it ain’t broken,
don’t restart it
One does not
simply restart things
pod issue
restart
actor issue
resumerestart
stop
@ticofab
ticofab.io
Conclusions
@ticofab
ticofab.ioApplication Infrastructure🤝
@ticofab
ticofab.ioReview of the Akka-Kubernetes Stack
Kubernetes is a great
infrastructure choice for your
clustered application
⚙
It provides location
transparency with
cluster formation

🖇
It introduces resilience at
an infrastructure level
(
Akka has a cloud-native
programming model,
ready to scale from day 1
📬
It enables transparent
communication between
different nodes of a service
📟
Resilience is built in
your service with
granular control
+
@ticofab
ticofab.ioConclusion
Akka & Kubernetes together give you superpowers.
Superman is a ™ of DC Comics
@ticofab
ticofab.ioFurther Work… More Abstractions & Features!
• Streaming

• Event Sourcing & CQRS

• Reactive Streams connectors

• Cluster membership

• CRDTs

• …
• Storage

• Confidentiality

• Rolling rollouts

• Automatic rollbacks

• DNS management

• …
@ticofab
ticofab.ioReferences
J. Bonér, R. Kuhn, D. Farley, M. Thompson: The Reactive Manifesto

R. Kuhn, B. Hanafee, J. Allen “Reactive Design Patterns”
http://github.com/ticofab/akka-cluster-kubernetes
Tools:
Akka

Docker

Kubernetes
akka.io

docker.com

kubernetes.io
Code example:
Resources:
@ticofab
ticofab.ioQ&A
@ticofab
ticofab.io
Akka and Kubernetes:
Reactive from Code to Cloud

Akka and Kubernetes: Reactive From Code To Cloud