SlideShare a Scribd company logo
1 of 25
Download to read offline
Two Reactive approaches to scale
1
Comparing two approaches
for scalable, message-driven, backend applications
in Java
Spring Boot μServices and Akka
Lorenzo Nicora Lorenzo.nicora@opencredo.com
2
“Reactive” is…
Reactive
Semantically overloaded term
adj. “Readily responsive to stimulus” [Merrian-Webster dictionary]
From Latin “reagere”: act in return
• Reactive as Responsive
Quickly prompt to user actions
Reactive as…
• Reactive as Data binding
Declarative, as opposed to Imperative
a=b+3
e.g. Spreadsheets
• Reactive streams as Asynchronous Data Streams
• Reactive as Reactive Manifesto
ü Responsive à Low latency
ü Resilient à Stay responsive on failure
ü Elastic à Scale as needed
ü Message-Driven
• Async messages as only communication between components
Reactive Manifesto
✗ No Blocking operation
✗ No Synchronization
✗ No Resource hogging
Decoupling and isolation in…
ü Time à Allow concurrency
ü Space à Components location decoupling
Reactive Manifesto promotes
Top-down approach: from Macro
(at μService boundaries)
o Message based communication between services
o Isolation at service level
Bottom-Up approach: from Micro
(within the service)
o Message based communication between components
o Non-blocking processing
o Isolation at component level
Macro and Micro approaches
Two real world projects
Spring Boot
μService
Akka
Spring Boot μService application
ü Message-based communication between services
ü Non-blocking (where possible)
o Java 8 CompletableFutures
o Http non-blocking Servlets
o Fast-returning API endpoints
ü Event sourcing persistence
o Concursus forerunner
ü Spring Boot and Spring Cloud Config
Spring Boot μService
Java application using Akka, Cluster
ü Akka Actor programming model
ü Event-sourcing by Akka Persistence
ü Akka Cluster
ü Deployed using ConductR [Commercial]
ü Akka Http server (no container), non blocking
ü TypeSafe Config
✗ not Lagom framework
✗ not Akka Streams
Akka Cluster
TL;DR
“The actor model in computer science is a mathematical model of
concurrent computation that treats "actors" as the universal primitives of
concurrent computation.
In response to a message that it receives, an actor can: make local
decisions, create more actors, send more messages, and determine how to
respond to the next message received. Actors may modify private state, but
can only affect each other through messages (avoiding the need for any
locks).”
[Wikipedia]
Actor model
Actor
Actor
Actor
Mailbox Mailbox
Mailbox
ü Article by Carl Hewitt (1973)
ü Erlang (1986)
ü Akka framework (2009)
A different way to concurrency
Actors, !Threads
Actor is the primary computational entity
o In Java, still a mixed world of Objects and Actors
Actors interact exclusively via asynchronous messages
o As opposed to Objects interacting through method calls
o Actors REACT on receiving a message
o No synchronisation; no lock
Actor model for dummies
Actor
Actor
Actor
Mailbox Mailbox
Mailbox
Actor handles one message a time
o Message handling code is intrinsically thread safe
o May have simple state: Instance properties in Java
Actor is lightweight
o Little overhead over creating an object
o May be used to hold request context
• Per-request Actors: a common pattern
Actor model
Collaborating Actors
≠ Dependency Injection
o Akka: Actor Refs (location/lifecycle transparent) ≠ object refs
Actors are created by Actors (…then may be passed around)
Parent à Children
Supervision hierarchy
Failure handling
Supervision
Implementing Reactive principles
Implementing Reactive principles
from Macro and from Micro
Plain Java/Spring or Akka
Never block threads waiting
Macro
o Asynchronous messaging protocols between services
Micro
Plain Java
o CompletableFuture
o Non-blocking Servlets
o Low level NIO (!)
Akka
o Actors REACT to messages: never blocks waiting.
o Have to use some discipline not to block
e.g. waiting for a response from a synchronous resource
Non-blocking
Handle timeouts,
for resiliency
Macro (at service boundaries)
o Outbound connection timeouts (client)
o Inbound request/response (ack) handling timeouts (server)
Micro
Plain Java
o Not easy to handle timeouts consistently à ...unhandled or use default
Akka
o Everything has an explicit timeout à impossible to forget
o Actor message receiving timeout handler
Timeouts handlings
Asynchronous Failure handling
Java CompletableFuture à handle exceptional completion
o Error prone; easily forgotten
o No way to separate Error and Failure handling
Actors à failure handled by Supervisor
Akka: Supervisor is notified when an Actor throws an Exception
• Failure : handled externally from message flow
• Error: part of message handling behaviour
Handling Failure, Asynchronously
Event/Command sourcing
natural persistence patterns
for distributed, asynchronous applications
Plain Java/Spring
o Write your own Event Sourcing à Concursus
Event Sourcing naturally fits Actors
o Actors may be stateful
o Events and Commands are messages
• When received à Actor change its state
• May be saved and replayed
o Actors may represent Aggregate Root (DDD) or Command Processor
ü Akka Persistence: Command and Event Sourcing out of the box
Persistence: Event-sourcing
Conclusions
Keep in mind Reactive principles
…even when not using “reactive” technologies
à Scalable and resilient applications
Many implications behind the generic principles
Reactive principles
Does a “Reactive” technology like Akka help?
at Micro
ü Simpler, more testable concurrent code
ü Requires less discipline then plain Java 8
✗ A new programming model to learn
Does Akka help?
Does a “Reactive” technology like Akka help?
at Macro
• Still requires discipline at architectural level
✗ Akka forces to reinvent a lot of wheels on integration
✗ Akka doesn’t integrate with Spring
Does Akka help?
Akka/Actor model
μServices:
NOT mutually exclusive
Consider adopting Akka for some services
• The most business-critical (+resilient)
• Highest concurrency
Akka and μServices
Reactive Manifesto
http://www.reactivemanifesto.org/
à Glossary: http://www.reactivemanifesto.org/glossary
Concurrency in Erlang & Scala: The Actor Model
https://rocketeer.be/articles/concurrency-in-erlang-scala/
Introducing Actors (Akka)
http://rerun.me/2014/09/11/introducing-actors-akka-notes-part-1/
DDD and Actor model (Vaughn Vernon, DDD eXchange 2013)
https://skillsmatter.com/skillscasts/4185-vaughn-vernon
Akka project
https://github.com/akka/akka
More…
Thanks!
Questions?

