SlideShare a Scribd company logo
1 of 57
Real World Akka Recipes
Jamie Allen
Björn Antonsson
Patrik Nordwall
The Fallacy of
Guaranteed Delivery
Jamie Allen
@jamie_allen
Guaranteed Delivery
• From Enterprise Integration Patterns
• Messaging system uses built-in store
to persist
• ACK everywhere
– Producer to sender
– Sender to receiver
– Receiver to consumer
@jamie_allen
3
Akka Guarantees
• Not much, intentionally
• At most once, with no reordering
• Pick your poison:
– At most once
– At least once
– Exactly once
• You have to add it on top
@jamie_allen
4
How Do I Do It?
• Handle “at least” semantics on receiver
to deal with duplicates
– Idempotent behavior in receiver
– Check message ID
• Handle “at most” semantics on the
sender via retries
– ACK every time message is handled
– Cancel repeated send
@jamie_allen
5
Durable Mailboxes?
@jamie_allen
6
Uh,	
  no.
@jamie_allen
• Doesn’t work with future-based message
sending (ask, ?)
• No guarantee is there that the message
even got to the mailbox in distributed
systems
• Asking for guarantees in an uncertain
world
7
Durable Mailboxes
Event Sourcing?
• Wonderful pattern for compiling a list of
time-series events
• Separation of concerns from actor
mailboxes
• Still lots of things that can go wrong
– Disk writing
– Replication consistency
– Network partitions
– Application latency
@jamie_allen
8
External Durable Message Queue
• You still have to ACK
• No certainty the message you needed
even got this far
• Additional dependencies in your
architecture
@jamie_allen
9
Guaranteed Delivery Doesn’t Exist
• We don’t know what we don’t know
• Increased effort
• Increased complexity
• Increased latency
• No guarantees of consistency
• Doesn’t guarantee ordering
@jamie_allen
10
So What Do We Do?
• This falls outside of actor supervision;
nothing the actors know about has
gone wrong
• Listen to Roland Kuhn:
“Recovery ... should ideally be
automatic in order to restore normal
service as quickly as possible.”
@jamie_allen
11
Sentinels
12
@jamie_allen
Sentinels
• Supervisors handle failure BELOW them.
Sentinels handle failure ABOVE.
• Responsible for querying a “source of truth” and
getting latest state
• Sends data to supervisor, who resolves
differences in which instances of actors should
exist versus those that do
• Supervisor forwards data to instances that
should exist for them to resolve their internal
state
@jamie_allen
13
Missed Events
@jamie_allen
Customer	
  2Customer	
  1
Customer	
  
Supervisor
Add	
  Customer	
  3
Delete	
  Customer	
  1
Update	
  Customer	
  2
Sentinels
@jamie_allen
Customer	
  
2
Customer	
  1
Customer	
  
Supervisor
Customer	
  
Sentinel
Customer	
  2
Customer	
  3
Sentinels
@jamie_allen
Customer	
  
2
Customer	
  1
Customer	
  
Supervisor
Customer	
  
Sentinel
Customer	
  2
Customer	
  3
Sentinels
@jamie_allen
Customer	
  
2
Customer	
  1
Customer	
  
Supervisor
Customer	
  
Sentinel
X
Customer	
  2
Customer	
  3
Sentinels
@jamie_allen
Customer	
  
2
Customer	
  
Supervisor
Customer	
  
Sentinel
Customer	
  2
Customer	
  3
Customer	
  2
Sentinels
@jamie_allen
Customer	
  
2
Customer	
  
Supervisor
Customer	
  
Sentinel
Customer	
  2
Customer	
  3
Customer	
  
