SlideShare a Scribd company logo
1 of 28
Download to read offline
Scaling modern JVM applications
with Akka toolkit
Bojan Babić
About me
• Full stack developer, focused on JVM
• Currently focused on scaling in messaging
@tenzki github.com/tenzki
Basic
• Unit of computation
• Motivated by relatable concepts
• Application as human organization
Mailbox
Actor
Isolated State
21 3 54 6
S1
S0
S2
Supervisor
Actor 0
Supervisor
Actor 1
Subordinate
Actors
Akka
• Toolset with actor model as its foundation
• Written in Scala
• JVM with Java and Scala API
Example
• User in organization
• Described by name
• Can read and change it
// messages
case object GetName
case class SetName(name: String)
// actor
class User(var name: String) extends Actor {
override def receive: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => name = newName
}
}
Plain actor
// messages
case object GetName
case class SetName(name: String)
// actor
class User(var name: String) extends Actor {
override def receive: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => name = newName
}
}
Plain actor
// messages
case object GetName
case class SetName(name: String)
// actor
class User(var name: String) extends Actor {
override def receive: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => name = newName
}
}
Plain actor
Persisting state
• Event sourcing
• Supported with persistence module
• Cassandra, with support for relational databases, mongo…
Persistent actor
// commands
case object GetName
case class SetName(name: String)
// events
case class NameSet(name: String)
class User(id: UUID) extends PersistentActor {
var name: String = null
override def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
override def receiveCommand: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name)
}
override def persistenceId: String = s"user:${id.toString}"
}
// commands
case object GetName
case class SetName(name: String)
// events
case class NameSet(name: String)
class User(id: UUID) extends PersistentActor {
var name: String = null
override def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
override def receiveCommand: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name)
}
override def persistenceId: String = s"user:${id.toString}"
}
Persistent actor
// commands
case object GetName
case class SetName(name: String)
// events
case class NameSet(name: String)
class User(id: UUID) extends PersistentActor {
var name: String = null
override def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
override def receiveCommand: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name)
}
override def persistenceId: String = s"user:${id.toString}"
}
Persistent actor
// commands
case object GetName
case class SetName(name: String)
// events
case class NameSet(name: String)
class User(id: UUID) extends PersistentActor {
var name: String = null
override def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
override def receiveCommand: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name)
}
override def persistenceId: String = s"user:${id.toString}"
}
Persistent actor
// commands
case object GetName
case class SetName(name: String)
// events
case class NameSet(name: String)
class User(id: UUID) extends PersistentActor {
var name: String = null
override def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
override def receiveCommand: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name)
}
override def persistenceId: String = s"user:${id.toString}"
}
Persistent actor
// commands
case object GetName
case class SetName(name: String)
// events
case class NameSet(name: String)
class User(id: UUID) extends PersistentActor {
var name: String = null
override def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
override def receiveCommand: Receive = {
case GetName => sender() ! name
case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name)
}
override def persistenceId: String = s"user:${id.toString}"
}
Persistent actor
Running on multiple machines
• Cluster module
• Gossip protocol
• Cluster sharding
3
21
USERS
A B C Shards
User Actors
Cluster
Sharded actor
// commands
trait UserMsg {val id: UUID}
case class SetName(id: UUID, name: String) extends UserMsg
case class GetName(id: UUID) extends UserMsg
// events
case class NameSet(name: String)
class User extends PersistentActor {
var name: String = null
def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
def receiveCommand: Receive = {
case GetName(_) => sender() ! name
case SetName(_, newName: String) => persist(NameSet(newName))(e => name = e.name)
}
def persistenceId: String = s"user:persistence:${self.path.name}"
}
Sharded actor
// commands
trait UserMsg {val id: UUID}
case class SetName(id: UUID, name: String) extends UserMsg
case class GetName(id: UUID) extends UserMsg
// events
case class NameSet(name: String)
class User extends PersistentActor {
var name: String = null
def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
def receiveCommand: Receive = {
case GetName(_) => sender() ! name
case SetName(_, newName: String) => persist(NameSet(newName))(e => name = e.name)
}
def persistenceId: String = s"user:persistence:${self.path.name}"
}
Sharded actor
// commands
trait UserMsg {val id: UUID}
case class SetName(id: UUID, name: String) extends UserMsg
case class GetName(id: UUID) extends UserMsg
// events
case class NameSet(name: String)
class User extends PersistentActor {
var name: String = null
def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
def receiveCommand: Receive = {
case GetName(_) => sender() ! name
case SetName(_, newName: String) => persist(NameSet(newName))(e => name = e.name)
}
def persistenceId: String = s"user:persistence:${self.path.name}"
}
Sharded actor
object User {
val NAME = "user"
val extractEntityId: ShardRegion.ExtractEntityId = {
case command: UserMsg => (command.id.toString, command)
}
val numberOfShards = 100
val extractShardId: ShardRegion.ExtractShardId = {
case command: UserMsg => (command.id.toString.hashCode %
numberOfShards).toString
}
}
Optimize for scaling
• Command query responsibility segregation
• Different databases, eventually consistent
trait UserMsg {val id: UUID}
// commands
case class SetName(id: UUID, name: String) extends UserMsg
// events
case class NameSet(name: String)
class UserProcessor extends PersistentActor {
var name: String = null
override def receiveRecover: Receive = {
case NameSet(changeName: String) => name = changeName
}
def receiveCommand: Receive = {
case SetName(_, newName: String) => persist(NameSet(newName))(e => name = e.name)
}
def persistenceId: String = s"user:cqrs:${self.path.name}"
}
CQRS actors
CQRS actors
// query
case class GetName(id: UUID) extends UserMsg
class UserView extends Actor with Stash {
var name: String = null
def receive: Receive = {
case GetName(id: UUID) => stash()
case EventEnvelope(_, _, _, NameSet(newName: String)) =>
name = newName
unstashAll()
context.become(active)
sender() ! Done
}
def active: Receive = {
case GetName(_) => sender() ! name
case EventEnvelope(_, _, _, NameSet(newName: String)) =>
name = newName
sender() ! Done
}
}
Linking write and read
• Persistence query, API for streaming events
• Akka streams and reactive streams
• Streaming events from journal to any read database
Thanks!

