A Pragmatic View of Reactive

Lutz Hühnken
Lutz HühnkenHead of Engineering at Upvest
So how do I do a 2PC in Akka then?
or
Lutz Hühnken (@lutzhuehnken)
A Pragmatic View of Reactive
So how do I do a 2PC in Akka then?
Lutz Hühnken (@lutzhuehnken)
A misleading title, really.
Answer: You don’t want to
(we’ll get back to that later)
Valuable Experience vs. Bad Habit
From Enterprise to Reactive
Transitions
…
Lutz Hühnken (@lutzhuehnken)
Other failed naming attempts..
Lutz Hühnken (@lutzhuehnken)
A Pragmatic View of Reactive
A Pragmatic View of Reactive
Yes, of course. But who doesn’t
claim that for their system?
Come on. Now you’re just selling
Akka to me..
Real, Pragmatic Questions
WAR?
Servlet Container?
Library X
(which uses
ThreadLocal)
?
RDBMS/
JDBC?
How to do 2PC?
Pragmatic Problem Fields
Deployment
Concurrency Model
I/O
Distribution
The Pragmatic Reactive Manifesto
Threads vs. task level concurrency
Pragmatic Reactive
Threads … A supposedly great idea
• Threads are
• lightweight processes
• easier programming model, no IPC
12
Pragmatic Reactive
Lightweight?
13
Slide from John Rose, Java VM Architect, JFokus, Stockholm, February 2015
Pragmatic Reactive
The problem with Threads
14
They discard the most essential and
appealing properties of sequential
computation: understandability,
predictability, and determinism.
Threads, as a model of computation,
are wildly nondeterministic, and the
job of the programmer becomes one
of pruning that nondeterminism.
+
Let’s talk about
Multi-Threading
Every time…
Pragmatic Reactive
Threads
• not efficient
• memory consumption
• cost for context switch
• bad match modern NUMA architectures
• locks lead to contention

• not a good programming model
• shared mutual state is difficult to reason about
16
Pragmatic Reactive
What would be better?
Goals
• task level (sub-thread) concurrency
• share nothing approach
• # threads ~ # of cores
17
Pragmatic Reactive
Thread alternatives (successors?)
• Green threads / coroutines / fibres
• other granularity, but basically same programming
model
• Event-loop (e.g. vert.x, Reactor)
• very loose coupling, slightly limited, 1 x n dispatch
• Actors !
• truly share-nothing, flexible, resilience-proven, 