3
Sentinels
• Localize them for each kind of data
that must be synchronized in your
supervisor hierarchy
• Do not create one big one and try to
resolve the entire tree at once
@jamie_allen
20
Drawbacks
• Doesn’t work well with localized event
sourcing - time series can be lost
• Does introduce additional complexity
and tunable latency over applications
with no guarantees
• Pattern only works when there is a
queryable source of truth
@jamie_allen
21
Inconsistent Views?
• Using Sentinels at multiple levels of a
supervisory hierarchy can lead to
temporarily inconsistent views when
child actors are resolved before
parents on delete (no atomicity)
• But is this necessarily bad?
@jamie_allen
22
Sentinels in Hierarchy
@jamie_allen
C2C1
CS
A2A1
AS
D2D1
DS
A2
SS
S
Sentinels in Hierarchy
@jamie_allen
C2C1
CS
A2A1
AS
D2D1
DS
A2
SS
S
X
Sentinels in Hierarchy
@jamie_allen
C2C1
CS
A2A1
AS
D2D1
DS
A2
SS
S
X
Sentinels in Hierarchy
@jamie_allen
C2C1
CS
AS
D2D1
DS SS
S
X
Sentinels in Hierarchy
@jamie_allen
C2C1
CS
D2D1
DS S
S
X
AS S
Sentinels in Hierarchy
@jamie_allen
C1
CS S
A Huge Win
• Your system is resilient to external
failures
• You can tune sentinel update
frequency to meet changing
requirements
• Your system is considerably less
complex than attempting to guarantee
no message loss
@jamie_allen
29
Flow Control
Björn Antonsson
@bantonsson
Pure Push Applications
• Often the first Actor application you
write
– Once you start telling and stop asking
• Easy to implement and reason about
• Fits nicely with short lived jobs that
come at a fixed rate
31
@bantonsson
32
@bantonsson
Why do you need anything else?
• Produce jobs faster than you can finish
them
• Jobs are expensive compute/memory
wise
• External resources impose limits
• Unpredictable job patterns
33
@bantonsson
What can you do instead?
• Push with rate limiting
– A fixed number of jobs per time unit are
pushed
• Push with acknowledgment
– A fixed number of jobs can be in progress.
– New jobs are pushed after old jobs finish
• Pull
– Jobs are pulled from the master at the rate
that they are completed
34
@bantonsson
Push with rate limiting
• A timer sends the master ticks at fixed
intervals
• When a tick arrives, the master fills up
its token count
• If a job arrives and there are no tokens,
it gets queued
• When the master has tokens, it pulls
jobs off the queue and pushes them
35
@bantonsson
36
@bantonsson
Push with acknowledgement
• The master push a fixed number of jobs
before waiting for an acknowledgement
• If a job arrives and the master can't
push, it gets queued
• To keep workers busy, push more than
one job per worker
– You can use a high water mark to stop and
a low water mark to start pushing
37
@bantonsson
38
@bantonsson
Pull
• The master actor queues incoming jobs
• Worker actors ask the master for a job
and receives jobs when available
• The workers don't need to do active
polling
• Can lead to lag if jobs are small
compared to the time it takes to get a
new one
– Use batching to counteract lag
39
@bantonsson
40
@bantonsson
References
• Push with rate limiting
– Kaspar Fischer
http://letitcrash.com/post/28901663062/throttling-messages-in-akka-2
• Pull
– Derek Wyatt
http://letitcrash.com/post/29044669086/balancing-workload-across-
nodes-with-akka-2
– Michael Pollmeier
http://www.michaelpollmeier.com/akka-work-pulling-pattern-to-
throttle-work/
41
@bantonsson
Distributed
Workers
Patrik Nordwall
@patriknw
43
Goal
• elastic addition/removal of front end
nodes
• elastic addition/removal of workers
• thousands of workers
• jobs should not be lost
44
45
46
47
48
49
50
51
DistributedPubSubMediator
52
53
54
55
56
Real world akka recepies v3

More Related Content

Viewers also liked

深入剖析Concurrent hashmap中的同步机制(上)
深入剖析Concurrent hashmap中的同步机制(上)深入剖析Concurrent hashmap中的同步机制(上)
深入剖析Concurrent hashmap中的同步机制(上)
wang hongjiang
 
Exodus重构和向apollo迁移
Exodus重构和向apollo迁移Exodus重构和向apollo迁移
Exodus重构和向apollo迁移
wang hongjiang
 
深入剖析Concurrent hashmap中的同步机制(下)
深入剖析Concurrent hashmap中的同步机制(下)深入剖析Concurrent hashmap中的同步机制(下)
深入剖析Concurrent hashmap中的同步机制(下)
wang hongjiang
 

Viewers also liked (20)

聊一些电影
聊一些电影聊一些电影
聊一些电影
 
Aswan&hump
Aswan&humpAswan&hump
Aswan&hump
 
深入剖析Concurrent hashmap中的同步机制(上)
深入剖析Concurrent hashmap中的同步机制(上)深入剖析Concurrent hashmap中的同步机制(上)
深入剖析Concurrent hashmap中的同步机制(上)
 
Exodus重构和向apollo迁移
Exodus重构和向apollo迁移Exodus重构和向apollo迁移
Exodus重构和向apollo迁移
 
Java7 fork join framework and closures
Java7 fork join framework and closuresJava7 fork join framework and closures
Java7 fork join framework and closures
 
Effective linux.3.(diagnosis)
Effective linux.3.(diagnosis)Effective linux.3.(diagnosis)
Effective linux.3.(diagnosis)
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)
 