More Related Content

What's hot

Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebChristian Baranowski
 
Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2Luis Miguel Reis
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objectsPhúc Đỗ
 
The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185Mahmoud Samir Fayed
 
Beyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeBeyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeAijaz Ansari
 
To infinity and beyond
To infinity and beyondTo infinity and beyond
To infinity and beyondclintongormley
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...Databricks
 
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...Matthew Tovbin
 
David Kopal - Unleash the power of the higher-order components
David Kopal - Unleash the power of the higher-order componentsDavid Kopal - Unleash the power of the higher-order components
David Kopal - Unleash the power of the higher-order componentsOdessaJS Conf
 
初めてのQuickで初めてのテスト
初めてのQuickで初めてのテスト初めてのQuickで初めてのテスト
初めてのQuickで初めてのテストKenji Tanaka
 

What's hot (15)

Python Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit TestingPython Ireland Nov 2010 Talk: Unit Testing
Python Ireland Nov 2010 Talk: Unit Testing
 
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und GebBDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
BDD - Behavior Driven Development Webapps mit Groovy Spock und Geb
 
Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2Functional streams with Kafka - A comparison between Akka-streams and FS2
Functional streams with Kafka - A comparison between Akka-streams and FS2
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185The Ring programming language version 1.5.4 book - Part 44 of 185
The Ring programming language version 1.5.4 book - Part 44 of 185
 
Beyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCodeBeyond Breakpoints: Advanced Debugging with XCode
Beyond Breakpoints: Advanced Debugging with XCode
 
To infinity and beyond
To infinity and beyondTo infinity and beyond
To infinity and beyond
 
Drupal 8 database api
Drupal 8 database apiDrupal 8 database api
Drupal 8 database api
 
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
The Rule of 10,000 Spark Jobs: Learning From Exceptions and Serializing Your ...
 
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
The Rule of 10,000 Spark Jobs - Learning from Exceptions and Serializing Your...
 
David Kopal - Unleash the power of the higher-order components
David Kopal - Unleash the power of the higher-order componentsDavid Kopal - Unleash the power of the higher-order components
David Kopal - Unleash the power of the higher-order components
 
Spock and Geb in Action
Spock and Geb in ActionSpock and Geb in Action
Spock and Geb in Action
 
Scala in practice
Scala in practiceScala in practice
Scala in practice
 
Gorm
GormGorm
Gorm
 
初めてのQuickで初めてのテスト
初めてのQuickで初めてのテスト初めてのQuickで初めてのテスト
初めてのQuickで初めてのテスト
 

Viewers also liked