m x n dispatch
18
Pragmatic Reactive
Example: Http Request handling
Java EE: Threads. Servlet API: Thread per Request
19
Note: This is a snapshot at one point in time, not a sequence of events.
Pragmatic Reactive
Example: Http Request handling
Reactive: Sub-Thread. Play: n threads per m requests
20
Note: This is a snapshot at one point in time, not a sequence of events.
Pragmatic Reactive
Consequences
• We have effectively (even without explicitly
using Actors) switched to a task level
concurrency model
• As a consequence, ThreadLocal becomes
an anti-pattern.
• Libraries that depend on them need extra
work, might better be avoided
• What does it mean for (blocking) I/O?
21
Pragmatic Reactive
Pragmatic reactive learnings cont’d
• You’ll be using sub-thread level
concurrency. Accept it, embrace it.
22
Blocking vs. non-blocking I/O
Pragmatic Reactive
High concurrency matters
24
But there’s one thing we can all agree on: At high levels of
concurrency (thousands of connections) your server needs to
go to asynchronous non-blocking. [..] any part of your server
code blocks you’re going to need a thread. And at these levels
of concurrency, you can’t go creating threads for every
connection.
From https://strongloop.com/strongblog/node-js-is-faster-than-java/
Pragmatic Reactive
Blocking I/O
Reactive: Sub-Thread. Play: n threads per m requests
25
What does using blocking I/O mean for this?
Pragmatic Reactive
Non-blocking
26
For task level (sub-thread level) concurrency
• each thread is responsible for n tasks
• and that n might be pretty big
You don’t want to block such a thread with blocking I/O
Pragmatic Reactive
But what if I need this..?
27
try {
stmt = con.createStatement();
ResultSet rs = stmt.executeQuery(query);
while (rs.next()) {
String coffeeName = rs.getString("COF_NAME");
int supplierID = rs.getInt("SUP_ID");
float price = rs.getFloat("PRICE");
int sales = rs.getInt("SALES");
int total = rs.getInt("TOTAL");
System.out.println(coffeeName + "t" + supplierID +
"t" + price + "t" + sales +
Pragmatic Reactive
Isolate!
28
vert.x has „worker verticles“
Play/Akka: Configure Dispatchers
Slick 3 takes care of this for you!
Pragmatic Reactive
Pragmatic reactive learnings cont’d
• You’ll be using sub-thread level
concurrency. Accept it, embrace it.
• Use asynchronous I/O. If you really can’t,
isolate.
29
„Distributed Transactions“
vs. Distributed Systems
Pragmatic Reactive
But what if I need this..?
31
@Transactional
public static class GreetingService {
@Inject
private JmsTemplate jmsTemplate;
@PersistenceContext
private EntityManager entityManager;
public void createGreeting(String name) {
Greeting greeting = new Greeting(name);
this.entityManager.persist(greeting);
this.jmsTemplate.convertAndSend("greetings", greeting);
…
Pragmatic Reactive
Avoid, separate, recycle..
32
Pragmatic Reactive
Avoid…
33
@Transactional
public static class GreetingService {
@Inject
private JmsTemplate jmsTemplate;
@PersistenceContext
private EntityManager entityManager;
public void createGreeting(String name) {
Greeting greeting = new Greeting(name);
this.entityManager.persist(greeting);
this.jmsTemplate.convertAndSend("greetings", greeting);
…
The example: In fact not really all-or-nothing, but reconciliation.
Pragmatic Reactive
Separate (the steps..)
34
Claim: Any 2PC can be expressed in
terms of asynchronous messaging.
Pragmatic Reactive
Life beyond Distributed Transactions
35
In general, application
developers simply do not
implement large scalable
applications assuming
distributed transactions. When
they attempt to use distributed
transactions, the projects
founder because the
performance costs and fragility
make them impractical. [..]
36
Want Almost-Infinite Scaling

• More of everything… Year by year, bigger and bigger
• If it fits on your machines, multiply by 10, if that fits, multiply by 1000…
• Strive to scale almost linearly (N log N for some big log).
Assumptions

(Don’t Have to Prove These… Just Plain Believe Them)
Grown-Ups Don’t Use Distributed Transactions
•The apps using distributed transactions become too fragile…
• Let’s just consider local transactions.
! Multiple disjoint scopes of serializability
Want Scale-Agnostic Apps

• Two layers to the application: 

scale-agnostic and scale-aware
• Consider scale-agnostic API
Scale Agnostic Code
Scale-Aware-Code
Application
Upper Layer
Lower Layer
Scale Agnostic API
Pragmatic Reactive
2 PC => messaging
37
Item-BCancellation Tentative
Op
Item-A
Restrictions / Requirements
•at-least-once delivery
•idempotent messages
•tentative operations
Pragmatic Reactive
Pragmatic
38
Real world solution: Saga Pattern
Source: http://kellabyte.com/2012/05/30/clarifying-the-saga-pattern/
Pragmatic Reactive
Pragmatic
39
Example (by Caitie McCaffrey)
Source: https://speakerdeck.com/caitiem20/applying-the-saga-pattern
Pragmatic Reactive
Distributed Transactions
40
Distributed Transactions („2PC“) are a source of
unnecessary failure and of contention.
It can usually be avoided. Generally, local transactions
and at-least-once delivery can be used instead.
The Saga Pattern provides a pragmatic solution for „all-or-
nothing“ in a distributed system.
Pragmatic Reactive
Food for thought
41
The data storage landscape is changing, moving towards
event sourcing and immutability. This is a great match for
reactive systems.
The „all-or-nothing“ problems are closely related to
wanting a global truth at a point in time. But what is
now… the illusion of present… result of series of events..
Pragmatic Reactive
Pragmatic reactive learnings cont’d
• You’ll be using sub-thread level
concurrency. Accept it, embrace it.
• Use asynchronous I/O. If you really can’t,
isolate.
• Do not use distributed transactions. If you
really must, isolate.
42
App Servers vs. Standalone
Pragmatic Reactive 44
Pragmatic Reactive 45
Pragmatic Reactive
Java EE Application Servers
46
Servlet API was developed for thread-per-
request, synchronous I/O.
Application servers are not of much use
anyway, nobody uses them as containers for
multiple applications. So effectively they’re
just a library dependency.
The ops convenience can be provided by
other tools.
Pragmatic Reactive
Pragmatic reactive learnings cont’d
• You’ll be using sub-thread level
concurrency. Accept it, embrace it.
• Use asynchronous I/O. If you really can’t,
isolate.
• Do not use distributed transactions. If you
really must, isolate.
• Don’t use an application server / servlet
container.
47
Summary
Pragmatic Reactive
Conclusion
49
If
• Threads are the smallest unit of concurrency in
your code, or
• You use blocking I/O (without clear separation), or
• You use 2-phase-commit across systems, or
• You use a Java EE Application Server / Servlet
Container
Then your application is not reactive.
Pragmatic Reactive
The Pragmatic Reactive Checklist
50
• Task-level (sub-thread level)
concurrency
• Non-blocking I/O
• Distributed
• Containerless
Reactive Manifesto revisited
We really only talked about the elastic part
will lead to
will lead to
Thank you
Lutz Hühnken (@lutzhuehnken)
1 of 54

Recommended

Scala, Akka, and Play: An Introduction on Heroku by
Scala, Akka, and Play: An Introduction on HerokuScala, Akka, and Play: An Introduction on Heroku
Scala, Akka, and Play: An Introduction on HerokuHavoc Pennington
16.8K views51 slides
Scala Days NYC 2016 by
Scala Days NYC 2016Scala Days NYC 2016
Scala Days NYC 2016Martin Odersky
74.2K views63 slides
Reactive Streams: Handling Data-Flow the Reactive Way by
Reactive Streams: Handling Data-Flow the Reactive WayReactive Streams: Handling Data-Flow the Reactive Way
Reactive Streams: Handling Data-Flow the Reactive WayRoland Kuhn
34.8K views60 slides
Stream processing from single node to a cluster by
Stream processing from single node to a clusterStream processing from single node to a cluster
Stream processing from single node to a clusterGal Marder
278 views33 slides
Introduction of failsafe by
Introduction of failsafeIntroduction of failsafe
Introduction of failsafeSunghyouk Bae
825 views46 slides
Effective testing for spark programs Strata NY 2015 by
Effective testing for spark programs   Strata NY 2015Effective testing for spark programs   Strata NY 2015
Effective testing for spark programs Strata NY 2015Holden Karau
13.5K views38 slides

More Related Content

What's hot

Lambdas puzzler - Peter Lawrey by
Lambdas puzzler - Peter LawreyLambdas puzzler - Peter Lawrey
Lambdas puzzler - Peter LawreyJAXLondon_Conference
673 views47 slides
How Scala code is expressed in the JVM by
How Scala code is expressed in the JVMHow Scala code is expressed in the JVM
How Scala code is expressed in the JVMKoichi Sakata
8.3K views89 slides
Akka Actor presentation by
Akka Actor presentationAkka Actor presentation
Akka Actor presentationGene Chang
4.7K views70 slides
Build Cloud Applications with Akka and Heroku by
Build Cloud Applications with Akka and HerokuBuild Cloud Applications with Akka and Heroku
Build Cloud Applications with Akka and HerokuSalesforce Developers
3.2K views60 slides
Actor Model Akka Framework by
Actor Model Akka FrameworkActor Model Akka Framework
Actor Model Akka FrameworkHarinath Krishnamoorthy
361 views30 slides
Java Serialization Facts and Fallacies by
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and FallaciesRoman Elizarov
5.9K views35 slides

What's hot(20)

How Scala code is expressed in the JVM by Koichi Sakata
How Scala code is expressed in the JVMHow Scala code is expressed in the JVM
How Scala code is expressed in the JVM
Koichi Sakata8.3K views
Akka Actor presentation by Gene Chang
Akka Actor presentationAkka Actor presentation
Akka Actor presentation
Gene Chang4.7K views
Java Serialization Facts and Fallacies by Roman Elizarov
Java Serialization Facts and FallaciesJava Serialization Facts and Fallacies
Java Serialization Facts and Fallacies
Roman Elizarov5.9K views
Java Garbage Collection, Monitoring, and Tuning by Carol McDonald
Java Garbage Collection, Monitoring, and TuningJava Garbage Collection, Monitoring, and Tuning
Java Garbage Collection, Monitoring, and Tuning
Carol McDonald22.2K views
The Cloud-natives are RESTless @ JavaOne by Konrad Malawski
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
Konrad Malawski1K views
The Need for Async @ ScalaWorld by Konrad Malawski
The Need for Async @ ScalaWorldThe Need for Async @ ScalaWorld
The Need for Async @ ScalaWorld
Konrad Malawski4.5K views
Concurrency in Scala - the Akka way by Yardena Meymann
Concurrency in Scala - the Akka wayConcurrency in Scala - the Akka way
Concurrency in Scala - the Akka way
Yardena Meymann3.6K views
Clustering In The Wild by Sergio Bossa
Clustering In The WildClustering In The Wild
Clustering In The Wild
Sergio Bossa440 views
An Introduction to JVM Internals and Garbage Collection in Java by Abhishek Asthana
An Introduction to JVM Internals and Garbage Collection in JavaAn Introduction to JVM Internals and Garbage Collection in Java
An Introduction to JVM Internals and Garbage Collection in Java
Abhishek Asthana13.9K views
How and why I turned my old Java projects into a first-class serverless compo... by Mario Fusco
How and why I turned my old Java projects into a first-class serverless compo...How and why I turned my old Java projects into a first-class serverless compo...
How and why I turned my old Java projects into a first-class serverless compo...
Mario Fusco1.8K views
Apache Storm by masifqadri
Apache StormApache Storm
Apache Storm
masifqadri588 views
State of Akka 2017 - The best is yet to come by Konrad Malawski
State of Akka 2017 - The best is yet to comeState of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to come
Konrad Malawski5.5K views
Quick introduction to Java Garbage Collector (JVM GC) by Marcos García
Quick introduction to Java Garbage Collector (JVM GC)Quick introduction to Java Garbage Collector (JVM GC)
Quick introduction to Java Garbage Collector (JVM GC)
Marcos García2.2K views

Viewers also liked

Lambda Architecture with Spark Streaming, Kafka, Cassandra, Akka, Scala by
Lambda Architecture with Spark Streaming, Kafka, Cassandra, Akka, ScalaLambda Architecture with Spark Streaming, Kafka, Cassandra, Akka, Scala
Lambda Architecture with Spark Streaming, Kafka, Cassandra, Akka, ScalaHelena Edelson
75K views100 slides
Life Beyond the Illusion of Present by
Life Beyond the Illusion of PresentLife Beyond the Illusion of Present
Life Beyond the Illusion of PresentJonas Bonér
81.7K views89 slides
Akka in Production - ScalaDays 2015 by
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Evan Chan
53.3K views56 slides
Java SE 8 best practices by
Java SE 8 best practicesJava SE 8 best practices
Java SE 8 best practicesStephen Colebourne
100.8K views88 slides
200 Open Source Projects Later: Source Code Static Analysis Experience by
200 Open Source Projects Later: Source Code Static Analysis Experience200 Open Source Projects Later: Source Code Static Analysis Experience
200 Open Source Projects Later: Source Code Static Analysis ExperienceAndrey Karpov
10.4K views38 slides
RPG Combat Kata by
RPG Combat KataRPG Combat Kata
RPG Combat KataDaniel Ojeda Loisel
4.9K views10 slides

Viewers also liked(20)

Lambda Architecture with Spark Streaming, Kafka, Cassandra, Akka, Scala by Helena Edelson
Lambda Architecture with Spark Streaming, Kafka, Cassandra, Akka, ScalaLambda Architecture with Spark Streaming, Kafka, Cassandra, Akka, Scala
Lambda Architecture with Spark Streaming, Kafka, Cassandra, Akka, Scala
Helena Edelson75K views
Life Beyond the Illusion of Present by Jonas Bonér
Life Beyond the Illusion of PresentLife Beyond the Illusion of Present
Life Beyond the Illusion of Present
Jonas Bonér81.7K views
Akka in Production - ScalaDays 2015 by Evan Chan
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015
Evan Chan53.3K views
200 Open Source Projects Later: Source Code Static Analysis Experience by Andrey Karpov
200 Open Source Projects Later: Source Code Static Analysis Experience200 Open Source Projects Later: Source Code Static Analysis Experience
200 Open Source Projects Later: Source Code Static Analysis Experience
Andrey Karpov10.4K views
20160609 nike techtalks reactive applications tools of the trade by shinolajla
20160609 nike techtalks reactive applications   tools of the trade20160609 nike techtalks reactive applications   tools of the trade
20160609 nike techtalks reactive applications tools of the trade
shinolajla731 views
CompletableFuture by koji lin
CompletableFutureCompletableFuture
CompletableFuture
koji lin9.2K views
Functional Reactive Programming in the Netflix API by C4Media
Functional Reactive Programming in the Netflix APIFunctional Reactive Programming in the Netflix API
Functional Reactive Programming in the Netflix API
C4Media9.7K views
Asynchronous Processing in Java/JEE/Spring by Naresh Chintalcheru
Asynchronous Processing in Java/JEE/SpringAsynchronous Processing in Java/JEE/Spring
Asynchronous Processing in Java/JEE/Spring
Naresh Chintalcheru10.8K views
Go Reactive: Building Responsive, Resilient, Elastic & Message-Driven Systems by Jonas Bonér
Go Reactive: Building Responsive, Resilient, Elastic & Message-Driven SystemsGo Reactive: Building Responsive, Resilient, Elastic & Message-Driven Systems
Go Reactive: Building Responsive, Resilient, Elastic & Message-Driven Systems
Jonas Bonér8.6K views
Vert.x v3 - high performance polyglot application toolkit by Sages
Vert.x v3 - high performance  polyglot application toolkitVert.x v3 - high performance  polyglot application toolkit
Vert.x v3 - high performance polyglot application toolkit
Sages2.9K views
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems by Jonas Bonér
Go Reactive: Event-Driven, Scalable, Resilient & Responsive SystemsGo Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems
Jonas Bonér30.9K views
Viral Installs - getting your users to share and rate your game by Yaniv Nizan
Viral Installs - getting your users to share and rate your gameViral Installs - getting your users to share and rate your game
Viral Installs - getting your users to share and rate your game
Yaniv Nizan3K views
Apple iOS 7.1 new options for In-App Purchase Restrictions by Yaniv Nizan
Apple iOS 7.1 new options for In-App Purchase RestrictionsApple iOS 7.1 new options for In-App Purchase Restrictions
Apple iOS 7.1 new options for In-App Purchase Restrictions
Yaniv Nizan2.9K views
5 Mistakes with Virtual Economies in Mobile Games by Yaniv Nizan
5 Mistakes with Virtual Economies in Mobile Games5 Mistakes with Virtual Economies in Mobile Games
5 Mistakes with Virtual Economies in Mobile Games
Yaniv Nizan3.1K views
Blue print - framework for worlds, levels, missions and records in mobile games by Yaniv Nizan
Blue print - framework for worlds, levels, missions and records in mobile gamesBlue print - framework for worlds, levels, missions and records in mobile games
Blue print - framework for worlds, levels, missions and records in mobile games
Yaniv Nizan2.5K views
Fighting In-App Purchase Hacks by Gur Dotan
Fighting In-App Purchase HacksFighting In-App Purchase Hacks
Fighting In-App Purchase Hacks
Gur Dotan11.7K views

Similar to A Pragmatic View of Reactive

Concurrency on the JVM by
Concurrency on the JVMConcurrency on the JVM
Concurrency on the JVMBernhard Huemer
1.2K views30 slides
Reactive programming with rx java by
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
707 views101 slides
EuroAD 2021: ChainRules.jl by
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl Lyndon White
231 views29 slides
Concurrency - Why it's hard ? by
Concurrency - Why it's hard ?Concurrency - Why it's hard ?
Concurrency - Why it's hard ?Ramith Jayasinghe
867 views24 slides
Why Concurrency is hard ? by
Why Concurrency is hard ?Why Concurrency is hard ?
Why Concurrency is hard ?Ramith Jayasinghe
455 views24 slides
Reactive java - Reactive Programming + RxJava by
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaNexThoughts Technologies
416 views56 slides

Similar to A Pragmatic View of Reactive(20)

Reactive programming with rx java by CongTrung Vnit
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
CongTrung Vnit707 views
EuroAD 2021: ChainRules.jl by Lyndon White
EuroAD 2021: ChainRules.jl EuroAD 2021: ChainRules.jl
EuroAD 2021: ChainRules.jl
Lyndon White231 views
Reactive Applications with Apache Pulsar and Spring Boot by VMware Tanzu
Reactive Applications with Apache Pulsar and Spring BootReactive Applications with Apache Pulsar and Spring Boot
Reactive Applications with Apache Pulsar and Spring Boot
VMware Tanzu1.1K views
Low latency in java 8 v5 by Peter Lawrey
Low latency in java 8 v5Low latency in java 8 v5
Low latency in java 8 v5
Peter Lawrey3.9K views
AEM Clean Code - Miklos Csere by Miklos Csere
AEM Clean Code - Miklos Csere AEM Clean Code - Miklos Csere
AEM Clean Code - Miklos Csere
Miklos Csere270 views
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016) by Rick Hightower
Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)Reactive Java:  Promises and Streams with Reakt (JavaOne Talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne Talk 2016)
Rick Hightower776 views
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016) by Rick Hightower
Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)Reactive Java: Promises and Streams with Reakt  (JavaOne talk 2016)
Reactive Java: Promises and Streams with Reakt (JavaOne talk 2016)
Rick Hightower512 views
Reactive programming with examples by Peter Lawrey
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
Peter Lawrey8.3K views
Reactive web applications by Juan Sandoval
Reactive web applicationsReactive web applications
Reactive web applications
Juan Sandoval339 views
Stream Processing with CompletableFuture and Flow in Java 9 by Trayan Iliev
Stream Processing with CompletableFuture and Flow in Java 9Stream Processing with CompletableFuture and Flow in Java 9
Stream Processing with CompletableFuture and Flow in Java 9
Trayan Iliev3.1K views
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor by VMware Tanzu
Reactive Card Magic: Understanding Spring WebFlux and Project ReactorReactive Card Magic: Understanding Spring WebFlux and Project Reactor
Reactive Card Magic: Understanding Spring WebFlux and Project Reactor
VMware Tanzu3.7K views
GoF Design patterns I: Introduction + Structural Patterns by Sameh Deabes
GoF Design patterns I:   Introduction + Structural PatternsGoF Design patterns I:   Introduction + Structural Patterns
GoF Design patterns I: Introduction + Structural Patterns
Sameh Deabes3.1K views
Understanding react hooks by Maulik Shah
Understanding react hooksUnderstanding react hooks
Understanding react hooks
Maulik Shah1.9K views

More from Lutz Hühnken

Lagom at Java Forum Nord, October 20, 2016 by
Lagom at Java Forum Nord, October 20, 2016Lagom at Java Forum Nord, October 20, 2016
Lagom at Java Forum Nord, October 20, 2016Lutz Hühnken
613 views63 slides
Lagom at hybris Reactive Software Munich Meetup, April 13, 2016 by
Lagom at hybris Reactive Software Munich Meetup, April 13, 2016Lagom at hybris Reactive Software Munich Meetup, April 13, 2016
Lagom at hybris Reactive Software Munich Meetup, April 13, 2016Lutz Hühnken
957 views47 slides
JVM Concurrency auf der JavaLand am 8. März 2016 by
JVM Concurrency auf der JavaLand am 8. März 2016JVM Concurrency auf der JavaLand am 8. März 2016
JVM Concurrency auf der JavaLand am 8. März 2016Lutz Hühnken
988 views63 slides
Building Applications with the Typesafe Reactive Platform at Skills Matter, L... by
Building Applications with the Typesafe Reactive Platform at Skills Matter, L...Building Applications with the Typesafe Reactive Platform at Skills Matter, L...
Building Applications with the Typesafe Reactive Platform at Skills Matter, L...Lutz Hühnken
479 views37 slides
JVM Concurrency on Devoxx at Nov 12 2015 by
JVM Concurrency on Devoxx at Nov 12 2015JVM Concurrency on Devoxx at Nov 12 2015
JVM Concurrency on Devoxx at Nov 12 2015Lutz Hühnken
1.4K views64 slides
Concurrency-Modelle auf der JVM auf der w-jax 3.11.2015 by
Concurrency-Modelle auf der JVM auf der w-jax 3.11.2015Concurrency-Modelle auf der JVM auf der w-jax 3.11.2015
Concurrency-Modelle auf der JVM auf der w-jax 3.11.2015Lutz Hühnken
1.4K views48 slides

More from Lutz Hühnken(11)

Lagom at Java Forum Nord, October 20, 2016 by Lutz Hühnken
Lagom at Java Forum Nord, October 20, 2016Lagom at Java Forum Nord, October 20, 2016
Lagom at Java Forum Nord, October 20, 2016
Lutz Hühnken613 views
Lagom at hybris Reactive Software Munich Meetup, April 13, 2016 by Lutz Hühnken
Lagom at hybris Reactive Software Munich Meetup, April 13, 2016Lagom at hybris Reactive Software Munich Meetup, April 13, 2016
Lagom at hybris Reactive Software Munich Meetup, April 13, 2016
Lutz Hühnken957 views
JVM Concurrency auf der JavaLand am 8. März 2016 by Lutz Hühnken
JVM Concurrency auf der JavaLand am 8. März 2016JVM Concurrency auf der JavaLand am 8. März 2016
JVM Concurrency auf der JavaLand am 8. März 2016
Lutz Hühnken988 views
Building Applications with the Typesafe Reactive Platform at Skills Matter, L... by Lutz Hühnken
Building Applications with the Typesafe Reactive Platform at Skills Matter, L...Building Applications with the Typesafe Reactive Platform at Skills Matter, L...
Building Applications with the Typesafe Reactive Platform at Skills Matter, L...
Lutz Hühnken479 views
JVM Concurrency on Devoxx at Nov 12 2015 by Lutz Hühnken
JVM Concurrency on Devoxx at Nov 12 2015JVM Concurrency on Devoxx at Nov 12 2015
JVM Concurrency on Devoxx at Nov 12 2015
Lutz Hühnken1.4K views
Concurrency-Modelle auf der JVM auf der w-jax 3.11.2015 by Lutz Hühnken
Concurrency-Modelle auf der JVM auf der w-jax 3.11.2015Concurrency-Modelle auf der JVM auf der w-jax 3.11.2015
Concurrency-Modelle auf der JVM auf der w-jax 3.11.2015
Lutz Hühnken1.4K views
Scala in Practice at Jazoon Tech Day, Oct 23 2015, Zurich by Lutz Hühnken
Scala in Practice at Jazoon Tech Day, Oct 23 2015, ZurichScala in Practice at Jazoon Tech Day, Oct 23 2015, Zurich
Scala in Practice at Jazoon Tech Day, Oct 23 2015, Zurich
Lutz Hühnken530 views
JVM Concurreny Models at code.talks, Hamburg, 30.9.2015 by Lutz Hühnken
JVM Concurreny Models at code.talks, Hamburg, 30.9.2015JVM Concurreny Models at code.talks, Hamburg, 30.9.2015
JVM Concurreny Models at code.talks, Hamburg, 30.9.2015
Lutz Hühnken1.5K views
Scala.js at code.talks 2014, Hamburg by Lutz Hühnken
Scala.js at code.talks 2014, HamburgScala.js at code.talks 2014, Hamburg
Scala.js at code.talks 2014, Hamburg
Lutz Hühnken1K views
Reactive Slick at Scala User Group Vienna May 20 2015 by Lutz Hühnken
Reactive Slick at Scala User Group Vienna May 20 2015Reactive Slick at Scala User Group Vienna May 20 2015
Reactive Slick at Scala User Group Vienna May 20 2015
Lutz Hühnken1.1K views
Von "Enterprise" zu "Reactive" (JAX 2015) by Lutz Hühnken
Von "Enterprise" zu "Reactive" (JAX 2015)Von "Enterprise" zu "Reactive" (JAX 2015)
Von "Enterprise" zu "Reactive" (JAX 2015)
Lutz Hühnken1.6K views

Recently uploaded

DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...Deltares
5 views28 slides
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... by
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...Deltares
6 views22 slides
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionMárton Kodok
5 views55 slides
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema by
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDeltares
17 views13 slides
Headless JS UG Presentation.pptx by
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptxJack Spektor
7 views24 slides
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...sparkfabrik
5 views46 slides

Recently uploaded(20)

DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme... by Deltares
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
DSD-INT 2023 Salt intrusion Modelling of the Lauwersmeer, towards a measureme...
Deltares5 views
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the... by Deltares
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
DSD-INT 2023 Leveraging the results of a 3D hydrodynamic model to improve the...
Deltares6 views
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action by Márton Kodok
Gen Apps on Google Cloud PaLM2 and Codey APIs in ActionGen Apps on Google Cloud PaLM2 and Codey APIs in Action
Gen Apps on Google Cloud PaLM2 and Codey APIs in Action
Márton Kodok5 views
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema by Deltares
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - GeertsemaDSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
DSD-INT 2023 Delft3D FM Suite 2024.01 1D2D - Beta testing programme - Geertsema
Deltares17 views
Headless JS UG Presentation.pptx by Jack Spektor
Headless JS UG Presentation.pptxHeadless JS UG Presentation.pptx
Headless JS UG Presentation.pptx
Jack Spektor7 views
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with... by sparkfabrik
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
20231129 - Platform @ localhost 2023 - Application-driven infrastructure with...
sparkfabrik5 views
Software testing company in India.pptx by SakshiPatel82
Software testing company in India.pptxSoftware testing company in India.pptx
Software testing company in India.pptx
SakshiPatel827 views
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ... by Deltares
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
DSD-INT 2023 Wave-Current Interaction at Montrose Tidal Inlet System and Its ...
Deltares10 views
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t... by Deltares
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
DSD-INT 2023 Thermobaricity in 3D DCSM-FM - taking pressure into account in t...
Deltares9 views
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs by Deltares
DSD-INT 2023 The Danube Hazardous Substances Model - KovacsDSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
DSD-INT 2023 The Danube Hazardous Substances Model - Kovacs
Deltares8 views
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -... by Deltares
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
DSD-INT 2023 Simulating a falling apron in Delft3D 4 - Engineering Practice -...
Deltares6 views
AI and Ml presentation .pptx by FayazAli87
AI and Ml presentation .pptxAI and Ml presentation .pptx
AI and Ml presentation .pptx
FayazAli8711 views
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ... by Donato Onofri
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Unmasking the Dark Art of Vectored Exception Handling: Bypassing XDR and EDR ...
Donato Onofri795 views
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated... by TomHalpin9
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
Dev-HRE-Ops - Addressing the _Last Mile DevOps Challenge_ in Highly Regulated...
TomHalpin95 views
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium... by Lisi Hocke
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Team Transformation Tactics for Holistic Testing and Quality (Japan Symposium...
Lisi Hocke28 views
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h... by Deltares
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
DSD-INT 2023 Exploring flash flood hazard reduction in arid regions using a h...
Deltares5 views
Advanced API Mocking Techniques by Dimpy Adhikary
Advanced API Mocking TechniquesAdvanced API Mocking Techniques
Advanced API Mocking Techniques
Dimpy Adhikary19 views

A Pragmatic View of Reactive

  • 1. So how do I do a 2PC in Akka then? or Lutz Hühnken (@lutzhuehnken) A Pragmatic View of Reactive
  • 2. So how do I do a 2PC in Akka then? Lutz Hühnken (@lutzhuehnken) A misleading title, really. Answer: You don’t want to (we’ll get back to that later)
  • 3. Valuable Experience vs. Bad Habit From Enterprise to Reactive Transitions … Lutz Hühnken (@lutzhuehnken) Other failed naming attempts..
  • 4. Lutz Hühnken (@lutzhuehnken) A Pragmatic View of Reactive
  • 6. Yes, of course. But who doesn’t claim that for their system?
  • 7. Come on. Now you’re just selling Akka to me..
  • 8. Real, Pragmatic Questions WAR? Servlet Container? Library X (which uses ThreadLocal) ? RDBMS/ JDBC? How to do 2PC?
  • 11. Threads vs. task level concurrency
  • 12. Pragmatic Reactive Threads … A supposedly great idea • Threads are • lightweight processes • easier programming model, no IPC 12
  • 13. Pragmatic Reactive Lightweight? 13 Slide from John Rose, Java VM Architect, JFokus, Stockholm, February 2015
  • 14. Pragmatic Reactive The problem with Threads 14 They discard the most essential and appealing properties of sequential computation: understandability, predictability, and determinism. Threads, as a model of computation, are wildly nondeterministic, and the job of the programmer becomes one of pruning that nondeterminism.
  • 16. Pragmatic Reactive Threads • not efficient • memory consumption • cost for context switch • bad match modern NUMA architectures • locks lead to contention
 • not a good programming model • shared mutual state is difficult to reason about 16
  • 17. Pragmatic Reactive What would be better? Goals • task level (sub-thread) concurrency • share nothing approach • # threads ~ # of cores 17
  • 18. Pragmatic Reactive Thread alternatives (successors?) • Green threads / coroutines / fibres • other granularity, but basically same programming model • Event-loop (e.g. vert.x, Reactor) • very loose coupling, slightly limited, 1 x n dispatch • Actors ! • truly share-nothing, flexible, resilience-proven, 
 m x n dispatch 18
  • 19. Pragmatic Reactive Example: Http Request handling Java EE: Threads. Servlet API: Thread per Request 19 Note: This is a snapshot at one point in time, not a sequence of events.
  • 20. Pragmatic Reactive Example: Http Request handling Reactive: Sub-Thread. Play: n threads per m requests 20 Note: This is a snapshot at one point in time, not a sequence of events.
  • 21. Pragmatic Reactive Consequences • We have effectively (even without explicitly using Actors) switched to a task level concurrency model • As a consequence, ThreadLocal becomes an anti-pattern. • Libraries that depend on them need extra work, might better be avoided • What does it mean for (blocking) I/O? 21
  • 22. Pragmatic Reactive Pragmatic reactive learnings cont’d • You’ll be using sub-thread level concurrency. Accept it, embrace it. 22
  • 24. Pragmatic Reactive High concurrency matters 24 But there’s one thing we can all agree on: At high levels of concurrency (thousands of connections) your server needs to go to asynchronous non-blocking. [..] any part of your server code blocks you’re going to need a thread. And at these levels of concurrency, you can’t go creating threads for every connection. From https://strongloop.com/strongblog/node-js-is-faster-than-java/
  • 25. Pragmatic Reactive Blocking I/O Reactive: Sub-Thread. Play: n threads per m requests 25 What does using blocking I/O mean for this?
  • 26. Pragmatic Reactive Non-blocking 26 For task level (sub-thread level) concurrency • each thread is responsible for n tasks • and that n might be pretty big You don’t want to block such a thread with blocking I/O
  • 27. Pragmatic Reactive But what if I need this..? 27 try { stmt = con.createStatement(); ResultSet rs = stmt.executeQuery(query); while (rs.next()) { String coffeeName = rs.getString("COF_NAME"); int supplierID = rs.getInt("SUP_ID"); float price = rs.getFloat("PRICE"); int sales = rs.getInt("SALES"); int total = rs.getInt("TOTAL"); System.out.println(coffeeName + "t" + supplierID + "t" + price + "t" + sales +
  • 28. Pragmatic Reactive Isolate! 28 vert.x has „worker verticles“ Play/Akka: Configure Dispatchers Slick 3 takes care of this for you!
  • 29. Pragmatic Reactive Pragmatic reactive learnings cont’d • You’ll be using sub-thread level concurrency. Accept it, embrace it. • Use asynchronous I/O. If you really can’t, isolate. 29
  • 31. Pragmatic Reactive But what if I need this..? 31 @Transactional public static class GreetingService { @Inject private JmsTemplate jmsTemplate; @PersistenceContext private EntityManager entityManager; public void createGreeting(String name) { Greeting greeting = new Greeting(name); this.entityManager.persist(greeting); this.jmsTemplate.convertAndSend("greetings", greeting); …
  • 33. Pragmatic Reactive Avoid… 33 @Transactional public static class GreetingService { @Inject private JmsTemplate jmsTemplate; @PersistenceContext private EntityManager entityManager; public void createGreeting(String name) { Greeting greeting = new Greeting(name); this.entityManager.persist(greeting); this.jmsTemplate.convertAndSend("greetings", greeting); … The example: In fact not really all-or-nothing, but reconciliation.
  • 34. Pragmatic Reactive Separate (the steps..) 34 Claim: Any 2PC can be expressed in terms of asynchronous messaging.
  • 35. Pragmatic Reactive Life beyond Distributed Transactions 35 In general, application developers simply do not implement large scalable applications assuming distributed transactions. When they attempt to use distributed transactions, the projects founder because the performance costs and fragility make them impractical. [..]
  • 36. 36 Want Almost-Infinite Scaling
 • More of everything… Year by year, bigger and bigger • If it fits on your machines, multiply by 10, if that fits, multiply by 1000… • Strive to scale almost linearly (N log N for some big log). Assumptions
 (Don’t Have to Prove These… Just Plain Believe Them) Grown-Ups Don’t Use Distributed Transactions •The apps using distributed transactions become too fragile… • Let’s just consider local transactions. ! Multiple disjoint scopes of serializability Want Scale-Agnostic Apps
 • Two layers to the application: 
 scale-agnostic and scale-aware • Consider scale-agnostic API Scale Agnostic Code Scale-Aware-Code Application Upper Layer Lower Layer Scale Agnostic API
  • 37. Pragmatic Reactive 2 PC => messaging 37 Item-BCancellation Tentative Op Item-A Restrictions / Requirements •at-least-once delivery •idempotent messages •tentative operations
  • 38. Pragmatic Reactive Pragmatic 38 Real world solution: Saga Pattern Source: http://kellabyte.com/2012/05/30/clarifying-the-saga-pattern/
  • 39. Pragmatic Reactive Pragmatic 39 Example (by Caitie McCaffrey) Source: https://speakerdeck.com/caitiem20/applying-the-saga-pattern
  • 40. Pragmatic Reactive Distributed Transactions 40 Distributed Transactions („2PC“) are a source of unnecessary failure and of contention. It can usually be avoided. Generally, local transactions and at-least-once delivery can be used instead. The Saga Pattern provides a pragmatic solution for „all-or- nothing“ in a distributed system.
  • 41. Pragmatic Reactive Food for thought 41 The data storage landscape is changing, moving towards event sourcing and immutability. This is a great match for reactive systems. The „all-or-nothing“ problems are closely related to wanting a global truth at a point in time. But what is now… the illusion of present… result of series of events..
  • 42. Pragmatic Reactive Pragmatic reactive learnings cont’d • You’ll be using sub-thread level concurrency. Accept it, embrace it. • Use asynchronous I/O. If you really can’t, isolate. • Do not use distributed transactions. If you really must, isolate. 42
  • 43. App Servers vs. Standalone
  • 46. Pragmatic Reactive Java EE Application Servers 46 Servlet API was developed for thread-per- request, synchronous I/O. Application servers are not of much use anyway, nobody uses them as containers for multiple applications. So effectively they’re just a library dependency. The ops convenience can be provided by other tools.
  • 47. Pragmatic Reactive Pragmatic reactive learnings cont’d • You’ll be using sub-thread level concurrency. Accept it, embrace it. • Use asynchronous I/O. If you really can’t, isolate. • Do not use distributed transactions. If you really must, isolate. • Don’t use an application server / servlet container. 47
  • 49. Pragmatic Reactive Conclusion 49 If • Threads are the smallest unit of concurrency in your code, or • You use blocking I/O (without clear separation), or • You use 2-phase-commit across systems, or • You use a Java EE Application Server / Servlet Container Then your application is not reactive.
  • 50. Pragmatic Reactive The Pragmatic Reactive Checklist 50 • Task-level (sub-thread level) concurrency • Non-blocking I/O • Distributed • Containerless
  • 52. We really only talked about the elastic part
  • 53. will lead to will lead to
  • 54. Thank you Lutz Hühnken (@lutzhuehnken)