SlideShare une entreprise Scribd logo
1  sur  29
Building Reactive Systems with Akka
Today’s Agenda
 Part 1 – Introduction to Akka
 Part 2 – Scala Crash Course™
 Part 3 – Hello Reactive World
 Part 4 – A more complex example
Part 1 – Introduction to Akka
Problems with traditional systems
 Extreme growth of data and number of clients
 Mobile web (*), Internet of Things, etc.
 Threads won’t scale
 1 thread for each user
 1 Mb minimum stack size / thread on 64 bit VMs
 10 000 concurrent users => do the math 
 Existing programming models won’t scale either
 Writing bug-free thread synchronization / locking code manually is extreme hard
 Mutable state is the root of all evil
 Mutable state is the basic idea of Object Oriented Programming.. (oops)
 Polling sucks, we live in a realtime world
Properties of Reactive Systems
 Responsive
 Gives low-latency responses even for overloaded systems
 Resilient
 Stays responsive even upon system failures
 Message driven
 Asynchronous and non-blocking, concurrent by design
 Has no mutable shared state
 Elastic
 Can scale out horizontally on demand
Introducing Akka
 A framework and runtime engine for building reactive systems on the JVM
 Implements the Actor model (mathematical model of Carl Hewitt, 1973)
 Asynchronous, distributed by design
 Resilient and self-healing system (motto: “Let it crash”)
 High performance
 50 million message / sec
 2.5 million actor instances per GB of heap space
 Written in the Scala language, has Scala and Java bindings
 Open source with Apache2 license, commercially supported by Typesafe Inc.
Introducing Akka Actors
 Actors are the base building blocks of actor systems
 Actors are lightweight objects
 ~300 bytes / instance
 Encapsulate state and behavior
 Have no shared state ever
 Actors are asynchronous and non-blocking
 Communicate only via message passing
 Have a mailbox for inbound messages
 Always process messages in order
 Actors live in hierarchy
 Used for supervising
 Actors have a reference
 Phone number analogy
Part 2 – Scala Crash Course™
The Scala language
 Strong static type system
 Compiles to Java bytecode, runs on the JVM
 Mixes object-oriented and functional style
 Designed by Martin Odersky (javac)
 Publicly available since 2004
 Commercial support by Typesafe Inc. since 2011
Scala Crash Course in 9 lines
 Things to observe:
 Packages, objects and classes
 Constructor in object body
 Values and method calls
 Also note there are:
 no semicolons (;)
Scala Crash Course in 9 lines
 Things to observe:
 Packages, objects and classes
 Constructor in object body
 Values and method calls
 Method definitions
 Also note there are:
 no semicolons (;)
 no explicit types, unless necessary
Scala Crash Course in 9 lines
 Things to observe:
 Packages, objects and classes
 Constructor in object body
 Values and method calls
 Method definitions
 Case classes
 Also note there are:
 no semicolons (;)
 no explicit types, unless necessary
 no unnecessary braces ({ } ( ))
Scala Crash Course in 9 lines
 Things to observe:
 Packages, objects and classes
 Constructor in object body
 Values and method calls
 Method definitions
 Case classes
 Higher order functions
 String interpolation
 Also note there are:
 no semicolons (;)
 no unnecessary braces ({ } ( ))
 no explicit types, unless necessary
Part 3 – Hello Reactive World
Akka basics in Scala
 Actors live in an ActorSystem
 val system = ActorSystem(“hello”)
 Actors are created via Props (factories)
 val actor: ActorRef = system.actorOf(Props(classOf[MyActor.class]))
 Messages are most often plain case classes / case objects
 case class HelloMessage(message: String)
 ActorRefs are used to send messages
 actor ! HelloMessage(s“hello from $self”)
Akka HelloWorld
Part 4 – A more complex example
Building a Twitter streamer
 Twitter == poor man’s Big Data (up to 50msg/sec)
 Goal: Build a web application which displays the Twitter stream
and the number of connected users
 Tech stack
 Twitter4J – twitter API
 Play! – Scala web framework with WebSocket support, built on Akka
 Akka – actors based middleware
 Websocket JS API, JQuery, Bootstrap CSS
 Gatling – stress test tool