Engaging e-Patients in a Digital World: How Collaboration, Transparency, and ...
Engaging e-Patients in a Digital World: How Collaboration, Transparency, and ...Engaging e-Patients in a Digital World: How Collaboration, Transparency, and ...
Engaging e-Patients in a Digital World: How Collaboration, Transparency, and ...Daniel Sands
 
Taller de Resiliencia y Agilidad en la conferencia Ágiles 2015, Montevideo 23...
Taller de Resiliencia y Agilidad en la conferencia Ágiles 2015, Montevideo 23...Taller de Resiliencia y Agilidad en la conferencia Ágiles 2015, Montevideo 23...
Taller de Resiliencia y Agilidad en la conferencia Ágiles 2015, Montevideo 23...Pablo Lischinsky
 
SK MERU 2 test paper 1
SK MERU 2 test paper 1SK MERU 2 test paper 1
SK MERU 2 test paper 1Fadz Ibrahim
 
Presentations: Openings signposting survival techniques
Presentations: Openings signposting survival techniquesPresentations: Openings signposting survival techniques
Presentations: Openings signposting survival techniqueslcslidepresentations
 
Transformación Ágil con Agile Kaizen y Lego Star Wars
Transformación Ágil con Agile Kaizen y Lego Star WarsTransformación Ágil con Agile Kaizen y Lego Star Wars
Transformación Ágil con Agile Kaizen y Lego Star WarsXimena Higuera Moriones
 
Training, Coaching And Mentoring
Training, Coaching And MentoringTraining, Coaching And Mentoring
Training, Coaching And MentoringAlec McPhedran
 
Programming Actor-based Collective Adaptive Systems
Programming Actor-based Collective Adaptive SystemsProgramming Actor-based Collective Adaptive Systems
Programming Actor-based Collective Adaptive SystemsRoberto Casadei
 
Discourse analysis for language teachers
Discourse analysis for language teachersDiscourse analysis for language teachers
Discourse analysis for language teachersMaria Fernanda Morocho
 
28443119 soalan-bm-bahasa-melayu-pemahaman-tahun-4-131115050029-phpapp01
28443119 soalan-bm-bahasa-melayu-pemahaman-tahun-4-131115050029-phpapp0128443119 soalan-bm-bahasa-melayu-pemahaman-tahun-4-131115050029-phpapp01
28443119 soalan-bm-bahasa-melayu-pemahaman-tahun-4-131115050029-phpapp01mohd fahmie mohd fauzi
 
Cohesion: Referring to other parts of a text
Cohesion: Referring to other parts of a textCohesion: Referring to other parts of a text
Cohesion: Referring to other parts of a texttheLecturette
 
Coaching & Mentoring
Coaching & MentoringCoaching & Mentoring
Coaching & MentoringAhmed Yasser
 
28437129 soalan-bm-bahasa-melayu-pemahaman-tahun-3
28437129 soalan-bm-bahasa-melayu-pemahaman-tahun-328437129 soalan-bm-bahasa-melayu-pemahaman-tahun-3
28437129 soalan-bm-bahasa-melayu-pemahaman-tahun-3Viran Gill
 
Non-defining relative clauses
Non-defining relative clausesNon-defining relative clauses
Non-defining relative clausestheLecturette
 
Writing Report Abstracts
Writing Report AbstractsWriting Report Abstracts
Writing Report AbstractstheLecturette
 
Comparison/ Contrast Essay
Comparison/ Contrast EssayComparison/ Contrast Essay
Comparison/ Contrast EssaytheLecturette
 
Instrumen cth upsr bm pemahaman bah b 7 sept 2015
Instrumen cth upsr bm pemahaman  bah b 7 sept 2015Instrumen cth upsr bm pemahaman  bah b 7 sept 2015
Instrumen cth upsr bm pemahaman bah b 7 sept 2015Che Siti Wismail
 

Viewers also liked (20)

Lembaran kerja Imbuhan 01
Lembaran kerja Imbuhan 01Lembaran kerja Imbuhan 01
Lembaran kerja Imbuhan 01
 
Engaging e-Patients in a Digital World: How Collaboration, Transparency, and ...
Engaging e-Patients in a Digital World: How Collaboration, Transparency, and ...Engaging e-Patients in a Digital World: How Collaboration, Transparency, and ...
Engaging e-Patients in a Digital World: How Collaboration, Transparency, and ...
 
F*** the Manifesto
F*** the ManifestoF*** the Manifesto
F*** the Manifesto
 
