SlideShare une entreprise Scribd logo
1  sur  58
Rossen Stoyanchev
Servlet vs Reactive
5 use cases
stacks
in
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
servlet-reactive-stack
Presented at QCon New York
www.qconnewyork.com
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Servlet Stack
● Servlet container
● Servlet API
● Spring MVC
Reactive Stack
● Netty, Servlet 3.1+, Undertow
● Reactive Streams
● Spring WebFlux
Reactive Spring
Reactive starters in Spring Boot 2.0
Spring Framework 5 WebFlux endpoints + reactive WebClient
Reactive Spring Data Kay repositories
Spring Security
and more…
Servlet Stack
FilterFilter Controller
Spring
MVC
Servlet API
container
thread
SERVLET STACK
Synchronous API
Filter, Servlet … void
SERVLET STACK
Blocking I/O
InputStream, OutputStream
SERVLET STACK
servletRequest.startAsync()
SERVLET STACK
Filter ControllerFilter Servlet
SERVLET STACKSERVLET STACK
Filter ControllerFilter Servlet
… do work or receive event + dispatch()…
container-
thread-1
container-
thread-2
Servlet API
Container
thread pool
Controller
SERVLET STACK
can use
reactive clients
Input & OutputStream
startAsync()
Concurrency
modelsConcurrencyConcurrencyConcurrency
“elastic”
thread pool
“parallel”
thread pool
100s, 1000s
waiting blocked threads
~ per CPU core
busy worker threads
Synchronous APIs Non-blocking code
What does it take to not block ?
event loop at the core
event driven architecture
message passing
means to compose async logic
bonus:
back pressure (a.k.a flow control)
Reactive Stack
Spring
WebFlux
Web
Filter
NO
BLOCKING
ANY
TIME
Controller
Reactive
Server
Adapter
Web
Filter
HTTP Server
Event Loop
REACTIVE
STACK
Asynchronous API
WebFilter, WebHandler…
Mono<Void>
REACTIVE
STACK
REACTIVE
STACK
Reactor Mono
Reactive Streams Publisher
0..1 elements
Non-blocking read:
Flux<DataBuffer> getBody()
REACTIVE
STACK
Non-blocking write:
writeWith(Flux<DataBuffer>)
REACTIVE
STACK
REACTIVE
STACK
Reactor Flux
Reactive Streams Publisher
0..N elements
request(1)
onNext(item)
Flux
Reactive Streams back pressure
request(1)
onNext(item)
request(n)
onNext(item)
FMonoEFluxDMonoCMonoB
Controller
Spring
WebFlux
WebFilter
Composition of async logic
MonoA
A B C
EF D
Actual processing
HTTP Server
Event Loop
REACTIVE
STACK
repository
Use Case #1
dataReactive
Demo
HTTP GET with reactive data repository
Designed to work on both Spring MVC and Spring WebFlux
Simply return reactive type (Flux, Observable) from @Controller
Flux<T>:
finite collection or infinite stream?
Use media type to decide
“application/json”
finite collection (JSON array)
No back pressure:
Flux#collectToList
(request all + buffer)
Use Case #2
back pressure
with
Response stream
“text/event-stream”,
“application/stream+json”
infinite stream
Back pressure:
request(n),
write, flush,
repeat
HTTP GET with streaming response
Simply return reactive type (Flux, Observable) from @Controller
Back pressure on Spring MVC and WebFlux
Servlet
Container
Servlet
API
Spring
MVC
Flux
Back pressure against blocking OutputStream
Controller Flux
Data
Repository
onNext(T)onNext(T)
Blocking write on
MvcAsync thread pool
request(n)request(1)
SERVLET STACK …
Servlet 3.1 non-blocking I/O ?
Unlike Servlet 3.0 async, Servlet 3.1 non-blocking is hard to retrofit
Requires deeper change
Mutually exclusive with rest of the Servlet API
HTTP
Server
Server
Adapter
Flux
Spring
WebFlux
Flux
Response streaming on reactive stack
Controller Flux
Data
Repo
onNext(T)onNext(T)onNext(T)
Non-blocking write
back pressure
to socket
request(n)request(n)request(n)
Demo
Use Case #3
remote service
orchestration
Reactive
Demo
Orchestrate non-blocking, nested remote service calls with ease
Similar to reactive data access
Spring MVC and Spring WebFlux
Reactive WebClient
Use Case #4
request inputReactive
Back pressure to socket
No reading until reactive demand signalled from upstream
Non-blocking
Reactive stack only territory !
HTTP POST with data
@RequestBody argument with reactive type (Mono, Single)
Reactive type is not required
Use Case #5
Data Ingestion
back pressure
with
Media type indicates infinite stream is expected
Non-blocking streaming + back pressure
HTTP POST with stream of data
HTTP
Server
Server
Adapter
Flux
Spring
WebFlux
Flux
Data ingestion on reactive stack
Controller
onNext(T)onNext(T)
Non-blocking read
back pressure
from socket
request(n)request(n)
Servlet stack summary
Reactive data repository
Streaming to the response with back pressure
Reactive orchestration of remote services
Reactive request input
Data ingestion with back pressure
Reactive stack summary
Reactive data repository
Streaming to the response with back pressure
Reactive orchestration of remote services
Reactive request input
Data ingestion with back pressure
Q & A
@rstoya05
Watch the video with slide synchronization on
InfoQ.com!
https://www.infoq.com/presentations/servlet-
reactive-stack

Contenu connexe

Plus de C4Media

Plus de C4Media (20)

Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 
Navigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery TeamsNavigating Complexity: High-performance Delivery and Discovery Teams
Navigating Complexity: High-performance Delivery and Discovery Teams
 
High Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in AdtechHigh Performance Cooperative Distributed Systems in Adtech
High Performance Cooperative Distributed Systems in Adtech
 
Rust's Journey to Async/await
Rust's Journey to Async/awaitRust's Journey to Async/await
Rust's Journey to Async/await
 
Opportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven UtopiaOpportunities and Pitfalls of Event-Driven Utopia
Opportunities and Pitfalls of Event-Driven Utopia
 
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/DayDatadog: a Real-Time Metrics Database for One Quadrillion Points/Day
Datadog: a Real-Time Metrics Database for One Quadrillion Points/Day
 
Are We Really Cloud-Native?
Are We Really Cloud-Native?Are We Really Cloud-Native?
Are We Really Cloud-Native?
 
CockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL DatabaseCockroachDB: Architecture of a Geo-Distributed SQL Database
CockroachDB: Architecture of a Geo-Distributed SQL Database
 
A Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with BrooklinA Dive into Streams @LinkedIn with Brooklin
A Dive into Streams @LinkedIn with Brooklin
 

Dernier

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Dernier (20)

Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
AI+A11Y 11MAY2024 HYDERBAD GAAD 2024 - HelloA11Y (11 May 2024)
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Servlet vs Reactive Stacks in Five Use Cases