Demo
A reactive architecture
 System components:
 Akka Event Bus
 Play! Framework controller
 Actors in the system:
 1 x Streamer – connects to Twitter, receives status updates
 n x WSProxy – proxies events via WebSocket to client
 1 x ClientsTracker – tracks the number of clients, publishes the number every N seconds
 WebSocket in the browser:
 Registers with Play! controller, connects to Actor
 Receives push messages in JSON
 Replaces DOM with JQuery
Areactivearchitecture
Code review
Code review - Streamer actor
Code review - ClientsTracker actor
Code review - WSProxy actor
Code review - Play! controller class
WebSocket JS code
Demo – Load Test
Resources
 Twitter streamer source - https://github.com/kjozsa/reactive2
 Akka - http://akka.io/
 Play! Framework - https://playframework.com/

Contenu connexe

Tendances

Real-World Scala Design Patterns
Real-World Scala Design PatternsReal-World Scala Design Patterns
Real-World Scala Design Patterns
NLJUG
 

Tendances (20)

Java 201 Intro to Test Driven Development in Java
Java 201   Intro to Test Driven Development in JavaJava 201   Intro to Test Driven Development in Java
Java 201 Intro to Test Driven Development in Java
 
Introduction to Scala
Introduction to ScalaIntroduction to Scala
Introduction to Scala
 
Semantic DEX Components
Semantic DEX ComponentsSemantic DEX Components
Semantic DEX Components
 
Introduction To MacWire
Introduction To MacWireIntroduction To MacWire
Introduction To MacWire
 
Core java lessons
Core java lessonsCore java lessons
Core java lessons
 
java-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbaijava-corporate-training-institute-in-mumbai
java-corporate-training-institute-in-mumbai
 
Practical type mining in Scala
Practical type mining in ScalaPractical type mining in Scala
Practical type mining in Scala
 
Tonel repositories in VA Smalltalk by Esteban Maringolo
Tonel repositories in VA Smalltalk by Esteban MaringoloTonel repositories in VA Smalltalk by Esteban Maringolo
Tonel repositories in VA Smalltalk by Esteban Maringolo
 
Core java
Core javaCore java
Core java
 
Java
JavaJava
Java
 
Java8 features
Java8 featuresJava8 features
Java8 features
 
Introduction to java
Introduction to javaIntroduction to java
Introduction to java
 
Java 101 Intro to Java Programming - Exercises
Java 101   Intro to Java Programming - ExercisesJava 101   Intro to Java Programming - Exercises
Java 101 Intro to Java Programming - Exercises
 
RIBBUN SOFTWARE
RIBBUN SOFTWARERIBBUN SOFTWARE
RIBBUN SOFTWARE
 
Java intro
Java introJava intro
Java intro
 
Java01
Java01Java01
Java01
 
Java fundamentals 2
Java fundamentals 2Java fundamentals 2
Java fundamentals 2
 
Java interview questions and answers for cognizant By Data Council Pune
Java interview questions and answers for cognizant By Data Council PuneJava interview questions and answers for cognizant By Data Council Pune
Java interview questions and answers for cognizant By Data Council Pune
 
Real-World Scala Design Patterns
Real-World Scala Design PatternsReal-World Scala Design Patterns
Real-World Scala Design Patterns
 
C Sharp Course 101.5
C Sharp Course 101.5C Sharp Course 101.5
C Sharp Course 101.5
 

En vedette

Travel Portfolio
Travel PortfolioTravel Portfolio
Travel Portfolio
chrissnyny
 
Jasig-sakai2012-communitytranslation-kajita
Jasig-sakai2012-communitytranslation-kajitaJasig-sakai2012-communitytranslation-kajita
Jasig-sakai2012-communitytranslation-kajita
Shoji Kajita
 

En vedette (12)

Travel Portfolio
Travel PortfolioTravel Portfolio
Travel Portfolio
 
Chris Sanders
Chris SandersChris Sanders
Chris Sanders
 
Diablo II
Diablo IIDiablo II
Diablo II
 
Lifestyle
LifestyleLifestyle
Lifestyle
 
WebSocket bemutatás
WebSocket bemutatásWebSocket bemutatás
WebSocket bemutatás
 
Jasig-sakai2012-communitytranslation-kajita
Jasig-sakai2012-communitytranslation-kajitaJasig-sakai2012-communitytranslation-kajita
Jasig-sakai2012-communitytranslation-kajita
 
Dividends
DividendsDividends
Dividends
 