Taller de Resiliencia y Agilidad en la conferencia Ágiles 2015, Montevideo 23...
Taller de Resiliencia y Agilidad en la conferencia Ágiles 2015, Montevideo 23...Taller de Resiliencia y Agilidad en la conferencia Ágiles 2015, Montevideo 23...
Taller de Resiliencia y Agilidad en la conferencia Ágiles 2015, Montevideo 23...
 
SK MERU 2 test paper 1
SK MERU 2 test paper 1SK MERU 2 test paper 1
SK MERU 2 test paper 1
 
Presentations: Openings signposting survival techniques
Presentations: Openings signposting survival techniquesPresentations: Openings signposting survival techniques
Presentations: Openings signposting survival techniques
 
Transformación Ágil con Agile Kaizen y Lego Star Wars
Transformación Ágil con Agile Kaizen y Lego Star WarsTransformación Ágil con Agile Kaizen y Lego Star Wars
Transformación Ágil con Agile Kaizen y Lego Star Wars
 
DISCOURSE ANALYSIS FOR LANGUAGE TEACHER
DISCOURSE ANALYSIS FOR LANGUAGE TEACHERDISCOURSE ANALYSIS FOR LANGUAGE TEACHER
DISCOURSE ANALYSIS FOR LANGUAGE TEACHER
 
Training, Coaching And Mentoring
Training, Coaching And MentoringTraining, Coaching And Mentoring
Training, Coaching And Mentoring
 
Programming Actor-based Collective Adaptive Systems
Programming Actor-based Collective Adaptive SystemsProgramming Actor-based Collective Adaptive Systems
Programming Actor-based Collective Adaptive Systems
 
Discourse analysis for language teachers
Discourse analysis for language teachersDiscourse analysis for language teachers
Discourse analysis for language teachers
 
28443119 soalan-bm-bahasa-melayu-pemahaman-tahun-4-131115050029-phpapp01
28443119 soalan-bm-bahasa-melayu-pemahaman-tahun-4-131115050029-phpapp0128443119 soalan-bm-bahasa-melayu-pemahaman-tahun-4-131115050029-phpapp01
28443119 soalan-bm-bahasa-melayu-pemahaman-tahun-4-131115050029-phpapp01
 
Cohesion: Referring to other parts of a text
Cohesion: Referring to other parts of a textCohesion: Referring to other parts of a text
Cohesion: Referring to other parts of a text
 
Persuasive writing
Persuasive writingPersuasive writing
Persuasive writing
 
Coaching & Mentoring
Coaching & MentoringCoaching & Mentoring
Coaching & Mentoring
 
28437129 soalan-bm-bahasa-melayu-pemahaman-tahun-3
28437129 soalan-bm-bahasa-melayu-pemahaman-tahun-328437129 soalan-bm-bahasa-melayu-pemahaman-tahun-3
28437129 soalan-bm-bahasa-melayu-pemahaman-tahun-3
 
Non-defining relative clauses
Non-defining relative clausesNon-defining relative clauses
Non-defining relative clauses
 
Writing Report Abstracts
Writing Report AbstractsWriting Report Abstracts
Writing Report Abstracts
 
Comparison/ Contrast Essay
Comparison/ Contrast EssayComparison/ Contrast Essay
Comparison/ Contrast Essay
 
Instrumen cth upsr bm pemahaman bah b 7 sept 2015
Instrumen cth upsr bm pemahaman  bah b 7 sept 2015Instrumen cth upsr bm pemahaman  bah b 7 sept 2015
Instrumen cth upsr bm pemahaman bah b 7 sept 2015
 

Similar to Scaling modern JVM applications with Akka toolkit

Message-based communication patterns in distributed Akka applications
Message-based communication patterns in distributed Akka applicationsMessage-based communication patterns in distributed Akka applications
Message-based communication patterns in distributed Akka applicationsAndrii Lashchenko
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfHiroshi Ono
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesEelco Visser
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scalaparag978978
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
Project Gålbma – Actors vs Types
Project Gålbma – Actors vs TypesProject Gålbma – Actors vs Types
Project Gålbma – Actors vs TypesRoland Kuhn
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologyDaniel Knell
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kirill Rozov
 
Activator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupActivator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupHenrik Engström
 
Tools for Making Machine Learning more Reactive
Tools for Making Machine Learning more ReactiveTools for Making Machine Learning more Reactive
Tools for Making Machine Learning more ReactiveJeff Smith
 
Akka Typed — between Session Types and the Actor Model
Akka Typed — between Session Types and the Actor ModelAkka Typed — between Session Types and the Actor Model
Akka Typed — between Session Types and the Actor ModelRoland Kuhn
 
