SlideShare une entreprise Scribd logo
1  sur  59
Télécharger pour lire hors ligne
Coding
in

Resiliently
Akka
Scala
with

Derek Wyatt
Twitter: @derekwyatt
Email: derek@derekwyatt.org
Tuesday, 4 February, 14
’s Resiliency?
What

Tuesday, 4 February, 14
’s Resiliency?
What
W

Tolerance against faults

Tuesday, 4 February, 14
’s Resiliency?
What
W

Tolerance against faults

W

Grace in the face of insane success

Tuesday, 4 February, 14
’s Resiliency?
What
W

Tolerance against faults

W

Grace in the face of insane success

W

Slowing down instead of shutting down

Tuesday, 4 February, 14
’s Resiliency?
What
W

Tolerance against faults

W

Grace in the face of insane success

W

Slowing down instead of shutting down
Resiliency is about reacting to the crap that happens
because life is, basically a problem

Tuesday, 4 February, 14
C
Cloud Resiliency
C

Tuesday, 4 February, 14
C
Cloud Resiliency
C
Queues
C

Virtual Machines
C

C
Clustered Databases

Zookeeper
C
Tuesday, 4 February, 14

Load
C Balancers
C
Cloud Resiliency
C

g to
Queues s. Virtual Machines
oin
C
mg
C
I’
ol
t to
m.
rea
G
the
use
C you Databases
Clustered
me
su
s
aZookeeper
C
Load
C Balancers

Tuesday, 4 February, 14
How Akka Helps

Tuesday, 4 February, 14
How Akka Helps
5 Akka is a toolki for asynchrony
Resilient systems are asynchronous systems

Tuesday, 4 February, 14
How Akka Helps
5 Akka is a toolki for asynchrony
Resilient systems are asynchronous systems

5 Akka is buil using queues
Queues add resilient points of communication

Tuesday, 4 February, 14
How Akka Helps
5 Akka is a toolki for asynchrony
Resilient systems are asynchronous systems

5 Akka is buil using queues
Queues add resilient points of communication

5 Akka divorces threads from work
Improper use of threads kills resiliency

Tuesday, 4 February, 14
How Akka Helps
5 Akka is a toolki for asynchrony
Resilient systems are asynchronous systems

5 Akka is buil using queues
Queues add resilient points of communication

5 Akka divorces threads from work
Improper use of threads kills resiliency

5 Akka’s Actors incorporate faul tolerance
A crash is just standard operating procedure

Tuesday, 4 February, 14
How Akka Helps
5 Akka is a toolki for asynchrony
Resilient systems are asynchronous systems

5 Akka is buil using queues
Queues add resilient points of communication

5 Akka divorces threads from work
Improper use of threads kills resiliency

5 Akka’s Actors incorporate faul tolerance
A crash is just standard operating procedure

5 Akka Clusters
Clustering? Come on... Resilient
Tuesday, 4 February, 14
How Akka Helps
5 Akka is a toolki for asynchrony

!
re
o
m
’s
re
e
th
d
n

Resilient systems are asynchronous systems

5 Akka is buil using queues

Queues add resilient points of communication

5 Akka divorces threads from work

Improper use of threads kills resiliency

A

5 Akka’s Actors incorporate faul tolerance

A crash is just standard operating procedure

5 Akka Clusters

Clustering? Come on... Resilient
Tuesday, 4 February, 14
Why We Don’t Code Resiliently

Tuesday, 4 February, 14
Why.k.a Don’t backResiliently
We Call Code Hell
a
1) REST request comes in
2) Validate user identity
3) Get profile from DB
4) Grab a few pics
5) Get recent Twitter activity
6) Return REST response

Tuesday, 4 February, 14
Why.k.a Don’t backResiliently
We Call Code Hell
a
Do i
1) REST request comes in
t
2) Validate user identity
and
3) Get profile from DB
4) Grab a few pics
5) Get recent Twitter activity
6) Return REST response

Tuesday, 4 February, 14

asyn
chro
nous
don’
ly
t bl
ock
Why.k.a Don’t backResiliently
We Call Code Hell
a
Do i
1) REST request comes in
t
2) Validate user identity
and
3) Get profile from DB
4) Grab a few pics
5) Get recent Twitter activity
6) Return REST response