Introduction to Big Data
Introduction to Big DataIntroduction to Big Data
Introduction to Big Data
 
50 ans d'anticipation n°5 : le journal de TNS Sofres
50 ans d'anticipation n°5 : le journal de TNS Sofres50 ans d'anticipation n°5 : le journal de TNS Sofres
50 ans d'anticipation n°5 : le journal de TNS Sofres
 
Pourquoi créer un bulletin paroissial électronique
Pourquoi créer un bulletin paroissial électroniquePourquoi créer un bulletin paroissial électronique
Pourquoi créer un bulletin paroissial électronique
 
Microsoft TechDays 2012 France - BPOS301 La réversibilité des données dans le...
Microsoft TechDays 2012 France - BPOS301 La réversibilité des données dans le...Microsoft TechDays 2012 France - BPOS301 La réversibilité des données dans le...
Microsoft TechDays 2012 France - BPOS301 La réversibilité des données dans le...
 
Etude de marché Beiersdorf/Nivea
Etude de marché Beiersdorf/NiveaEtude de marché Beiersdorf/Nivea
Etude de marché Beiersdorf/Nivea
 

Similaire à Building reactive systems with Akka

Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
Skills Matter
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
Salesforce Developers
 
Manuel - SPR - Intro to Java Language_2016
Manuel - SPR - Intro to Java Language_2016Manuel - SPR - Intro to Java Language_2016
Manuel - SPR - Intro to Java Language_2016
Manuel Fomitescu
 

Similaire à Building reactive systems with Akka (20)

A Survey of Concurrency Constructs
A Survey of Concurrency ConstructsA Survey of Concurrency Constructs
A Survey of Concurrency Constructs
 
Akka london scala_user_group
Akka london scala_user_groupAkka london scala_user_group
Akka london scala_user_group
 
EnScript Workshop
EnScript WorkshopEnScript Workshop
EnScript Workshop
 
iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)iPhone development from a Java perspective (Jazoon '09)
iPhone development from a Java perspective (Jazoon '09)
 
10-DesignPatterns.ppt
10-DesignPatterns.ppt10-DesignPatterns.ppt
10-DesignPatterns.ppt
 
Build Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and Heroku
 
Ruby On Rails
Ruby On RailsRuby On Rails
Ruby On Rails
 
Manuel - SPR - Intro to Java Language_2016
Manuel - SPR - Intro to Java Language_2016Manuel - SPR - Intro to Java Language_2016
Manuel - SPR - Intro to Java Language_2016
 
Devoxx
DevoxxDevoxx
Devoxx
 
Concurrency Constructs Overview
Concurrency Constructs OverviewConcurrency Constructs Overview
Concurrency Constructs Overview
 
Functional Programming In Jdk8
Functional Programming In Jdk8 Functional Programming In Jdk8
Functional Programming In Jdk8
 
Scale up your thinking
Scale up your thinkingScale up your thinking
Scale up your thinking
 
Java-Intro.pptx
Java-Intro.pptxJava-Intro.pptx
Java-Intro.pptx
 
Unit 1 notes.pdf
Unit 1 notes.pdfUnit 1 notes.pdf
Unit 1 notes.pdf
 
Introduction java programming
Introduction java programmingIntroduction java programming
Introduction java programming
 
Introducing Akka
Introducing AkkaIntroducing Akka
Introducing Akka
 
Discovering the Service Fabric's actor model
Discovering the Service Fabric's actor modelDiscovering the Service Fabric's actor model
Discovering the Service Fabric's actor model
 
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
Beyond fault tolerance with actor programming - Fabio Tiriticco - Codemotion ...
 
Beyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingBeyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor Programming
 
Building Stateful Microservices With Akka
Building Stateful Microservices With AkkaBuilding Stateful Microservices With Akka
Building Stateful Microservices With Akka
 

Dernier

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Dernier (20)

Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 

Building reactive systems with Akka

  • 2. Today’s Agenda  Part 1 – Introduction to Akka  Part 2 – Scala Crash Course™  Part 3 – Hello Reactive World  Part 4 – A more complex example
  • 3. Part 1 – Introduction to Akka
  • 4. Problems with traditional systems  Extreme growth of data and number of clients  Mobile web (*), Internet of Things, etc.  Threads won’t scale  1 thread for each user  1 Mb minimum stack size / thread on 64 bit VMs  10 000 concurrent users => do the math   Existing programming models won’t scale either  Writing bug-free thread synchronization / locking code manually is extreme hard  Mutable state is the root of all evil  Mutable state is the basic idea of Object Oriented Programming.. (oops)  Polling sucks, we live in a realtime world
  • 5. Properties of Reactive Systems  Responsive  Gives low-latency responses even for overloaded systems  Resilient  Stays responsive even upon system failures  Message driven  Asynchronous and non-blocking, concurrent by design  Has no mutable shared state  Elastic  Can scale out horizontally on demand
  • 6. Introducing Akka  A framework and runtime engine for building reactive systems on the JVM  Implements the Actor model (mathematical model of Carl Hewitt, 1973)  Asynchronous, distributed by design  Resilient and self-healing system (motto: “Let it crash”)  High performance  50 million message / sec  2.5 million actor instances per GB of heap space  Written in the Scala language, has Scala and Java bindings  Open source with Apache2 license, commercially supported by Typesafe Inc.
  • 7. Introducing Akka Actors  Actors are the base building blocks of actor systems  Actors are lightweight objects  ~300 bytes / instance  Encapsulate state and behavior  Have no shared state ever  Actors are asynchronous and non-blocking  Communicate only via message passing  Have a mailbox for inbound messages  Always process messages in order  Actors live in hierarchy  Used for supervising  Actors have a reference  Phone number analogy
  • 8. Part 2 – Scala Crash Course™
  • 9. The Scala language  Strong static type system  Compiles to Java bytecode, runs on the JVM  Mixes object-oriented and functional style  Designed by Martin Odersky (javac)  Publicly available since 2004  Commercial support by Typesafe Inc. since 2011
  • 10. Scala Crash Course in 9 lines  Things to observe:  Packages, objects and classes  Constructor in object body  Values and method calls  Also note there are:  no semicolons (;)
  • 11. Scala Crash Course in 9 lines  Things to observe:  Packages, objects and classes  Constructor in object body  Values and method calls  Method definitions  Also note there are:  no semicolons (;)  no explicit types, unless necessary
  • 12. Scala Crash Course in 9 lines  Things to observe:  Packages, objects and classes  Constructor in object body  Values and method calls  Method definitions  Case classes  Also note there are:  no semicolons (;)  no explicit types, unless necessary  no unnecessary braces ({ } ( ))
  • 13. Scala Crash Course in 9 lines  Things to observe:  Packages, objects and classes  Constructor in object body  Values and method calls  Method definitions  Case classes  Higher order functions  String interpolation  Also note there are:  no semicolons (;)  no unnecessary braces ({ } ( ))  no explicit types, unless necessary
  • 14. Part 3 – Hello Reactive World
  • 15. Akka basics in Scala  Actors live in an ActorSystem  val system = ActorSystem(“hello”)  Actors are created via Props (factories)  val actor: ActorRef = system.actorOf(Props(classOf[MyActor.class]))  Messages are most often plain case classes / case objects  case class HelloMessage(message: String)  ActorRefs are used to send messages  actor ! HelloMessage(s“hello from $self”)
  • 17. Part 4 – A more complex example
  • 18. Building a Twitter streamer  Twitter == poor man’s Big Data (up to 50msg/sec)  Goal: Build a web application which displays the Twitter stream and the number of connected users  Tech stack  Twitter4J – twitter API  Play! – Scala web framework with WebSocket support, built on Akka  Akka – actors based middleware  Websocket JS API, JQuery, Bootstrap CSS  Gatling – stress test tool
  • 19. Demo
  • 20. A reactive architecture  System components:  Akka Event Bus  Play! Framework controller  Actors in the system:  1 x Streamer – connects to Twitter, receives status updates  n x WSProxy – proxies events via WebSocket to client  1 x ClientsTracker – tracks the number of clients, publishes the number every N seconds  WebSocket in the browser:  Registers with Play! controller, connects to Actor  Receives push messages in JSON  Replaces DOM with JQuery
  • 23. Code review - Streamer actor
  • 24. Code review - ClientsTracker actor
  • 25. Code review - WSProxy actor
  • 26. Code review - Play! controller class
  • 29. Resources  Twitter streamer source - https://github.com/kjozsa/reactive2  Akka - http://akka.io/  Play! Framework - https://playframework.com/