ScalikeJDBC Tutorial for Beginners
ScalikeJDBC Tutorial for BeginnersScalikeJDBC Tutorial for Beginners
ScalikeJDBC Tutorial for BeginnersKazuhiro Sera
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecordscalaconfjp
 
Kotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureKotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureDmytro Zaitsev
 

Similar to Scaling modern JVM applications with Akka toolkit (20)

Message-based communication patterns in distributed Akka applications
Message-based communication patterns in distributed Akka applicationsMessage-based communication patterns in distributed Akka applications
Message-based communication patterns in distributed Akka applications
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdfpragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
pragmaticrealworldscalajfokus2009-1233251076441384-2.pdf
 
Ti1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and ScopesTi1220 Lecture 2: Names, Bindings, and Scopes
Ti1220 Lecture 2: Names, Bindings, and Scopes
 
Pragmatic Real-World Scala
Pragmatic Real-World ScalaPragmatic Real-World Scala
Pragmatic Real-World Scala
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Akka tips
Akka tipsAkka tips
Akka tips
 
Project Gålbma – Actors vs Types
Project Gålbma – Actors vs TypesProject Gålbma – Actors vs Types
Project Gålbma – Actors vs Types
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
Controle de estado
Controle de estadoControle de estado
Controle de estado
 
Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3Kotlin Advanced - Apalon Kotlin Sprint Part 3
Kotlin Advanced - Apalon Kotlin Sprint Part 3
 
Activator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetupActivator and Reactive at Play NYC meetup
Activator and Reactive at Play NYC meetup
 
Tools for Making Machine Learning more Reactive
Tools for Making Machine Learning more ReactiveTools for Making Machine Learning more Reactive
Tools for Making Machine Learning more Reactive
 
Akka Typed — between Session Types and the Actor Model
Akka Typed — between Session Types and the Actor ModelAkka Typed — between Session Types and the Actor Model
Akka Typed — between Session Types and the Actor Model
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
ScalikeJDBC Tutorial for Beginners
ScalikeJDBC Tutorial for BeginnersScalikeJDBC Tutorial for Beginners
ScalikeJDBC Tutorial for Beginners
 
Scala ActiveRecord
Scala ActiveRecordScala ActiveRecord
Scala ActiveRecord
 
Kotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasureKotlin on Android: Delegate with pleasure
Kotlin on Android: Delegate with pleasure
 

Recently uploaded

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 

Recently uploaded (20)

Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 