More Related Content

What's hot

What's hot (20)

Apache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals ExplainedApache Kafka Architecture & Fundamentals Explained
Apache Kafka Architecture & Fundamentals Explained
 
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkrout
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron SchildkroutKafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkrout
Kafka + Uber- The World’s Realtime Transit Infrastructure, Aaron Schildkrout
 
Microservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and KafkaMicroservices Part 3 Service Mesh and Kafka
Microservices Part 3 Service Mesh and Kafka
 
From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.From cache to in-memory data grid. Introduction to Hazelcast.
From cache to in-memory data grid. Introduction to Hazelcast.
 
Data in Motion을 위한 이벤트 기반 마이크로서비스 아키텍처 소개
Data in Motion을 위한 이벤트 기반 마이크로서비스 아키텍처 소개Data in Motion을 위한 이벤트 기반 마이크로서비스 아키텍처 소개
Data in Motion을 위한 이벤트 기반 마이크로서비스 아키텍처 소개
 
Apache Pulsar Development 101 with Python
Apache Pulsar Development 101 with PythonApache Pulsar Development 101 with Python
Apache Pulsar Development 101 with Python
 
Event Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQEvent Sourcing & CQRS, Kafka, Rabbit MQ
Event Sourcing & CQRS, Kafka, Rabbit MQ
 
Autoscaling Kubernetes
Autoscaling KubernetesAutoscaling Kubernetes
Autoscaling Kubernetes
 
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)Kafka Tutorial - Introduction to Apache Kafka (Part 1)
Kafka Tutorial - Introduction to Apache Kafka (Part 1)
 
