際際滷

際際滷Share a Scribd company logo
Failing gracefully
With the actor model
Roger Johansson
Akka.NET and Proto.Actor Founder
Solution Architect - Betsson Group
Twitter: @rogeralsing
Github: rogeralsing
Mail: rogeralsing@gmail.com
Github.com/rogeralsing/presentations
http://Proto.Actor
Design for failure
Dealing with, mitigating and preventing failures.
In the small, and at scale.
An escalator can never break: it can only become stairs.
You should never see an Escalator Temporarily Out Of Order
sign, just Escalator Temporarily Stairs.
Sorry for the convenience.
-Mitch Hedberg
Failing Gracefully with the actor model
Actors
Actor Model
Three axioms:
Send  an actor can send messages to other actors
Create  an actor can create new actors
Become  an actor can decide how to handle its next message
An island of consistency in a sea of concurrency
Shared nothing, Black box
Location transparent, Distributable by design
Actor Model
Actor Model
Implementations:
BEAM  Erlang, Elixir, LFE
JVM  Akka, Orbit
.NET  Akka.NET, Proto.Actor, Microsoft Orleans
Go  Proto.Actor
Event-driven thread
PID
Actor
State
Supervision
Children
Mailbox
Behavior
Transport
/c2
/b2/b1
/a1 /a2
/b3
/c3 /c4 /c5
/
/c1
/b1
ComponentConsumer 2
Consumer 1
Data Access
Website
Businesslogic
Vendor
machine
Insert coins
Gets coffee
Me
Need more coins
Vendor
machine
Insert coins
Out of beans
Service guy
Refill beans
Gets coffee
Me
Service
Request
Application error
Supervisor
Manage failures
Response
Validation error
Client
/c2
/b2/b1
/a1 /a2
/b3
/c3 /c4 /c5
/
Error Kernel
/c1
OneForOne supervisor AllForOne supervisor
/b1 /b3
Let it crash
child
parent
Protect state by
delegating work
Performs work,
can be restarted
Mitigating Failures
Exponential Backoff
child
parent
Attempts
Delay
DB Actor
DB Query
DB Result
DB Up
DB Query
DB Error
DB Down
Circuit Breaker
Idle
Active
Gated
Quarantined
Akka Remote Associations
Active Passive Consumers
Node 2
Node 1
Primary
Queue
Secondary
Consistent Hash Pairs
Queue
Hash Slot 1
Hash Slot 2
Hash Slot 3
Fan out and quickest reply
?
?
?
? Router
Worker 1
Worker 2
Worker 3
Fan out
Consumer
Fan out and quickest reply
!
!
!
! Router
Worker 1
Worker 2
Worker 3
Return first reply
Consumer
N-Modular Redundancy
!
!
!
! Router Worker 2
Worker 3
Require same reply from
at least N workers
Consumer
Worker 1
Dealing with load
Throttling
Add a delay after
each message
Throttling
Limit messages per
time slice
Bounded Mailboxes
ActorMailbox
Actor
Bounded Mailboxes
Mailbox
Limit Concurrency
12
1
2
3
34
4
Router
Worker 1
Worker 2
Worker 3
Limit concurrent
access to a resource
Work Pulling
Worker 1
Producer
Work to be done
Send work
Worker 2Work to be done
Send work
Work Done
Work Done
Virtual ActorsAlways Exists, Never Fails
Failing Gracefully with the actor model
Virtual Actors
Node A
433
Node B
24345
Node C
82327
Hash:
989123
Node E
943772
Grain Id:
Roger
Names:
Roger
Actors:
Roger : User
Virtual Actors
Node A
433
Node B
24345
Node C
82327
Hash:
989123
Node E
943772
Node F
987234
Grain Id:
Roger
Names:
Roger
Actors:
Roger : User
Virtual Actors
Coordinator
Akka Cluster Sharding
The End
Roger Johansson
Twitter: @rogeralsing
Github: rogeralsing
Mail: rogeralsing@gmail.com
Github.com/rogeralsing/presentations
http://Proto.Actor

More Related Content

Failing Gracefully with the actor model