Scaling modern JVM applications with Akka toolkit

  • 1. Scaling modern JVM applications with Akka toolkit Bojan Babić
  • 2. About me • Full stack developer, focused on JVM • Currently focused on scaling in messaging @tenzki github.com/tenzki
  • 3. Basic • Unit of computation • Motivated by relatable concepts • Application as human organization
  • 5. 21 3 54 6 S1 S0 S2 Supervisor Actor 0 Supervisor Actor 1 Subordinate Actors
  • 6. Akka • Toolset with actor model as its foundation • Written in Scala • JVM with Java and Scala API
  • 7. Example • User in organization • Described by name • Can read and change it
  • 8. // messages case object GetName case class SetName(name: String) // actor class User(var name: String) extends Actor { override def receive: Receive = { case GetName => sender() ! name case SetName(newName: String) => name = newName } } Plain actor
  • 9. // messages case object GetName case class SetName(name: String) // actor class User(var name: String) extends Actor { override def receive: Receive = { case GetName => sender() ! name case SetName(newName: String) => name = newName } } Plain actor
  • 10. // messages case object GetName case class SetName(name: String) // actor class User(var name: String) extends Actor { override def receive: Receive = { case GetName => sender() ! name case SetName(newName: String) => name = newName } } Plain actor
  • 11. Persisting state • Event sourcing • Supported with persistence module • Cassandra, with support for relational databases, mongo…
  • 12. Persistent actor // commands case object GetName case class SetName(name: String) // events case class NameSet(name: String) class User(id: UUID) extends PersistentActor { var name: String = null override def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } override def receiveCommand: Receive = { case GetName => sender() ! name case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name) } override def persistenceId: String = s"user:${id.toString}" }
  • 13. // commands case object GetName case class SetName(name: String) // events case class NameSet(name: String) class User(id: UUID) extends PersistentActor { var name: String = null override def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } override def receiveCommand: Receive = { case GetName => sender() ! name case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name) } override def persistenceId: String = s"user:${id.toString}" } Persistent actor
  • 14. // commands case object GetName case class SetName(name: String) // events case class NameSet(name: String) class User(id: UUID) extends PersistentActor { var name: String = null override def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } override def receiveCommand: Receive = { case GetName => sender() ! name case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name) } override def persistenceId: String = s"user:${id.toString}" } Persistent actor
  • 15. // commands case object GetName case class SetName(name: String) // events case class NameSet(name: String) class User(id: UUID) extends PersistentActor { var name: String = null override def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } override def receiveCommand: Receive = { case GetName => sender() ! name case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name) } override def persistenceId: String = s"user:${id.toString}" } Persistent actor
  • 16. // commands case object GetName case class SetName(name: String) // events case class NameSet(name: String) class User(id: UUID) extends PersistentActor { var name: String = null override def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } override def receiveCommand: Receive = { case GetName => sender() ! name case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name) } override def persistenceId: String = s"user:${id.toString}" } Persistent actor
  • 17. // commands case object GetName case class SetName(name: String) // events case class NameSet(name: String) class User(id: UUID) extends PersistentActor { var name: String = null override def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } override def receiveCommand: Receive = { case GetName => sender() ! name case SetName(newName: String) => persist(NameSet(newName))(e => name = e.name) } override def persistenceId: String = s"user:${id.toString}" } Persistent actor
  • 18. Running on multiple machines • Cluster module • Gossip protocol • Cluster sharding
  • 19. 3 21 USERS A B C Shards User Actors Cluster
  • 20. Sharded actor // commands trait UserMsg {val id: UUID} case class SetName(id: UUID, name: String) extends UserMsg case class GetName(id: UUID) extends UserMsg // events case class NameSet(name: String) class User extends PersistentActor { var name: String = null def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } def receiveCommand: Receive = { case GetName(_) => sender() ! name case SetName(_, newName: String) => persist(NameSet(newName))(e => name = e.name) } def persistenceId: String = s"user:persistence:${self.path.name}" }
  • 21. Sharded actor // commands trait UserMsg {val id: UUID} case class SetName(id: UUID, name: String) extends UserMsg case class GetName(id: UUID) extends UserMsg // events case class NameSet(name: String) class User extends PersistentActor { var name: String = null def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } def receiveCommand: Receive = { case GetName(_) => sender() ! name case SetName(_, newName: String) => persist(NameSet(newName))(e => name = e.name) } def persistenceId: String = s"user:persistence:${self.path.name}" }
  • 22. Sharded actor // commands trait UserMsg {val id: UUID} case class SetName(id: UUID, name: String) extends UserMsg case class GetName(id: UUID) extends UserMsg // events case class NameSet(name: String) class User extends PersistentActor { var name: String = null def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } def receiveCommand: Receive = { case GetName(_) => sender() ! name case SetName(_, newName: String) => persist(NameSet(newName))(e => name = e.name) } def persistenceId: String = s"user:persistence:${self.path.name}" }
  • 23. Sharded actor object User { val NAME = "user" val extractEntityId: ShardRegion.ExtractEntityId = { case command: UserMsg => (command.id.toString, command) } val numberOfShards = 100 val extractShardId: ShardRegion.ExtractShardId = { case command: UserMsg => (command.id.toString.hashCode % numberOfShards).toString } }
  • 24. Optimize for scaling • Command query responsibility segregation • Different databases, eventually consistent
  • 25. trait UserMsg {val id: UUID} // commands case class SetName(id: UUID, name: String) extends UserMsg // events case class NameSet(name: String) class UserProcessor extends PersistentActor { var name: String = null override def receiveRecover: Receive = { case NameSet(changeName: String) => name = changeName } def receiveCommand: Receive = { case SetName(_, newName: String) => persist(NameSet(newName))(e => name = e.name) } def persistenceId: String = s"user:cqrs:${self.path.name}" } CQRS actors
  • 26. CQRS actors // query case class GetName(id: UUID) extends UserMsg class UserView extends Actor with Stash { var name: String = null def receive: Receive = { case GetName(id: UUID) => stash() case EventEnvelope(_, _, _, NameSet(newName: String)) => name = newName unstashAll() context.become(active) sender() ! Done } def active: Receive = { case GetName(_) => sender() ! name case EventEnvelope(_, _, _, NameSet(newName: String)) => name = newName sender() ! Done } }
  • 27. Linking write and read • Persistence query, API for streaming events • Akka streams and reactive streams • Streaming events from journal to any read database