Introduction to Google Cloud Platform
Introduction to Google Cloud PlatformIntroduction to Google Cloud Platform
Introduction to Google Cloud Platform
 
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
Simplifying Distributed Transactions with Sagas in Kafka (Stephen Zoio, Simpl...
 
Grafana 7.0
Grafana 7.0Grafana 7.0
Grafana 7.0
 
02 api gateway
02 api gateway02 api gateway
02 api gateway
 
Introduction to Vault
Introduction to VaultIntroduction to Vault
Introduction to Vault
 
gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!gRPC vs REST: let the battle begin!
gRPC vs REST: let the battle begin!
 
Microservices & API Gateways
Microservices & API Gateways Microservices & API Gateways
Microservices & API Gateways
 
RabbitMQ & Kafka
RabbitMQ & KafkaRabbitMQ & Kafka
RabbitMQ & Kafka
 
Apache kafka
Apache kafkaApache kafka
Apache kafka
 
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
 Grokking Techtalk #39: How to build an event driven architecture with Kafka ... Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
Grokking Techtalk #39: How to build an event driven architecture with Kafka ...
 
Micro services Architecture
Micro services ArchitectureMicro services Architecture
Micro services Architecture
 

Similar to Spring Boot Microservices vs Akka Actor Cluster

Agile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAAgile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKA
Paolo Platter
 
Reactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala MeetupReactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala Meetup
Miguel Pastor
 

Similar to Spring Boot Microservices vs Akka Actor Cluster (20)

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
 
Why Actor-Based Systems Are The Best For Microservices
Why Actor-Based Systems Are The Best For MicroservicesWhy Actor-Based Systems Are The Best For Microservices
Why Actor-Based Systems Are The Best For Microservices
 
Reactive Principles and Microservices
Reactive Principles and MicroservicesReactive Principles and Microservices
Reactive Principles and Microservices
 
Reactive Microservices By Lorenzo Nicora
Reactive Microservices By Lorenzo NicoraReactive Microservices By Lorenzo Nicora
Reactive Microservices By Lorenzo Nicora
 
Reactive microservices
Reactive microservicesReactive microservices
Reactive microservices
 
Akka for big data developers
Akka for big data developersAkka for big data developers
Akka for big data developers
 
Oop2011 actor presentation_stal
Oop2011 actor presentation_stalOop2011 actor presentation_stal
Oop2011 actor presentation_stal
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
 
Sharing-akka-pub
Sharing-akka-pubSharing-akka-pub
Sharing-akka-pub
 
RxJava@DAUG
RxJava@DAUGRxJava@DAUG
RxJava@DAUG
 
Rx Swift
Rx SwiftRx Swift
Rx Swift
 
Akka and Kubernetes, the beginning of a beautiful relationship
Akka and Kubernetes, the beginning of a beautiful relationshipAkka and Kubernetes, the beginning of a beautiful relationship
Akka and Kubernetes, the beginning of a beautiful relationship
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
Agile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKAAgile Lab_BigData_Meetup_AKKA
Agile Lab_BigData_Meetup_AKKA
 
Reactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala MeetupReactive applications and Akka intro used in the Madrid Scala Meetup
Reactive applications and Akka intro used in the Madrid Scala Meetup
 
Streams of RDF Events Derive2015
Streams of RDF Events Derive2015Streams of RDF Events Derive2015
Streams of RDF Events Derive2015
 
Akka (1)
Akka (1)Akka (1)
Akka (1)
 
CrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked dataCrawlerLD - Distributed crawler for linked data
CrawlerLD - Distributed crawler for linked data
 
Take a Look at Akka+Java (English version)
Take a Look at Akka+Java (English version)Take a Look at Akka+Java (English version)
Take a Look at Akka+Java (English version)
 

More from OpenCredo

Kafka Summit 2018: A Journey Building Kafka Connectors - Pegerto Fernandez
Kafka Summit 2018: A Journey Building Kafka Connectors - Pegerto FernandezKafka Summit 2018: A Journey Building Kafka Connectors - Pegerto Fernandez
Kafka Summit 2018: A Journey Building Kafka Connectors - Pegerto Fernandez
OpenCredo
 
MuCon 2017: A not So(A) Trivial Question by Tareq Abedrabbo
MuCon 2017: A not So(A) Trivial Question by Tareq AbedrabboMuCon 2017: A not So(A) Trivial Question by Tareq Abedrabbo
MuCon 2017: A not So(A) Trivial Question by Tareq Abedrabbo
OpenCredo
 
Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant
Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant
Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant
OpenCredo
 

More from OpenCredo (20)

Webinar - Design Thinking for Platform Engineering
Webinar - Design Thinking for Platform EngineeringWebinar - Design Thinking for Platform Engineering
Webinar - Design Thinking for Platform Engineering
 
MuCon 2019: Exploring Your Microservices Architecture Through Network Science...
MuCon 2019: Exploring Your Microservices Architecture Through Network Science...MuCon 2019: Exploring Your Microservices Architecture Through Network Science...
MuCon 2019: Exploring Your Microservices Architecture Through Network Science...
 
Goto Chicago; Journeys To Cloud Native Architecture: Sun, Sea And Emergencies...
Goto Chicago; Journeys To Cloud Native Architecture: Sun, Sea And Emergencies...Goto Chicago; Journeys To Cloud Native Architecture: Sun, Sea And Emergencies...
Goto Chicago; Journeys To Cloud Native Architecture: Sun, Sea And Emergencies...
 
Mucon 2018: Heuristics for Identifying Microservice Boundaries By Erich Eichi...
Mucon 2018: Heuristics for Identifying Microservice Boundaries By Erich Eichi...Mucon 2018: Heuristics for Identifying Microservice Boundaries By Erich Eichi...
Mucon 2018: Heuristics for Identifying Microservice Boundaries By Erich Eichi...
 
Journeys To Cloud Native Architecture: Sun, Sea And Emergencies - Nicki Watt
Journeys To Cloud Native Architecture: Sun, Sea And Emergencies - Nicki WattJourneys To Cloud Native Architecture: Sun, Sea And Emergencies - Nicki Watt
Journeys To Cloud Native Architecture: Sun, Sea And Emergencies - Nicki Watt
 
Machine Learning Game Changer for IT - Maartens Lourens
Machine Learning Game Changer for IT - Maartens LourensMachine Learning Game Changer for IT - Maartens Lourens
Machine Learning Game Changer for IT - Maartens Lourens
 
Kafka Summit 2018: A Journey Building Kafka Connectors - Pegerto Fernandez
Kafka Summit 2018: A Journey Building Kafka Connectors - Pegerto FernandezKafka Summit 2018: A Journey Building Kafka Connectors - Pegerto Fernandez
Kafka Summit 2018: A Journey Building Kafka Connectors - Pegerto Fernandez
 
MuCon 2017: A not So(A) Trivial Question by Tareq Abedrabbo
MuCon 2017: A not So(A) Trivial Question by Tareq AbedrabboMuCon 2017: A not So(A) Trivial Question by Tareq Abedrabbo
MuCon 2017: A not So(A) Trivial Question by Tareq Abedrabbo
 
DevOpsCon Berlin 2017: Project Management from Stone Age to DevOps By Antoni...
DevOpsCon Berlin 2017: Project Management from Stone Age to DevOps  By Antoni...DevOpsCon Berlin 2017: Project Management from Stone Age to DevOps  By Antoni...
DevOpsCon Berlin 2017: Project Management from Stone Age to DevOps By Antoni...
 
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
Hashidays London 2017 - Evolving your Infrastructure with Terraform By Nicki ...
 
Succeeding with DevOps Transformation - Rafal Gancarz
Succeeding with DevOps Transformation - Rafal GancarzSucceeding with DevOps Transformation - Rafal Gancarz
Succeeding with DevOps Transformation - Rafal Gancarz
 
Progscon 2017: Serverless Architectures - Rafal Gancarz
Progscon 2017: Serverless Architectures - Rafal GancarzProgscon 2017: Serverless Architectures - Rafal Gancarz
Progscon 2017: Serverless Architectures - Rafal Gancarz
 
QCON London 2017 - Monitoring Serverless Architectures by Rafal Gancarz
QCON London 2017 - Monitoring Serverless Architectures by Rafal GancarzQCON London 2017 - Monitoring Serverless Architectures by Rafal Gancarz
QCON London 2017 - Monitoring Serverless Architectures by Rafal Gancarz
 
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
Voxxed Bristol 2017 - From C to Q, one event at a time: Event Sourcing illust...
 
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
London Hashicorp Meetup #8 -  Testing Programmable Infrastructure By Matt LongLondon Hashicorp Meetup #8 -  Testing Programmable Infrastructure By Matt Long
London Hashicorp Meetup #8 - Testing Programmable Infrastructure By Matt Long
 
ServerlessConf: Serverless for the Enterprise - Rafal Gancarz
ServerlessConf: Serverless for the Enterprise - Rafal GancarzServerlessConf: Serverless for the Enterprise - Rafal Gancarz
ServerlessConf: Serverless for the Enterprise - Rafal Gancarz
 
O'Reilly 2016: "Continuous Delivery with Containers: The Trials and Tribulati...
O'Reilly 2016: "Continuous Delivery with Containers: The Trials and Tribulati...O'Reilly 2016: "Continuous Delivery with Containers: The Trials and Tribulati...
O'Reilly 2016: "Continuous Delivery with Containers: The Trials and Tribulati...
 
Haufe #msaday - The Actor model: an alternative approach to concurrency By Lo...
Haufe #msaday - The Actor model: an alternative approach to concurrency By Lo...Haufe #msaday - The Actor model: an alternative approach to concurrency By Lo...
Haufe #msaday - The Actor model: an alternative approach to concurrency By Lo...
 
Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant
Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant
Haufe #msaday - Seven More Deadly Sins of Microservices by Daniel Bryant
 
Haufe #msaday - Building a Microservice Ecosystem by Daniel Bryant
Haufe #msaday - Building a Microservice Ecosystem by Daniel Bryant Haufe #msaday - Building a Microservice Ecosystem by Daniel Bryant
Haufe #msaday - Building a Microservice Ecosystem by Daniel Bryant
 

Recently uploaded

Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
chiefasafspells
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 

Recently uploaded (20)

WSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - KeynoteWSO2Con204 - Hard Rock Presentation - Keynote
WSO2Con204 - Hard Rock Presentation - Keynote
 
What Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the SituationWhat Goes Wrong with Language Definitions and How to Improve the Situation
What Goes Wrong with Language Definitions and How to Improve the Situation
 
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open SourceWSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
WSO2CON 2024 - Freedom First—Unleashing Developer Potential with Open Source
 
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
Love witchcraft +27768521739 Binding love spell in Sandy Springs, GA |psychic...
 
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni%in Benoni+277-882-255-28 abortion pills for sale in Benoni
%in Benoni+277-882-255-28 abortion pills for sale in Benoni
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
Devoxx UK 2024 - Going serverless with Quarkus, GraalVM native images and AWS...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
Abortion Pill Prices Tembisa [(+27832195400*)] 🏥 Women's Abortion Clinic in T...
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
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
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?WSO2CON 2024 - Does Open Source Still Matter?
WSO2CON 2024 - Does Open Source Still Matter?
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
WSO2CON 2024 - API Management Usage at La Poste and Its Impact on Business an...
 

Spring Boot Microservices vs Akka Actor Cluster

  • 1. Two Reactive approaches to scale 1 Comparing two approaches for scalable, message-driven, backend applications in Java Spring Boot μServices and Akka Lorenzo Nicora Lorenzo.nicora@opencredo.com
  • 2. 2 “Reactive” is… Reactive Semantically overloaded term adj. “Readily responsive to stimulus” [Merrian-Webster dictionary] From Latin “reagere”: act in return
  • 3. • Reactive as Responsive Quickly prompt to user actions Reactive as… • Reactive as Data binding Declarative, as opposed to Imperative a=b+3 e.g. Spreadsheets • Reactive streams as Asynchronous Data Streams • Reactive as Reactive Manifesto
  • 4. ü Responsive à Low latency ü Resilient à Stay responsive on failure ü Elastic à Scale as needed ü Message-Driven • Async messages as only communication between components Reactive Manifesto
  • 5. ✗ No Blocking operation ✗ No Synchronization ✗ No Resource hogging Decoupling and isolation in… ü Time à Allow concurrency ü Space à Components location decoupling Reactive Manifesto promotes
  • 6. Top-down approach: from Macro (at μService boundaries) o Message based communication between services o Isolation at service level Bottom-Up approach: from Micro (within the service) o Message based communication between components o Non-blocking processing o Isolation at component level Macro and Micro approaches
  • 7. Two real world projects Spring Boot μService Akka
  • 8. Spring Boot μService application ü Message-based communication between services ü Non-blocking (where possible) o Java 8 CompletableFutures o Http non-blocking Servlets o Fast-returning API endpoints ü Event sourcing persistence o Concursus forerunner ü Spring Boot and Spring Cloud Config Spring Boot μService
  • 9. Java application using Akka, Cluster ü Akka Actor programming model ü Event-sourcing by Akka Persistence ü Akka Cluster ü Deployed using ConductR [Commercial] ü Akka Http server (no container), non blocking ü TypeSafe Config ✗ not Lagom framework ✗ not Akka Streams Akka Cluster
  • 10. TL;DR “The actor model in computer science is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent computation. In response to a message that it receives, an actor can: make local decisions, create more actors, send more messages, and determine how to respond to the next message received. Actors may modify private state, but can only affect each other through messages (avoiding the need for any locks).” [Wikipedia] Actor model Actor Actor Actor Mailbox Mailbox Mailbox ü Article by Carl Hewitt (1973) ü Erlang (1986) ü Akka framework (2009)
  • 11. A different way to concurrency Actors, !Threads Actor is the primary computational entity o In Java, still a mixed world of Objects and Actors Actors interact exclusively via asynchronous messages o As opposed to Objects interacting through method calls o Actors REACT on receiving a message o No synchronisation; no lock Actor model for dummies Actor Actor Actor Mailbox Mailbox Mailbox
  • 12. Actor handles one message a time o Message handling code is intrinsically thread safe o May have simple state: Instance properties in Java Actor is lightweight o Little overhead over creating an object o May be used to hold request context • Per-request Actors: a common pattern Actor model
  • 13. Collaborating Actors ≠ Dependency Injection o Akka: Actor Refs (location/lifecycle transparent) ≠ object refs Actors are created by Actors (…then may be passed around) Parent à Children Supervision hierarchy Failure handling Supervision
  • 14. Implementing Reactive principles Implementing Reactive principles from Macro and from Micro Plain Java/Spring or Akka
  • 15. Never block threads waiting Macro o Asynchronous messaging protocols between services Micro Plain Java o CompletableFuture o Non-blocking Servlets o Low level NIO (!) Akka o Actors REACT to messages: never blocks waiting. o Have to use some discipline not to block e.g. waiting for a response from a synchronous resource Non-blocking
  • 16. Handle timeouts, for resiliency Macro (at service boundaries) o Outbound connection timeouts (client) o Inbound request/response (ack) handling timeouts (server) Micro Plain Java o Not easy to handle timeouts consistently à ...unhandled or use default Akka o Everything has an explicit timeout à impossible to forget o Actor message receiving timeout handler Timeouts handlings
  • 17. Asynchronous Failure handling Java CompletableFuture à handle exceptional completion o Error prone; easily forgotten o No way to separate Error and Failure handling Actors à failure handled by Supervisor Akka: Supervisor is notified when an Actor throws an Exception • Failure : handled externally from message flow • Error: part of message handling behaviour Handling Failure, Asynchronously
  • 18. Event/Command sourcing natural persistence patterns for distributed, asynchronous applications Plain Java/Spring o Write your own Event Sourcing à Concursus Event Sourcing naturally fits Actors o Actors may be stateful o Events and Commands are messages • When received à Actor change its state • May be saved and replayed o Actors may represent Aggregate Root (DDD) or Command Processor ü Akka Persistence: Command and Event Sourcing out of the box Persistence: Event-sourcing
  • 20. Keep in mind Reactive principles …even when not using “reactive” technologies à Scalable and resilient applications Many implications behind the generic principles Reactive principles
  • 21. Does a “Reactive” technology like Akka help? at Micro ü Simpler, more testable concurrent code ü Requires less discipline then plain Java 8 ✗ A new programming model to learn Does Akka help?
  • 22. Does a “Reactive” technology like Akka help? at Macro • Still requires discipline at architectural level ✗ Akka forces to reinvent a lot of wheels on integration ✗ Akka doesn’t integrate with Spring Does Akka help?
  • 23. Akka/Actor model μServices: NOT mutually exclusive Consider adopting Akka for some services • The most business-critical (+resilient) • Highest concurrency Akka and μServices
  • 24. Reactive Manifesto http://www.reactivemanifesto.org/ à Glossary: http://www.reactivemanifesto.org/glossary Concurrency in Erlang & Scala: The Actor Model https://rocketeer.be/articles/concurrency-in-erlang-scala/ Introducing Actors (Akka) http://rerun.me/2014/09/11/introducing-actors-akka-notes-part-1/ DDD and Actor model (Vaughn Vernon, DDD eXchange 2013) https://skillsmatter.com/skillscasts/4185-vaughn-vernon Akka project https://github.com/akka/akka More…