深入剖析Concurrent hashmap中的同步机制(下)
深入剖析Concurrent hashmap中的同步机制(下)深入剖析Concurrent hashmap中的同步机制(下)
深入剖析Concurrent hashmap中的同步机制(下)
 
Effective linux.2.(tools)
Effective linux.2.(tools)Effective linux.2.(tools)
Effective linux.2.(tools)
 
Enum开锁
Enum开锁Enum开锁
Enum开锁
 
Jvm内存管理基础
Jvm内存管理基础Jvm内存管理基础
Jvm内存管理基础
 
Ali-tomcat
Ali-tomcatAli-tomcat
Ali-tomcat
 
中等创业公司后端技术选型
中等创业公司后端技术选型中等创业公司后端技术选型
中等创业公司后端技术选型
 
Automatic Scaling Iterative Computations
Automatic Scaling Iterative ComputationsAutomatic Scaling Iterative Computations
Automatic Scaling Iterative Computations
 
Behavioral Simulations in MapReduce
Behavioral Simulations in MapReduceBehavioral Simulations in MapReduce
Behavioral Simulations in MapReduce
 
Apache Kafka at LinkedIn
Apache Kafka at LinkedInApache Kafka at LinkedIn
Apache Kafka at LinkedIn
 
Apache Kafka, and the Rise of Stream Processing
Apache Kafka, and the Rise of Stream ProcessingApache Kafka, and the Rise of Stream Processing
Apache Kafka, and the Rise of Stream Processing
 
Building Realtim Data Pipelines with Kafka Connect and Spark Streaming
Building Realtim Data Pipelines with Kafka Connect and Spark StreamingBuilding Realtim Data Pipelines with Kafka Connect and Spark Streaming
Building Realtim Data Pipelines with Kafka Connect and Spark Streaming
 
Introduction to Cassandra Basics
Introduction to Cassandra BasicsIntroduction to Cassandra Basics
Introduction to Cassandra Basics
 
Building a Replicated Logging System with Apache Kafka
Building a Replicated Logging System with Apache KafkaBuilding a Replicated Logging System with Apache Kafka
Building a Replicated Logging System with Apache Kafka
 

Similar to Real world akka recepies v3

Similar to Real world akka recepies v3 (20)

Kanban vs Scrum: What's the difference, and which should you use?
Kanban vs Scrum: What's the difference, and which should you use?Kanban vs Scrum: What's the difference, and which should you use?
Kanban vs Scrum: What's the difference, and which should you use?
 
Benchmarking (RICON 2014)
Benchmarking (RICON 2014)Benchmarking (RICON 2014)
Benchmarking (RICON 2014)
 
Risk Management and Reliable Forecasting using Un-reliable Data (magennis) - ...
Risk Management and Reliable Forecasting using Un-reliable Data (magennis) - ...Risk Management and Reliable Forecasting using Un-reliable Data (magennis) - ...
Risk Management and Reliable Forecasting using Un-reliable Data (magennis) - ...
 
Devops London 2013 - Robust systems or, not fucking the customer
Devops London 2013 - Robust systems or, not fucking the customerDevops London 2013 - Robust systems or, not fucking the customer
Devops London 2013 - Robust systems or, not fucking the customer
 
Benchmarking: You're Doing It Wrong (StrangeLoop 2014)
Benchmarking: You're Doing It Wrong (StrangeLoop 2014)Benchmarking: You're Doing It Wrong (StrangeLoop 2014)
Benchmarking: You're Doing It Wrong (StrangeLoop 2014)
 
Splunk live! Customer Presentation – Prelert
Splunk live! Customer Presentation – PrelertSplunk live! Customer Presentation – Prelert
Splunk live! Customer Presentation – Prelert
 
Fighting Spam at Flickr
Fighting Spam at FlickrFighting Spam at Flickr
Fighting Spam at Flickr
 
New accounting system implementation – Best Practices
New accounting system implementation – Best PracticesNew accounting system implementation – Best Practices
New accounting system implementation – Best Practices
 
Fault-tolerance on the Cheap: Making Systems That (Probably) Won't Fall Over
Fault-tolerance on the Cheap: Making Systems That (Probably) Won't Fall Over Fault-tolerance on the Cheap: Making Systems That (Probably) Won't Fall Over
Fault-tolerance on the Cheap: Making Systems That (Probably) Won't Fall Over
 
6/18/14 Billing & Payments Engineering Meetup I
6/18/14 Billing & Payments Engineering Meetup I6/18/14 Billing & Payments Engineering Meetup I
6/18/14 Billing & Payments Engineering Meetup I
 