asyn
chro
nous
don’
ly
t bl
ock

Welcome to Callback
Hell
Tuesday, 4 February, 14
ack Hell
Callb

Tuesday, 4 February, 14
ack Hell
Callb
public void restHandler(RESTRequest req) {
idService.validate(req.userInfo,
new Callback(ValidateResult result) {
if (result.isValid) {
db.getProfile(req.userId,
new Callback(UserProfile profile) {
picServer.get(profile.pic1, new Callback(Pic p1) {
picServer.get(profile.pic2, new Callback(Pic p2) {
picServer.get(profile.pic3, new Callback(Pic p3) {
picServer.get(profile.pic4, new Callback(Pic p4) {
picServer.get(profile.pic5, new Callback(Pic p5) {
twitterServer.getRecentActivity(req.userInfo, new Callback(TwitterActivity activity) {
req.sendResponse(pic1, pic2, pic3, pic4, pic5, activity)
})
})
})
})
})
})
}

})

Tuesday, 4 February, 14

})
ack Hell
Callb
public void restHandler(RESTRequest req) {

☉ We didn’t handle timeouts
idService.validate(req.userInfo,
new Callback(ValidateResult result) {
if (result.isValid) {
We didn’t handle
☉db.getProfile(req.userId, errors
new Callback(UserProfile profile) {
☉ We actually didn’t make it thread
picServer.get(profile.pic1, new Callback(Pic p1) {
picServer.get(profile.pic2, new Callback(Pic p2) {

☉

picServer.get(profile.pic3, new Callback(Pic p3) {

We did throw up a little though...
picServer.get(profile.pic4, new Callback(Pic p4) {
picServer.get(profile.pic5, new Callback(Pic p5) {

twitterServer.getRecentActivity(req.userInfo, new Callback(TwitterActivity activity) {
req.sendResponse(pic1, pic2, pic3, pic4, pic5, activity)
})
})
})
})
})
})
}

})

Tuesday, 4 February, 14

})

safe
synchrony
nctional A
Fu

Tuesday, 4 February, 14
synchrony
nctional A
Fu

implicit val timeout = Timeout(30.seconds)
def restHandler(req: RESTRequest): Future[RESTResponse] = {
val resp = for {
validity <- idService.validate(req.userInfo)
if validity.isValid
profile <- db.getProfile(req.userId)
pic1 <- picServer.get(profile.pic1)
pic2 <- picServer.get(profile.pic2)
pic3 <- picServer.get(profile.pic3)
pic4 <- picServer.get(profile.pic4)
pic5 <- picServer.get(profile.pic5)
activity <- twitterServer.getRecentActivity(req.userInfo)
} yield SuccessfulResponse(pic1, pic2, pic3, pic4, pic5, activity)
resp.recover { e => FailedResponse(e) }
}

Tuesday, 4 February, 14
synchrony
nctional A
Fu

implicit val timeout = Timeout(30.seconds)
def restHandler(req: RESTRequest): Future[RESTResponse] = {
val resp = for {
validity <- idService.validate(req.userInfo)
if validity.isValid
profile <- db.getProfile(req.userId)
pic1 <- picServer.get(profile.pic1)
pic2 <- picServer.get(profile.pic2)
pic3 <- picServer.get(profile.pic3)
pic4 <- picServer.get(profile.pic4)
pic5 <- picServer.get(profile.pic5)
activity <- twitterServer.getRecentActivity(req.userInfo)
} yield SuccessfulResponse(pic1, pic2, pic3, pic4, pic5, activity)
resp.recover { e => FailedResponse(e) }
}

☉
☉
☉

We handle timeouts (!!)

☉

We got to keep our lunch down

Tuesday, 4 February, 14

We handle errors (!!)

It’s immutable and thread safe (!!)
The Circuit Breaker

Tuesday, 4 February, 14
The Circuit Breaker
⦿

For the times when you gotta fail the whale

Tuesday, 4 February, 14
The Circuit Breaker
⦿

For the times when you gotta fail the whale
Calls Failing
Fast

Su
cc
ess

p
Tri

r
ake
Bre

Open

eset

Closed
Trip

Reset Bre

Tuesday, 4 February, 14

Atte
mpt R

aker

Brea

ker

Half
Open
The Circuit Breaker
⦿

For the times when you gotta fail the whale
Calls Failing
Fast

Su
cc
ess

p
Tri

r
ake
Bre

Open

eset

Closed
Trip

Reset Bre

Tuesday, 4 February, 14

Atte
mpt R

aker

Brea

ker

Half
Open

DB
The Circuit Breaker
⦿

For the times when you gotta fail the whale
Calls Failing
Fast

Su
cc
ess

p
Tri

r
ake
Bre

Open

eset

Closed
Trip

Reset Bre

Tuesday, 4 February, 14

Atte
mpt R

pen
it O
ircu
C

aker

Brea

ker

Half
Open

Circu
it Clo
sed

DB
ad Balancing
Lo
Actors are untyped endpoints
You can easily swap one for another
Actors have dispatchers
How messages are dispatched is configurable
You can only communicate through messages
You can route them however you like
Messages can carry the state data
Actors then become completely stateless and
Resilient
Tuesday, 4 February, 14
Scaling Up

Tuesday, 4 February, 14
Scaling Up
⦿ It’s all about dispatchers and untyped endpoints

Tuesday, 4 February, 14
Scaling Up
⦿ It’s all about dispatchers and untyped endpoints

ActorRef

Client

Actor

ActorRef

Balancing
Dispatcher

Actor

ActorRef

•
•

Tuesday, 4 February, 14

Actor

Normally the
message from the
client would go to
the middle Actor,
but the Balancing
Dispatcher lets
the last one “steal”
it because it can
handle it faster.
Scaling Out

Tuesday, 4 February, 14
Scaling Out
☉Routers are another way for messages to reach Actors

Tuesday, 4 February, 14
Scaling Out
☉Routers are another way for messages to reach Actors
A router igures ou which Actor
☉to send to based on rules

Tuesday, 4 February, 14
Scaling Out
☉Routers are another way for messages to reach Actors
A router igures ou which Actor
☉to send to based on rules
DB
Actor

Tuesday, 4 February, 14

Router

DB
Actor

DB Cluster
Machine 2

DB
Actor

Client

DB Cluster
Machine 1

DB Cluster
Machine 3
Scaling Out
☉Routers are another way for messages to reach Actors
A router igures ou which Actor
☉to send to based on rules
Client

Tuesday, 4 February, 14

Router

DB Cluster
Machine 1

DB
Actor

DB Cluster
Machine 2

DB
Actor

This router can
ute consistently
ro
based on sender

DB
Actor

DB Cluster
Machine 3
Scaling Out
☉Routers are another way for messages to reach Actors
A router igures ou which Actor
☉to send to based on rules
This router can
ute consistently
ro
based on sender

Client

☉

Router

Routers can also resize the
number o Actors dynamically

Tuesday, 4 February, 14

DB
Actor

DB Cluster
Machine 1

DB
Actor

DB Cluster
Machine 2

DB
Actor

DB Cluster
Machine 3
Clustering

Tuesday, 4 February, 14
Clustering
Akka can spawn and communicate with Actors
⦿
on remote nodes

Tuesday, 4 February, 14
Clustering
Akka can spawn and communicate with Actors
⦿
on remote nodes

oring!
B

Tuesday, 4 February, 14
Clustering
Akka can spawn and communicate with Actors
⦿
on remote nodes
(OK, that’s really cool, but...)

oring!
B

Tuesday, 4 February, 14
Clustering
Akka can spawn and communicate with Actors
⦿
on remote nodes
(OK, that’s really cool, but...)

oring!
B

⦿ You can cluster your Actors as well

Tuesday, 4 February, 14
Clustering
Akka can spawn and communicate with Actors
⦿
on remote nodes
(OK, that’s really cool, but...)

oring!
B

⦿ You can cluster your Actors as well

Akka takes care of letting you know when
⦿
nodes come and go

Tuesday, 4 February, 14
Clustering
Akka can spawn and communicate with Actors
⦿
on remote nodes
(OK, that’s really cool, but...)

oring!
B

⦿ You can cluster your Actors as well

Akka takes care of letting you know when
⦿
nodes come and go
Clustering provides a ton of possibilities to
⦿
design for resiliency
Tuesday, 4 February, 14
nce - Event Sourcing
Persiste

Tuesday, 4 February, 14
nce - Event Sourcing
Persiste
⨂ Akka provides the ability to persist incoming messages

Tuesday, 4 February, 14
nce - Event Sourcing
Persiste
⨂ Akka provides the ability to persist incoming messages
⨂ This helps for fault tolerance... DUH

Tuesday, 4 February, 14
nce - Event Sourcing
Persiste
⨂ Akka provides the ability to persist incoming messages
⨂ This helps for fault tolerance... DUH
⨂ It also provides the ability to move stateful Actors

Tuesday, 4 February, 14
nce - Event Sourcing
Persiste
⨂ Akka provides the ability to persist incoming messages
⨂ This helps for fault tolerance... DUH
⨂ It also provides the ability to move stateful Actors
⨂ Or provide tools for “Crash-Only” software

sh!
ra
C Actor

Message

Actor
Event 1
Event 2
Event 3

Tuesday, 4 February, 14

Good to go!
Being Resilient

Tuesday, 4 February, 14
Being Resilient
☉Akka provides the foundation for resilien programming and design
⨳ Queues, Dispatchers, Async, Messages, realistic guarantees

Tuesday, 4 February, 14
Being Resilient
☉Akka provides the foundation for resilien programming and design
⨳ Queues, Dispatchers, Async, Messages, realistic guarantees

☉

Then you ge...

Message Oriented
Flexibility

⨳ Routers
⨳
⨳ Persistence
⨳ Clustering
⨳ Resiliency Patterns
⨳ Remote Deployment

Tuesday, 4 February, 14
Being Resilient
☉Akka provides the foundation for resilien programming and design
⨳ Queues, Dispatchers, Async, Messages, realistic guarantees

☉

Then you ge...

Message Oriented
Flexibility

⨳ Routers
⨳
⨳ Persistence
⨳ Clustering
⨳ Resiliency Patterns
⨳ Remote Deployment

☉

Existing cloud components are vial for resiliency

Tuesday, 4 February, 14
Being Resilient
☉Akka provides the foundation for resilien programming and design
⨳ Queues, Dispatchers, Async, Messages, realistic guarantees

☉

Then you ge...

Message Oriented
Flexibility

⨳ Routers
⨳
⨳ Persistence
⨳ Clustering
⨳ Resiliency Patterns
⨳ Remote Deployment

☉
Akka picks up where those components leave of
☉
Existing cloud components are vial for resiliency

Tuesday, 4 February, 14
Go write some Code

Get Scala

http://scala-lang.org
http://github.com/scala/scala

Get Akka
http://akka.io
http://github.com/akka/akka

Tuesday, 4 February, 14

Derek Wyatt
Twitter: @derekwyatt
Email: derek@derekwyatt.org

Contenu connexe

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusZilliz
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...apidays
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 

Dernier (20)

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 

En vedette

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

En vedette (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

Coding Resiliently with Akka

  • 3. ’s Resiliency? What W Tolerance against faults Tuesday, 4 February, 14
  • 4. ’s Resiliency? What W Tolerance against faults W Grace in the face of insane success Tuesday, 4 February, 14
  • 5. ’s Resiliency? What W Tolerance against faults W Grace in the face of insane success W Slowing down instead of shutting down Tuesday, 4 February, 14
  • 6. ’s Resiliency? What W Tolerance against faults W Grace in the face of insane success W Slowing down instead of shutting down Resiliency is about reacting to the crap that happens because life is, basically a problem Tuesday, 4 February, 14
  • 8. C Cloud Resiliency C Queues C Virtual Machines C C Clustered Databases Zookeeper C Tuesday, 4 February, 14 Load C Balancers
  • 9. C Cloud Resiliency C g to Queues s. Virtual Machines oin C mg C I’ ol t to m. rea G the use C you Databases Clustered me su s aZookeeper C Load C Balancers Tuesday, 4 February, 14
  • 10. How Akka Helps Tuesday, 4 February, 14
  • 11. How Akka Helps 5 Akka is a toolki for asynchrony Resilient systems are asynchronous systems Tuesday, 4 February, 14
  • 12. How Akka Helps 5 Akka is a toolki for asynchrony Resilient systems are asynchronous systems 5 Akka is buil using queues Queues add resilient points of communication Tuesday, 4 February, 14
  • 13. How Akka Helps 5 Akka is a toolki for asynchrony Resilient systems are asynchronous systems 5 Akka is buil using queues Queues add resilient points of communication 5 Akka divorces threads from work Improper use of threads kills resiliency Tuesday, 4 February, 14
  • 14. How Akka Helps 5 Akka is a toolki for asynchrony Resilient systems are asynchronous systems 5 Akka is buil using queues Queues add resilient points of communication 5 Akka divorces threads from work Improper use of threads kills resiliency 5 Akka’s Actors incorporate faul tolerance A crash is just standard operating procedure Tuesday, 4 February, 14
  • 15. How Akka Helps 5 Akka is a toolki for asynchrony Resilient systems are asynchronous systems 5 Akka is buil using queues Queues add resilient points of communication 5 Akka divorces threads from work Improper use of threads kills resiliency 5 Akka’s Actors incorporate faul tolerance A crash is just standard operating procedure 5 Akka Clusters Clustering? Come on... Resilient Tuesday, 4 February, 14
  • 16. How Akka Helps 5 Akka is a toolki for asynchrony ! re o m ’s re e th d n Resilient systems are asynchronous systems 5 Akka is buil using queues Queues add resilient points of communication 5 Akka divorces threads from work Improper use of threads kills resiliency A 5 Akka’s Actors incorporate faul tolerance A crash is just standard operating procedure 5 Akka Clusters Clustering? Come on... Resilient Tuesday, 4 February, 14
  • 17. Why We Don’t Code Resiliently Tuesday, 4 February, 14
  • 18. Why.k.a Don’t backResiliently We Call Code Hell a 1) REST request comes in 2) Validate user identity 3) Get profile from DB 4) Grab a few pics 5) Get recent Twitter activity 6) Return REST response Tuesday, 4 February, 14
  • 19. Why.k.a Don’t backResiliently We Call Code Hell a Do i 1) REST request comes in t 2) Validate user identity and 3) Get profile from DB 4) Grab a few pics 5) Get recent Twitter activity 6) Return REST response Tuesday, 4 February, 14 asyn chro nous don’ ly t bl ock
  • 20. Why.k.a Don’t backResiliently We Call Code Hell a Do i 1) REST request comes in t 2) Validate user identity and 3) Get profile from DB 4) Grab a few pics 5) Get recent Twitter activity 6) Return REST response asyn chro nous don’ ly t bl ock Welcome to Callback Hell Tuesday, 4 February, 14
  • 22. ack Hell Callb public void restHandler(RESTRequest req) { idService.validate(req.userInfo, new Callback(ValidateResult result) { if (result.isValid) { db.getProfile(req.userId, new Callback(UserProfile profile) { picServer.get(profile.pic1, new Callback(Pic p1) { picServer.get(profile.pic2, new Callback(Pic p2) { picServer.get(profile.pic3, new Callback(Pic p3) { picServer.get(profile.pic4, new Callback(Pic p4) { picServer.get(profile.pic5, new Callback(Pic p5) { twitterServer.getRecentActivity(req.userInfo, new Callback(TwitterActivity activity) { req.sendResponse(pic1, pic2, pic3, pic4, pic5, activity) }) }) }) }) }) }) } }) Tuesday, 4 February, 14 })
  • 23. ack Hell Callb public void restHandler(RESTRequest req) { ☉ We didn’t handle timeouts idService.validate(req.userInfo, new Callback(ValidateResult result) { if (result.isValid) { We didn’t handle ☉db.getProfile(req.userId, errors new Callback(UserProfile profile) { ☉ We actually didn’t make it thread picServer.get(profile.pic1, new Callback(Pic p1) { picServer.get(profile.pic2, new Callback(Pic p2) { ☉ picServer.get(profile.pic3, new Callback(Pic p3) { We did throw up a little though... picServer.get(profile.pic4, new Callback(Pic p4) { picServer.get(profile.pic5, new Callback(Pic p5) { twitterServer.getRecentActivity(req.userInfo, new Callback(TwitterActivity activity) { req.sendResponse(pic1, pic2, pic3, pic4, pic5, activity) }) }) }) }) }) }) } }) Tuesday, 4 February, 14 }) safe
  • 25. synchrony nctional A Fu implicit val timeout = Timeout(30.seconds) def restHandler(req: RESTRequest): Future[RESTResponse] = { val resp = for { validity <- idService.validate(req.userInfo) if validity.isValid profile <- db.getProfile(req.userId) pic1 <- picServer.get(profile.pic1) pic2 <- picServer.get(profile.pic2) pic3 <- picServer.get(profile.pic3) pic4 <- picServer.get(profile.pic4) pic5 <- picServer.get(profile.pic5) activity <- twitterServer.getRecentActivity(req.userInfo) } yield SuccessfulResponse(pic1, pic2, pic3, pic4, pic5, activity) resp.recover { e => FailedResponse(e) } } Tuesday, 4 February, 14
  • 26. synchrony nctional A Fu implicit val timeout = Timeout(30.seconds) def restHandler(req: RESTRequest): Future[RESTResponse] = { val resp = for { validity <- idService.validate(req.userInfo) if validity.isValid profile <- db.getProfile(req.userId) pic1 <- picServer.get(profile.pic1) pic2 <- picServer.get(profile.pic2) pic3 <- picServer.get(profile.pic3) pic4 <- picServer.get(profile.pic4) pic5 <- picServer.get(profile.pic5) activity <- twitterServer.getRecentActivity(req.userInfo) } yield SuccessfulResponse(pic1, pic2, pic3, pic4, pic5, activity) resp.recover { e => FailedResponse(e) } } ☉ ☉ ☉ We handle timeouts (!!) ☉ We got to keep our lunch down Tuesday, 4 February, 14 We handle errors (!!) It’s immutable and thread safe (!!)
  • 28. The Circuit Breaker ⦿ For the times when you gotta fail the whale Tuesday, 4 February, 14
  • 29. The Circuit Breaker ⦿ For the times when you gotta fail the whale Calls Failing Fast Su cc ess p Tri r ake Bre Open eset Closed Trip Reset Bre Tuesday, 4 February, 14 Atte mpt R aker Brea ker Half Open
  • 30. The Circuit Breaker ⦿ For the times when you gotta fail the whale Calls Failing Fast Su cc ess p Tri r ake Bre Open eset Closed Trip Reset Bre Tuesday, 4 February, 14 Atte mpt R aker Brea ker Half Open DB
  • 31. The Circuit Breaker ⦿ For the times when you gotta fail the whale Calls Failing Fast Su cc ess p Tri r ake Bre Open eset Closed Trip Reset Bre Tuesday, 4 February, 14 Atte mpt R pen it O ircu C aker Brea ker Half Open Circu it Clo sed DB
  • 32. ad Balancing Lo Actors are untyped endpoints You can easily swap one for another Actors have dispatchers How messages are dispatched is configurable You can only communicate through messages You can route them however you like Messages can carry the state data Actors then become completely stateless and Resilient Tuesday, 4 February, 14
  • 33. Scaling Up Tuesday, 4 February, 14
  • 34. Scaling Up ⦿ It’s all about dispatchers and untyped endpoints Tuesday, 4 February, 14
  • 35. Scaling Up ⦿ It’s all about dispatchers and untyped endpoints ActorRef Client Actor ActorRef Balancing Dispatcher Actor ActorRef • • Tuesday, 4 February, 14 Actor Normally the message from the client would go to the middle Actor, but the Balancing Dispatcher lets the last one “steal” it because it can handle it faster.
  • 36. Scaling Out Tuesday, 4 February, 14
  • 37. Scaling Out ☉Routers are another way for messages to reach Actors Tuesday, 4 February, 14
  • 38. Scaling Out ☉Routers are another way for messages to reach Actors A router igures ou which Actor ☉to send to based on rules Tuesday, 4 February, 14
  • 39. Scaling Out ☉Routers are another way for messages to reach Actors A router igures ou which Actor ☉to send to based on rules DB Actor Tuesday, 4 February, 14 Router DB Actor DB Cluster Machine 2 DB Actor Client DB Cluster Machine 1 DB Cluster Machine 3
  • 40. Scaling Out ☉Routers are another way for messages to reach Actors A router igures ou which Actor ☉to send to based on rules Client Tuesday, 4 February, 14 Router DB Cluster Machine 1 DB Actor DB Cluster Machine 2 DB Actor This router can ute consistently ro based on sender DB Actor DB Cluster Machine 3
  • 41. Scaling Out ☉Routers are another way for messages to reach Actors A router igures ou which Actor ☉to send to based on rules This router can ute consistently ro based on sender Client ☉ Router Routers can also resize the number o Actors dynamically Tuesday, 4 February, 14 DB Actor DB Cluster Machine 1 DB Actor DB Cluster Machine 2 DB Actor DB Cluster Machine 3
  • 43. Clustering Akka can spawn and communicate with Actors ⦿ on remote nodes Tuesday, 4 February, 14
  • 44. Clustering Akka can spawn and communicate with Actors ⦿ on remote nodes oring! B Tuesday, 4 February, 14
  • 45. Clustering Akka can spawn and communicate with Actors ⦿ on remote nodes (OK, that’s really cool, but...) oring! B Tuesday, 4 February, 14
  • 46. Clustering Akka can spawn and communicate with Actors ⦿ on remote nodes (OK, that’s really cool, but...) oring! B ⦿ You can cluster your Actors as well Tuesday, 4 February, 14
  • 47. Clustering Akka can spawn and communicate with Actors ⦿ on remote nodes (OK, that’s really cool, but...) oring! B ⦿ You can cluster your Actors as well Akka takes care of letting you know when ⦿ nodes come and go Tuesday, 4 February, 14
  • 48. Clustering Akka can spawn and communicate with Actors ⦿ on remote nodes (OK, that’s really cool, but...) oring! B ⦿ You can cluster your Actors as well Akka takes care of letting you know when ⦿ nodes come and go Clustering provides a ton of possibilities to ⦿ design for resiliency Tuesday, 4 February, 14
  • 49. nce - Event Sourcing Persiste Tuesday, 4 February, 14
  • 50. nce - Event Sourcing Persiste ⨂ Akka provides the ability to persist incoming messages Tuesday, 4 February, 14
  • 51. nce - Event Sourcing Persiste ⨂ Akka provides the ability to persist incoming messages ⨂ This helps for fault tolerance... DUH Tuesday, 4 February, 14
  • 52. nce - Event Sourcing Persiste ⨂ Akka provides the ability to persist incoming messages ⨂ This helps for fault tolerance... DUH ⨂ It also provides the ability to move stateful Actors Tuesday, 4 February, 14
  • 53. nce - Event Sourcing Persiste ⨂ Akka provides the ability to persist incoming messages ⨂ This helps for fault tolerance... DUH ⨂ It also provides the ability to move stateful Actors ⨂ Or provide tools for “Crash-Only” software sh! ra C Actor Message Actor Event 1 Event 2 Event 3 Tuesday, 4 February, 14 Good to go!
  • 55. Being Resilient ☉Akka provides the foundation for resilien programming and design ⨳ Queues, Dispatchers, Async, Messages, realistic guarantees Tuesday, 4 February, 14
  • 56. Being Resilient ☉Akka provides the foundation for resilien programming and design ⨳ Queues, Dispatchers, Async, Messages, realistic guarantees ☉ Then you ge... Message Oriented Flexibility ⨳ Routers ⨳ ⨳ Persistence ⨳ Clustering ⨳ Resiliency Patterns ⨳ Remote Deployment Tuesday, 4 February, 14
  • 57. Being Resilient ☉Akka provides the foundation for resilien programming and design ⨳ Queues, Dispatchers, Async, Messages, realistic guarantees ☉ Then you ge... Message Oriented Flexibility ⨳ Routers ⨳ ⨳ Persistence ⨳ Clustering ⨳ Resiliency Patterns ⨳ Remote Deployment ☉ Existing cloud components are vial for resiliency Tuesday, 4 February, 14
  • 58. Being Resilient ☉Akka provides the foundation for resilien programming and design ⨳ Queues, Dispatchers, Async, Messages, realistic guarantees ☉ Then you ge... Message Oriented Flexibility ⨳ Routers ⨳ ⨳ Persistence ⨳ Clustering ⨳ Resiliency Patterns ⨳ Remote Deployment ☉ Akka picks up where those components leave of ☉ Existing cloud components are vial for resiliency Tuesday, 4 February, 14
  • 59. Go write some Code Get Scala http://scala-lang.org http://github.com/scala/scala Get Akka http://akka.io http://github.com/akka/akka Tuesday, 4 February, 14 Derek Wyatt Twitter: @derekwyatt Email: derek@derekwyatt.org