Gr8conf US 2015 - Intro to Event Sourcing with Groovy
Gr8conf US 2015 - Intro to Event Sourcing with GroovyGr8conf US 2015 - Intro to Event Sourcing with Groovy
Gr8conf US 2015 - Intro to Event Sourcing with Groovy
 
Montali: Declarative, Constraint-Based Business Process Management - Seville ...
Montali: Declarative, Constraint-Based Business Process Management - Seville ...Montali: Declarative, Constraint-Based Business Process Management - Seville ...
Montali: Declarative, Constraint-Based Business Process Management - Seville ...
 
6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection6 Scope & 7 Live Data Collection
6 Scope & 7 Live Data Collection
 
Five Cliches of Online Game Development
Five Cliches of Online Game DevelopmentFive Cliches of Online Game Development
Five Cliches of Online Game Development
 
Storm 2012-03-29
Storm 2012-03-29Storm 2012-03-29
Storm 2012-03-29
 
Skepticism at work - Logical Fallacies. ASQ Buffalo
Skepticism at work - Logical Fallacies. ASQ BuffaloSkepticism at work - Logical Fallacies. ASQ Buffalo
Skepticism at work - Logical Fallacies. ASQ Buffalo
 
A Story of Continuous Integration
A Story of Continuous IntegrationA Story of Continuous Integration
A Story of Continuous Integration
 
Jeff Lopez - To Affinity and Beyond
Jeff Lopez - To Affinity and BeyondJeff Lopez - To Affinity and Beyond
Jeff Lopez - To Affinity and Beyond
 
Jeff Lopez - To Affinity and Beyond
Jeff Lopez - To Affinity and BeyondJeff Lopez - To Affinity and Beyond
Jeff Lopez - To Affinity and Beyond
 
Online Accounting
Online AccountingOnline Accounting
Online Accounting
 

More from shinolajla

20150411 mutability matrix of pain scala
20150411 mutability matrix of pain scala20150411 mutability matrix of pain scala
20150411 mutability matrix of pain scala
shinolajla
 
20140228 fp and_performance
20140228 fp and_performance20140228 fp and_performance
20140228 fp and_performance
shinolajla
 
Effective akka scalaio
Effective akka scalaioEffective akka scalaio
Effective akka scalaio
shinolajla
 
Effective actors japanesesub
Effective actors japanesesubEffective actors japanesesub
Effective actors japanesesub
shinolajla
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
shinolajla
 

More from shinolajla (18)

20180416 reactive is_a_product_rs
20180416 reactive is_a_product_rs20180416 reactive is_a_product_rs
20180416 reactive is_a_product_rs
 
20180416 reactive is_a_product
20180416 reactive is_a_product20180416 reactive is_a_product
20180416 reactive is_a_product
 
20161027 scala io_keynote
20161027 scala io_keynote20161027 scala io_keynote
20161027 scala io_keynote
 
20160609 nike techtalks reactive applications tools of the trade
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
 
20160524 ibm fast data meetup
20160524 ibm fast data meetup20160524 ibm fast data meetup
20160524 ibm fast data meetup
 
20160520 The Future of Services
20160520 The Future of Services20160520 The Future of Services
20160520 The Future of Services
 
20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas20160520 what youneedtoknowaboutlambdas
20160520 what youneedtoknowaboutlambdas
 
20160317 lagom sf scala
20160317 lagom sf scala20160317 lagom sf scala
20160317 lagom sf scala
 
Effective Akka v2
Effective Akka v2Effective Akka v2
Effective Akka v2
 
20150411 mutability matrix of pain scala
20150411 mutability matrix of pain scala20150411 mutability matrix of pain scala
20150411 mutability matrix of pain scala
 
Reactive applications tools of the trade huff po
Reactive applications   tools of the trade huff poReactive applications   tools of the trade huff po
Reactive applications tools of the trade huff po
 
20140228 fp and_performance
20140228 fp and_performance20140228 fp and_performance
20140228 fp and_performance
 
Effective akka scalaio
Effective akka scalaioEffective akka scalaio
Effective akka scalaio
 
Cpu Caches
Cpu CachesCpu Caches
Cpu Caches
 
Effective actors japanesesub
Effective actors japanesesubEffective actors japanesesub
Effective actors japanesesub
 
Effective Actors
Effective ActorsEffective Actors
Effective Actors
 
Taxonomy of Scala
Taxonomy of ScalaTaxonomy of Scala
Taxonomy of Scala
 
CPU Caches
CPU CachesCPU Caches
CPU Caches
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Recently uploaded (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
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...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

Real world akka recepies v3